puppet-lint-improved_arrow_alignment 0.0.1

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: c99848491e74f1bd13f483d306162aa7471ded63e223e40f0d4829685f9c2510
4
+ data.tar.gz: eb43057ff3f2b48773860d15618d2708f55e41fb8296d3ee14d30e4839f9aac9
5
+ SHA512:
6
+ metadata.gz: cce4814a5d75d9a529b0c72240913296a71d7651e693b5492a4c83feec12c81823b10640e9ea7ed0a16ba1e782360b494fa765b456d0745a8b567e160384dba0
7
+ data.tar.gz: 043d6d59ef125e0c7e67fa0b1c13eb5ea2646672f6b99ebbe98d22f2bbd1e574e74d24b2315ce5c3d080d73b1362616baba1c0270f58c06f870d73b4ed876685
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dean Wilson
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,28 @@
1
+ # puppet-lint-improved_arrow_alignment
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/puppet-lint-improved_arrow_alignment.svg)](https://badge.fury.io/rb/puppet-lint-improved_arrow_alignment)
4
+
5
+ ## Installation
6
+ To add the provided lint checks into a module utilizing the PDK:
7
+
8
+ 1. Add the following to the `.sync.yml` in the root of your module
9
+ ``` yaml
10
+ ---
11
+ Gemfile:
12
+ optional:
13
+ ':development':
14
+ - gem: 'puppet-lint-improved_arrow_alignment'
15
+ ```
16
+ 2. Run `pdk update` from the root of the module
17
+ 3. `pdk validate` will now also use the lint checks provided by this plugin
18
+
19
+ ## Usage
20
+ This plugin provides one new check to `puppet-lint`
21
+
22
+ ### **improved_arrow_alignment**
23
+ `--fix` support: No
24
+
25
+ This check raises an warning if the arrow alignment is off anywhere within a class.
26
+ ```
27
+ warning: indentation of => is not properly aligned (expected in column %d, but found it in column %d)
28
+ ```
@@ -0,0 +1,87 @@
1
+ PuppetLint.new_check(:improved_arrow_alignment) do
2
+ def check
3
+ class_indexes.each do |res_idx|
4
+ arrow_column = [0]
5
+ level_idx = 0
6
+ level_tokens = []
7
+ param_column = [nil]
8
+ resource_tokens = res_idx[:tokens]
9
+ resource_tokens.reject! do |token|
10
+ COMMENT_TYPES.include?(token.type)
11
+ end
12
+
13
+ # If this is a single line resource, skip it
14
+ first_arrow = resource_tokens.index { |r| r.type == :FARROW }
15
+ last_arrow = resource_tokens.rindex { |r| r.type == :FARROW }
16
+ next if first_arrow.nil?
17
+ next if last_arrow.nil?
18
+ next if resource_tokens[first_arrow].line == resource_tokens[last_arrow].line
19
+
20
+ resource_tokens.each do |token|
21
+ if token.type == :FARROW
22
+ param_token = token.prev_code_token
23
+
24
+ if param_token.type == :DQPOST
25
+ param_length = 0
26
+ iter_token = param_token
27
+ while iter_token.type != :DQPRE
28
+ param_length += iter_token.to_manifest.length
29
+ iter_token = iter_token.prev_token
30
+ end
31
+ param_length += iter_token.to_manifest.length
32
+ else
33
+ param_length = param_token.to_manifest.length
34
+ end
35
+
36
+ if param_column[level_idx].nil?
37
+ param_column[level_idx] = if param_token.type == :DQPOST
38
+ iter_token.column
39
+ else
40
+ param_token.column
41
+ end
42
+ end
43
+
44
+ if (level_tokens[level_idx] ||= []).any? { |t| t.line == token.line }
45
+ this_arrow_column = param_column[level_idx] + param_length + 1
46
+ else
47
+ this_arrow_column = param_token.column + param_token.to_manifest.length
48
+ this_arrow_column += 1
49
+ end
50
+
51
+ if arrow_column[level_idx] < this_arrow_column
52
+ arrow_column[level_idx] = this_arrow_column
53
+ end
54
+
55
+ (level_tokens[level_idx] ||= []) << token
56
+ elsif token.type == :LBRACE
57
+ level_idx += 1
58
+ arrow_column << 0
59
+ level_tokens[level_idx] ||= []
60
+ param_column << nil
61
+ elsif token.type == :RBRACE || token.type == :SEMIC
62
+ if (level_tokens[level_idx] ||= []).map(&:line).uniq.length > 1
63
+ level_tokens[level_idx].each do |arrow_tok|
64
+ next if arrow_tok.column == arrow_column[level_idx] || level_tokens[level_idx].size == 1
65
+
66
+ arrows_on_line = level_tokens[level_idx].select { |t| t.line == arrow_tok.line }
67
+ notify(
68
+ :warning,
69
+ :message => "indentation of => is not properly aligned (expected in column #{arrow_column[level_idx]}, but found it in column #{arrow_tok.column})",
70
+ :line => arrow_tok.line,
71
+ :column => arrow_tok.column,
72
+ :token => arrow_tok,
73
+ :arrow_column => arrow_column[level_idx],
74
+ :newline => arrows_on_line.index(arrow_tok) != 0,
75
+ :newline_indent => param_column[level_idx] - 1
76
+ )
77
+ end
78
+ end
79
+ arrow_column[level_idx] = 0
80
+ level_tokens[level_idx].clear
81
+ param_column[level_idx] = nil
82
+ level_idx -= 1
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'improved_arrow_alignment' do
4
+ context 'resource default with correctly alligned' do
5
+ let(:code) do
6
+ <<-EOS
7
+ class imatest {
8
+ File {
9
+ ensure => present,
10
+ mode => '0755'
11
+ }
12
+ }
13
+ EOS
14
+ end
15
+
16
+ it 'should not detect any problems' do
17
+ expect(problems).to have(0).problems
18
+ end
19
+ end
20
+
21
+ # and these should cause failiures
22
+
23
+ context 'resource default with misaligned' do
24
+ let(:msg) { 'indentation of => is not properly aligned (expected in column %d, but found it in column %d)' }
25
+
26
+ let(:code) do
27
+ <<-EOS
28
+ class imatest {
29
+ File {
30
+ ensure => present,
31
+ mode => '0755',
32
+ owner => root,
33
+ }
34
+ }
35
+ EOS
36
+ end
37
+
38
+ it 'should detect two problems' do
39
+ expect(problems).to have(2).problem
40
+ end
41
+
42
+ it 'should create a warning' do
43
+ expect(problems).to contain_warning(format(msg, 20, 19)).on_line(4).in_column(19)
44
+ expect(problems).to contain_warning(format(msg, 20, 22)).on_line(5).in_column(22)
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-improved_arrow_alignment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Garrett Rowell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-08 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.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 3.9.0
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 3.9.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-its
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec-collection_matchers
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rubocop
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.80.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.80.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 13.0.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 13.0.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec-json_expectations
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.2'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.2'
117
+ - !ruby/object:Gem::Dependency
118
+ name: simplecov
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.18.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.18.0
131
+ description: " Extends puppet-lint to better handle => alignment.\n"
132
+ email: garrett@puppet.com
133
+ executables: []
134
+ extensions: []
135
+ extra_rdoc_files: []
136
+ files:
137
+ - LICENSE
138
+ - README.md
139
+ - lib/puppet-lint/plugins/improved_arrow_alignment.rb
140
+ - spec/puppet-lint/plugins/improved_arrow_alignment_spec.rb
141
+ - spec/spec_helper.rb
142
+ homepage: https://rubygems.org/gems/puppet-lint-improved_arrow_alignment
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ source_code_uri: https://github.com/garrettrowell/puppet-lint-improved_arrow_alignment
147
+ documentation_uri: https://github.com/garrettrowell/puppet-lint-improved_arrow_alignment/blob/master/README.md
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.7.6
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: improved puppet-lint arrow alignment checks
168
+ test_files:
169
+ - spec/spec_helper.rb
170
+ - spec/puppet-lint/plugins/improved_arrow_alignment_spec.rb