puppet-lint 2.0.2 → 2.1.0
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/.gitignore +2 -1
- data/.rspec +1 -0
- data/CHANGELOG.md +56 -0
- data/Gemfile +15 -4
- data/README.md +60 -5
- data/Rakefile +13 -0
- data/lib/puppet-lint.rb +21 -4
- data/lib/puppet-lint/configuration.rb +1 -0
- data/lib/puppet-lint/data.rb +12 -4
- data/lib/puppet-lint/lexer.rb +32 -7
- data/lib/puppet-lint/optparser.rb +4 -3
- data/lib/puppet-lint/plugins/check_classes.rb +73 -0
- data/lib/puppet-lint/plugins/check_comments.rb +4 -0
- data/lib/puppet-lint/plugins/check_conditionals.rb +4 -0
- data/lib/puppet-lint/plugins/check_documentation.rb +2 -0
- data/lib/puppet-lint/plugins/check_nodes.rb +2 -0
- data/lib/puppet-lint/plugins/check_resources.rb +80 -3
- data/lib/puppet-lint/plugins/check_strings.rb +13 -1
- data/lib/puppet-lint/plugins/check_variables.rb +6 -0
- data/lib/puppet-lint/plugins/check_whitespace.rb +12 -0
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +0 -2
- data/spec/fixtures/test/manifests/ignore_reason.pp +4 -1
- data/spec/fixtures/test/manifests/mismatched_control_comment.pp +1 -0
- data/spec/puppet-lint/bin_spec.rb +25 -12
- data/spec/puppet-lint/configuration_spec.rb +1 -0
- data/spec/puppet-lint/lexer_spec.rb +56 -2
- data/spec/puppet-lint/plugins/check_classes/code_on_top_scope_spec.rb +43 -0
- data/spec/puppet-lint/plugins/check_classes/name_contains_uppercase_spec.rb +66 -0
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +49 -0
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +140 -51
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +24 -0
- data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +17 -0
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +8 -0
- data/spec/spec_helper.rb +5 -0
- metadata +9 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe0f69ff9db46b574f04cdb2344e600ae0b1e10
|
4
|
+
data.tar.gz: 8c8344befd98f41083fc3e0408e5ae4ba1017245
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c27ca6ec8948d1c2e654c830cad26806243643f4e0e8c29f2aad9ba7f215a2be1196fb7bed16bec0b541955e9235a43f7ccdfddf519a81505779ef806bc3e1
|
7
|
+
data.tar.gz: 398daafadce6e29e4d97d116166658a76ad9d6fcd3fa2cbac12f7b4a204524eb1333d8b45bb96188129a0828ef8f6bb334cee77eddd9c103f2bc8198776e04b2
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,59 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [2.1.0](https://github.com/rodjek/puppet-lint/tree/2.1.0) (2016-12-30)
|
4
|
+
[Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.0.2...2.1.0)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- No documentation on how to use plugins [\#602](https://github.com/rodjek/puppet-lint/issues/602)
|
9
|
+
- Excessive number of warnings from code\_on\_top\_scope [\#579](https://github.com/rodjek/puppet-lint/issues/579)
|
10
|
+
- Syntax error for references starting with Regexp [\#566](https://github.com/rodjek/puppet-lint/issues/566)
|
11
|
+
- --fix flag discoverability is low [\#556](https://github.com/rodjek/puppet-lint/issues/556)
|
12
|
+
- Module names must only contain lowercase letters [\#554](https://github.com/rodjek/puppet-lint/issues/554)
|
13
|
+
- incorrect error on inline template [\#545](https://github.com/rodjek/puppet-lint/issues/545)
|
14
|
+
- parameter\_order check does not work default hash is added in parameter [\#544](https://github.com/rodjek/puppet-lint/issues/544)
|
15
|
+
- Remove formatting with `linenumber` [\#539](https://github.com/rodjek/puppet-lint/issues/539)
|
16
|
+
- Incorrect warning of required parameter when using array that includes variable. [\#537](https://github.com/rodjek/puppet-lint/issues/537)
|
17
|
+
- names\_containing\_dash is broken and unignorable [\#534](https://github.com/rodjek/puppet-lint/issues/534)
|
18
|
+
- Puppet-lint 2.0 fails on unquoted string starting with underscore. [\#531](https://github.com/rodjek/puppet-lint/issues/531)
|
19
|
+
- syntax error on valid file when: if /regex/ in array [\#517](https://github.com/rodjek/puppet-lint/issues/517)
|
20
|
+
- crashes if there is a \# line:endignore with no begining. [\#509](https://github.com/rodjek/puppet-lint/issues/509)
|
21
|
+
- Wrong behaviour of variable\_contains\_dash [\#504](https://github.com/rodjek/puppet-lint/issues/504)
|
22
|
+
- puppet-lint reports incorrect line numbers [\#403](https://github.com/rodjek/puppet-lint/issues/403)
|
23
|
+
- lint ignore comments feature not documented [\#369](https://github.com/rodjek/puppet-lint/issues/369)
|
24
|
+
|
25
|
+
**Merged pull requests:**
|
26
|
+
|
27
|
+
- Documentation on plugin usage. [\#611](https://github.com/rodjek/puppet-lint/pull/611) ([rnelson0](https://github.com/rnelson0))
|
28
|
+
- Puppet-lint version bump to 2.1.0.pre [\#608](https://github.com/rodjek/puppet-lint/pull/608) ([rnelson0](https://github.com/rnelson0))
|
29
|
+
- \(\#369\) Document existence of control comments [\#600](https://github.com/rodjek/puppet-lint/pull/600) ([rnelson0](https://github.com/rnelson0))
|
30
|
+
- Ignore \*.pp files at the top level [\#597](https://github.com/rodjek/puppet-lint/pull/597) ([rnelson0](https://github.com/rnelson0))
|
31
|
+
- Show logs in rspec tests [\#596](https://github.com/rodjek/puppet-lint/pull/596) ([ghoneycutt](https://github.com/ghoneycutt))
|
32
|
+
- \(\#517\) Update the allowed tokens prior to a regex [\#594](https://github.com/rodjek/puppet-lint/pull/594) ([rnelson0](https://github.com/rnelson0))
|
33
|
+
- \(\#531\) Treat barewords beginning with an underscore as :NAME tokens [\#593](https://github.com/rodjek/puppet-lint/pull/593) ([rnelson0](https://github.com/rnelson0))
|
34
|
+
- \(\#544, \#537\) Skip hash contents when checking optional parameters [\#592](https://github.com/rodjek/puppet-lint/pull/592) ([rnelson0](https://github.com/rnelson0))
|
35
|
+
- \(\#545\) Exempt inline\_epp and inline\_template from single quoted strin… [\#591](https://github.com/rodjek/puppet-lint/pull/591) ([rnelson0](https://github.com/rnelson0))
|
36
|
+
- Disable code\_on\_top\_scope by default until the noise can be reduced \(… [\#590](https://github.com/rodjek/puppet-lint/pull/590) ([rnelson0](https://github.com/rnelson0))
|
37
|
+
- Changelog generator task [\#589](https://github.com/rodjek/puppet-lint/pull/589) ([rnelson0](https://github.com/rnelson0))
|
38
|
+
- Count lines in comments and double quoted strings [\#577](https://github.com/rodjek/puppet-lint/pull/577) ([paran1](https://github.com/paran1))
|
39
|
+
- Handle mismatched control comments gracefully [\#573](https://github.com/rodjek/puppet-lint/pull/573) ([rodjek](https://github.com/rodjek))
|
40
|
+
- Reimplementation of --fix support for unenclosed variables delimited by dashes [\#572](https://github.com/rodjek/puppet-lint/pull/572) ([rodjek](https://github.com/rodjek))
|
41
|
+
- Anchor the end of the :TYPE token regexp [\#571](https://github.com/rodjek/puppet-lint/pull/571) ([rodjek](https://github.com/rodjek))
|
42
|
+
- Multi line strings [\#570](https://github.com/rodjek/puppet-lint/pull/570) ([jiuka](https://github.com/jiuka))
|
43
|
+
- @node\_indexes should be reset too. [\#569](https://github.com/rodjek/puppet-lint/pull/569) ([jiuka](https://github.com/jiuka))
|
44
|
+
- True up reserved keywords [\#564](https://github.com/rodjek/puppet-lint/pull/564) ([rnelson0](https://github.com/rnelson0))
|
45
|
+
- \[561\] Provide style guide references for each check [\#562](https://github.com/rodjek/puppet-lint/pull/562) ([rnelson0](https://github.com/rnelson0))
|
46
|
+
- Add names\_containing\_uppercase docs [\#559](https://github.com/rodjek/puppet-lint/pull/559) ([arrdem](https://github.com/arrdem))
|
47
|
+
- Implement a linter for uppercase class names [\#558](https://github.com/rodjek/puppet-lint/pull/558) ([arrdem](https://github.com/arrdem))
|
48
|
+
- Include --fix usage instructions [\#557](https://github.com/rodjek/puppet-lint/pull/557) ([QuinnyPig](https://github.com/QuinnyPig))
|
49
|
+
- Add puppet-lint plugins from deanwilson to plugins page [\#553](https://github.com/rodjek/puppet-lint/pull/553) ([deanwilson](https://github.com/deanwilson))
|
50
|
+
- Updates PR for \#223 [\#552](https://github.com/rodjek/puppet-lint/pull/552) ([binford2k](https://github.com/binford2k))
|
51
|
+
- add legacy\_facts [\#543](https://github.com/rodjek/puppet-lint/pull/543) ([mmckinst](https://github.com/mmckinst))
|
52
|
+
- Remove formatting with `linenumber` [\#540](https://github.com/rodjek/puppet-lint/pull/540) ([rski](https://github.com/rski))
|
53
|
+
- Adding support for logging to STDOUT as JSON [\#487](https://github.com/rodjek/puppet-lint/pull/487) ([binford2k](https://github.com/binford2k))
|
54
|
+
- Potential README changes [\#420](https://github.com/rodjek/puppet-lint/pull/420) ([rothsa](https://github.com/rothsa))
|
55
|
+
- Add fix to "ensure found on line but it's not the first attribute" [\#375](https://github.com/rodjek/puppet-lint/pull/375) ([sathieu](https://github.com/sathieu))
|
56
|
+
|
3
57
|
## [2.0.2](https://github.com/rodjek/puppet-lint/tree/2.0.2) (2016-08-19)
|
4
58
|
[Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.0.1...2.0.2)
|
5
59
|
|
@@ -12,6 +66,7 @@
|
|
12
66
|
|
13
67
|
**Merged pull requests:**
|
14
68
|
|
69
|
+
- Release 2.0.2 [\#536](https://github.com/rodjek/puppet-lint/pull/536) ([rnelson0](https://github.com/rnelson0))
|
15
70
|
- Revert "Bugfix: properly handling $gronk-$grouik with --fix \(fix \#442\)" [\#535](https://github.com/rodjek/puppet-lint/pull/535) ([rnelson0](https://github.com/rnelson0))
|
16
71
|
|
17
72
|
## [2.0.1](https://github.com/rodjek/puppet-lint/tree/2.0.1) (2016-08-18)
|
@@ -311,6 +366,7 @@ If the additional gems you use for checks are pinned to 1.x, you should pin pupp
|
|
311
366
|
|
312
367
|
**Merged pull requests:**
|
313
368
|
|
369
|
+
- Checks for code outside class/define block [\#223](https://github.com/rodjek/puppet-lint/pull/223) ([dLobatog](https://github.com/dLobatog))
|
314
370
|
- explains in README that puppet-lint is not for checking syntax [\#186](https://github.com/rodjek/puppet-lint/pull/186) ([ghoneycutt](https://github.com/ghoneycutt))
|
315
371
|
- Use the current workdir as reference to calculate the expanded\_path of a filename [\#175](https://github.com/rodjek/puppet-lint/pull/175) ([vStone](https://github.com/vStone))
|
316
372
|
- Update code documentation [\#298](https://github.com/rodjek/puppet-lint/pull/298) ([rodjek](https://github.com/rodjek))
|
data/Gemfile
CHANGED
@@ -7,16 +7,27 @@ group :test do
|
|
7
7
|
gem 'rspec', '~> 3.0'
|
8
8
|
gem 'rspec-its', '~> 1.0'
|
9
9
|
gem 'rspec-collection_matchers', '~> 1.0'
|
10
|
-
gem 'rack', '~> 1.0'
|
11
10
|
|
12
11
|
if RUBY_VERSION < '2.0'
|
13
12
|
# json 2.x requires ruby 2.0. Lock to 1.8
|
14
|
-
gem 'json', '
|
15
|
-
# json_pure 2.0.2 requires ruby 2.0. Lock to
|
16
|
-
gem 'json_pure', '=
|
13
|
+
gem 'json', '= 1.8'
|
14
|
+
# json_pure 2.0.2 requires ruby 2.0, and 2.0.1 requires ruby 1.9. Lock to 1.8.3.
|
15
|
+
gem 'json_pure', '= 1.8.3'
|
17
16
|
# addressable 2.4.0 requires ruby 1.9.0. Lock to 2.3.8.
|
18
17
|
gem 'addressable', '= 2.3.8'
|
19
18
|
else
|
20
19
|
gem 'json'
|
21
20
|
end
|
21
|
+
|
22
|
+
if RUBY_VERSION > '1.8'
|
23
|
+
# requires ruby 1.9+, on 1.8 we'll fall back to the old regex parsing
|
24
|
+
gem 'rspec-json_expectations', '~> 1.4'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
group :development do
|
29
|
+
# For Changelog generation
|
30
|
+
gem 'github_changelog_generator', :require => false if RUBY_VERSION >= '2.2.2'
|
31
|
+
gem 'github_changelog_generator', '~> 1.13.0', :require => false if RUBY_VERSION < '2.2.2'
|
32
|
+
gem 'rack', '~> 1.0', :require => false if RUBY_VERSION < '2.2.2'
|
22
33
|
end
|
data/README.md
CHANGED
@@ -4,15 +4,15 @@
|
|
4
4
|
Status](https://secure.travis-ci.org/rodjek/puppet-lint.png)](http://travis-ci.org/rodjek/puppet-lint)
|
5
5
|
[](http://inch-ci.org/github/rodjek/puppet-lint)
|
6
6
|
|
7
|
-
|
7
|
+
Puppet Lint will test modules and manifests against the recommended Puppet
|
8
8
|
style guidelines from the [Puppet Labs style
|
9
|
-
guide](http://docs.puppetlabs.com/guides/style_guide.html) as practical. It is not meant to validate syntax. Please use `puppet parser validate` for that.
|
9
|
+
guide](http://docs.puppetlabs.com/guides/style_guide.html) as closely as practical. It is not meant to validate syntax. Please use `puppet parser validate` for that.
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
13
13
|
gem install puppet-lint
|
14
14
|
|
15
|
-
##
|
15
|
+
## Usage
|
16
16
|
|
17
17
|
### By hand
|
18
18
|
|
@@ -20,7 +20,44 @@ You can test a single manifest file by running
|
|
20
20
|
|
21
21
|
puppet-lint <path to file>
|
22
22
|
|
23
|
-
|
23
|
+
Puppet Lint has a large number of options to modify which checks should be run.
|
24
|
+
|
25
|
+
You can disable any of the checks when running the `puppet-lint` command by
|
26
|
+
adding a `--no-<check name>-check` flag to the command. For example, if you
|
27
|
+
wanted to skip the 140 character check, you would run
|
28
|
+
```
|
29
|
+
puppet-lint --no-140chars-check <path to file>
|
30
|
+
```
|
31
|
+
|
32
|
+
You can also instruct puppet-lint to automatically fix issues it detects with the `--fix` flag.
|
33
|
+
```
|
34
|
+
puppet-lint --fix /modules
|
35
|
+
```
|
36
|
+
|
37
|
+
Note that this can be combined with the `--only-checks` option to help avoid enormous patch sets.
|
38
|
+
```
|
39
|
+
puppet-lint --only-checks trailing_whitespace --fix modules/
|
40
|
+
```
|
41
|
+
|
42
|
+
You can also use [control comments](http://puppet-lint.com/controlcomments/) to disable checks
|
43
|
+
within puppet code on a per line or per block basis using `#lint:ignore:<check_name>`:
|
44
|
+
```
|
45
|
+
class foo {
|
46
|
+
$bar = 'bar'
|
47
|
+
# This ignores the double_quoted_strings check over multiple lines
|
48
|
+
# lint:ignore:double_quoted_strings
|
49
|
+
$baz = "baz"
|
50
|
+
$gronk = "gronk"
|
51
|
+
# lint:endignore
|
52
|
+
|
53
|
+
# This ignores the 140chars check on a single line
|
54
|
+
$this_line_has_a_really_long_name_and_value_that_is_much_longer_than_the_style_guide_recommends = "I mean, a really, really long line like you can't believe" # lint:ignore:140chars
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
See puppet-lint --help for a full list of options.
|
59
|
+
|
60
|
+
### Rake
|
24
61
|
|
25
62
|
If you want to test your entire Puppet manifest directory, you can add
|
26
63
|
`require 'puppet-lint/tasks/puppet-lint'` to your Rakefile and then run
|
@@ -64,7 +101,22 @@ the PuppetLint configuration by defining the task yourself.
|
|
64
101
|
config.relative = true
|
65
102
|
end
|
66
103
|
|
67
|
-
|
104
|
+
### Settings
|
105
|
+
|
106
|
+
puppet-lint will also check for a `.puppet-lint.rc` file in the current
|
107
|
+
directory and your home directory and read in flags from there, so if you
|
108
|
+
wanted to always skip the hard tab character check, you could create
|
109
|
+
`~/.puppet-lint.rc` containing
|
110
|
+
|
111
|
+
```
|
112
|
+
--no-hard_tabs-check
|
113
|
+
```
|
114
|
+
|
115
|
+
## Compatibility Warning
|
116
|
+
|
117
|
+
Release 2.1.0 of puppet-lint is the last planned version with support for Puppet 3 and Ruby 1.8.7. Future versions will drop support for these versions.
|
118
|
+
|
119
|
+
## Implemented Tests
|
68
120
|
|
69
121
|
At the moment, the following tests have been implemented:
|
70
122
|
|
@@ -88,6 +140,9 @@ At the moment, the following tests have been implemented:
|
|
88
140
|
* All variables should be enclosed in braces when interpolated in a string.
|
89
141
|
* Variables standing by themselves should not be quoted.
|
90
142
|
|
143
|
+
### Capitalization
|
144
|
+
* All variables should be in lowercase
|
145
|
+
|
91
146
|
### Resources
|
92
147
|
|
93
148
|
* All resource titles should be quoted.
|
data/Rakefile
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'puppet-lint'
|
3
4
|
|
4
5
|
task :default => :test
|
5
6
|
|
6
7
|
RSpec::Core::RakeTask.new(:test)
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'github_changelog_generator/task'
|
11
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
12
|
+
version = PuppetLint::VERSION
|
13
|
+
config.future_release = "#{version}"
|
14
|
+
config.exclude_labels = %w{duplicate question invalid wontfix}
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim: syntax=ruby
|
data/lib/puppet-lint.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'set'
|
2
|
+
require 'json'
|
2
3
|
require 'puppet-lint/version'
|
3
4
|
require 'puppet-lint/lexer'
|
4
5
|
require 'puppet-lint/configuration'
|
@@ -105,6 +106,16 @@ class PuppetLint
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
109
|
+
# Internal: Get the line of the manifest on which the problem was found
|
110
|
+
#
|
111
|
+
# message - A Hash containing all the information about a problem.
|
112
|
+
#
|
113
|
+
# Returns the problematic line as a string.
|
114
|
+
def get_context(message)
|
115
|
+
line = PuppetLint::Data.manifest_lines[message[:line] - 1]
|
116
|
+
return line.strip
|
117
|
+
end
|
118
|
+
|
108
119
|
# Internal: Print out the line of the manifest on which the problem was found
|
109
120
|
# as well as a marker pointing to the location on the line.
|
110
121
|
#
|
@@ -114,7 +125,7 @@ class PuppetLint
|
|
114
125
|
def print_context(message)
|
115
126
|
return if message[:check] == 'documentation'
|
116
127
|
return if message[:kind] == :fixed
|
117
|
-
line =
|
128
|
+
line = get_context(message)
|
118
129
|
offset = line.index(/\S/) || 1
|
119
130
|
puts "\n #{line.strip}"
|
120
131
|
printf "%#{message[:column] + 2 - offset}s\n\n", '^'
|
@@ -127,17 +138,23 @@ class PuppetLint
|
|
127
138
|
#
|
128
139
|
# Returns nothing.
|
129
140
|
def report(problems)
|
141
|
+
json = []
|
130
142
|
problems.each do |message|
|
131
143
|
next if message[:kind] == :ignored && !PuppetLint.configuration.show_ignored
|
132
144
|
|
133
145
|
message[:KIND] = message[:kind].to_s.upcase
|
134
|
-
message[:linenumber] = message[:line]
|
135
146
|
|
136
147
|
if message[:kind] == :fixed || [message[:kind], :all].include?(configuration.error_level)
|
137
|
-
|
138
|
-
|
148
|
+
if configuration.json
|
149
|
+
message['context'] = get_context(message) if configuration.with_context
|
150
|
+
json << message
|
151
|
+
else
|
152
|
+
format_message message
|
153
|
+
print_context(message) if configuration.with_context
|
154
|
+
end
|
139
155
|
end
|
140
156
|
end
|
157
|
+
puts JSON.pretty_generate(json) if configuration.json
|
141
158
|
end
|
142
159
|
|
143
160
|
# Public: Determine if PuppetLint found any errors in the manifest.
|
data/lib/puppet-lint/data.rb
CHANGED
@@ -25,6 +25,7 @@ class PuppetLint::Data
|
|
25
25
|
@resource_indexes = nil
|
26
26
|
@class_indexes = nil
|
27
27
|
@defined_type_indexes = nil
|
28
|
+
@node_indexes = nil
|
28
29
|
@function_indexes = nil
|
29
30
|
@array_indexes = nil
|
30
31
|
@hash_indexes = nil
|
@@ -505,10 +506,17 @@ class PuppetLint::Data
|
|
505
506
|
stack_add << [token.line, reason, check]
|
506
507
|
end
|
507
508
|
else
|
508
|
-
stack.pop
|
509
|
-
|
510
|
-
|
511
|
-
|
509
|
+
top_override = stack.pop
|
510
|
+
if top_override.nil?
|
511
|
+
# TODO: refactor to provide a way to expose problems from
|
512
|
+
# PuppetLint::Data via the normal problem reporting mechanism.
|
513
|
+
puts "WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line #{token.line}"
|
514
|
+
else
|
515
|
+
top_override.each do |start|
|
516
|
+
unless start.nil?
|
517
|
+
(start[0]..token.line).each do |i|
|
518
|
+
(ignore_overrides[start[2]] ||= {})[i] = start[1]
|
519
|
+
end
|
512
520
|
end
|
513
521
|
end
|
514
522
|
end
|
data/lib/puppet-lint/lexer.rb
CHANGED
@@ -33,24 +33,42 @@ class PuppetLint
|
|
33
33
|
|
34
34
|
# Internal: A Hash whose keys are Strings representing reserved keywords in
|
35
35
|
# the Puppet DSL.
|
36
|
+
# From https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/parser/lexer2.rb#L116-L137
|
37
|
+
# or thereabouts
|
36
38
|
KEYWORDS = {
|
37
|
-
'class' => true,
|
38
39
|
'case' => true,
|
40
|
+
'class' => true,
|
39
41
|
'default' => true,
|
40
42
|
'define' => true,
|
41
43
|
'import' => true,
|
42
44
|
'if' => true,
|
43
|
-
'else' => true,
|
44
45
|
'elsif' => true,
|
46
|
+
'else' => true,
|
45
47
|
'inherits' => true,
|
46
48
|
'node' => true,
|
47
49
|
'and' => true,
|
48
50
|
'or' => true,
|
49
51
|
'undef' => true,
|
50
|
-
'true' => true,
|
51
52
|
'false' => true,
|
53
|
+
'true' => true,
|
52
54
|
'in' => true,
|
53
55
|
'unless' => true,
|
56
|
+
'function' => true,
|
57
|
+
'type' => true,
|
58
|
+
'attr' => true,
|
59
|
+
'private' => true,
|
60
|
+
}
|
61
|
+
|
62
|
+
# Internal: A Hash whose keys are Strings representing reserved keywords in
|
63
|
+
# the Puppet DSL when Application Management is enabled
|
64
|
+
# From https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/parser/lexer2.rb#L142-L159
|
65
|
+
# or therabouts
|
66
|
+
# Currently unused
|
67
|
+
APP_MANAGEMENT_TOKENS = {
|
68
|
+
'application' => true,
|
69
|
+
'consumes' => true,
|
70
|
+
'produces' => true,
|
71
|
+
'site' => true,
|
54
72
|
}
|
55
73
|
|
56
74
|
# Internal: A Hash whose keys are Symbols representing token types which
|
@@ -63,6 +81,8 @@ class PuppetLint
|
|
63
81
|
:NOMATCH => true,
|
64
82
|
:COMMA => true,
|
65
83
|
:LBRACK => true,
|
84
|
+
:IF => true,
|
85
|
+
:ELSIF => true,
|
66
86
|
}
|
67
87
|
|
68
88
|
# Internal: An Array of Arrays containing tokens that can be described by
|
@@ -70,10 +90,10 @@ class PuppetLint
|
|
70
90
|
# name of the token as a Symbol and a regular expression describing the
|
71
91
|
# value of the token.
|
72
92
|
KNOWN_TOKENS = [
|
73
|
-
[:TYPE, /\A(Integer|Float|Boolean|Regexp|String|Array|Hash|Resource|Class|Collection|Scalar|Numeric|CatalogEntry|Data|Tuple|Struct|Optional|NotUndef|Variant|Enum|Pattern|Any|Callable|Type|Runtime|Undef|Default)/],
|
93
|
+
[:TYPE, /\A(Integer|Float|Boolean|Regexp|String|Array|Hash|Resource|Class|Collection|Scalar|Numeric|CatalogEntry|Data|Tuple|Struct|Optional|NotUndef|Variant|Enum|Pattern|Any|Callable|Type|Runtime|Undef|Default)\b/],
|
74
94
|
[:CLASSREF, /\A(((::){0,1}[A-Z][-\w]*)+)/],
|
75
95
|
[:NUMBER, /\A\b((?:0[xX][0-9A-Fa-f]+|0?\d+(?:\.\d+)?(?:[eE]-?\d+)?))\b/],
|
76
|
-
[:NAME, /\A(((::)?[
|
96
|
+
[:NAME, /\A(((::)?[_a-z0-9][-\w]*)(::[a-z0-9][-\w]*)*)/],
|
77
97
|
[:LBRACK, /\A(\[)/],
|
78
98
|
[:RBRACK, /\A(\])/],
|
79
99
|
[:LBRACE, /\A(\{)/],
|
@@ -170,7 +190,7 @@ class PuppetLint
|
|
170
190
|
end
|
171
191
|
|
172
192
|
unless found
|
173
|
-
if var_name = chunk[/\A\$((::)?(
|
193
|
+
if var_name = chunk[/\A\$((::)?(\w+(-\w+)*::)*\w+(-\w+)*(\[.+?\])*)/, 1]
|
174
194
|
length = var_name.size + 1
|
175
195
|
tokens << new_token(:VARIABLE, var_name, length)
|
176
196
|
|
@@ -293,6 +313,11 @@ class PuppetLint
|
|
293
313
|
@line_no += 1
|
294
314
|
@column = 1
|
295
315
|
end
|
316
|
+
if [:MLCOMMENT, :SSTRING, :STRING].include? type and /(?:\r\n|\r|\n)/.match(value)
|
317
|
+
lines = value.split(/(?:\r\n|\r|\n)/, -1)
|
318
|
+
@line_no += lines.length-1
|
319
|
+
@column = lines.last.length
|
320
|
+
end
|
296
321
|
|
297
322
|
token
|
298
323
|
end
|
@@ -346,7 +371,7 @@ class PuppetLint
|
|
346
371
|
tokens << new_token(:DQMID, value, value.size, :line => line, :column => token_column)
|
347
372
|
end
|
348
373
|
if ss.scan(/\{/).nil?
|
349
|
-
var_name = ss.scan(/(::)?(
|
374
|
+
var_name = ss.scan(/(::)?(\w+(-\w+)*::)*\w+(-\w+)*/)
|
350
375
|
if var_name.nil?
|
351
376
|
token_column = column + ss.pos - 1
|
352
377
|
tokens << new_token(:DQMID, "$", 1, :line => line, :column => token_column)
|
@@ -83,12 +83,13 @@ class PuppetLint::OptParser
|
|
83
83
|
'%{check} - The name of the check.',
|
84
84
|
'%{message} - The message.'
|
85
85
|
) do |format|
|
86
|
-
if format.include?('%{linenumber}')
|
87
|
-
$stderr.puts "DEPRECATION: Please use %{line} instead of %{linenumber}"
|
88
|
-
end
|
89
86
|
PuppetLint.configuration.log_format = format
|
90
87
|
end
|
91
88
|
|
89
|
+
opts.on('--json', 'Log output as JSON') do
|
90
|
+
PuppetLint.configuration.json = true
|
91
|
+
end
|
92
|
+
|
92
93
|
opts.separator ''
|
93
94
|
opts.separator ' Checks:'
|
94
95
|
|