cookstyle 5.1.19 → 5.2.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bebad52b67940ef2ea18a69715758710d78e83d08e6fd3629647c44df467d79
4
- data.tar.gz: 48af992c7bf5f18d5b3a948912ff57386439bbc57029ec3a6b962d5192b168f6
3
+ metadata.gz: 5b693c3f963fdd6689770744a4ba49fc1461c9312976cfcef2947ff938b04bc9
4
+ data.tar.gz: 629951dbaa3f1c0e3e116b42f0848415b524886351f67eda55c1f7208715de6f
5
5
  SHA512:
6
- metadata.gz: 31950bedb48fc769d8359183b7a7f8a95bb109cd446ed55748bcb90c97688735b4dc063d12660a3573e8a299eb145ca3f912100a2f0086038eaedf714194dce5
7
- data.tar.gz: 721544b1d118f01f29be8d025e927df03fd588e5379f58e7c4748cbc4b3325c225b90a32d44f15c914794bb2faf0fd93c8c214c721d3341e02689fa92b1a3187
6
+ metadata.gz: 92a8fca655802ef1627025fca46a23531290aba1bd7240805ba74d648b775d876bf72a5ae955b35c47852110ca05492882afb6334124b79eda310165e8930645
7
+ data.tar.gz: da43f5422b02cb8d57d15b13b2390f7d9064a80c4ec0b58fce0371b81eb1ab3a0ba68928475316466b52ae9f05eb7af74fa33a33be2fddd64a60da4134995ca8
data/bin/cookstyle CHANGED
@@ -12,7 +12,8 @@ unless ARGV.include?('--fail-level')
12
12
  ARGV << 'C'
13
13
  end
14
14
 
15
- if ARGV.size == 1 && %w(-v --version).include?(ARGV.first)
15
+ # if only -v is passed we'll get 3 args (-v, --fail-level, and C)
16
+ if ARGV.size == 3 && %w(-v --version).include?(ARGV.first)
16
17
  puts "Cookstyle #{Cookstyle::VERSION}"
17
18
  print ' * RuboCop '
18
19
  end
data/config/cookstyle.yml CHANGED
@@ -94,6 +94,20 @@ Chef/NamePropertyIsRequired:
94
94
  Enabled: true
95
95
  VersionAdded: '5.1.0'
96
96
 
97
+ Chef/InvalidLicenseString:
98
+ Description: Cookbook metadata.rb does not use a SPDX compliant license string or "all rights reserved"
99
+ Enabled: true
100
+ VersionAdded: '5.2.0'
101
+ Include:
102
+ - '**/metadata.rb'
103
+
104
+ Chef/InvalidPlatformMetadata:
105
+ Description: metadata.rb "supports" platform is invalid
106
+ Enabled: true
107
+ VersionAdded: '5.2.0'
108
+ Include:
109
+ - '**/metadata.rb'
110
+
97
111
  ###############################
98
112
  # Resolving Deprecations
99
113
  ###############################
@@ -155,6 +169,13 @@ Chef/AttributeMetadata:
155
169
  Include:
156
170
  - '**/metadata.rb'
157
171
 
172
+ Chef/LongDescriptionMetadata:
173
+ Description: The long_description metadata.rb method is not used and is unnecessary in cookbooks
174
+ Enabled: true
175
+ VersionAdded: '5.2.0'
176
+ Include:
177
+ - '**/metadata.rb'
178
+
158
179
  Chef/CookbookDependsOnCompatResource:
159
180
  Description: Don't depend on the deprecated compat_resource cookbook made obsolete by Chef 12.19+
160
181
  Enabled: true
@@ -179,6 +200,11 @@ Chef/ErlCallResource:
179
200
  Enabled: true
180
201
  VersionAdded: '5.1.0'
181
202
 
203
+ Chef/RequireRecipe:
204
+ Description: Use include_recipe instead of the require_recipe method
205
+ Enabled: true
206
+ VersionAdded: '5.2.0'
207
+
182
208
  ###############################
