puppet-lint-class_parameter-check 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3663acc66b36254c1017c9145596504e78c39b5f
4
+ data.tar.gz: 2c3b8da8980a632060b6b7c73627d5593a80aeda
5
+ SHA512:
6
+ metadata.gz: f22bc8bc8e4007aa5d4dd409803e4de9d5c829c32396e3d5eba9aebc699a09e14f0706bda227e33063a5fe366761f2ee50b9191a9ac90fddcf1fb8a8482eee7e
7
+ data.tar.gz: dbecaf74eabb6ca5856916b1e48dce652b83c29aba3147eead6958c64f8993fb676531de6186a2b59769b3d8b0ca192afb806650bbf717528ec81833816b0055
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Coolblue b.v. NL
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,13 @@
1
+ # Puppet-lint plugin for checking class parameters
2
+ A puppet-lint plugin that checks class parameters. Class parameters should be split in two groups, the first group with no default values, the second group with default values. Both groups should be sorted alphabetically.
3
+
4
+ [ ![Codeship Status for ryreitsma/puppet-lint-class_parameter-check](https://codeship.com/projects/61472600-279e-0131-879c-36bc4bd39c71/status?branch=master)](https://codeship.com/projects/9002)
5
+
6
+ ## Installation
7
+ To use this plugin, add the following like to the Gemfile in your Puppet code base and run `bundle install`.
8
+
9
+ ```ruby
10
+ gem 'puppet-lint-class_parameter-check', git: 'git@github.com:ryreitsma/puppet-lint-class_parameter-check.git'
11
+ ```
12
+ ## Usage
13
+ This plugin provides a new check to `puppet-lint`.
@@ -0,0 +1,41 @@
1
+ PuppetLint.new_check(:class_parameter) do
2
+ def check
3
+ class_indexes.each do |class_index|
4
+ next if class_index[:param_tokens].nil?
5
+
6
+ params = []
7
+ optional_params = []
8
+
9
+ class_index[:param_tokens].each do |parameter_token|
10
+ next unless parameter_token.type == :VARIABLE
11
+
12
+ if parameter_token.next_code_token.nil? || parameter_token.next_code_token.type != :EQUALS
13
+ notify :error, {
14
+ :message => "Required parameters should be specified before optional parameters",
15
+ :line => parameter_token.line,
16
+ :column => parameter_token.column
17
+ } if optional_params.any?
18
+
19
+ params.push(parameter_token)
20
+ elsif parameter_token.next_code_token && parameter_token.next_code_token.type == :EQUALS
21
+ optional_params.push(parameter_token)
22
+ end
23
+ end
24
+
25
+ check_alphabetical_order(params)
26
+ check_alphabetical_order(optional_params)
27
+ end
28
+ end
29
+
30
+ def check_alphabetical_order(params)
31
+ parameter_names = params.map(&:value)
32
+
33
+ if parameter_names != parameter_names.sort
34
+ notify :error, {
35
+ :message => "Parameters not in alphabetical order",
36
+ :line => params.first.line,
37
+ :column => params.first.column
38
+ }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'class_parameter' do
4
+ context 'with fix disabled' do
5
+ context 'class with no parameters' do
6
+ let(:code) { <<-EOF
7
+ class puppet_module() { }
8
+ EOF
9
+ }
10
+
11
+ it 'has no problems' do
12
+ expect(problems).to have(0).problems
13
+ end
14
+ end
15
+
16
+ context 'class with only required parameters' do
17
+ context 'sorted alphabetically' do
18
+ let(:code) { <<-EOF
19
+ class puppet_module(
20
+ String $alphabetical,
21
+ String $non_alphabetical
22
+ ) { }
23
+ EOF
24
+ }
25
+
26
+ it 'has no problems' do
27
+ expect(problems).to have(0).problems
28
+ end
29
+ end
30
+
31
+ context 'not sorted alphabetically' do
32
+ let(:code) { <<-EOF
33
+ class puppet_module(
34
+ String $non_alphabetical,
35
+ String $alphabetical
36
+ ) { }
37
+ EOF
38
+ }
39
+
40
+ it 'has a problem' do
41
+ expect(problems).to have(1).problems
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'class with required and optional parameters' do
47
+ context 'sorted alphabetically per group' do
48
+ let(:code) { <<-EOF
49
+ class puppet_module(
50
+ String $alphabetical,
51
+ String $non_alphabetical,
52
+ String $alphabetical_optional = "default",
53
+ String $non_alphabetical_optional = "default"
54
+ ) { }
55
+ EOF
56
+ }
57
+
58
+ it 'has no problems' do
59
+ expect(problems).to have(0).problems
60
+ end
61
+ end
62
+
63
+ context 'not sorted alphabetically per group' do
64
+ let(:code) { <<-EOF
65
+ class puppet_module(
66
+ String $non_alphabetical,
67
+ String $alphabetical,
68
+ String $non_alphabetical_optional = "default",
69
+ String $alphabetical_optional = "default"
70
+ ) { }
71
+ EOF
72
+ }
73
+
74
+ it 'has two problems' do
75
+ expect(problems).to have(2).problems
76
+ end
77
+ end
78
+
79
+ context 'not sorted in groups' do
80
+ let(:code) { <<-EOF
81
+ class puppet_module(
82
+ String $alphabetical_optional = "default",
83
+ String $alphabetical,
84
+ String $non_alphabetical_optional = "default"
85
+ ) { }
86
+ EOF
87
+ }
88
+
89
+ it 'has a problem' do
90
+ expect(problems).to have(1).problems
91
+ end
92
+ end
93
+
94
+ context 'not sorted in groups and not alphabetically' do
95
+ let(:code) { <<-EOF
96
+ class puppet_module(
97
+ String $non_alphabetical,
98
+ String $non_alphabetical_optional = "default",
99
+ String $alphabetical,
100
+ String $alphabetical_optional = "default"
101
+ ) { }
102
+ EOF
103
+ }
104
+
105
+ it 'has three problems' do
106
+ expect(problems).to have(3).problems
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-class_parameter-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roelof Reitsma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-28 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
+ description: |2
84
+ A puppet-lint plugin that checks class parameters. Class parameters should be split in two groups,
85
+ the first group with no default values, the second group with default values. Both groups should be
86
+ sorted alphabetically.
87
+ email: r.reitsma@coolblue.nl
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - README.md
93
+ - LICENSE
94
+ - lib/puppet-lint/plugins/check_class_parameter.rb
95
+ - spec/puppet-lint/plugins/check_class_parameter_spec.rb
96
+ - spec/spec_helper.rb
97
+ homepage: https://github.com/ryreitsma/puppet-lint-class_parameter-check
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.14
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Puppet lint check for class parameters
121
+ test_files: []