puppet-lint-unquoted_string-check 0.2.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d0da62169a6718196034aff4f7ab841c9220fb93
4
- data.tar.gz: 3c32f8a9a476915f75eba6df3b042d20cbc68891
2
+ SHA256:
3
+ metadata.gz: 5056a8e636e2dd9390aa92ac9c848135ad6a978032a18109eba4bf2719acafcb
4
+ data.tar.gz: f4ce77685a8b3d9048ad2fc40e9cf7e4fd3b6e6352dca6a72b1167592d361565
5
5
  SHA512:
6
- metadata.gz: 53561bea1d4e76646a010c4d2a1318f87b243658aa029b4bbd86e4dfca4477862560f3f6c6d980167516913d6c35d00c4b355332e2931380bec0dec49a8eb2f6
7
- data.tar.gz: ccd89bbf93c121df5ac76816a8f45192ac38c6bfaa5b0dd69840fcea34c4dc76353b344c43098acb518d9b1b3eb6db919d5fba100976424fa594675ca41fbc7d
6
+ metadata.gz: 3bf2d5f7e2ac07bba5af7e803d07b898a8447710e07b2d531e99601e9408c855aec59f71717642394f05010549149f9b3793823701236934fcbe351e1c279173
7
+ data.tar.gz: 72ac10a4a2b8af40eafe634b0fac963140e57558c4e2423b9855134da4a1298b53b007635178647c739672e17770b1fa123df926396d704db50ac1909d27d474
data/README.md CHANGED
@@ -1,4 +1,124 @@
1
1
  puppet-lint-unquoted_string-check
2
2
  =================================
3
3
 
