puppet-lint 2.5.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +522 -0
  3. data/lib/puppet-lint/bin.rb +71 -6
  4. data/lib/puppet-lint/checkplugin.rb +43 -9
  5. data/lib/puppet-lint/checks.rb +16 -16
  6. data/lib/puppet-lint/configuration.rb +134 -134
  7. data/lib/puppet-lint/data.rb +28 -28
  8. data/lib/puppet-lint/lexer/string_slurper.rb +138 -140
  9. data/lib/puppet-lint/lexer/token.rb +188 -190
  10. data/lib/puppet-lint/lexer.rb +416 -417
  11. data/lib/puppet-lint/monkeypatches.rb +1 -1
  12. data/lib/puppet-lint/optparser.rb +5 -1
  13. data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +6 -4
  14. data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +5 -3
  15. data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +6 -4
  16. data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +5 -3
  17. data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +5 -3
  18. data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +5 -3
  19. data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +7 -5
  20. data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +5 -3
  21. data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +7 -4
  22. data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +5 -3
  23. data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +15 -13
  24. data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +9 -7
  25. data/lib/puppet-lint/plugins/check_comments/star_comments.rb +10 -8
  26. data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +6 -4
  27. data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +5 -3
  28. data/lib/puppet-lint/plugins/check_documentation/documentation.rb +7 -3
  29. data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +15 -11
  30. data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +5 -3
  31. data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +8 -5
  32. data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +11 -8
  33. data/lib/puppet-lint/plugins/check_resources/file_mode.rb +14 -9
  34. data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +11 -6
  35. data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +6 -4
  36. data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +12 -7
  37. data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +8 -6
  38. data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +14 -8
  39. data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +11 -7
  40. data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +11 -6
  41. data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +12 -8
  42. data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +11 -7
  43. data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +11 -7
  44. data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +3 -8
  45. data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +10 -8
  46. data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +3 -8
  47. data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +10 -8
  48. data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +11 -7
  49. data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +29 -0
  50. data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +13 -7
  51. data/lib/puppet-lint/plugins.rb +63 -61
  52. data/lib/puppet-lint/report/github.rb +17 -0
  53. data/lib/puppet-lint/report/sarif_template.json +63 -0
  54. data/lib/puppet-lint/tasks/puppet-lint.rb +84 -83
  55. data/lib/puppet-lint/tasks/release_test.rb +4 -1
  56. data/lib/puppet-lint/version.rb +1 -1
  57. data/lib/puppet-lint.rb +27 -12
  58. data/spec/acceptance/puppet_lint_spec.rb +46 -0
  59. data/spec/spec_helper.rb +92 -91
  60. data/spec/spec_helper_acceptance.rb +6 -0
  61. data/spec/spec_helper_acceptance_local.rb +38 -0
  62. data/spec/{puppet-lint → unit/puppet-lint}/bin_spec.rb +79 -35
  63. data/spec/{puppet-lint → unit/puppet-lint}/checks_spec.rb +36 -36
  64. data/spec/unit/puppet-lint/configuration_spec.rb +88 -0
  65. data/spec/{puppet-lint → unit/puppet-lint}/data_spec.rb +6 -3
  66. data/spec/{puppet-lint → unit/puppet-lint}/ignore_overrides_spec.rb +17 -17
  67. data/spec/{puppet-lint → unit/puppet-lint}/lexer/string_slurper_spec.rb +128 -128
  68. data/spec/{puppet-lint → unit/puppet-lint}/lexer/token_spec.rb +1 -1
  69. data/spec/{puppet-lint → unit/puppet-lint}/lexer_spec.rb +653 -671
  70. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/arrow_on_right_operand_line_spec.rb +16 -16
  71. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/autoloader_layout_spec.rb +13 -13
  72. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/class_inherits_from_params_class_spec.rb +3 -3
  73. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/code_on_top_scope_spec.rb +4 -4
  74. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/inherits_across_namespaces_spec.rb +4 -4
  75. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/name_contains_uppercase_spec.rb +10 -10
  76. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/names_containing_dash_spec.rb +7 -7
  77. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/nested_classes_or_defines_spec.rb +7 -7
  78. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/parameter_order_spec.rb +9 -9
  79. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/right_to_left_relationship_spec.rb +3 -3
  80. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/variable_scope_spec.rb +25 -25
  81. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/slash_comments_spec.rb +7 -7
  82. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/star_comments_spec.rb +13 -13
  83. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/case_without_default_spec.rb +10 -10
  84. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/selector_inside_resource_spec.rb +3 -3
  85. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_documentation/documentation_spec.rb +8 -8
  86. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_nodes/unquoted_node_name_spec.rb +24 -24
  87. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/duplicate_params_spec.rb +9 -9
  88. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_first_param_spec.rb +19 -19
  89. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_not_symlink_target_spec.rb +10 -10
  90. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/file_mode_spec.rb +40 -40
  91. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_file_mode_spec.rb +20 -20
  92. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_resource_title_spec.rb +24 -24
  93. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/double_quoted_strings_spec.rb +28 -27
  94. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/only_variable_string_spec.rb +18 -18
  95. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/puppet_url_without_modules_spec.rb +9 -9
  96. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/quoted_booleans_spec.rb +22 -22
  97. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/single_quote_string_with_variables_spec.rb +2 -2
  98. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/variables_not_enclosed_spec.rb +21 -21
  99. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_contains_dash_spec.rb +6 -6
  100. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_is_lowercase_spec.rb +7 -7
  101. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/140chars_spec.rb +5 -5
  102. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/2sp_soft_tabs_spec.rb +2 -2
  103. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/80chars_spec.rb +6 -6
  104. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/arrow_alignment_spec.rb +127 -127
  105. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/hard_tabs_spec.rb +7 -7
  106. data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/trailing_whitespace_spec.rb +15 -15
  107. data/spec/unit/puppet-lint/puppet-lint_spec.rb +18 -0
  108. metadata +69 -120
  109. data/CHANGELOG.md +0 -1130
  110. data/spec/puppet-lint/configuration_spec.rb +0 -66
  111. data/spec/puppet-lint_spec.rb +0 -16