183
209
  # Cleaning up Legacy Code
184
210
  ###############################
@@ -195,25 +221,25 @@ Chef/WhyRunSupportedTrue:
195
221
  Enabled: true
196
222
  VersionAdded: '5.1.0'
197
223
  Include:
198
- - '**/resources/.*\.rb'
199
- - '**/providers/.*\.rb'
200
- - '**/libraries/.*\.rb'
224
+ - '**/resources/*.rb'
225
+ - '**/providers/*.rb'
226
+ - '**/libraries/*.rb'
201
227
 
202
- PropertyWithNameAttribute:
228
+ Chef/PropertyWithNameAttribute:
203
229
  Description: Resource property sets name_attribute not name_property
204
230
  Enabled: true
205
231
  VersionAdded: '5.1.0'
206
232
  Include:
207
- - '**/resources/.*\.rb'
208
- - '**/libraries/.*\.rb'
233
+ - '**/resources/*.rb'
234
+ - '**/libraries/*.rb'
209
235
 
210
- PropertyWithRequiredAndDefault:
236
+ Chef/PropertyWithRequiredAndDefault:
211
237
  Description: Resource property should not be both required and have a default value
212
238
  Enabled: true
213
239
  VersionAdded: '5.1.0'
214
240
  Include:
215
- - '**/resources/.*\.rb'
216
- - '**/libraries/.*\.rb'
241
+ - '**/resources/*.rb'
242
+ - '**/libraries/*.rb'
217
243
 
218
244
  Chef/UnnecessaryDependsChef14:
219
245
  Description: Don't depend on cookbooks made obsolete by Chef 14
@@ -222,13 +248,81 @@ Chef/UnnecessaryDependsChef14:
222
248
  Include:
223
249
  - '**/metadata.rb'
224
250
 
251
+ Chef/RespondToInMetadata:
252
+ Description: It is no longer necessary to use respond_to? in metadata.rb in Chef 12.15 and later
253
+ Enabled: true
254
+ VersionAdded: '5.2.0'
255
+ Include:
256
+ - '**/metadata.rb'
257
+
258
+ Chef/RespondToResourceName:
259
+ Description: respond_to?(:resource_name) in resources is no longer necessary in Chef Infra Client 12.5+
260
+ Enabled: true
261
+ VersionAdded: '5.2.0'
262
+ Include:
263
+ - '**/resources/*.rb'
264
+ - '**/libraries/*.rb'
265
+
266
+ Chef/RespondToProvides:
267
+ Description: respond_to?(:provides) in resources is no longer necessary in Chef Infra Client 12+
268
+ Enabled: true
269
+ VersionAdded: '5.2.0'
270
+ Include:
271
+ - '**/providers/*.rb'
272
+ - '**/libraries/*.rb'
273
+
274
+ Chef/SetOrReturnInResources:
275
+ Description: Do not use set_or_return within a method to define a property for a resource. Use the property method instead, which supports validation, reporting, and documentation functionality.
276
+ Enabled: true
277
+ VersionAdded: '5.2.0'
278
+ Include:
279
+ - '**/resources/*.rb'
280
+ - '**/libraries/*.rb'
281
+
282
+ Chef/CustomResourceWithAttributes:
283
+ Description: Custom Resources should contain properties not attributes.
284
+ Enabled: true
285
+ VersionAdded: '5.2.0'
286
+ Include:
287
+ - '**/resources/*.rb'
288
+
289
+ Chef/CustomResourceWithAllowedActions:
290
+ Description: Custom Resources don't need to define the allowed actions with allowed_actions or actions methods
291
+ Enabled: true
292
+ VersionAdded: '5.2.0'
293
+ Include:
294
+ - '**/resources/*.rb'
295
+
296
+ ###############################
297
+ # Detecting code that breaks Chef
298
+ ###############################
299
+
300
+ Chef/CookbooksDependsOnSelf:
301
+ Description: A cookbook cannot depend on itself
302
+ Enabled: true
303
+ VersionAdded: '5.2.0'
304
+ Include:
305
+ - '**/metadata.rb'
306
+
307
+ Chef/MetadataMissingName:
308
+ Description: MetadataMissingName
309
+ Enabled: true
310
+ VersionAdded: '5.2.0'
311
+ Include:
312
+ - '**/metadata.rb'
313
+
314
+ Chef/BlockGuardWithOnlyString:
315
+ Description: A resource guard (not_if/only_if) that is a string should not be wrapped in {}. Wrapping a guard string in {} causes it be executed as Ruby code which will always returns true instead of a shell command that will actually run.
316
+ Enabled: true
317
+ VersionAdded: '5.2.0'
318
+
225
319
  ###############################