4
+ [![License](https://img.shields.io/github/license/voxpupuli/puppet-lint-unquoted_string-check.svg)](https://github.com/voxpupuli/puppet-lint-unquoted_string-check/blob/master/LICENSE)
5
+ [![Test](https://github.com/voxpupuli/puppet-lint-param-docs/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-param-docs/actions/workflows/test.yml)
6
+ [![Gem Version](https://img.shields.io/gem/v/puppet-lint-unquoted_string-check.svg)](https://rubygems.org/gems/puppet-lint-unquoted_string-check)
7
+ [![RubyGem Downloads](https://img.shields.io/gem/dt/puppet-lint-unquoted_string-check.svg)](https://rubygems.org/gems/puppet-lint-unquoted_string-check)
8
+ [![Donated by Camptocamp](https://img.shields.io/badge/donated%20by-camptocamp-fb7047.svg)](#transfer-notice)
9
+
4
10
  A puppet-lint plugin to check that selectors and case statements cases are quoted.
11
+
12
+ ## Installing
13
+
14
+ ### From the command line
15
+
16
+ ```shell
17
+ $ gem install puppet-lint-unquoted_string-check
18
+ ```
19
+
20
+ ### In a Gemfile
21
+
22
+ ```ruby
23
+ gem 'puppet-lint-unquoted_string-check', :require => false
24
+ ```
25
+
26
+ ## Checks
27
+
28
+ ### Unquoted string in case
29
+
30
+ Unquoted strings in case statements are not valid with the future parser.
31
+
32
+ #### What you have done
33
+
34
+ ```puppet
35
+ case $::osfamily {
36
+ Debian: { }
37
+ RedHat: { }
38
+ default: { }
39
+ }
40
+ ```
41
+
42
+ #### What you should have done
43
+
44
+ ```puppet
45
+ case $::osfamily {
46
+ 'Debian': { }
47
+ 'RedHat': { }
48
+ default: { }
49
+ }
50
+ ```
51
+
52
+ #### Disabling the check
53
+
54
+ To disable this check, you can add `--no-unquoted_string_in_case-check` to your puppet-lint command line.
55
+
56
+ ```shell
57
+ $ puppet-lint --no-unquoted_string_in_case-check path/to/file.pp
58
+ ```
59
+
60
+ Alternatively, if you’re calling puppet-lint via the Rake task, you should insert the following line to your `Rakefile`.
61
+
62
+ ```ruby
63
+ PuppetLint.configuration.send('disable_unquoted_string_in_case')
64
+ ```
65
+
66
+
67
+ ### Unquoted string in selector
68
+
69
+ Unquoted strings in selector statements are not valid with the future parser.
70
+
71
+ #### What you have done
72
+
73
+ ```puppet
74
+ $foo = $::osfamily ? {
75
+ Debian => 'bar',
76
+ RedHat => 'baz',
77
+ default => 'qux',
78
+ }
79
+ ```
80
+
81
+ #### What you should have done
82
+
83
+ ```puppet
84
+ $foo = $::osfamily ? {
85
+ 'Debian' => 'bar',
86
+ 'RedHat' => 'baz',
87
+ default => 'qux',
88
+ }
89
+ ```
90
+
91
+ #### Disabling the check
92
+
93
+ To disable this check, you can add `--no-unquoted_string_in_selector-check` to your puppet-lint command line.
94
+
95
+ ```shell
96
+ $ puppet-lint --no-unquoted_string_in_selector-check path/to/file.pp
97
+ ```
98
+
99
+ Alternatively, if you’re calling puppet-lint via the Rake task, you should insert the following line to your `Rakefile`.
100
+
101
+ ```ruby
102
+ PuppetLint.configuration.send('disable_unquoted_string_in_selector')
103
+ ```
104
+
105
+ ## Transfer Notice
106
+
107
+ This plugin was originally authored by [Camptocamp](http://www.camptocamp.com).
108
+ The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance.
109
+ Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of Camptocamp.
110
+
111
+ Previously: https://github.com/camptocamp/puppet-lint-unquoted_string-check
112
+
113
+ ## License
114
+
115
+ This gem is licensed under the Apache-2 license.
116
+
117
+ ## Release information
118
+
119
+ To make a new release, please do:
120
+ * Update the version in the `puppet-lint-absolute_classname-check.gemspec` file
121
+ * Install gems with `bundle install --with release --path .vendor`
122
+ * generate the changelog with `bundle exec rake changelog`
123
+ * Create a PR with it
124
+ * After it got merged, push a tag. Travis will do the actual release
@@ -0,0 +1,4 @@
1
+ class PuppetLintUnquotedStringCheck
2
+ VERSION = '2.1.0'.freeze
3
+ end
4
+
@@ -5,14 +5,21 @@ def type_indexes(type)
5
5
  tokens.each_index do |token_idx|
6
6
  if tokens[token_idx].type == type
7
7
  depth = 0
8
+ start = token_idx
8
9
  tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
9
10
  idx = case_token_idx + token_idx + 1
10
11
  if tokens[idx].type == :LBRACE
11
12
  depth += 1
13
+ if depth == 2
14
+ type_indexes << {:start => start, :end => idx}
15
+ end
12
16
  elsif tokens[idx].type == :RBRACE
17
+ if depth == 2
18
+ start = idx
19
+ end
13
20
  depth -= 1
14
21
  if depth == 0
15
- type_indexes << {:start => token_idx, :end => idx}
22
+ type_indexes << {:start => start, :end => idx}
16
23
  break
17
24
  end
18
25
  end
@@ -28,8 +35,8 @@ def notify_tokens(type, sep_type, message)
28
35
  type_tokens.index do |r|
29
36
  if r.type == sep_type
30
37
  s = r.prev_token
31
- while s.type != :NEWLINE and s.type != :LBRACE
32
- if s.type == :NAME || s.type == :CLASSREF
38
+ while (s.type != :NEWLINE) && (s.type != :LBRACE)
39
+ if s.type == :NAME || (s.type == :CLASSREF && !s.value.include?('::'))
33
40
  notify :warning, {
34
41
  :message => message,
35
42
  :line => s.line,
@@ -47,7 +54,7 @@ end
47
54
  PuppetLint.new_check(:unquoted_string_in_case) do
48
55
  def check
49
56
  notify_tokens(:CASE, :COLON, 'unquoted string in case')
50
- end
57
+ end
51
58
 
52
59
  def fix(problem)
53
60
  problem[:token].type = :SSTRING
@@ -57,7 +64,7 @@ end
57
64
  PuppetLint.new_check(:unquoted_string_in_selector) do
58
65
  def check
59
66
  notify_tokens(:QMARK, :FARROW, 'unquoted string in selector')
60
- end
67
+ end
61
68
 
62
69
  def fix(problem)
63
70
  problem[:token].type = :SSTRING
@@ -141,6 +141,23 @@ describe 'unquoted_string_in_case' do
141
141
  expect(problems).to contain_warning(msg).on_line(2).in_column(11)
142
142
  end
143
143
  end
144
+
145
+ context 'Puppet Types in case' do
146
+ let(:code) do
147
+ <<-EOS
148
+ case $value {
149
+ Integer: { notice('yes int')}
150
+ Array: { notice('yes array')}
151
+ 'Debian': { notice('this is Sparta')}
152
+ default: { notice('something else')}
153
+ }
154
+ EOS
155
+ end
156
+
157
+ it 'should not detect any problems' do
158
+ expect(problems).to have(0).problems
159
+ end
160
+ end
144
161
  end
145
162
 
146
163
  context 'with fix enabled' do
@@ -353,5 +370,26 @@ describe 'unquoted_string_in_case' do
353
370
  )
354
371
  end
355
372
  end
373
+
374
+ context 'Puppet Types in case' do
375
+ let(:code) do
376
+ <<-EOS
377
+ case $value {
378
+ Integer: { notice('yes int')}
379
+ Array: { notice('yes array')}
380
+ 'Debian': { notice('this is Sparta')}
381
+ default: { notice('something else')}
382
+ }
383
+ EOS
384
+ end
385
+
386
+ it 'should not detect any problems' do
387
+ expect(problems).to have(0).problems
388
+ end
389
+
390
+ it 'should not modify the manifest' do
391
+ expect(manifest).to eq(code)
392
+ end
393
+ end
356
394
  end
357
395
  end
@@ -51,6 +51,22 @@ describe 'unquoted_string_in_selector' do
51
51
  expect(problems).to contain_warning(msg).on_line(2).in_column(11)
52
52
  end
53
53
  end
54
+
55
+ context ':TYPE in case' do
56
+ let(:code) do
57
+ <<-PUPPET
58
+ $listen_socket = $service_bind ? {
59
+ Undef => undef,
60
+ Stdlib::IP::Address::V6 => "[${service_bind}]:${service_port}",
61
+ default => "${service_bind}:${service_port}",
62
+ }
63
+ PUPPET
64
+ end
65
+
66
+ it 'should not detect any problems' do
67
+ expect(problems).to have(0).problems
68
+ end
69
+ end
54
70
  end
55
71
 
56
72
  context 'with fix enabled' do
@@ -145,5 +161,28 @@ describe 'unquoted_string_in_selector' do
145
161
  )
146
162
  end
147
163
  end
164
+
165
+ context 'hashes in case' do
166
+ let(:code) do
167
+ <<-EOS
168
+ $postfix_configuration = $configuration ? {
169
+ 'relay' => {
170
+ relayhost => '[example.com]:587',
171
+ satellite => true,
172
+ },
173
+ 'smarthost' => {
174
+ smtp_listen => 'all',
175
+ master_submission => 'submission inet n - - - - smtpd -o smtpd_tls_security_level=encrypt',
176
+ mta => true,
177
+ relayhost => 'direct',
178
+ },
179
+ }
180
+ EOS
181
+ end
182
+
183
+ it 'should not detect any problems' do
184
+ expect(problems).to have(0).problems
185
+ end
186
+ end
148
187
  end
149
188
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
1
4
  require 'puppet-lint'
2
5
 
3
6
  PuppetLint::Plugins.load_spec_helper
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-unquoted_string-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Camptocamp
7
+ - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '2.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: '1.0'
29
+ version: '2.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +72,34 @@ dependencies:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  version: '1.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: github_changelog_generator
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: coveralls
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.7'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.7'
69
103
  - !ruby/object:Gem::Dependency
70
104
  name: rake
71
105
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +114,21 @@ dependencies:
80
114
  - - ">="
81
115
  - !ruby/object:Gem::Version
82
116
  version: '0'
83
- description: |2
84
- A puppet-lint plugin to check that selectors and case statements cases are quoted.
85
- email: mickael.canevet@camptocamp.com
117
+ description: " A puppet-lint plugin to check that selectors and case statements
118
+ cases are quoted.\n"
119
+ email: voxpupuli@groups.io
86
120
  executables: []
87
121
  extensions: []
88
122
  extra_rdoc_files: []
89
123
  files:
90
124
  - LICENSE
91
125
  - README.md
126
+ - lib/puppet-lint-unquoted-string-check/version.rb
92
127
  - lib/puppet-lint/plugins/check_unquoted_string_in_case.rb
93
128
  - spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_case_spec.rb
94
129
  - spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_selector_spec.rb
95
130
  - spec/spec_helper.rb
96
- homepage: https://github.com/camptocamp/puppet-lint-unquoted_string-check
131
+ homepage: https://github.com/puppet-community/puppet-lint-unquoted_string-check
97
132
  licenses:
98
133
  - Apache-2.0
99
134
  metadata: {}
@@ -105,20 +140,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
140
  requirements:
106
141
  - - ">="
107
142
  - !ruby/object:Gem::Version
108
- version: '0'
143
+ version: '2.4'
109
144
  required_rubygems_version: !ruby/object:Gem::Requirement
110
145
  requirements:
111
146
  - - ">="
112
147
  - !ruby/object:Gem::Version
113
148
  version: '0'
114
149
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.2.2
150
+ rubygems_version: 3.1.6
117
151
  signing_key:
118
152
  specification_version: 4
119
153
  summary: A puppet-lint plugin to check that selectors and case statements cases are
120
154
  quoted.
121
155
  test_files:
122
156
  - spec/spec_helper.rb
123
- - spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_selector_spec.rb
124
157
  - spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_case_spec.rb
158
+ - spec/puppet-lint/plugins/check_unquoted_string_in_case/check_unquoted_string_in_selector_spec.rb