puppet-lint 2.5.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +522 -0
- data/lib/puppet-lint/bin.rb +71 -6
- data/lib/puppet-lint/checkplugin.rb +43 -9
- data/lib/puppet-lint/checks.rb +16 -16
- data/lib/puppet-lint/configuration.rb +134 -134
- data/lib/puppet-lint/data.rb +28 -28
- data/lib/puppet-lint/lexer/string_slurper.rb +138 -140
- data/lib/puppet-lint/lexer/token.rb +188 -190
- data/lib/puppet-lint/lexer.rb +416 -417
- data/lib/puppet-lint/monkeypatches.rb +1 -1
- data/lib/puppet-lint/optparser.rb +5 -1
- data/lib/puppet-lint/plugins/check_classes/arrow_on_right_operand_line.rb +6 -4
- data/lib/puppet-lint/plugins/check_classes/autoloader_layout.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/class_inherits_from_params_class.rb +6 -4
- data/lib/puppet-lint/plugins/check_classes/code_on_top_scope.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/inherits_across_namespaces.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/names_containing_dash.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/names_containing_uppercase.rb +7 -5
- data/lib/puppet-lint/plugins/check_classes/nested_classes_or_defines.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/parameter_order.rb +7 -4
- data/lib/puppet-lint/plugins/check_classes/right_to_left_relationship.rb +5 -3
- data/lib/puppet-lint/plugins/check_classes/variable_scope.rb +15 -13
- data/lib/puppet-lint/plugins/check_comments/slash_comments.rb +9 -7
- data/lib/puppet-lint/plugins/check_comments/star_comments.rb +10 -8
- data/lib/puppet-lint/plugins/check_conditionals/case_without_default.rb +6 -4
- data/lib/puppet-lint/plugins/check_conditionals/selector_inside_resource.rb +5 -3
- data/lib/puppet-lint/plugins/check_documentation/documentation.rb +7 -3
- data/lib/puppet-lint/plugins/check_nodes/unquoted_node_name.rb +15 -11
- data/lib/puppet-lint/plugins/check_resources/duplicate_params.rb +5 -3
- data/lib/puppet-lint/plugins/check_resources/ensure_first_param.rb +8 -5
- data/lib/puppet-lint/plugins/check_resources/ensure_not_symlink_target.rb +11 -8
- data/lib/puppet-lint/plugins/check_resources/file_mode.rb +14 -9
- data/lib/puppet-lint/plugins/check_resources/unquoted_file_mode.rb +11 -6
- data/lib/puppet-lint/plugins/check_resources/unquoted_resource_title.rb +6 -4
- data/lib/puppet-lint/plugins/check_strings/double_quoted_strings.rb +12 -7
- data/lib/puppet-lint/plugins/check_strings/only_variable_string.rb +8 -6
- data/lib/puppet-lint/plugins/check_strings/puppet_url_without_modules.rb +14 -8
- data/lib/puppet-lint/plugins/check_strings/quoted_booleans.rb +11 -7
- data/lib/puppet-lint/plugins/check_strings/single_quote_string_with_variables.rb +11 -6
- data/lib/puppet-lint/plugins/check_strings/variables_not_enclosed.rb +12 -8
- data/lib/puppet-lint/plugins/check_variables/variable_contains_dash.rb +11 -7
- data/lib/puppet-lint/plugins/check_variables/variable_is_lowercase.rb +11 -7
- data/lib/puppet-lint/plugins/check_whitespace/140chars.rb +3 -8
- data/lib/puppet-lint/plugins/check_whitespace/2sp_soft_tabs.rb +10 -8
- data/lib/puppet-lint/plugins/check_whitespace/80chars.rb +3 -8
- data/lib/puppet-lint/plugins/check_whitespace/arrow_alignment.rb +10 -8
- data/lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb +11 -7
- data/lib/puppet-lint/plugins/check_whitespace/line_length.rb +29 -0
- data/lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb +13 -7
- data/lib/puppet-lint/plugins.rb +63 -61
- data/lib/puppet-lint/report/github.rb +17 -0
- data/lib/puppet-lint/report/sarif_template.json +63 -0
- data/lib/puppet-lint/tasks/puppet-lint.rb +84 -83
- data/lib/puppet-lint/tasks/release_test.rb +4 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/lib/puppet-lint.rb +27 -12
- data/spec/acceptance/puppet_lint_spec.rb +46 -0
- data/spec/spec_helper.rb +92 -91
- data/spec/spec_helper_acceptance.rb +6 -0
- data/spec/spec_helper_acceptance_local.rb +38 -0
- data/spec/{puppet-lint → unit/puppet-lint}/bin_spec.rb +79 -35
- data/spec/{puppet-lint → unit/puppet-lint}/checks_spec.rb +36 -36
- data/spec/unit/puppet-lint/configuration_spec.rb +88 -0
- data/spec/{puppet-lint → unit/puppet-lint}/data_spec.rb +6 -3
- data/spec/{puppet-lint → unit/puppet-lint}/ignore_overrides_spec.rb +17 -17
- data/spec/{puppet-lint → unit/puppet-lint}/lexer/string_slurper_spec.rb +128 -128
- data/spec/{puppet-lint → unit/puppet-lint}/lexer/token_spec.rb +1 -1
- data/spec/{puppet-lint → unit/puppet-lint}/lexer_spec.rb +653 -671
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/arrow_on_right_operand_line_spec.rb +16 -16
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/autoloader_layout_spec.rb +13 -13
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/class_inherits_from_params_class_spec.rb +3 -3
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/code_on_top_scope_spec.rb +4 -4
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/inherits_across_namespaces_spec.rb +4 -4
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/name_contains_uppercase_spec.rb +10 -10
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/names_containing_dash_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/nested_classes_or_defines_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/parameter_order_spec.rb +9 -9
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/right_to_left_relationship_spec.rb +3 -3
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_classes/variable_scope_spec.rb +25 -25
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/slash_comments_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_comments/star_comments_spec.rb +13 -13
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/case_without_default_spec.rb +10 -10
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_conditionals/selector_inside_resource_spec.rb +3 -3
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_documentation/documentation_spec.rb +8 -8
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_nodes/unquoted_node_name_spec.rb +24 -24
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/duplicate_params_spec.rb +9 -9
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_first_param_spec.rb +19 -19
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/ensure_not_symlink_target_spec.rb +10 -10
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/file_mode_spec.rb +40 -40
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_file_mode_spec.rb +20 -20
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_resources/unquoted_resource_title_spec.rb +24 -24
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/double_quoted_strings_spec.rb +27 -27
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/only_variable_string_spec.rb +18 -18
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/puppet_url_without_modules_spec.rb +9 -9
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/quoted_booleans_spec.rb +22 -22
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/single_quote_string_with_variables_spec.rb +2 -2
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_strings/variables_not_enclosed_spec.rb +21 -21
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_contains_dash_spec.rb +6 -6
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_variables/variable_is_lowercase_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/140chars_spec.rb +5 -5
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/2sp_soft_tabs_spec.rb +2 -2
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/80chars_spec.rb +6 -6
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/arrow_alignment_spec.rb +127 -127
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/hard_tabs_spec.rb +7 -7
- data/spec/{puppet-lint → unit/puppet-lint}/plugins/check_whitespace/trailing_whitespace_spec.rb +15 -15
- data/spec/unit/puppet-lint/puppet-lint_spec.rb +18 -0
- metadata +63 -119
- data/CHANGELOG.md +0 -33
- data/HISTORY.md +0 -1130
- data/spec/puppet-lint/configuration_spec.rb +0 -66
- data/spec/puppet-lint_spec.rb +0 -16
@@ -26,7 +26,7 @@ class CommandRun
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe PuppetLint::Bin do
|
29
|
-
subject do
|
29
|
+
subject(:bin) do
|
30
30
|
sane_args = if args.is_a?(Array)
|
31
31
|
args
|
32
32
|
else
|
@@ -57,18 +57,19 @@ describe PuppetLint::Bin do
|
|
57
57
|
|
58
58
|
context 'when asked to display available checks' do
|
59
59
|
let(:args) { '--list-checks' }
|
60
|
+
|
60
61
|
all_checks = PuppetLint.configuration.checks.map(&:to_s)
|
61
62
|
|
62
63
|
its(:exitstatus) { is_expected.to eq(0) }
|
63
64
|
|
64
65
|
all_checks.each do |c|
|
65
66
|
it "includes check #{c} in its output" do
|
66
|
-
expect(
|
67
|
+
expect(bin.stdout).to include c
|
67
68
|
end
|
68
69
|
end
|
69
70
|
end
|
70
71
|
|
71
|
-
context 'when passed a backslash separated path on Windows', :
|
72
|
+
context 'when passed a backslash separated path on Windows', if: Gem.win_platform? do
|
72
73
|
let(:args) do
|
73
74
|
[
|
74
75
|
'spec\fixtures\test\manifests',
|
@@ -93,7 +94,7 @@ describe PuppetLint::Bin do
|
|
93
94
|
[
|
94
95
|
"#{args[0]} - WARNING: optional parameter listed before required parameter on line 2 (check: parameter_order)",
|
95
96
|
"#{args[1]} - ERROR: test::foo not in autoload module layout on line 2 (check: autoloader_layout)",
|
96
|
-
].join("\n")
|
97
|
+
].join("\n"),
|
97
98
|
)
|
98
99
|
end
|
99
100
|
end
|
@@ -144,8 +145,10 @@ describe PuppetLint::Bin do
|
|
144
145
|
end
|
145
146
|
|
146
147
|
its(:exitstatus) { is_expected.to eq(1) }
|
147
|
-
its(:stdout)
|
148
|
-
|
148
|
+
its(:stdout) do
|
149
|
+
is_expected.to match(%r{WARNING})
|
150
|
+
is_expected.not_to match(%r{ERROR})
|
151
|
+
end
|
149
152
|
end
|
150
153
|
|
151
154
|
context 'when specifying a specific check to run' do
|
@@ -159,8 +162,10 @@ describe PuppetLint::Bin do
|
|
159
162
|
end
|
160
163
|
|
161
164
|
its(:exitstatus) { is_expected.to eq(0) }
|
162
|
-
its(:stdout)
|
163
|
-
|
165
|
+
its(:stdout) do
|
166
|
+
is_expected.not_to match(%r{ERROR})
|
167
|
+
is_expected.to match(%r{WARNING})
|
168
|
+
end
|
164
169
|
end
|
165
170
|
|
166
171
|
context 'when asked to display filenames ' do
|
@@ -202,7 +207,7 @@ describe PuppetLint::Bin do
|
|
202
207
|
'',
|
203
208
|
" define test::warning($foo='bar', $baz) { }",
|
204
209
|
' ^',
|
205
|
-
].join("\n")
|
210
|
+
].join("\n"),
|
206
211
|
)
|
207
212
|
end
|
208
213
|
end
|
@@ -397,6 +402,41 @@ describe PuppetLint::Bin do
|
|
397
402
|
end
|
398
403
|
end
|
399
404
|
|
405
|
+
context 'when displaying results as SARIF' do
|
406
|
+
let(:args) do
|
407
|
+
[
|
408
|
+
'--sarif',
|
409
|
+
'spec/fixtures/test/manifests/warning.pp',
|
410
|
+
]
|
411
|
+
end
|
412
|
+
|
413
|
+
its(:exitstatus) { is_expected.to eq(0) }
|
414
|
+
|
415
|
+
its(:stdout) do
|
416
|
+
is_expected.to match(%r{"ruleId": "parameter_order"})
|
417
|
+
is_expected.to match(%r{"uri": "warning.pp"})
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
context 'when displaying results for multiple targets as SARIF' do
|
422
|
+
let(:args) do
|
423
|
+
[
|
424
|
+
'--sarif',
|
425
|
+
'spec/fixtures/test/manifests/fail.pp',
|
426
|
+
'spec/fixtures/test/manifests/warning.pp',
|
427
|
+
]
|
428
|
+
end
|
429
|
+
|
430
|
+
its(:exitstatus) { is_expected.to eq(1) }
|
431
|
+
|
432
|
+
its(:stdout) do
|
433
|
+
is_expected.to match(%r{"ruleId": "autoloader_layout"})
|
434
|
+
is_expected.to match(%r{"uri": "fail.pp"})
|
435
|
+
is_expected.to match(%r{"ruleId": "parameter_order"})
|
436
|
+
is_expected.to match(%r{"uri": "warning.pp"})
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
400
440
|
context 'when hiding ignored problems' do
|
401
441
|
let(:args) do
|
402
442
|
[
|
@@ -405,7 +445,7 @@ describe PuppetLint::Bin do
|
|
405
445
|
end
|
406
446
|
|
407
447
|
its(:exitstatus) { is_expected.to eq(0) }
|
408
|
-
its(:stdout) { is_expected.
|
448
|
+
its(:stdout) { is_expected.not_to match(%r{IGNORED}) }
|
409
449
|
end
|
410
450
|
|
411
451
|
context 'when showing ignored problems' do
|
@@ -434,7 +474,7 @@ describe PuppetLint::Bin do
|
|
434
474
|
[
|
435
475
|
'IGNORED: double quoted string containing no variables on line 3 (check: double_quoted_strings)',
|
436
476
|
' for a good reason',
|
437
|
-
].join("\n")
|
477
|
+
].join("\n"),
|
438
478
|
)
|
439
479
|
end
|
440
480
|
end
|
@@ -468,7 +508,7 @@ describe PuppetLint::Bin do
|
|
468
508
|
end
|
469
509
|
|
470
510
|
its(:exitstatus) { is_expected.to eq(0) }
|
471
|
-
its(:
|
511
|
+
its(:stderr) { is_expected.to match(%r{WARNING: lint:endignore comment with no opening lint:ignore:<check> comment found on line 1}) }
|
472
512
|
end
|
473
513
|
|
474
514
|
context 'when a lint:ignore control comment block is not terminated properly' do
|
@@ -478,48 +518,52 @@ describe PuppetLint::Bin do
|
|
478
518
|
]
|
479
519
|
end
|
480
520
|
|
481
|
-
its(:
|
521
|
+
its(:stderr) { is_expected.to match(%r{WARNING: lint:ignore:140chars comment on line 2 with no closing lint:endignore comment}) }
|
482
522
|
end
|
483
523
|
|
484
524
|
context 'when fixing a file with \n line endings' do
|
485
|
-
|
486
|
-
|
487
|
-
@posix_file = Tempfile.new('posix')
|
488
|
-
|
489
|
-
@windows_file.binmode
|
490
|
-
@posix_file.binmode
|
491
|
-
|
492
|
-
@windows_file.write("\r\n")
|
493
|
-
@posix_file.write("\n")
|
494
|
-
|
495
|
-
@windows_file.close
|
496
|
-
@posix_file.close
|
525
|
+
let(:windows_file) do
|
526
|
+
Tempfile.new('windows')
|
497
527
|
end
|
498
528
|
|
499
|
-
|
500
|
-
|
501
|
-
@posix_file.unlink
|
529
|
+
let(:posix_file) do
|
530
|
+
Tempfile.new('posix')
|
502
531
|
end
|
503
532
|
|
504
533
|
let(:args) do
|
505
534
|
[
|
506
535
|
'--fix',
|
507
|
-
|
508
|
-
|
536
|
+
posix_file.path,
|
537
|
+
windows_file.path,
|
509
538
|
]
|
510
539
|
end
|
511
540
|
|
541
|
+
before(:each) do
|
542
|
+
windows_file.binmode
|
543
|
+
windows_file.write("\r\n")
|
544
|
+
windows_file.close
|
545
|
+
|
546
|
+
posix_file.binmode
|
547
|
+
posix_file.write("\n")
|
548
|
+
posix_file.close
|
549
|
+
end
|
550
|
+
|
551
|
+
after(:each) do
|
552
|
+
windows_file.unlink
|
553
|
+
posix_file.unlink
|
554
|
+
end
|
555
|
+
|
512
556
|
its(:exitstatus) { is_expected.to eq(0) }
|
513
557
|
|
514
558
|
it 'does not change the line endings' do
|
515
|
-
File.open(
|
559
|
+
File.open(posix_file.path, 'rb') do |f|
|
516
560
|
data = f.read
|
517
561
|
|
518
562
|
expect(data).to match(%r{\n\Z}m)
|
519
|
-
expect(data).
|
563
|
+
expect(data).not_to match(%r{\r\n\Z}m)
|
520
564
|
end
|
521
565
|
|
522
|
-
File.open(
|
566
|
+
File.open(windows_file.path, 'rb') do |f|
|
523
567
|
data = f.read
|
524
568
|
|
525
569
|
expect(data).to match(%r{\r\n\Z}m)
|
@@ -543,7 +587,7 @@ describe PuppetLint::Bin do
|
|
543
587
|
|
544
588
|
context 'and command-line does not override "--only-checks"' do
|
545
589
|
let(:args) do
|
546
|
-
File.join(File.dirname(__FILE__), '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp')
|
590
|
+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp')
|
547
591
|
end
|
548
592
|
|
549
593
|
its(:exitstatus) { is_expected.to eq(0) }
|
@@ -556,7 +600,7 @@ describe PuppetLint::Bin do
|
|
556
600
|
let(:args) do
|
557
601
|
[
|
558
602
|
'--only-checks=variable_is_lowercase',
|
559
|
-
File.join(File.dirname(__FILE__), '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp'),
|
603
|
+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp'),
|
560
604
|
]
|
561
605
|
end
|
562
606
|
|
@@ -7,18 +7,18 @@ describe PuppetLint::Checks do
|
|
7
7
|
let(:content) { "notify { 'test': }" }
|
8
8
|
|
9
9
|
describe '#initialize' do
|
10
|
-
it { is_expected.to have_attributes(:
|
10
|
+
it { is_expected.to have_attributes(problems: []) }
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '#load_data' do
|
14
14
|
let(:lexer) { PuppetLint::Lexer.new }
|
15
15
|
|
16
|
-
before do
|
16
|
+
before(:each) do
|
17
17
|
allow(PuppetLint::Lexer).to receive(:new).and_return(lexer)
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'when the tokeniser encounters an error' do
|
21
|
-
before do
|
21
|
+
before(:each) do
|
22
22
|
allow(lexer).to receive(:tokenise).with(content).and_raise(lexer_error)
|
23
23
|
instance.load_data(path, content)
|
24
24
|
end
|
@@ -33,14 +33,14 @@ describe PuppetLint::Checks do
|
|
33
33
|
it 'creates a syntax error problem for the file' do
|
34
34
|
expect(instance.problems).to have(1).problem
|
35
35
|
expect(instance.problems.first).to include(
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
36
|
+
kind: :error,
|
37
|
+
check: :syntax,
|
38
|
+
message: 'Syntax error',
|
39
|
+
line: 1,
|
40
|
+
column: 2,
|
41
|
+
path: anything,
|
42
|
+
fullpath: anything,
|
43
|
+
filename: anything,
|
44
44
|
)
|
45
45
|
end
|
46
46
|
end
|
@@ -55,14 +55,14 @@ describe PuppetLint::Checks do
|
|
55
55
|
it 'creates a syntax error problem for the file' do
|
56
56
|
expect(instance.problems).to have(1).problem
|
57
57
|
expect(instance.problems.first).to include(
|
58
|
-
:
|
59
|
-
:
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
58
|
+
kind: :error,
|
59
|
+
check: :syntax,
|
60
|
+
message: 'Syntax error (some reason)',
|
61
|
+
line: 1,
|
62
|
+
column: 2,
|
63
|
+
path: anything,
|
64
|
+
fullpath: anything,
|
65
|
+
filename: anything,
|
66
66
|
)
|
67
67
|
end
|
68
68
|
end
|
@@ -74,12 +74,12 @@ describe PuppetLint::Checks do
|
|
74
74
|
let(:data) { "notify { 'test': }" }
|
75
75
|
let(:enabled_checks) { [] }
|
76
76
|
|
77
|
-
before do
|
78
|
-
allow(instance).to receive(:enabled_checks).and_return(enabled_checks)
|
77
|
+
before(:each) do
|
78
|
+
allow(instance).to receive(:enabled_checks).and_return(enabled_checks) # rubocop: disable RSpec/SubjectStub
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'loads the manifest data' do
|
82
|
-
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original
|
82
|
+
expect(instance).to receive(:load_data).with(fileinfo, data).and_call_original # rubocop: disable RSpec/SubjectStub
|
83
83
|
instance.run(fileinfo, data)
|
84
84
|
end
|
85
85
|
|
@@ -98,7 +98,7 @@ describe PuppetLint::Checks do
|
|
98
98
|
it 'does not run the disabled checks' do
|
99
99
|
# expect().to_not all(matcher) is not supported
|
100
100
|
disabled_check_classes.each do |check_class|
|
101
|
-
expect(check_class).
|
101
|
+
expect(check_class).not_to receive(:new)
|
102
102
|
end
|
103
103
|
|
104
104
|
instance.run(fileinfo, data)
|
@@ -110,12 +110,12 @@ describe PuppetLint::Checks do
|
|
110
110
|
let(:mock_arrow_alignment) do
|
111
111
|
instance_double(
|
112
112
|
PuppetLint::CheckPlugin,
|
113
|
-
:
|
114
|
-
:
|
113
|
+
run: [{ kind: :error, check: :arrow_alignment }],
|
114
|
+
fix_problems: [{ kind: :fixed, check: :arrow_alignment }],
|
115
115
|
)
|
116
116
|
end
|
117
117
|
let(:mock_hard_tabs) do
|
118
|
-
instance_double(PuppetLint::CheckPlugin, :
|
118
|
+
instance_double(PuppetLint::CheckPlugin, run: [], fix_problems: [])
|
119
119
|
end
|
120
120
|
let(:fix_state) { false }
|
121
121
|
|
@@ -127,22 +127,22 @@ describe PuppetLint::Checks do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'adds the found problems to the problems array' do
|
130
|
-
expect(instance).to have_attributes(:
|
130
|
+
expect(instance).to have_attributes(problems: [{ kind: :error, check: :arrow_alignment }])
|
131
131
|
end
|
132
132
|
|
133
133
|
context 'and fix is enabled' do
|
134
134
|
let(:fix_state) { true }
|
135
135
|
|
136
136
|
it 'calls #fix_problems on the check and adds the results to the problems array' do
|
137
|
-
expect(instance).to have_attributes(:
|
137
|
+
expect(instance).to have_attributes(problems: [{ kind: :fixed, check: :arrow_alignment }])
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
143
|
context 'when an unhandled exception is raised' do
|
144
|
-
before do
|
145
|
-
allow(instance).to receive(:load_data).with(fileinfo, data).and_raise(StandardError.new('test message'))
|
144
|
+
before(:each) do
|
145
|
+
allow(instance).to receive(:load_data).with(fileinfo, data).and_raise(StandardError.new('test message')) # rubocop: disable RSpec/SubjectStub
|
146
146
|
allow($stdout).to receive(:puts).with(anything)
|
147
147
|
end
|
148
148
|
|
@@ -173,7 +173,7 @@ describe PuppetLint::Checks do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
context 'and the file being linted is readable' do
|
176
|
-
before do
|
176
|
+
before(:each) do
|
177
177
|
allow(File).to receive(:readable?).with(fileinfo).and_return(true)
|
178
178
|
allow(File).to receive(:read).with(fileinfo).and_return(data)
|
179
179
|
end
|
@@ -196,7 +196,7 @@ describe PuppetLint::Checks do
|
|
196
196
|
|
197
197
|
let(:expected_enabled_checks) { [:arrow_alignment, :trailing_whitespace] }
|
198
198
|
|
199
|
-
before do
|
199
|
+
before(:each) do
|
200
200
|
PuppetLint.configuration.checks.each do |check|
|
201
201
|
allow(PuppetLint.configuration).to receive("#{check}_enabled?").and_return(expected_enabled_checks.include?(check))
|
202
202
|
end
|
@@ -212,13 +212,13 @@ describe PuppetLint::Checks do
|
|
212
212
|
|
213
213
|
let(:tokens) do
|
214
214
|
[
|
215
|
-
instance_double(PuppetLint::Lexer::Token, :
|
216
|
-
instance_double(PuppetLint::Lexer::Token, :
|
217
|
-
instance_double(PuppetLint::Lexer::Token, :
|
215
|
+
instance_double(PuppetLint::Lexer::Token, to_manifest: '1'),
|
216
|
+
instance_double(PuppetLint::Lexer::Token, to_manifest: '2'),
|
217
|
+
instance_double(PuppetLint::Lexer::Token, to_manifest: '3'),
|
218
218
|
]
|
219
219
|
end
|
220
220
|
|
221
|
-
before do
|
221
|
+
before(:each) do
|
222
222
|
allow(PuppetLint::Data).to receive(:tokens).and_return(tokens)
|
223
223
|
end
|
224
224
|
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PuppetLint::Configuration do
|
4
|
+
subject(:config) { described_class.new }
|
5
|
+
|
6
|
+
it 'creates check methods on the fly' do
|
7
|
+
klass = Class.new
|
8
|
+
config.add_check('foo', klass)
|
9
|
+
|
10
|
+
expect(config).to respond_to(:foo_enabled?)
|
11
|
+
expect(config).not_to respond_to(:bar_enabled?)
|
12
|
+
expect(config).to respond_to(:enable_foo)
|
13
|
+
expect(config).to respond_to(:disable_foo)
|
14
|
+
|
15
|
+
config.disable_foo
|
16
|
+
expect(config.settings['foo_disabled']).to be_truthy
|
17
|
+
expect(config.foo_enabled?).to be_falsey
|
18
|
+
|
19
|
+
config.enable_foo
|
20
|
+
expect(config.settings['foo_disabled']).to be_falsey
|
21
|
+
expect(config.foo_enabled?).to be_truthy
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'knows what checks have been added' do
|
25
|
+
klass = Class.new
|
26
|
+
config.add_check('foo', klass)
|
27
|
+
expect(config.checks).to include('foo')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'responds nil to unknown config options' do
|
31
|
+
expect(config.foobarbaz).to be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'is able to explicitly add options' do
|
35
|
+
config.add_option('bar')
|
36
|
+
|
37
|
+
expect(config.bar).to be_nil
|
38
|
+
|
39
|
+
config.bar = 'aoeui'
|
40
|
+
expect(config.bar).to eq('aoeui')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is able to add options on the fly' do
|
44
|
+
expect(config.test_option).to eq(nil)
|
45
|
+
|
46
|
+
config.test_option = 'test'
|
47
|
+
|
48
|
+
expect(config.test_option).to eq('test')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'is able to set sane defaults' do
|
52
|
+
override_env do
|
53
|
+
ENV.delete('GITHUB_ACTION')
|
54
|
+
config.defaults
|
55
|
+
end
|
56
|
+
|
57
|
+
expect(config.settings).to eq(
|
58
|
+
'with_filename' => false,
|
59
|
+
'fail_on_warnings' => false,
|
60
|
+
'error_level' => :all,
|
61
|
+
'log_format' => '',
|
62
|
+
'sarif' => false,
|
63
|
+
'with_context' => false,
|
64
|
+
'fix' => false,
|
65
|
+
'github_actions' => false,
|
66
|
+
'show_ignored' => false,
|
67
|
+
'json' => false,
|
68
|
+
'ignore_paths' => ['vendor/**/*.pp'],
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'detects github actions' do
|
73
|
+
override_env do
|
74
|
+
ENV['GITHUB_ACTION'] = 'action'
|
75
|
+
config.defaults
|
76
|
+
end
|
77
|
+
|
78
|
+
expect(config.settings['github_actions']).to be(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
def override_env
|
82
|
+
old_env = ENV.to_h
|
83
|
+
yield
|
84
|
+
ensure
|
85
|
+
ENV.clear
|
86
|
+
ENV.update(old_env)
|
87
|
+
end
|
88
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe PuppetLint::Data do
|
4
|
-
subject(:data) {
|
4
|
+
subject(:data) { described_class }
|
5
|
+
|
5
6
|
let(:lexer) { PuppetLint::Lexer.new }
|
6
7
|
|
7
8
|
describe '.resource_indexes' do
|
@@ -39,7 +40,8 @@ describe PuppetLint::Data do
|
|
39
40
|
let(:new_token) { PuppetLint::Lexer::Token.new(:PLUS, '+', 0, 0) }
|
40
41
|
let(:original_tokens) { lexer.tokenise(manifest) }
|
41
42
|
let(:tokens) { original_tokens.dup }
|
42
|
-
|
43
|
+
|
44
|
+
before(:each) do
|
43
45
|
data.tokens = tokens
|
44
46
|
data.insert(2, new_token)
|
45
47
|
end
|
@@ -86,7 +88,8 @@ describe PuppetLint::Data do
|
|
86
88
|
let(:token) { tokens[2] }
|
87
89
|
let(:original_tokens) { lexer.tokenise(manifest) }
|
88
90
|
let(:tokens) { original_tokens.dup }
|
89
|
-
|
91
|
+
|
92
|
+
before(:each) do
|
90
93
|
data.tokens = tokens
|
91
94
|
data.delete(token)
|
92
95
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'quoted_booleans', :
|
3
|
+
describe 'quoted_booleans', type: :lint do
|
4
4
|
let(:msg) { 'quoted boolean value found' }
|
5
5
|
|
6
6
|
context 'with a single line ignore' do
|
@@ -12,16 +12,16 @@ describe 'quoted_booleans', :type => :lint do
|
|
12
12
|
END
|
13
13
|
end
|
14
14
|
|
15
|
-
it '
|
15
|
+
it 'detects three problems' do
|
16
16
|
expect(problems).to have(3).problems
|
17
17
|
end
|
18
18
|
|
19
|
-
it '
|
19
|
+
it 'has two warnings' do
|
20
20
|
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
21
21
|
expect(problems).to contain_warning(msg).on_line(3).in_column(9)
|
22
22
|
end
|
23
23
|
|
24
|
-
it '
|
24
|
+
it 'has one ignored problem' do
|
25
25
|
expect(problems).to contain_ignored(msg).on_line(2).in_column(9)
|
26
26
|
end
|
27
27
|
end
|
@@ -35,16 +35,16 @@ describe 'quoted_booleans', :type => :lint do
|
|
35
35
|
END
|
36
36
|
end
|
37
37
|
|
38
|
-
it '
|
38
|
+
it 'detects three problems' do
|
39
39
|
expect(problems).to have(3).problems
|
40
40
|
end
|
41
41
|
|
42
|
-
it '
|
42
|
+
it 'has two warnings' do
|
43
43
|
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
44
44
|
expect(problems).to contain_warning(msg).on_line(3).in_column(9)
|
45
45
|
end
|
46
46
|
|
47
|
-
it '
|
47
|
+
it 'has one ignored problem with a reason' do
|
48
48
|
expect(problems).to contain_ignored(msg).on_line(2).in_column(9).with_reason('some good reason')
|
49
49
|
end
|
50
50
|
end
|
@@ -61,16 +61,16 @@ describe 'quoted_booleans', :type => :lint do
|
|
61
61
|
END
|
62
62
|
end
|
63
63
|
|
64
|
-
it '
|
64
|
+
it 'detects four problems' do
|
65
65
|
expect(problems).to have(4).problems
|
66
66
|
end
|
67
67
|
|
68
|
-
it '
|
68
|
+
it 'has two warnings' do
|
69
69
|
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
70
70
|
expect(problems).to contain_warning(msg).on_line(6).in_column(9)
|
71
71
|
end
|
72
72
|
|
73
|
-
it '
|
73
|
+
it 'has two ignored problems' do
|
74
74
|
expect(problems).to contain_ignored(msg).on_line(3).in_column(9)
|
75
75
|
expect(problems).to contain_ignored(msg).on_line(4).in_column(9)
|
76
76
|
end
|
@@ -88,16 +88,16 @@ describe 'quoted_booleans', :type => :lint do
|
|
88
88
|
END
|
89
89
|
end
|
90
90
|
|
91
|
-
it '
|
91
|
+
it 'detects four problems' do
|
92
92
|
expect(problems).to have(4).problems
|
93
93
|
end
|
94
94
|
|
95
|
-
it '
|
95
|
+
it 'has two warnings' do
|
96
96
|
expect(problems).to contain_warning(msg).on_line(1).in_column(9)
|
97
97
|
expect(problems).to contain_warning(msg).on_line(6).in_column(9)
|
98
98
|
end
|
99
99
|
|
100
|
-
it '
|
100
|
+
it 'has two ignored problems with a reason' do
|
101
101
|
expect(problems).to contain_ignored(msg).on_line(3).in_column(9).with_reason('another reason')
|
102
102
|
expect(problems).to contain_ignored(msg).on_line(4).in_column(9).with_reason('another reason')
|
103
103
|
end
|
@@ -106,11 +106,11 @@ describe 'quoted_booleans', :type => :lint do
|
|
106
106
|
context 'disable multiple checks on a line with a reason' do
|
107
107
|
let(:code) { '"true" # lint:ignore:quoted_booleans lint:ignore:double_quoted_string a reason' }
|
108
108
|
|
109
|
-
it '
|
109
|
+
it 'detects 1 problems' do
|
110
110
|
expect(problems).to have(1).problems
|
111
111
|
end
|
112
112
|
|
113
|
-
it '
|
113
|
+
it 'has one ignored problems' do
|
114
114
|
expect(problems).to contain_ignored(msg).on_line(1).in_column(1).with_reason('a reason')
|
115
115
|
end
|
116
116
|
end
|
@@ -128,11 +128,11 @@ describe 'quoted_booleans', :type => :lint do
|
|
128
128
|
END
|
129
129
|
end
|
130
130
|
|
131
|
-
it '
|
131
|
+
it 'detects 2 problems' do
|
132
132
|
expect(problems).to have(2).problems
|
133
133
|
end
|
134
134
|
|
135
|
-
it '
|
135
|
+
it 'ignores both problems' do
|
136
136
|
expect(problems).to contain_ignored(msg).on_line(4).in_column(19).with_reason('')
|
137
137
|
expect(problems).to contain_ignored(msg).on_line(5).in_column(25).with_reason('')
|
138
138
|
end
|