Class: PuppetLint::LineLengthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-lint/plugins/check_whitespace/line_length.rb

Overview

A utility class for checking the length of a given string.

Class Method Summary collapse

Class Method Details

.check(line_number, content, character_count) ⇒ Array

Check the current line to determine if it is more than character_count and record a warning if an instance is found. The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.

Can be passed directly to notify..

Parameters:

  • line_number (Integer)

    The line number of the current line.

  • content (String)

    The content of the current line.

  • character_count (Integer)

    The maximum number of characters allowed

Returns:

  • (Array)

    An array containing a description of the problem.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet-lint/plugins/check_whitespace/line_length.rb', line 14

def self.check(line_number, content, character_count)
  return if content.include? '://'
  return if content.include? 'template('
  return unless content.scan(%r{.}mu).size > character_count

  [
    :warning,
    { message: "line has more than #{character_count} characters",
      line: line_number,
      column: character_count,
      description: "Test the raw manifest string for lines containing more than #{character_count} characters and record a warning for each instance found. " \
                   'The only exceptions to this rule are lines containing URLs and template() calls which would hurt readability if split.',
      help_uri: 'https://puppet.com/docs/puppet/latest/style_guide.html#spacing-indentation-and-whitespace' },
  ]
end