puppet-lint-parameter_type-check 1.0.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: c360e6d8629127de13221f4cbc3fe6264b2df207ef68cc953b086803a5dd3ad0
4
+ data.tar.gz: '098c69bf5e1c8df87c168fe94a722339fbf60c68ced023e97d1bec018d20610a'
5
+ SHA512:
6
+ metadata.gz: 3cee50c627f81dc7f3ab1e17d5312bee64ed075b5c5c0d502c28fbcdbfe79fed78b780aa6350f2f5c9bb035da7f7119ce579b9173df5a58c933be7b6520a2846
7
+ data.tar.gz: 301ed3047d433c0e91151c54b40a42fb23097f158a48febd247458c5e30c77a846570edad9125ce233d6b5623c42376db117dd84c4849ede175204d0d5da4069
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Iacob Nicolaev
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,44 @@
1
+ # puppet-lint-parameter_type-check
2
+ puppet-lint plugin to check if all parameters are declared with a specific type
3
+
4
+ # Installation
5
+ To install add the following to your Gemfile and run `bundle install`
6
+ `gem puppet-lint-parameter_type-check, :require => false`
7
+
8
+ or
9
+
10
+ `gem install puppet-lint-parameter_type-check`
11
+
12
+ # Usage
13
+ The plugin provides new check through `puppet-lint`
14
+
15
+ ## parameter_type-check
16
+
17
+ ### --fix support: No
18
+
19
+ To disable this check use `--no-parameter_type-check`
20
+
21
+ This check will tell you if your parameters are not defined with a specific data type
22
+
23
+
24
+ ```
25
+ define foo(
26
+ $foo,
27
+ $bar,
28
+ ) { }
29
+ ```
30
+ will result in a warning with the fallowing message:
31
+
32
+ `WARNING: expected a parameter with type declared`
33
+
34
+ Define examle that will pass this check:
35
+
36
+ ```
37
+ define foo(
38
+ String $foo,
39
+ Integer $bar,
40
+ ) { }
41
+ ```
42
+
43
+ # References
44
+ https://puppet.com/docs/puppet/latest/style_guide.html#type-signatures
@@ -0,0 +1,22 @@
1
+ PuppetLint.new_check(:parameter_type) do
2
+ def check
3
+ pass_checks_types = Set.new([:TYPE, :RBRACK, :EQUALS, :DQPRE, :DQMID])
4
+ msg = "expected a parameter with type declared"
5
+ (class_indexes + defined_type_indexes).each do |class_idx|
6
+ next if class_idx[:param_tokens].nil?
7
+
8
+ class_idx[:param_tokens].each_with_index do |token, i|
9
+ if token.type == :VARIABLE
10
+ next if pass_checks_types.include? token.prev_code_token.type
11
+
12
+ notify(
13
+ :warning,
14
+ :message => msg,
15
+ :line => token.line,
16
+ :column => token.column
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'parameter_type' do
4
+ let(:msg) { 'expected a parameter with type declared' }
5
+
6
+ %w[define class].each do |type|
7
+ context "#{type} parameter without data type" do
8
+ let(:code) { "#{type} foo( $foo ) { }" }
9
+
10
+ it 'should detect a single problem' do
11
+ expect(problems).to have(1).problem
12
+ end
13
+ col = (type == 'class' ? 12 : 13)
14
+ it 'should create a warning' do
15
+ expect(problems).to contain_warning(msg).on_line(1).in_column(col)
16
+ end
17
+ end
18
+
19
+ context "#{type} parameter without data type and valua with unenc variable" do
20
+ let(:code) { "#{type} foo($foo = \"text=${unenc} text=${unenc}\" ) { }" }
21
+
22
+ it 'should detect a problem' do
23
+ expect(problems).to have(1).problems
24
+ end
25
+ col = (type == 'class' ? 11 : 12)
26
+ it 'should create a warning' do
27
+ expect(problems).to contain_warning(msg).on_line(1).in_column(col)
28
+ end
29
+ end
30
+
31
+ context "#{type} parameter without data type" do
32
+ let(:code) { "#{type} foo( $foo, $bar ) { }" }
33
+
34
+ it 'should detect two problem' do
35
+ expect(problems).to have(2).problem
36
+ end
37
+ end
38
+
39
+ context "#{type} parameter with data type" do
40
+ let(:code) { "#{type} foo( Hash $foo ) { }" }
41
+
42
+ it 'should not detect any problems' do
43
+ expect(problems).to have(0).problems
44
+ end
45
+ end
46
+
47
+ context "#{type} multiple parameter with data type" do
48
+ let(:code) { "#{type} foo(Hash $foo, String $foo,) { }" }
49
+
50
+ it 'should not detect any problems' do
51
+ expect(problems).to have(0).problems
52
+ end
53
+ end
54
+
55
+ context "#{type} Optional parameter with data type" do
56
+ let(:code) { "#{type} foo(Optionl[String] $foo) { }" }
57
+
58
+ it 'should not detect any problems' do
59
+ expect(problems).to have(0).problems
60
+ end
61
+ end
62
+
63
+ context "#{type} parameter with data type and valua with unenc variable" do
64
+ let(:code) { "#{type} foo(String $foo = \"text=${unenc} text=${unenc}\") { }" }
65
+
66
+ it 'should not detect any problems' do
67
+ expect(problems).to have(0).problems
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-parameter_type-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Iacob Nicolaev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-21 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: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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: simplecov
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
+ description: " A puppet-lint plugin to check if parameters in Classes and Defines
98
+ has types declared.\n"
99
+ email: nicolaev.iacob@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE
105
+ - README.md
106
+ - lib/puppet-lint/plugins/check_parameter_type.rb
107
+ - spec/puppet-lint/plugins/check_parameter_type_spec.rb
108
+ - spec/spec_helper.rb
109
+ homepage: https://github.com/iasha102/puppet-lint-parameter_type-check
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.0.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: A puppet-lint plugin to check if parameters in Classes and Defines has types
132
+ declared.
133
+ test_files:
134
+ - spec/puppet-lint/plugins/check_parameter_type_spec.rb
135
+ - spec/spec_helper.rb