@@ -1,173 +1,171 @@
1
1
  require 'strscan'
2
2
 
3
- class PuppetLint
4
- class Lexer
5
- # Document this
6
- # TODO
7
- class StringSlurper
8
- class UnterminatedStringError < StandardError; end
9
-
10
- attr_accessor :scanner
11
- attr_accessor :results
12
- attr_accessor :interp_stack
13
-
14
- START_INTERP_PATTERN = %r{\$\{}
15
- END_INTERP_PATTERN = %r{\}}
16
- END_STRING_PATTERN = %r{(\A|[^\\])(\\\\)*"}
17
- UNENC_VAR_PATTERN = %r{(\A|[^\\])\$(::)?(\w+(-\w+)*::)*\w+(-\w+)*}
18
- ESC_DQUOTE_PATTERN = %r{\\+"}
19
- LBRACE_PATTERN = %r{\{}
20
-
21
- def initialize(string)
22
- @scanner = StringScanner.new(string)
23
- @results = []
24
- @interp_stack = []
25
- @segment = []
26
- end
27
-
28
- def parse
29
- @segment_type = :STRING
30
-
31
- until scanner.eos?
32
- if scanner.match?(START_INTERP_PATTERN)
33
- start_interp
34
- elsif !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
35
- read_char
36
- elsif scanner.match?(END_INTERP_PATTERN)
37
- end_interp
38
- elsif unenclosed_variable?
39
- unenclosed_variable
40
- elsif scanner.match?(END_STRING_PATTERN)
41
- end_string
42
- break if interp_stack.empty?
43
- elsif scanner.match?(ESC_DQUOTE_PATTERN)
44
- @segment << scanner.scan(ESC_DQUOTE_PATTERN)
45
- else
46
- read_char
47
- end
48
- end
3
+ class PuppetLint::Lexer
4
+ # Internal: A class for slurping strings from a Puppet manifest.
5
+ class StringSlurper
6
+ attr_accessor :scanner
7
+ attr_accessor :results
8
+ attr_accessor :interp_stack
9
+
10
+ START_INTERP_PATTERN = %r{\$\{}.freeze
11
+ END_INTERP_PATTERN = %r{\}}.freeze
12
+ END_STRING_PATTERN = %r{(\A|[^\\])(\\\\)*"}.freeze
13
+ UNENC_VAR_PATTERN = %r{(\A|[^\\])\$(::)?(\w+(-\w+)*::)*\w+(-\w+)*}.freeze
14
+ ESC_DQUOTE_PATTERN = %r{\\+"}.freeze
15
+ LBRACE_PATTERN = %r{\{}.freeze
16
+
17
+ def initialize(string)
18
+ @scanner = StringScanner.new(string)
19
+ @results = []
20
+ @interp_stack = []
21
+ @segment = []
22
+ end
49
23
 
50
- raise UnterminatedStringError if results.empty? && scanner.matched?
24
+ def parse
25
+ @segment_type = :STRING
51
26
 
52
- results
27
+ until scanner.eos?
28
+ if scanner.match?(START_INTERP_PATTERN)
29
+ start_interp
30
+ elsif !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
31
+ read_char
32
+ elsif scanner.match?(END_INTERP_PATTERN)
33
+ end_interp
34
+ elsif unenclosed_variable?
35
+ unenclosed_variable
36
+ elsif scanner.match?(END_STRING_PATTERN)
37
+ end_string
38
+ break if interp_stack.empty?
39
+ elsif scanner.match?(ESC_DQUOTE_PATTERN)
40
+ @segment << scanner.scan(ESC_DQUOTE_PATTERN)
41
+ else
42
+ read_char
43
+ end
53
44
  end
54
45
 
55
- def unenclosed_variable?
56
- interp_stack.empty? &&
57
- scanner.match?(UNENC_VAR_PATTERN) &&
58
- (@segment.last.nil? ? true : !@segment.last.end_with?('\\'))
59
- end
46
+ raise UnterminatedStringError if results.empty? && scanner.matched?
60
47
 
61
- def parse_heredoc(heredoc_tag)
62
- heredoc_name = heredoc_tag[%r{\A"?(.+?)"?(:.+?)?#{PuppetLint::Lexer::WHITESPACE_RE}*(/.*)?\Z}, 1]
63
- end_heredoc_pattern = %r{^\|?\s*-?\s*#{Regexp.escape(heredoc_name)}$}
64
- interpolation = heredoc_tag.start_with?('"')
65
-
66
- @segment_type = :HEREDOC
67
-
68
- until scanner.eos?
69
- if scanner.match?(end_heredoc_pattern)
70
- end_heredoc(end_heredoc_pattern)
71
- break if interp_stack.empty?
72
- elsif interpolation && scanner.match?(START_INTERP_PATTERN)
73
- start_interp
74
- elsif interpolation && !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
75
- read_char
76
- elsif interpolation && unenclosed_variable?
77
- unenclosed_variable
78
- elsif interpolation && scanner.match?(END_INTERP_PATTERN)
79
- end_interp
80
- else
81
- read_char
82
- end
83
- end
48
+ results
49
+ end
84
50
 
85
- results
86
- end
51
+ def unenclosed_variable?
52
+ interp_stack.empty? &&
53
+ scanner.match?(UNENC_VAR_PATTERN) &&
54
+ (@segment.last.nil? ? true : !@segment.last.end_with?('\\'))
55
+ end
87
56
 
88
- def read_char
89
- @segment << scanner.getch
57
+ def parse_heredoc(heredoc_tag)
58
+ heredoc_name = heredoc_tag[%r{\A"?(.+?)"?(:.+?)?#{PuppetLint::Lexer::WHITESPACE_RE}*(/.*)?\Z}o, 1]
59
+ end_heredoc_pattern = %r{^\|?\s*-?\s*#{Regexp.escape(heredoc_name)}$}
60
+ interpolation = heredoc_tag.start_with?('"')
90
61
 
91
- return if interp_stack.empty?
62
+ @segment_type = :HEREDOC
92
63
 
93
- case @segment.last
94
- when '{'
95
- interp_stack.push(true)
96
- when '}'
97
- interp_stack.pop
64
+ until scanner.eos?
65
+ if scanner.match?(end_heredoc_pattern)
66
+ end_heredoc(end_heredoc_pattern)
67
+ break if interp_stack.empty?
68
+ elsif interpolation && scanner.match?(START_INTERP_PATTERN)
69
+ start_interp
70
+ elsif interpolation && !interp_stack.empty? && scanner.match?(LBRACE_PATTERN)
71
+ read_char
72
+ elsif interpolation && unenclosed_variable?
73
+ unenclosed_variable
74
+ elsif interpolation && scanner.match?(END_INTERP_PATTERN)
75
+ end_interp
76
+ else
77
+ read_char
98
78
  end
99
79
  end
100
80
 
101
- # Get the number of characters consumed by the StringSlurper.
102
- #
103
- # StringScanner from Ruby 2.0 onwards supports #charpos which returns
104
- # the number of characters and is multibyte character aware.
105
- #
106
- # Prior to this, Ruby's multibyte character support in Strings was a
107
- # bit unusual and neither String#length nor String#split behave as
108
- # expected, so we use String#scan to split all the consumed text using
109
- # a UTF-8 aware regex and use the length of the result
110
- def consumed_chars
111
- return scanner.charpos if scanner.respond_to?(:charpos)
112
-
113
- (scanner.pre_match + scanner.matched).scan(%r{.}mu).length
114
- end
81
+ results
82
+ end
115
83
 
116
- def start_interp
117
- if @segment.last && @segment.last == '\\'
118
- read_char
119
- return
120
- end
84
+ def read_char
85
+ @segment << scanner.getch
121
86
 
122
- if interp_stack.empty?
123
- scanner.skip(START_INTERP_PATTERN)
124
- results << [@segment_type, @segment.join]
125
- @segment = []
126
- else
127
- @segment << scanner.scan(START_INTERP_PATTERN)
128
- end
87
+ return if interp_stack.empty?
129
88
 
89
+ case @segment.last
90
+ when '{'
130
91
  interp_stack.push(true)
92
+ when '}'
93
+ interp_stack.pop
131
94
  end
95
+ end
132
96
 
133
- def end_interp
134
- if interp_stack.empty?
135
- @segment << scanner.scan(END_INTERP_PATTERN)
136
- return
137
- else
138
- interp_stack.pop
139
- end
97
+ # Get the number of characters consumed by the StringSlurper.
98
+ #
99
+ # StringScanner from Ruby 2.0 onwards supports #charpos which returns
100
+ # the number of characters and is multibyte character aware.
101
+ #
102
+ # Prior to this, Ruby's multibyte character support in Strings was a
103
+ # bit unusual and neither String#length nor String#split behave as
104
+ # expected, so we use String#scan to split all the consumed text using
105
+ # a UTF-8 aware regex and use the length of the result
106
+ def consumed_chars
107
+ return scanner.charpos if scanner.respond_to?(:charpos)
108
+
109
+ (scanner.pre_match + scanner.matched).scan(%r{.}mu).length
110
+ end
140
111
 
141
- if interp_stack.empty?
142
- results << [:INTERP, @segment.join]
143
- @segment = []
144
- scanner.skip(END_INTERP_PATTERN)
145
- else
146
- @segment << scanner.scan(END_INTERP_PATTERN)
147
- end
112
+ def start_interp
113
+ if @segment.last && @segment.last == '\\'
114
+ read_char
115
+ return
148
116
  end
149
117
 
150
- def unenclosed_variable
151
- read_char if scanner.match?(%r{.\$})
152
-
118
+ if interp_stack.empty?
119
+ scanner.skip(START_INTERP_PATTERN)
153
120
  results << [@segment_type, @segment.join]
154
- results << [:UNENC_VAR, scanner.scan(UNENC_VAR_PATTERN)]
155
121
  @segment = []
122
+ else
123
+ @segment << scanner.scan(START_INTERP_PATTERN)
156
124
  end
157
125
 
158
- def end_heredoc(pattern)
159
- results << [:HEREDOC, @segment.join]
160
- results << [:HEREDOC_TERM, scanner.scan(pattern)]
126
+ interp_stack.push(true)
127
+ end
128
+
129
+ def end_interp
130
+ if interp_stack.empty?
131
+ @segment << scanner.scan(END_INTERP_PATTERN)
132
+ return
133
+ else
134
+ interp_stack.pop
161
135
  end
162
136
 
163
- def end_string
164
- if interp_stack.empty?
165
- @segment << scanner.scan(END_STRING_PATTERN).gsub!(%r{"\Z}, '')
166
- results << [@segment_type, @segment.join]
167
- else
168
- @segment << scanner.scan(END_STRING_PATTERN)
169
- end
137
+ if interp_stack.empty?
138
+ results << [:INTERP, @segment.join]
139
+ @segment = []
140
+ scanner.skip(END_INTERP_PATTERN)
141
+ else
142
+ @segment << scanner.scan(END_INTERP_PATTERN)
143
+ end
144
+ end
145
+
146
+ def unenclosed_variable
147
+ read_char if scanner.match?(%r{.\$})
148
+
149
+ results << [@segment_type, @segment.join]
150
+ results << [:UNENC_VAR, scanner.scan(UNENC_VAR_PATTERN)]
151
+ @segment = []
152
+ end
153
+
154
+ def end_heredoc(pattern)
155
+ results << [:HEREDOC, @segment.join]
156
+ results << [:HEREDOC_TERM, scanner.scan(pattern)]
157
+ end
158
+
159
+ def end_string
160
+ if interp_stack.empty?
161
+ @segment << scanner.scan(END_STRING_PATTERN).gsub!(%r{"\Z}, '')
162
+ results << [@segment_type, @segment.join]
163
+ else
164
+ @segment << scanner.scan(END_STRING_PATTERN)
170
165
  end
171
166
  end
172
167
  end
173
168
  end
169
+
170
+ # Internal: An error thrown when an unterminated string is encountered.
171
+ class PuppetLint::Lexer::StringSlurper::UnterminatedStringError < StandardError; end