puppet-lint-last_comment_line-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 +7 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/lib/puppet-lint/plugins/check_last_empty_line_comment.rb +41 -0
- data/spec/puppet-lint/plugins/check_last_empty_line_comment_spec.rb +64 -0
- data/spec/spec_helper.rb +3 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 21d7fe92204d70fe6c9289ad484c611703ceeba987166dad7ecdbb3f1354dd22
|
4
|
+
data.tar.gz: 3c1010fde6d7bff5825866d3c1f4acc62c8662e80f2df7b62b02dea21da91822
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 614f669f67aad42691e7bacf30e6d5088984294541c9deeb2d1f8a2ced2600ff8d62c685ca2bc6e349ed5d9e86a82dd6f236fc781b700df5e770db3313bafcd7
|
7
|
+
data.tar.gz: ea5208aecef5be7bef341698f840a03c17b130179bc04a8ce13475e258df8f1fea75f6420ad7e0dce65f6505aa797bf4e86d0e6141db9a9651fd2751b15106f8
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 DO! DevOps
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Puppet lint last comment line check
|
2
|
+
|
3
|
+
This checks whether the last line in a class comment is an empty line
|
4
|
+
|
5
|
+
```
|
6
|
+
# @param mandatory
|
7
|
+
# A mandatory parameter
|
8
|
+
# @option mandatory [String] hashkey
|
9
|
+
# A key of the hash "mandatory" named "hashkey".
|
10
|
+
#
|
11
|
+
# @param withdefault
|
12
|
+
# A parameter with a default value
|
13
|
+
#
|
14
|
+
# @param optional
|
15
|
+
# An optional parameter
|
16
|
+
#
|
17
|
+
class my_class {
|
18
|
+
Hash $mandatory,
|
19
|
+
Boolean $withdefault = false,
|
20
|
+
Optional[String] $optional = undef,
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
To use the plugin, add the following line to the Gemfile:
|
26
|
+
|
27
|
+
gem 'puppet-lint-last_comment_line-check'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PuppetLint.new_check(:last_empty_line_comment) do
|
4
|
+
def warn(message, line = 1)
|
5
|
+
notify :warning, { message: message, line: line, column: 1 }
|
6
|
+
false
|
7
|
+
end
|
8
|
+
|
9
|
+
# Find the header comments for a class or a defined type
|
10
|
+
#
|
11
|
+
# @param tokens The list of all tokens
|
12
|
+
# @param token_start The index of the token to start from upwards
|
13
|
+
# @return The head comments
|
14
|
+
def get_comments(tokens, token_start)
|
15
|
+
comments = []
|
16
|
+
token_pointer = token_start - 1
|
17
|
+
while token_pointer >= 0
|
18
|
+
break unless %i[COMMENT NEWLINE].include? tokens[token_pointer].type
|
19
|
+
|
20
|
+
comments.append(tokens[token_pointer])
|
21
|
+
token_pointer -= 1
|
22
|
+
end
|
23
|
+
comments.reject { |comment| comment.type == :NEWLINE }.reverse
|
24
|
+
end
|
25
|
+
|
26
|
+
# Check class or defined type indexes
|
27
|
+
def check_indexes(indexes)
|
28
|
+
indexes.each do |index|
|
29
|
+
comments = get_comments(tokens, index[:start])
|
30
|
+
warn('Last line is not an empty comment') unless comments.last.value =~ /^\s*$/
|
31
|
+
end
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
# Run the check
|
36
|
+
def check
|
37
|
+
return unless check_indexes(class_indexes)
|
38
|
+
|
39
|
+
nil unless check_indexes(defined_type_indexes)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'last_empty_line_comment' do
|
4
|
+
context 'valid code' do
|
5
|
+
let(:code) do
|
6
|
+
<<~CODE
|
7
|
+
# @summary
|
8
|
+
# some class
|
9
|
+
#
|
10
|
+
# @param mandatory
|
11
|
+
# A mandatory parameter
|
12
|
+
# with two lines
|
13
|
+
#
|
14
|
+
# @param withdefault
|
15
|
+
# A parameter with a default value
|
16
|
+
#
|
17
|
+
# A two paragraph description
|
18
|
+
#
|
19
|
+
# @param optional
|
20
|
+
# An optional parameter
|
21
|
+
#
|
22
|
+
class my_class (
|
23
|
+
String $mandatory,
|
24
|
+
Boolean $withdefault = false,
|
25
|
+
Optional[String] $optional = undef
|
26
|
+
) {}
|
27
|
+
CODE
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should not detect any problems' do
|
31
|
+
expect(problems).to have(0).problems
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "missing last empty line" do
|
36
|
+
let(:code) do
|
37
|
+
<<~CODE
|
38
|
+
# @summary
|
39
|
+
# some class
|
40
|
+
#
|
41
|
+
# @param mandatory
|
42
|
+
# A mandatory parameter
|
43
|
+
# with two lines
|
44
|
+
#
|
45
|
+
# @param withdefault
|
46
|
+
# A parameter with a default value
|
47
|
+
#
|
48
|
+
# A two paragraph description
|
49
|
+
#
|
50
|
+
# @param optional
|
51
|
+
# An optional parameter
|
52
|
+
class my_class (
|
53
|
+
String $mandatory,
|
54
|
+
Boolean $withdefault = false,
|
55
|
+
Optional[String] $optional = undef
|
56
|
+
) {}
|
57
|
+
CODE
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should not detect any problems' do
|
61
|
+
expect(problems).to have(1).problems
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: puppet-lint-last_comment_line-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: 2023-09-05 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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.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: rspec-its
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.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: " An opinionated puppet lint check for checking if the last line of
|
112
|
+
a comment is blank.\n"
|
113
|
+
email: develop@dieploegers.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- lib/puppet-lint/plugins/check_last_empty_line_comment.rb
|
121
|
+
- spec/puppet-lint/plugins/check_last_empty_line_comment_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
homepage: https://github.com/dodevops/puppet-lint-last_comment_line-check
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubygems_version: 3.0.3.1
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: An opinionated puppet lint check for checking if the last line of a comment
|
146
|
+
is blank
|
147
|
+
test_files:
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/puppet-lint/plugins/check_last_empty_line_comment_spec.rb
|