226
320
  # Utilize new built-in resources
227
321
  ###############################
228
322
 
229
323
  Chef/UseBuildEssentialResource:
230
- Description: Use the build_essential resource instead of the legacy build-essential recipe
231
- Enabled: false
324
+ Description: Use the build_essential resource instead of the legacy build-essential recipe. This resource ships in the build-essential cookbook v5.0+ and is built into Chef Infra Client 14+
325
+ Enabled: true
232
326
  VersionAdded: '5.1.0'
233
327
 
234
328
  ###############################
@@ -1,4 +1,4 @@
1
1
  module Cookstyle
2
- VERSION = "5.1.19".freeze # rubocop: disable Style/StringLiterals
2
+ VERSION = "5.2.17".freeze # rubocop: disable Style/StringLiterals
3
3
  RUBOCOP_VERSION = '0.72.0'.freeze
4
4
  end
@@ -0,0 +1,60 @@
1
+ #
2
+ # Copyright:: Copyright 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Use secure Github and Gitlab URLs for source_url and issues_url
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # template '/etc/foo' do
26
+ # mode '0644'
27
+ # source 'foo.erb'
28
+ # only_if { 'test -f /etc/foo' }
29
+ # end
30
+ #
31
+ # # good
32
+ # template '/etc/foo' do
33
+ # mode '0644'
34
+ # source 'foo.erb'
35
+ # only_if 'test -f /etc/foo'
36
+ # end
37
+ #
38
+ class BlockGuardWithOnlyString < Cop
39
+ MSG = 'A resource guard (not_if/only_if) that is a string should not be wrapped in {}. Wrapping a guard string in {} causes it be executed as Ruby code which will always returns true instead of a shell command that will actually run.'.freeze
40
+
41
+ def_node_matcher :block_guard_with_only_string?, <<-PATTERN
42
+ (block (send nil? ${:not_if :only_if}) (args) (str $_) )
43
+ PATTERN
44
+
45
+ def on_block(node)
46
+ block_guard_with_only_string?(node) do
47
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
48
+ end
49
+ end
50
+
51
+ def autocorrect(node)
52
+ lambda do |corrector|
53
+ new_val = "#{node.method_name} #{node.body.source}"
54
+ corrector.replace(node.loc.expression, new_val)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ # Make sure a cookbook doesn't depend on itself
22
+ #
23
+ # @example
24
+ #
25
+ # # bad
26
+ # name 'foo'
27
+ # depends 'foo'
28
+ #
29
+ # # good
30
+ # name 'foo'
31
+ #
32
+ class CookbooksDependsOnSelf < Cop
33
+ MSG = 'A cookbook cannot depend on itself'.freeze
34
+
35
+ def_node_search :dependencies, '(send nil? :depends str ...)'
36
+ def_node_matcher :cb_name?, '(send nil? :name str ...)'
37
+
38
+ def on_send(node)
39
+ cb_name?(node) do
40
+ dependencies(processed_source.ast).each do |dep|
41
+ if dep.arguments == node.arguments
42
+ node = dep # set our dependency node as the node for autocorrecting later
43
+ add_offense(node, location: dep.source_range, message: MSG, severity: :refactor)
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def autocorrect(node)
50
+ lambda do |corrector|
51
+ corrector.remove(node.source_range)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,489 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ # metadata.rb license field should include a SPDX compliant string
22
+ # or "all right reserved" (not case sensitive)
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # license 'Apache 2.0'
28
+ #
29
+ # # good
30
+ # license 'Apache-2.0'
31
+ # license 'all rights reserved'
32
+ #
33
+ # list of valid SPDX.org license strings. To build an array run this:
34
+ # require 'json'
35
+ # require 'net/http'
36
+ # json_data = JSON.parse(Net::HTTP.get(URI('https://raw.githubusercontent.com/spdx/license-list-data/master/json/licenses.json')))
37
+ # licenses = json_data['licenses'].map {|l| l['licenseId'] }.sort
38
+ #
39
+
40
+ class InvalidLicenseString < Cop
41
+ VALID_LICENSE_STRING = %w(
42
+ 0BSD
43
+ AAL
44
+ ADSL
45
+ AFL-1.1
46
+ AFL-1.2
47
+ AFL-2.0
48
+ AFL-2.1
49
+ AFL-3.0
50
+ AGPL-1.0
51
+ AGPL-1.0-only
52
+ AGPL-1.0-or-later
53
+ AGPL-3.0
54
+ AGPL-3.0-only
55
+ AGPL-3.0-or-later
56
+ AMDPLPA
57
+ AML
58
+ AMPAS
59
+ ANTLR-PD
60
+ APAFML
61
+ APL-1.0
62
+ APSL-1.0
63
+ APSL-1.1
64
+ APSL-1.2
65
+ APSL-2.0
66
+ Abstyles
67
+ Adobe-2006
68
+ Adobe-Glyph
69
+ Afmparse
70
+ Aladdin
71
+ Apache-1.0
72
+ Apache-1.1
73
+ Apache-2.0
74
+ Artistic-1.0
75
+ Artistic-1.0-Perl
76
+ Artistic-1.0-cl8
77
+ Artistic-2.0
78
+ BSD-1-Clause
79
+ BSD-2-Clause
80
+ BSD-2-Clause-FreeBSD
81
+ BSD-2-Clause-NetBSD
82
+ BSD-2-Clause-Patent
83
+ BSD-3-Clause
84
+ BSD-3-Clause-Attribution
85
+ BSD-3-Clause-Clear
86
+ BSD-3-Clause-LBNL
87
+ BSD-3-Clause-No-Nuclear-License
88
+ BSD-3-Clause-No-Nuclear-License-2014
89
+ BSD-3-Clause-No-Nuclear-Warranty
90
+ BSD-3-Clause-Open-MPI
91
+ BSD-4-Clause
92
+ BSD-4-Clause-UC
93
+ BSD-Protection
94
+ BSD-Source-Code
95
+ BSL-1.0
96
+ Bahyph
97
+ Barr
98
+ Beerware
99
+ BitTorrent-1.0
100
+ BitTorrent-1.1
101
+ BlueOak-1.0.0
102
+ Borceux
103
+ CATOSL-1.1
104
+ CC-BY-1.0
105
+ CC-BY-2.0
106
+ CC-BY-2.5
107
+ CC-BY-3.0
108
+ CC-BY-4.0
109
+ CC-BY-NC-1.0
110
+ CC-BY-NC-2.0
111
+ CC-BY-NC-2.5
112
+ CC-BY-NC-3.0
113
+ CC-BY-NC-4.0
114
+ CC-BY-NC-ND-1.0
115
+ CC-BY-NC-ND-2.0
116
+ CC-BY-NC-ND-2.5
117
+ CC-BY-NC-ND-3.0
118
+ CC-BY-NC-ND-4.0
119
+ CC-BY-NC-SA-1.0
120
+ CC-BY-NC-SA-2.0
121
+ CC-BY-NC-SA-2.5
122
+ CC-BY-NC-SA-3.0
123
+ CC-BY-NC-SA-4.0
124
+ CC-BY-ND-1.0
125
+ CC-BY-ND-2.0
126
+ CC-BY-ND-2.5
127
+ CC-BY-ND-3.0
128
+ CC-BY-ND-4.0
129
+ CC-BY-SA-1.0
130
+ CC-BY-SA-2.0
131
+ CC-BY-SA-2.5
132
+ CC-BY-SA-3.0
133
+ CC-BY-SA-4.0
134
+ CC-PDDC
135
+ CC0-1.0
136
+ CDDL-1.0
137
+ CDDL-1.1
138
+ CDLA-Permissive-1.0
139
+ CDLA-Sharing-1.0
140
+ CECILL-1.0
141
+ CECILL-1.1
142
+ CECILL-2.0
143
+ CECILL-2.1
144
+ CECILL-B
145
+ CECILL-C
146
+ CERN-OHL-1.1
147
+ CERN-OHL-1.2
148
+ CNRI-Jython
149
+ CNRI-Python
150
+ CNRI-Python-GPL-Compatible
151
+ CPAL-1.0
152
+ CPL-1.0
153
+ CPOL-1.02
154
+ CUA-OPL-1.0
155
+ Caldera
156
+ ClArtistic
157
+ Condor-1.1
158
+ Crossword
159
+ CrystalStacker
160
+ Cube
161
+ D-FSL-1.0
162
+ DOC
163
+ DSDP
164
+ Dotseqn
165
+ ECL-1.0
166
+ ECL-2.0
167
+ EFL-1.0
168
+ EFL-2.0
169
+ EPL-1.0
170
+ EPL-2.0
171
+ EUDatagrid
172
+ EUPL-1.0
173
+ EUPL-1.1
174
+ EUPL-1.2
175
+ Entessa
176
+ ErlPL-1.1
177
+ Eurosym
178
+ FSFAP
179
+ FSFUL
180
+ FSFULLR
181
+ FTL
182
+ Fair
183
+ Frameworx-1.0
184
+ FreeImage
185
+ GFDL-1.1
186
+ GFDL-1.1-only
187
+ GFDL-1.1-or-later
188
+ GFDL-1.2
189
+ GFDL-1.2-only
190
+ GFDL-1.2-or-later
191
+ GFDL-1.3
192
+ GFDL-1.3-only
193
+ GFDL-1.3-or-later
194
+ GL2PS
195
+ GPL-1.0
196
+ GPL-1.0+
197
+ GPL-1.0-only
198
+ GPL-1.0-or-later
199
+ GPL-2.0
200
+ GPL-2.0+
201
+ GPL-2.0-only
202
+ GPL-2.0-or-later
203
+ GPL-2.0-with-GCC-exception
204
+ GPL-2.0-with-autoconf-exception
205
+ GPL-2.0-with-bison-exception
206
+ GPL-2.0-with-classpath-exception
207
+ GPL-2.0-with-font-exception
208
+ GPL-3.0
209
+ GPL-3.0+
210
+ GPL-3.0-only
211
+ GPL-3.0-or-later
212
+ GPL-3.0-with-GCC-exception
213
+ GPL-3.0-with-autoconf-exception
214
+ Giftware
215
+ Glide
216
+ Glulxe
217
+ HPND
218
+ HPND-sell-variant
219
+ HaskellReport
220
+ IBM-pibs
221
+ ICU
222
+ IJG
223
+ IPA
224
+ IPL-1.0
225
+ ISC
226
+ ImageMagick
227
+ Imlib2
228
+ Info-ZIP
229
+ Intel
230
+ Intel-ACPI
231
+ Interbase-1.0
232
+ JPNIC
233
+ JSON
234
+ JasPer-2.0
235
+ LAL-1.2
236
+ LAL-1.3
237
+ LGPL-2.0
238
+ LGPL-2.0+
239
+ LGPL-2.0-only
240
+ LGPL-2.0-or-later
241
+ LGPL-2.1
242
+ LGPL-2.1+
243
+ LGPL-2.1-only
244
+ LGPL-2.1-or-later
245
+ LGPL-3.0
246
+ LGPL-3.0+
247
+ LGPL-3.0-only
248
+ LGPL-3.0-or-later
249
+ LGPLLR
250
+ LPL-1.0
251
+ LPL-1.02
252
+ LPPL-1.0
253
+ LPPL-1.1
254
+ LPPL-1.2
255
+ LPPL-1.3a
256
+ LPPL-1.3c
257
+ Latex2e
258
+ Leptonica
259
+ LiLiQ-P-1.1
260
+ LiLiQ-R-1.1
261
+ LiLiQ-Rplus-1.1
262
+ Libpng
263
+ Linux-OpenIB
264
+ MIT
265
+ MIT-0
266
+ MIT-CMU
267
+ MIT-advertising
268
+ MIT-enna
269
+ MIT-feh
270
+ MITNFA
271
+ MPL-1.0
272
+ MPL-1.1
273
+ MPL-2.0
274
+ MPL-2.0-no-copyleft-exception
275
+ MS-PL
276
+ MS-RL
277
+ MTLL
278
+ MakeIndex
279
+ MirOS
280
+ Motosoto
281
+ Multics
282
+ Mup
283
+ NASA-1.3
284
+ NBPL-1.0
285
+ NCSA
286
+ NGPL
287
+ NLOD-1.0
288
+ NLPL
289
+ NOSL
290
+ NPL-1.0
291
+ NPL-1.1
292
+ NPOSL-3.0
293
+ NRL
294
+ NTP
295
+ Naumen
296
+ Net-SNMP
297
+ NetCDF
298
+ Newsletr
299
+ Nokia
300
+ Noweb
301
+ Nunit
302
+ OCCT-PL
303
+ OCLC-2.0
304
+ ODC-By-1.0
305
+ ODbL-1.0
306
+ OFL-1.0
307
+ OFL-1.1
308
+ OGL-UK-1.0
309
+ OGL-UK-2.0
310
+ OGL-UK-3.0
311
+ OGTSL
312
+ OLDAP-1.1
313
+ OLDAP-1.2
314
+ OLDAP-1.3
315
+ OLDAP-1.4
316
+ OLDAP-2.0
317
+ OLDAP-2.0.1
318
+ OLDAP-2.1
319
+ OLDAP-2.2
320
+ OLDAP-2.2.1
321
+ OLDAP-2.2.2
322
+ OLDAP-2.3
323
+ OLDAP-2.4
324
+ OLDAP-2.5
325
+ OLDAP-2.6
326
+ OLDAP-2.7
327
+ OLDAP-2.8
328
+ OML
329
+ OPL-1.0
330
+ OSET-PL-2.1
331
+ OSL-1.0
332
+ OSL-1.1
333
+ OSL-2.0
334
+ OSL-2.1
335
+ OSL-3.0
336
+ OpenSSL
337
+ PDDL-1.0
338
+ PHP-3.0
339
+ PHP-3.01
340
+ Parity-6.0.0
341
+ Plexus
342
+ PostgreSQL
343
+ Python-2.0
344
+ QPL-1.0
345
+ Qhull
346
+ RHeCos-1.1
347
+ RPL-1.1
348
+ RPL-1.5
349
+ RPSL-1.0
350
+ RSA-MD
351
+ RSCPL
352
+ Rdisc
353
+ Ruby
354
+ SAX-PD
355
+ SCEA
356
+ SGI-B-1.0
357
+ SGI-B-1.1
358
+ SGI-B-2.0
359
+ SHL-0.5
360
+ SHL-0.51
361
+ SISSL
362
+ SISSL-1.2
363
+ SMLNJ
364
+ SMPPL
365
+ SNIA
366
+ SPL-1.0
367
+ SSPL-1.0
368
+ SWL
369
+ Saxpath
370
+ Sendmail
371
+ Sendmail-8.23
372
+ SimPL-2.0
373
+ Sleepycat
374
+ Spencer-86
375
+ Spencer-94
376
+ Spencer-99
377
+ StandardML-NJ
378
+ SugarCRM-1.1.3
379
+ TAPR-OHL-1.0
380
+ TCL
381
+ TCP-wrappers
382
+ TMate
383
+ TORQUE-1.1
384
+ TOSL
385
+ TU-Berlin-1.0
386
+ TU-Berlin-2.0
387
+ UPL-1.0
388
+ Unicode-DFS-2015
389
+ Unicode-DFS-2016
390
+ Unicode-TOU
391
+ Unlicense
392
+ VOSTROM
393
+ VSL-1.0
394
+ Vim
395
+ W3C
396
+ W3C-19980720
397
+ W3C-20150513
398
+ WTFPL
399
+ Watcom-1.0
400
+ Wsuipa
401
+ X11
402
+ XFree86-1.1
403
+ XSkat
404
+ Xerox
405
+ Xnet
406
+ YPL-1.0
407
+ YPL-1.1
408
+ ZPL-1.1
409
+ ZPL-2.0
410
+ ZPL-2.1
411
+ Zed
412
+ Zend-2.0
413
+ Zimbra-1.3
414
+ Zimbra-1.4
415
+ Zlib
416
+ blessing
417
+ bzip2-1.0.5
418
+ bzip2-1.0.6
419
+ copyleft-next-0.3.0
420
+ copyleft-next-0.3.1
421
+ curl
422
+ diffmark
423
+ dvipdfm
424
+ eCos-2.0
425
+ eGenix
426
+ gSOAP-1.3b
427
+ gnuplot
428
+ iMatix
429
+ libpng-2.0
430
+ libtiff
431
+ mpich2
432
+ psfrag
433
+ psutils
434
+ wxWindows
435
+ xinetd
436
+ xpp
437
+ zlib-acknowledgement
438
+ ).freeze
439
+
440
+ COMMON_TYPOS = {
441
+ "all_rights": 'all rights reserved',
442
+ "apache 2.0": 'Apache-2.0',
443
+ "apache license version 2.0": 'Apache-2.0',
444
+ "apache2": 'Apache-2.0',
445
+ "mit": 'MIT',
446
+ '3-clause bsd': 'BSD-3-Clause',
447
+ 'gnu public license 3.0': 'GPL-3.0',
448
+ 'gpl v2': 'GPL-2.0',
449
+ 'gpl v3': 'GPL-3.0',
450
+ 'gplv2': 'GPL-2.0',
451
+ 'gplv3': 'GPL-3.0',
452
+ 'mit license': 'MIT',
453
+ }.freeze
454
+
455
+ MSG = 'Cookbook metadata.rb does not use a SPDX compliant license string or "all rights reserved". See https://spdx.org/licenses/ for a complete list of license identifiers.'.freeze
456
+
457
+ def_node_matcher :license?, '(send nil? :license $str ...)'
458
+
459
+ def on_send(node)
460
+ license?(node) do |license|
461
+ unless valid_license?(license.str_content)
462
+ add_offense(license, location: :expression, message: MSG, severity: :refactor)
463
+ end
464
+ end
465
+ end
466
+
467
+ def autocorrect(node)
468
+ correct_string = autocorrect_license_string(node.str_content)
469
+ if correct_string
470
+ lambda do |corrector|
471
+ corrector.replace(node.loc.expression, "'#{correct_string}'")
472
+ end
473
+ end
474
+ end
475
+
476
+ # private
477
+
478
+ def autocorrect_license_string(bad_string)
479
+ COMMON_TYPOS[bad_string.delete(',').downcase.to_sym]
480
+ end
481
+
482
+ def valid_license?(license)
483
+ VALID_LICENSE_STRING.include?(license) ||
484
+ license.downcase == 'all rights reserved'
485
+ end
486
+ end
487
+ end
488
+ end
489
+ end