puppet-lint-cuddled_else-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: 1b48ad06c4aadea657c41baaf5aa09d5b393024b04400efd3ebf83785a753957
4
+ data.tar.gz: 1d54d0b7273fb8715dd16b198476cb13e63d3f0d8ffeda11192bf6d2eb933a6a
5
+ SHA512:
6
+ metadata.gz: 79006155a35ed05cce79fde709db20fa58ad0a404fc4638b76f4e243da4d1b7adc32471fdf415177a9364dac372099d3cdb0e2912b7adb073af2952975f1b238
7
+ data.tar.gz: 0de7254bdd7b0377d7e47cf5efaae6c545f7a4ef666143ea35b9812e7a8e2284c15828119986e6c9348919b095d5dbc4287526b08624acb5c4183f1669747570
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2019] [Christian Bartolomäus]
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,61 @@
1
+ puppet-lint-cuddled_else-check
2
+ ==============================
3
+
4
+ A puppet-lint plugin to check for [cuddled else blocks](http://wiki.c2.com/?CuddledElseBlocks).
5
+
6
+ ## Installation
7
+
8
+ ### From the command line
9
+
10
+ ```shell
11
+ $ gem install puppet-lint-cuddled_else-check
12
+ ```
13
+
14
+ ## Checks
15
+
16
+ ### Cuddled else/elsif
17
+
18
+ There are two different styles regarding the placement of `else` and `elsif` keywords. It can be placed on the same line as the closing curly of the preceding if block (`cuddled`) or on a separate line below that closing curly (`uncuddled`). There are pros and cons for both styles -- cmp. http://wiki.c2.com/?CuddledElseBlocks.
19
+
20
+ This check helps to enforce a consistent style by warning about `cuddled` else/elsif keywords.
21
+
22
+ #### What you have done
23
+
24
+ The `else` (or `elsif`) keyword is on the same line as the closing curly brace of the preceding if block.
25
+
26
+ ```puppet
27
+ if $foo == 'bar' {
28
+ ## some stuff
29
+ } else {
30
+ ## other stuff
31
+ }
32
+ ```
33
+
34
+ #### What you should have done
35
+
36
+ The `else` (or `elsif`) keyword is on a new line below the closing curly brace of the preceding if block.
37
+
38
+ ```puppet
39
+ if $foo == 'bar' {
40
+ ## some stuff
41
+ }
42
+ else {
43
+ ## other stuff
44
+ }
45
+ ```
46
+
47
+ #### Disabling the check
48
+
49
+ To disable this check, you can add `--no-cuddled_else-check' to your puppet-lint command line.
50
+
51
+ ```
52
+ $ puppet-lint --no-cuddled_else-check /path/to/file.pp
53
+ ```
54
+
55
+ ## See also
56
+
57
+ There is a corresponding plugin `puppet-lint-uncuddled_else-check` that warns for uncuddled else blocks. Most probably you only want one of both checks. ;)
58
+
59
+ ## Acknowledgments
60
+
61
+ This plugin for `puppet-lint` has been written owing to the very nice [tutorial for writing puppet-lint checks](http://puppet-lint.com/developer/tutorial/).
@@ -0,0 +1,18 @@
1
+ PuppetLint.new_check(:cuddled_else) do
2
+ def check
3
+ tokens.each do |token|
4
+ next unless token.type == :ELSE || token.type == :ELSIF
5
+
6
+ ## 'else/elsif' should be first thing on line (but could be indented)
7
+ prev1 = token.prev_token
8
+ next if prev1.type == :NEWLINE || prev1.type == :INDENT
9
+
10
+ ## otherwise it's not an uncuddled else/elsif
11
+ notify :warning, {
12
+ :message => "found cuddled #{token.type.to_s.downcase}, should be on separate line",
13
+ :line => token.line,
14
+ :column => token.column,
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ # rubocop:disable Metrics/BlockLength, Metrics/LineLength
4
+ describe 'cuddled_else' do
5
+ ## cuddled else
6
+ context 'with fix disabled' do
7
+ let(:msg) { 'found cuddled else, should be on separate line' }
8
+
9
+ ## no indentation
10
+ context 'else on next line after closing curly of preceding if block' do
11
+ let(:code) { "if $foo == 'bar' {\n ## some stuff\n}\nelse {\n ## other stuff\n}\n" }
12
+
13
+ it 'should not detect any problems' do
14
+ expect(problems).to have(0).problems
15
+ end
16
+ end
17
+
18
+ context 'else on same line as closing curly of preceding if block' do
19
+ let(:code) { "if $foo == 'bar' {\n ## some stuff\n} else {\n ## other stuff\n}\n" }
20
+
21
+ it 'should detect a single problems' do
22
+ expect(problems).to have(1).problems
23
+ end
24
+
25
+ it 'should create a warning' do
26
+ expect(problems).to contain_warning(msg).on_line(3).in_column(3)
27
+ end
28
+ end
29
+
30
+ ## with indentation
31
+ context 'indented else on next line after closing curly of preceding if block' do
32
+ let(:code) { " if $foo == 'bar' {\n ## some stuff\n }\n else {\n ## other stuff\n }\n" }
33
+
34
+ it 'should not detect any problems' do
35
+ expect(problems).to have(0).problems
36
+ end
37
+ end
38
+
39
+ context 'else on same line as indented closing curly of preceding if block' do
40
+ let(:code) { " if $foo == 'bar' {\n ## some stuff\n } else {\n ## other stuff\n }\n" }
41
+
42
+ it 'should detect a single problems' do
43
+ expect(problems).to have(1).problems
44
+ end
45
+
46
+ it 'should create a warning' do
47
+ expect(problems).to contain_warning(msg).on_line(3).in_column(5)
48
+ end
49
+ end
50
+ end
51
+
52
+ ## cuddled elsif
53
+ context 'with fix disabled' do
54
+ let(:msg) { 'found cuddled elsif, should be on separate line' }
55
+
56
+ ## no indentation
57
+ context 'elsif on next line after closing curly of preceding if block' do
58
+ let(:code) { "if $foo == 'bar' {\n ## some stuff\n}\nelsif $foo == 'baz' {\n ## other stuff\n}\n" }
59
+
60
+ it 'should not detect any problems' do
61
+ expect(problems).to have(0).problems
62
+ end
63
+ end
64
+
65
+ context 'elsif on same line as closing curly of preceding if block' do
66
+ let(:code) { "if $foo == 'bar' {\n ## some stuff\n} elsif $foo == 'baz' {\n ## other stuff\n}\n" }
67
+
68
+ it 'should detect a single problems' do
69
+ expect(problems).to have(1).problems
70
+ end
71
+
72
+ it 'should create a warning' do
73
+ expect(problems).to contain_warning(msg).on_line(3).in_column(3)
74
+ end
75
+ end
76
+
77
+ ## with indentation
78
+ context 'indented elsif on next line after closing curly of preceding if block' do
79
+ let(:code) { " if $foo == 'bar' {\n ## some stuff\n }\n elsif $foo == 'baz' {\n ## other stuff\n }\n" }
80
+
81
+ it 'should not detect any problems' do
82
+ expect(problems).to have(0).problems
83
+ end
84
+ end
85
+
86
+ context 'elsif on same line as indented closing curly of preceding if block' do
87
+ let(:code) { " if $foo == 'bar' {\n ## some stuff\n } elsif $foo == 'baz' { \n ## other stuff\n }\n" }
88
+
89
+ it 'should detect a single problems' do
90
+ expect(problems).to have(1).problems
91
+ end
92
+
93
+ it 'should create a warning' do
94
+ expect(problems).to contain_warning(msg).on_line(3).in_column(5)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ # rubocop:enable Metrics/BlockLength, Metrics/LineLength
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-cuddled_else-check
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Christian Bartolomäus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-06 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: rspec-json_expectations
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
+ - !ruby/object:Gem::Dependency
98
+ name: rake
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 do not have cuddled
112
+ else blocks.\n"
113
+ email: use_v6@aglaz.de
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - LICENSE
119
+ - README.md
120
+ - lib/puppet-lint/plugins/check_cuddled_else.rb
121
+ - spec/puppet-lint/plugins/check_cuddled_else_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: https://github.com/optivo-org/puppet-lint-cuddled_else-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.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A puppet-lint plugin to check for cuddled else blocks.
146
+ test_files:
147
+ - spec/spec_helper.rb
148
+ - spec/puppet-lint/plugins/check_cuddled_else_spec.rb