puppet-lint 2.3.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +74 -0
- data/.rubocop_todo.yml +89 -0
- data/.travis.yml +11 -9
- data/CHANGELOG.md +54 -0
- data/Gemfile +3 -0
- data/Rakefile +14 -3
- data/appveyor.yml +1 -4
- data/bin/puppet-lint +1 -1
- data/lib/puppet-lint.rb +25 -21
- data/lib/puppet-lint/bin.rb +15 -19
- data/lib/puppet-lint/checkplugin.rb +24 -17
- data/lib/puppet-lint/checks.rb +42 -31
- data/lib/puppet-lint/configuration.rb +11 -8
- data/lib/puppet-lint/data.rb +236 -164
- data/lib/puppet-lint/lexer.rb +225 -203
- data/lib/puppet-lint/lexer/token.rb +34 -18
- data/lib/puppet-lint/optparser.rb +33 -30
- data/lib/puppet-lint/plugins.rb +42 -38
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +26 -28
- data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +21 -20
- data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +8 -9
- data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +9 -8
- data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +12 -11
- data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +13 -12
- data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +14 -13
- data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +9 -10
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +40 -31
- data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +3 -2
- data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +21 -24
- data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +3 -2
- data/lib/puppet-lint/plugins/check_comments/star_comments.rb +6 -5
- data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +21 -20
- data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +10 -13
- data/lib/puppet-lint/plugins/check_documentation/documentation.rb +26 -17
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +11 -11
- data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +4 -3
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +17 -18
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +17 -16
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +22 -23
- data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +14 -13
- data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +9 -8
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +8 -8
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +29 -42
- data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +5 -4
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +3 -2
- data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +4 -3
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +3 -2
- data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +9 -8
- data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +9 -8
- data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +9 -9
- data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +4 -3
- data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +10 -10
- data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +23 -22
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +3 -2
- data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +3 -2
- data/lib/puppet-lint/tasks/puppet-lint.rb +3 -3
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +4 -4
- data/spec/puppet-lint/bin_spec.rb +268 -140
- data/spec/puppet-lint/checks_spec.rb +229 -0
- data/spec/puppet-lint/configuration_spec.rb +10 -9
- data/spec/puppet-lint/data_spec.rb +84 -0
- data/spec/puppet-lint/ignore_overrides_spec.rb +71 -40
- data/spec/puppet-lint/lexer/token_spec.rb +1 -1
- data/spec/puppet-lint/lexer_spec.rb +306 -73
- data/spec/puppet-lint/plugins/check_classes/arrow_on_right_operand_line_spec.rb +12 -6
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +10 -10
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +15 -11
- data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +26 -21
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +3 -3
- data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +4 -5
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +13 -0
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +33 -25
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +80 -55
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +2 -2
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +165 -130
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +2 -2
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +53 -35
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +59 -49
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +14 -10
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +7 -7
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +54 -44
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +114 -89
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +41 -30
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +46 -40
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +46 -40
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +95 -71
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +28 -24
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +11 -9
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +1 -2
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +18 -14
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_variables/variable_is_lowercase_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_whitespace/140chars_spec.rb +22 -15
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +8 -6
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +23 -29
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +588 -494
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +1 -1
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +27 -19
- data/spec/puppet-lint_spec.rb +2 -12
- data/spec/spec_helper.rb +35 -30
- metadata +6 -5
- data/lib/puppet-lint/monkeypatches.rb +0 -2
- data/lib/puppet-lint/monkeypatches/string_percent.rb +0 -52
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +0 -13
@@ -73,17 +73,15 @@ class PuppetLint
|
|
73
73
|
when :SSTRING
|
74
74
|
"'#{@value}'"
|
75
75
|
when :DQPRE
|
76
|
-
"\"#{@value}"
|
76
|
+
"\"#{@value}#{string_suffix}"
|
77
77
|
when :DQPOST
|
78
|
-
"#{@value}\""
|
78
|
+
"#{string_prefix}#{@value}\""
|
79
|
+
when :DQMID
|
80
|
+
"#{string_prefix}#{@value}#{string_suffix}"
|
79
81
|
when :VARIABLE
|
80
82
|
enclose_token_types = Set[:DQPRE, :DQMID, :HEREDOC_PRE, :HEREDOC_MID].freeze
|
81
83
|
if !@prev_code_token.nil? && enclose_token_types.include?(@prev_code_token.type)
|
82
|
-
|
83
|
-
"${#{@value}}"
|
84
|
-
else
|
85
|
-
"${#{@raw}}"
|
86
|
-
end
|
84
|
+
@raw.nil? ? @value : @raw
|
87
85
|
else
|
88
86
|
"$#{@value}"
|
89
87
|
end
|
@@ -101,13 +99,35 @@ class PuppetLint
|
|
101
99
|
"@(#{@value})"
|
102
100
|
when :HEREDOC
|
103
101
|
@raw
|
102
|
+
when :HEREDOC_PRE
|
103
|
+
"#{@value}#{string_suffix}"
|
104
104
|
when :HEREDOC_POST
|
105
|
-
@raw
|
105
|
+
"#{string_prefix}#{@raw}"
|
106
|
+
when :HEREDOC_MID
|
107
|
+
"#{string_prefix}#{@value}#{string_suffix}"
|
106
108
|
else
|
107
109
|
@value
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
113
|
+
def string_suffix
|
114
|
+
no_enclose_tokens = Set.new([:UNENC_VARIABLE, :DQMID, :DQPOST, :HEREDOC_MID, :HEREDOC_POST])
|
115
|
+
if next_token && no_enclose_tokens.include?(next_token.type)
|
116
|
+
''
|
117
|
+
else
|
118
|
+
'${'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def string_prefix
|
123
|
+
no_enclose_tokens = Set.new([:UNENC_VARIABLE, :DQPRE, :DQMID, :HEREDOC_PRE, :HEREDOC_MID])
|
124
|
+
if prev_token && no_enclose_tokens.include?(prev_token.type)
|
125
|
+
''
|
126
|
+
else
|
127
|
+
'}'
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
111
131
|
# Public: Search from this token to find the next token of a given type.
|
112
132
|
#
|
113
133
|
# type - A Symbol type of the token to find, or an Array of Symbols.
|
@@ -154,18 +174,14 @@ class PuppetLint
|
|
154
174
|
opts[:skip_blocks] ||= true
|
155
175
|
to_find = Array[*type]
|
156
176
|
|
157
|
-
token_iter =
|
158
|
-
|
159
|
-
if to_find.include?
|
160
|
-
if opts[:value]
|
161
|
-
return token_iter if token_iter.value == opts[:value]
|
162
|
-
else
|
163
|
-
return token_iter
|
164
|
-
end
|
177
|
+
token_iter = send("#{direction}_token".to_sym)
|
178
|
+
until token_iter.nil?
|
179
|
+
if to_find.include?(token_iter.type)
|
180
|
+
return token_iter if opts[:value].nil? || token_iter.value == opts[:value]
|
165
181
|
end
|
166
182
|
|
167
|
-
opening_token = direction == :next ?
|
168
|
-
closing_token = direction == :next ?
|
183
|
+
opening_token = direction == :next ? 'L' : 'R'
|
184
|
+
closing_token = direction == :next ? 'R' : 'L'
|
169
185
|
|
170
186
|
if opts[:skip_blocks]
|
171
187
|
case token_iter.type
|
@@ -3,7 +3,7 @@ require 'optparse'
|
|
3
3
|
# Public: Contains the puppet-lint option parser so that it can be used easily
|
4
4
|
# in multiple places.
|
5
5
|
class PuppetLint::OptParser
|
6
|
-
HELP_TEXT = <<-EOF
|
6
|
+
HELP_TEXT = <<-EOF.freeze
|
7
7
|
puppet-lint
|
8
8
|
|
9
9
|
Basic Command Line Usage:
|
@@ -41,8 +41,11 @@ class PuppetLint::OptParser
|
|
41
41
|
PuppetLint.configuration.fail_on_warnings = true
|
42
42
|
end
|
43
43
|
|
44
|
-
opts.on(
|
45
|
-
|
44
|
+
opts.on(
|
45
|
+
'--error-level LEVEL',
|
46
|
+
[:all, :warning, :error],
|
47
|
+
'The level of error to return (warning, error or all).',
|
48
|
+
) do |el|
|
46
49
|
PuppetLint.configuration.error_level = el
|
47
50
|
end
|
48
51
|
|
@@ -55,13 +58,13 @@ class PuppetLint::OptParser
|
|
55
58
|
end
|
56
59
|
|
57
60
|
opts.on('-l', '--load FILE', 'Load a file containing custom puppet-lint checks.') do |f|
|
58
|
-
load
|
61
|
+
load(f)
|
59
62
|
end
|
60
63
|
|
61
64
|
opts.on('--load-from-puppet MODULEPATH', 'Load plugins from the given Puppet module path.') do |path|
|
62
65
|
path.split(':').each do |p|
|
63
66
|
Dir["#{p}/*/lib/puppet-lint/plugins/*.rb"].each do |file|
|
64
|
-
load
|
67
|
+
load(file)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
@@ -70,18 +73,19 @@ class PuppetLint::OptParser
|
|
70
73
|
PuppetLint.configuration.fix = true
|
71
74
|
end
|
72
75
|
|
73
|
-
opts.on(
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
76
|
+
opts.on(
|
77
|
+
'--log-format FORMAT',
|
78
|
+
'Change the log format.', 'Overrides --with-filename.',
|
79
|
+
'The following placeholders can be used:',
|
80
|
+
'%{filename} - Filename without path.',
|
81
|
+
'%{path} - Path as provided to puppet-lint.',
|
82
|
+
'%{fullpath} - Expanded path to the file.',
|
83
|
+
'%{line} - Line number.',
|
84
|
+
'%{column} - Column number.',
|
85
|
+
'%{kind} - The kind of message (warning, error).',
|
86
|
+
'%{KIND} - Uppercase version of %{kind}.',
|
87
|
+
'%{check} - The name of the check.',
|
88
|
+
'%{message} - The message.'
|
85
89
|
) do |format|
|
86
90
|
PuppetLint.configuration.log_format = format
|
87
91
|
end
|
@@ -90,13 +94,13 @@ class PuppetLint::OptParser
|
|
90
94
|
PuppetLint.configuration.json = true
|
91
95
|
end
|
92
96
|
|
93
|
-
opts.separator
|
94
|
-
opts.separator
|
97
|
+
opts.separator('')
|
98
|
+
opts.separator(' Checks:')
|
95
99
|
|
96
100
|
opts.on('--only-checks CHECKS', 'A comma separated list of checks that should be run') do |checks|
|
97
101
|
enable_checks = checks.split(',').map(&:to_sym)
|
98
|
-
|
99
|
-
if enable_checks.include?
|
102
|
+
PuppetLint.configuration.checks.each do |check|
|
103
|
+
if enable_checks.include?(check)
|
100
104
|
PuppetLint.configuration.send("enable_#{check}")
|
101
105
|
else
|
102
106
|
PuppetLint.configuration.send("disable_#{check}")
|
@@ -108,19 +112,18 @@ class PuppetLint::OptParser
|
|
108
112
|
opts.on("--no-#{check}-check", "Skip the #{check} check.") do
|
109
113
|
PuppetLint.configuration.send("disable_#{check}")
|
110
114
|
end
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
+
|
116
|
+
next if PuppetLint.configuration.send("#{check}_enabled?")
|
117
|
+
|
118
|
+
opts.on("--#{check}-check", "Enable the #{check} check.") do
|
119
|
+
PuppetLint.configuration.send("enable_#{check}")
|
115
120
|
end
|
116
121
|
end
|
117
122
|
|
118
123
|
opts.load('/etc/puppet-lint.rc')
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
# silently skip loading this file if HOME is set to a directory that
|
123
|
-
# the user doesn't have read access to.
|
124
|
+
if ENV.key?('HOME') && File.readable?(ENV['HOME'])
|
125
|
+
home_dotfile_path = File.expand_path('~/.puppet-lint.rc')
|
126
|
+
opts.load(home_dotfile_path) if File.readable?(home_dotfile_path)
|
124
127
|
end
|
125
128
|
opts.load('.puppet-lint.rc')
|
126
129
|
end
|
data/lib/puppet-lint/plugins.rb
CHANGED
@@ -14,8 +14,8 @@ class PuppetLint
|
|
14
14
|
gem_directories.select { |path|
|
15
15
|
(path + 'puppet-lint/plugins').directory?
|
16
16
|
}.each do |gem_path|
|
17
|
-
Dir["#{
|
18
|
-
load
|
17
|
+
Dir["#{gem_path + 'puppet-lint/plugins'}/*.rb"].each do |file|
|
18
|
+
load(file)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -25,49 +25,53 @@ class PuppetLint
|
|
25
25
|
# Returns nothings.
|
26
26
|
def self.load_spec_helper
|
27
27
|
gemspec = gemspecs.select { |spec| spec.name == 'puppet-lint' }.first
|
28
|
-
load
|
29
|
-
end
|
30
|
-
private
|
31
|
-
# Internal: Check if RubyGems is loaded and available.
|
32
|
-
#
|
33
|
-
# Returns true if RubyGems is available, false if not.
|
34
|
-
def self.has_rubygems?
|
35
|
-
defined? ::Gem
|
28
|
+
load(Pathname.new(gemspec.full_gem_path) + 'spec/spec_helper.rb')
|
36
29
|
end
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
Gem
|
31
|
+
class << self
|
32
|
+
private
|
33
|
+
|
34
|
+
# Internal: Check if RubyGems is loaded and available.
|
35
|
+
#
|
36
|
+
# Returns true if RubyGems is available, false if not.
|
37
|
+
def rubygems?
|
38
|
+
defined?(::Gem)
|
46
39
|
end
|
47
|
-
end
|
48
40
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
# Internal: Retrieve a list of avaliable gemspecs.
|
42
|
+
#
|
43
|
+
# Returns an Array of Gem::Specification objects.
|
44
|
+
def gemspecs
|
45
|
+
@gemspecs ||= if Gem::Specification.respond_to?(:latest_specs)
|
46
|
+
Gem::Specification.latest_specs(load_prerelease_plugins?)
|
47
|
+
else
|
48
|
+
Gem.searcher.init_gemspecs
|
49
|
+
end
|
57
50
|
end
|
58
|
-
false
|
59
|
-
end
|
60
51
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
# Internal: Determine whether to load plugins that contain a letter in their version number.
|
53
|
+
#
|
54
|
+
# Returns true if the configuration is set to load "prerelease" gems, false otherwise.
|
55
|
+
def load_prerelease_plugins?
|
56
|
+
# Load prerelease plugins (which ruby defines as any gem which has a letter in its version number).
|
57
|
+
# Can't use puppet-lint configuration object here because this code executes before the command line is parsed.
|
58
|
+
if ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS']
|
59
|
+
return %w[true yes].include?(ENV['PUPPET_LINT_LOAD_PRERELEASE_PLUGINS'].downcase)
|
60
|
+
end
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
# Internal: Retrieve a list of available gem paths from RubyGems.
|
65
|
+
#
|
66
|
+
# Returns an Array of Pathname objects.
|
67
|
+
def gem_directories
|
68
|
+
if rubygems?
|
69
|
+
gemspecs.reject { |spec| spec.name == 'puppet-lint' }.map do |spec|
|
70
|
+
Pathname.new(spec.full_gem_path) + 'lib'
|
71
|
+
end
|
72
|
+
else
|
73
|
+
[]
|
68
74
|
end
|
69
|
-
else
|
70
|
-
[]
|
71
75
|
end
|
72
76
|
end
|
73
77
|
end
|
@@ -5,42 +5,40 @@
|
|
5
5
|
PuppetLint.new_check(:arrow_on_right_operand_line) do
|
6
6
|
def check
|
7
7
|
tokens.select { |r| Set[:IN_EDGE, :IN_EDGE_SUB].include?(r.type) }.each do |token|
|
8
|
-
if token.next_code_token.line
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
next if token.next_code_token.line == token.line
|
9
|
+
|
10
|
+
notify(
|
11
|
+
:warning,
|
12
|
+
:message => 'arrow should be on the right operand\'s line',
|
13
|
+
:line => token.line,
|
14
|
+
:column => token.column,
|
15
|
+
:token => token,
|
16
|
+
)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
20
|
def fix(problem)
|
20
21
|
token = problem[:token]
|
21
|
-
tokens.delete(token)
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
tokens.delete(temp_token) if whitespace?(temp_token)
|
27
|
-
break if temp_token.type == :NEWLINE
|
28
|
-
end
|
23
|
+
prev_code_token = token.prev_code_token
|
24
|
+
next_code_token = token.next_code_token
|
25
|
+
indent_token = prev_code_token.prev_token_of(:INDENT)
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# Delete all tokens between the two code tokens the anchor is between
|
28
|
+
temp_token = prev_code_token
|
29
|
+
while (temp_token = temp_token.next_token) && (temp_token != next_code_token)
|
30
|
+
remove_token(temp_token) unless temp_token == token
|
31
|
+
end
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
token.
|
38
|
-
|
39
|
-
|
40
|
-
tokens.insert(index + 1, whitespace_token)
|
41
|
-
end
|
33
|
+
# Insert a newline and an indent before the arrow
|
34
|
+
index = tokens.index(token)
|
35
|
+
newline_token = PuppetLint::Lexer::Token.new(:NEWLINE, "\n", token.line, 0)
|
36
|
+
add_token(index, newline_token)
|
37
|
+
add_token(index + 1, indent_token) if indent_token
|
42
38
|
|
43
|
-
|
44
|
-
|
39
|
+
# Insert a space between the arrow and the following code token
|
40
|
+
index = tokens.index(token)
|
41
|
+
whitespace_token = PuppetLint::Lexer::Token.new(:WHITESPACE, ' ', token.line, 3)
|
42
|
+
add_token(index + 1, whitespace_token)
|
45
43
|
end
|
46
44
|
end
|
@@ -5,29 +5,30 @@
|
|
5
5
|
# https://docs.puppet.com/guides/style_guide.html#separate-files
|
6
6
|
PuppetLint.new_check(:autoloader_layout) do
|
7
7
|
def check
|
8
|
-
|
9
|
-
(class_indexes + defined_type_indexes).each do |class_idx|
|
10
|
-
title_token = class_idx[:name_token]
|
11
|
-
split_title = title_token.value.split('::')
|
12
|
-
mod = split_title.first
|
13
|
-
if split_title.length > 1
|
14
|
-
expected_path = "/#{mod}/manifests/#{split_title[1..-1].join('/')}.pp"
|
15
|
-
else
|
16
|
-
expected_path = "/#{title_token.value}/manifests/init.pp"
|
17
|
-
end
|
8
|
+
return if fullpath.nil? || fullpath == ''
|
18
9
|
|
19
|
-
|
20
|
-
|
21
|
-
|
10
|
+
(class_indexes + defined_type_indexes).each do |class_idx|
|
11
|
+
title_token = class_idx[:name_token]
|
12
|
+
split_title = title_token.value.split('::')
|
13
|
+
mod = split_title.first
|
14
|
+
expected_path = if split_title.length > 1
|
15
|
+
"/#{mod}/manifests/#{split_title[1..-1].join('/')}.pp"
|
16
|
+
else
|
17
|
+
"/#{title_token.value}/manifests/init.pp"
|
18
|
+
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
:message => "#{title_token.value} not in autoload module layout",
|
26
|
-
:line => title_token.line,
|
27
|
-
:column => title_token.column,
|
28
|
-
}
|
29
|
-
end
|
20
|
+
if PuppetLint.configuration.relative
|
21
|
+
expected_path = expected_path.gsub(%r{^/}, '').split('/')[1..-1].join('/')
|
30
22
|
end
|
23
|
+
|
24
|
+
next if fullpath.end_with?(expected_path)
|
25
|
+
|
26
|
+
notify(
|
27
|
+
:error,
|
28
|
+
:message => "#{title_token.value} not in autoload module layout",
|
29
|
+
:line => title_token.line,
|
30
|
+
:column => title_token.column,
|
31
|
+
)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -5,15 +5,14 @@
|
|
5
5
|
PuppetLint.new_check(:class_inherits_from_params_class) do
|
6
6
|
def check
|
7
7
|
class_indexes.each do |class_idx|
|
8
|
-
unless class_idx[:inherited_token].
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
8
|
+
next unless class_idx[:inherited_token] && class_idx[:inherited_token].value.end_with?('::params')
|
9
|
+
|
10
|
+
notify(
|
11
|
+
:warning,
|
12
|
+
:message => 'class inheriting from params class',
|
13
|
+
:line => class_idx[:inherited_token].line,
|
14
|
+
:column => class_idx[:inherited_token].column,
|
15
|
+
)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
end
|
@@ -7,14 +7,15 @@ PuppetLint.new_check(:code_on_top_scope) do
|
|
7
7
|
top_scope = tokens - class_scope
|
8
8
|
|
9
9
|
top_scope.each do |token|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
next if formatting_tokens.include?(token.type)
|
11
|
+
|
12
|
+
notify(
|
13
|
+
:warning,
|
14
|
+
:message => "code outside of class or define block - #{token.value}",
|
15
|
+
:line => token.line,
|
16
|
+
:column => token.column,
|
17
|
+
)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
20
|
-
PuppetLint.configuration.send(
|
21
|
+
PuppetLint.configuration.send('disable_code_on_top_scope')
|