puppet-lint-summary_comment-check 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 51143fea89148ee6cabc1ef187fb4b1d990d79b3285262e4d36b10756f4b68c1
4
+ data.tar.gz: 7a1513c2b5f67c8a0af47ae9197f09ba089978cf580a52df51110df7a50006c3
5
+ SHA512:
6
+ metadata.gz: a09522cffa734867e1eddfa6013751586a835de2d0f394d48475ca6e1b6e7b8e89b05432d87d40b84a6d24370c19df3c7dca90198069137fceac62ab27dc07a1
7
+ data.tar.gz: cca5dd439858ca0d485a0968780528fcec4d3f1ad1863c0c1408afda27be9eae809a7445db9e4ed4881905294ba3b03db2df818ec3c31657a54835559f70108b
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Puppet lint summary check
2
+
3
+ This checks whether a class contains a valid header comment that starts with a summary like this:
4
+
5
+ ```
6
+ # @summary
7
+ # This is a Puppet class
8
+
9
+ class my_class {
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ To use the plugin, add the following line to the Gemfile:
15
+
16
+ gem 'puppet-lint-summary_comment-check'
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ PuppetLint.new_check(:summary_comment) do
4
+ def warn(message, line = 1)
5
+ notify :warning, { message: message, line: line, column: 1 }
6
+ false
7
+ end
8
+
9
+ def check_token_types
10
+ return warn('No header comment found') unless tokens[0].type == :COMMENT
11
+ return warn('No newline after summary', 2) unless tokens[1].type == :NEWLINE
12
+ return warn('No comment after summary', 2) unless tokens[2].type == :COMMENT
13
+
14
+ true
15
+ end
16
+
17
+ def check_tokens
18
+ return warn('Summary line contains summary text.') if tokens[0].value =~ / @summary./
19
+ return warn('Summary line not found') unless tokens[0].value == ' @summary'
20
+ return warn('No summary found', 2) unless tokens[2].value =~ /^ {3}./
21
+
22
+ true
23
+ end
24
+
25
+ def check
26
+ return warn('Not enough tokens') if tokens.length < 3
27
+
28
+ return unless check_token_types
29
+
30
+ return unless check_tokens
31
+ end
32
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'summary_comment' do
6
+ context 'code containing the summary' do
7
+ let(:code) { "# @summary\n# Test" }
8
+
9
+ it 'should not detect any problems' do
10
+ expect(problems).to have(0).problems
11
+ end
12
+ end
13
+
14
+ context 'empty code' do
15
+ let(:code) { '' }
16
+ it 'should detect a single problem' do
17
+ expect(problems).to have(1).problem
18
+ end
19
+
20
+ it 'should create a warning' do
21
+ expect(problems).to contain_warning('Not enough tokens').on_line(1).in_column(1)
22
+ end
23
+ end
24
+
25
+ context 'code not containing a head comment' do
26
+ let(:code) { '\n\n\n' }
27
+ it 'should detect a single problem' do
28
+ expect(problems).to have(1).problem
29
+ end
30
+
31
+ it 'should create a warning' do
32
+ expect(problems).to contain_warning('No header comment found').on_line(1).in_column(1)
33
+ end
34
+ end
35
+
36
+ context 'code not containing the summary' do
37
+ let(:code) { "# Test\n#" }
38
+
39
+ it 'should detect a single problem' do
40
+ expect(problems).to have(1).problem
41
+ end
42
+
43
+ it 'should create a warning' do
44
+ expect(problems).to contain_warning('Summary line not found').on_line(1).in_column(1)
45
+ end
46
+ end
47
+
48
+ context 'code containing the summary in the same line' do
49
+ let(:code) { "# @summary Test\n#" }
50
+
51
+ it 'should detect a single problems' do
52
+ expect(problems).to have(1).problems
53
+ end
54
+
55
+ it 'should create a warning' do
56
+ expect(problems).to contain_warning('Summary line contains summary text.')
57
+ .on_line(1)
58
+ .in_column(1)
59
+ end
60
+ end
61
+
62
+ context 'code only containing the summary comment' do
63
+ let(:code) { "# @summary\n\n" }
64
+
65
+ it 'should detect a single problems' do
66
+ expect(problems).to have(1).problems
67
+ end
68
+
69
+ it 'should create a warning' do
70
+ expect(problems).to contain_warning('No comment after summary').on_line(2).in_column(1)
71
+ end
72
+ end
73
+
74
+ context 'code containing the summary comment but no indented summary' do
75
+ let(:code) { "# @summary\n#" }
76
+
77
+ it 'should detect a single problems' do
78
+ expect(problems).to have(1).problems
79
+ end
80
+
81
+ it 'should create a warning' do
82
+ expect(problems).to contain_warning('No summary found').on_line(2).in_column(1)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.add_filter 'vendor'
5
+ SimpleCov.start
6
+
7
+ require 'puppet-lint'
8
+
9
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-summary_comment-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Ploeger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-collection_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: " A puppet-lint plugin to check that manifest files contain a properly
112
+ formatted @summary comment.\n"
113
+ email: develop@dieploegers.de
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - README.md
119
+ - lib/puppet-lint/plugins/check_summary_comment.rb
120
+ - spec/puppet-lint/plugins/check_summary_comment_spec.rb
121
+ - spec/spec_helper.rb
122
+ homepage: https://github.com/dodevops/puppet-lint-summary_comment-check
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.0.3.1
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: A puppet-lint plugin to check the @summary comment.
145
+ test_files:
146
+ - spec/spec_helper.rb
147
+ - spec/puppet-lint/plugins/check_summary_comment_spec.rb