puppet-lint-strict_indent-check 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef74dd23e7f707cb92230b999f833b102a5069be9857a88e1500809ad57a8c20
4
- data.tar.gz: 5b4f48f0408cb5161c4d1cec7144c703399aa88d35fb319c7c2fe78e2e164075
3
+ metadata.gz: a813e32484645b3159a5cc786e1e1df8bb9ce13b7e72de92603836f8d88876d7
4
+ data.tar.gz: 812be78bb5e2d3eed4b37013d7a9ae2b4587d139ea8e1de1b95413b63b38a81a
5
5
  SHA512:
6
- metadata.gz: da47ec5cabfbb07a0b9cf4e50d2700f8a1f355791b950260b0dd8784d84a3569c2bd9bcb6dcd289ad431c298291f397e1f4218444ba1469dad828c0f9aadbc3d
7
- data.tar.gz: 90719145ab8fab866bacb471091bb4d8710b08a0c3627b18a3740bd0c92572ea584bb433de5fb765f4cfb55a03ccee42b8c6f65746d30b96ba5aa4ad897d199d
6
+ metadata.gz: f5d01a03406cfc9ff251e77b46059e31811346ffd6140c89e1920019f42b1a2590302b284399cc874053127a3645ac72cec725d7ad51bb5a76ede4992c0a8f3a
7
+ data.tar.gz: 0143dc2fc1d985646be7f22904ea3cd52dce21918c8829d69dfbc178a517af2784516120063ea5b45e2d02ee6a2335e2ae90d74de774302bd4479580c06ab40b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [3.0.0](https://github.com/voxpupuli/puppet-lint-strict_indent-check/tree/3.0.0) (2023-04-21)
6
+
7
+ [Full Changelog](https://github.com/voxpupuli/puppet-lint-strict_indent-check/compare/2.1.0...3.0.0)
8
+
9
+ **Breaking changes:**
10
+
11
+ - Drop Ruby \< 2.7; Add RuboCop [\#34](https://github.com/voxpupuli/puppet-lint-strict_indent-check/pull/34) ([bastelfreak](https://github.com/bastelfreak))
12
+
5
13
  ## [2.1.0](https://github.com/voxpupuli/puppet-lint-strict_indent-check/tree/2.1.0) (2022-11-29)
6
14
 
7
15
  [Full Changelog](https://github.com/voxpupuli/puppet-lint-strict_indent-check/compare/2.0.8...2.1.0)
@@ -1,30 +1,30 @@
1
1
  # Public: Check the manifest tokens for correct indent levels and
2
2
  # record a warning for each instance found.
3
3
 
4
- PuppetLint.new_check(:'strict_indent') do
4
+ PuppetLint.new_check(:strict_indent) do
5
5
  def match(tokens)
6
6
  opening_token = {
7
- :RBRACE => :LBRACE,
8
- :RBRACK => :LBRACK,
9
- :RPAREN => :LPAREN,
10
- :HEREDOC => :HEREDOC_OPEN,
11
- :HEREDOC_POST => :HEREDOC_OPEN,
7
+ RBRACE: :LBRACE,
8
+ RBRACK: :LBRACK,
9
+ RPAREN: :LPAREN,
10
+ HEREDOC: :HEREDOC_OPEN,
11
+ HEREDOC_POST: :HEREDOC_OPEN,
12
12
  }
13
13
  open = {
14
- :LBRACE => [],
15
- :LBRACK => [],
16
- :LPAREN => [],
17
- :HEREDOC_OPEN => [],
14
+ LBRACE: [],
15
+ LBRACK: [],
16
+ LPAREN: [],
17
+ HEREDOC_OPEN: [],
18
18
  }
19
19
 
20
20
  matches = {}
21
21
 
22
22
  tokens.each do |token|
23
- if [:LBRACE, :LBRACK, :LPAREN, :HEREDOC_OPEN].include?(token.type)
23
+ if %i[LBRACE LBRACK LPAREN HEREDOC_OPEN].include?(token.type)
24
24
  open[token.type] << token
25
- elsif [:RBRACE, :RBRACK, :RPAREN, :HEREDOC, :HEREDOC_POST].include?(token.type)
25
+ elsif %i[RBRACE RBRACK RPAREN HEREDOC HEREDOC_POST].include?(token.type)
26
26
  match = open[opening_token[token.type]].pop
27
- if not match.nil?
27
+ unless match.nil?
28
28
  matches[token] = match
29
29
  matches[match] = token
30
30
  end
@@ -41,26 +41,23 @@ PuppetLint.new_check(:'strict_indent') do
41
41
 
42
42
  matches = match(tokens)
43
43
 
44
- tokens.select { |token|
44
+ tokens.select do |token|
45
45
  token.type == :NEWLINE
46
- }.reject { |token|
46
+ end.reject do |token|
47
47
  # ignore newline at end of code
48
48
  token.next_token.nil?
49
- }.each do |token|
49
+ end.each do |token|
50
50
  temp_indent = 0
51
51
 
52
52
  # indent for open groups in the previous line
53
53
  open_groups = 0
54
54
  prev_token = token.prev_token
55
- while not prev_token.nil? and prev_token.type != :NEWLINE
56
- if prev_token.type == :HEREDOC_OPEN
57
- temp_indent += 1
58
- end
59
- if [:LBRACE, :LBRACK, :LPAREN].include?(prev_token.type)
60
- if matches[prev_token].nil? or matches[prev_token].line > prev_token.line
61
- # left braces not matched in the same line increase indent
62
- open_groups += 1
63
- end
55
+ while !prev_token.nil? and prev_token.type != :NEWLINE
56
+ temp_indent += 1 if prev_token.type == :HEREDOC_OPEN
57
+ if %i[LBRACE LBRACK
58
+ LPAREN].include?(prev_token.type) && (matches[prev_token].nil? or matches[prev_token].line > prev_token.line)
59
+ # left braces not matched in the same line increase indent
60
+ open_groups += 1
64
61
  end
65
62
  prev_token = prev_token.prev_token
66
63
  end
@@ -68,7 +65,7 @@ PuppetLint.new_check(:'strict_indent') do
68
65
 
69
66
  # reset prev_token to last non-whitespace token on previous line
70
67
  prev_token = token.prev_token
71
- while not prev_token.nil? and (prev_token.type == :WHITESPACE or prev_token.type == :COMMENT)
68
+ while !prev_token.nil? and (prev_token.type == :WHITESPACE or prev_token.type == :COMMENT)
72
69
  prev_token = prev_token.prev_token
73
70
  end
74
71
 
@@ -88,7 +85,7 @@ PuppetLint.new_check(:'strict_indent') do
88
85
  end
89
86
  end
90
87
  when :SEMIC
91
- if not colon_indent.nil?
88
+ unless colon_indent.nil?
92
89
  # only unindent for a semicolon when we've indented for a colon
93
90
  colon_indent = nil
94
91
  indent -= 1
@@ -99,18 +96,16 @@ PuppetLint.new_check(:'strict_indent') do
99
96
 
100
97
  # unindent for closing brackets in the current line
101
98
  next_token = token.next_token
102
- while not next_token.nil? and next_token.type != :NEWLINE
103
- if [:RBRACE, :RBRACK, :RPAREN].include?(next_token.type)
104
- if not matches[next_token].nil? and matches[next_token].line < next_token.line
99
+ while !next_token.nil? and next_token.type != :NEWLINE
100
+ if %i[RBRACE RBRACK RPAREN].include?(next_token.type)
101
+ if !matches[next_token].nil? and matches[next_token].line < next_token.line
105
102
  # right braces matched in a previous line decrease indent
106
103
  indent -= 1
107
104
  end
108
- if next_token.type == :RBRACE and not colon_indent.nil?
109
- if not matches[next_token].nil? and matches[next_token].line < colon_indent
110
- # unindent at the end of resources if needed
111
- indent -= 1
112
- colon_indent = nil
113
- end
105
+ if next_token.type == :RBRACE and !colon_indent.nil? && (!matches[next_token].nil? and matches[next_token].line < colon_indent)
106
+ # unindent at the end of resources if needed
107
+ indent -= 1
108
+ colon_indent = nil
114
109
  end
115
110
  end
116
111
  next_token = next_token.next_token
@@ -119,9 +114,9 @@ PuppetLint.new_check(:'strict_indent') do
119
114
  # obviously we have a problem
120
115
  if indent < 0
121
116
  notify :error, {
122
- :message => 'Error calculating indent. Please file an issue at https://github.com/relud/puppet-lint-indent-check/issues',
123
- :line => token.next_token.line,
124
- :column => token.next_token.column,
117
+ message: 'Error calculating indent. Please file an issue at https://github.com/relud/puppet-lint-indent-check/issues',
118
+ line: token.next_token.line,
119
+ column: token.next_token.column,
125
120
  }
126
121
  # stop parsing indent
127
122
  break
@@ -129,43 +124,43 @@ PuppetLint.new_check(:'strict_indent') do
129
124
 
130
125
  # get actual indent
131
126
  actual = 0
132
- if token.next_token.type == :INDENT
133
- actual = token.next_token.value.length
134
- elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC
135
- actual = token.prev_token.value.split("\n").last.length
136
- elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC_OPEN
137
- actual = next_token.prev_token.value.split("\n").last.length
138
- else
139
- actual = 0
140
- end
127
+ actual = if token.next_token.type == :INDENT
128
+ token.next_token.value.length
129
+ elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC
130
+ token.prev_token.value.split("\n").last.length
131
+ elsif !token.prev_token.nil? and token.prev_token.type == :HEREDOC_OPEN
132
+ next_token.prev_token.value.split("\n").last.length
133
+ else
134
+ 0
135
+ end
141
136
 
142
137
  # expected indent
143
138
  expected = (indent + temp_indent) * chars_per_indent
144
139
 
145
140
  # oh no! incorrect indent!
146
- if actual != expected
147
- # no one cares if blank lines and comments are indented correctly
148
- if not [:COMMENT, :NEWLINE].include?(token.next_token.type)
149
- notify :warning, {
150
- :message => "indent should be #{expected} chars and is #{actual}",
151
- :line => token.next_token.line,
152
- :column => token.next_token.column,
153
- :token => token.next_token,
154
- :indent => expected,
155
- }
156
- end
157
- end
141
+ next unless actual != expected
142
+
143
+ # no one cares if blank lines and comments are indented correctly
144
+ next if %i[COMMENT NEWLINE].include?(token.next_token.type)
145
+
146
+ notify :warning, {
147
+ message: "indent should be #{expected} chars and is #{actual}",
148
+ line: token.next_token.line,
149
+ column: token.next_token.column,
150
+ token: token.next_token,
151
+ indent: expected,
152
+ }
158
153
  end
159
154
  end
160
155
 
161
156
  def fix(problem)
162
157
  char_for_indent = ' '
163
- if [:INDENT,:WHITESPACE].include?(problem[:token].type)
158
+ if %i[INDENT WHITESPACE].include?(problem[:token].type)
164
159
  problem[:token].value = char_for_indent * problem[:indent]
165
160
  else
166
161
  tokens.insert(
167
162
  tokens.find_index(problem[:token]),
168
- PuppetLint::Lexer::Token.new(:INDENT, char_for_indent * problem[:indent], problem[:line], problem[:column])
163
+ PuppetLint::Lexer::Token.new(:INDENT, char_for_indent * problem[:indent], problem[:line], problem[:column]),
169
164
  )
170
165
  end
171
166
  end
@@ -3,18 +3,18 @@ require 'spec_helper'
3
3
  describe 'strict_indent' do
4
4
  before do
5
5
  # disable all other checks
6
- PuppetLint.configuration.checks.reject{ |check|
6
+ PuppetLint.configuration.checks.reject do |check|
7
7
  check == :indent
8
- }.each do |check|
8
+ end.each do |check|
9
9
  PuppetLint.configuration.send("disable_#{check}")
10
10
  end
11
11
  end
12
12
 
13
13
  after do
14
14
  # re-enable other checks
15
- PuppetLint.configuration.checks.reject{ |check|
15
+ PuppetLint.configuration.checks.reject do |check|
16
16
  check == :indent
17
- }.each do |check|
17
+ end.each do |check|
18
18
  PuppetLint.configuration.send("enable_#{check}")
19
19
  end
20
20
  end
@@ -24,7 +24,7 @@ describe 'strict_indent' do
24
24
  context manifest do
25
25
  let(:code) { File.read(manifest) }
26
26
 
27
- it 'should detect no problems' do
27
+ it 'detects no problems' do
28
28
  expect(problems).to have(0).problems
29
29
  end
30
30
  end
@@ -34,7 +34,7 @@ describe 'strict_indent' do
34
34
  context manifest do
35
35
  let(:code) { File.read(manifest) }
36
36
 
37
- it 'should detect problems' do
37
+ it 'detects problems' do
38
38
  expect(problems).to have(1).problems
39
39
  end
40
40
  end
@@ -42,7 +42,7 @@ describe 'strict_indent' do
42
42
  end
43
43
 
44
44
  context 'comment after resource title.' do
45
- let(:code) {
45
+ let(:code) do
46
46
  <<-EOF.gsub(/^ {8}/, '')
47
47
  class (
48
48
  ) {
@@ -52,15 +52,15 @@ describe 'strict_indent' do
52
52
  }
53
53
  }
54
54
  EOF
55
- }
55
+ end
56
56
 
57
- it 'should detect 0 problems' do
57
+ it 'detects 0 problems' do
58
58
  expect(problems).to have(0).problems
59
59
  end
60
60
  end
61
61
 
62
62
  context 'invalid array indent' do
63
- let(:code) {
63
+ let(:code) do
64
64
  <<-EOF.gsub(/^ {8}/, '')
65
65
  class (
66
66
  ) {
@@ -71,22 +71,22 @@ describe 'strict_indent' do
71
71
  }
72
72
  }
73
73
  EOF
74
- }
74
+ end
75
75
 
76
- it 'should detect 1 problems' do
76
+ it 'detects 1 problems' do
77
77
  expect(problems).to have(1).problems
78
78
  end
79
79
  end
80
80
 
81
81
  context 'blank line at beginning of file' do
82
- let(:code) {
82
+ let(:code) do
83
83
  <<-EOF.gsub(/^ {8}/, '')
84
84
 
85
85
  class () {}
86
86
  EOF
87
- }
87
+ end
88
88
 
89
- it 'should detect 0 problems' do
89
+ it 'detects 0 problems' do
90
90
  expect(problems).to have(0).problems
91
91
  end
92
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-strict_indent-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2023-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -16,104 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '3'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '4'
22
+ version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: '3'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '4'
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.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.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: rspec-json_expectations
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: '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'
89
- - !ruby/object:Gem::Dependency
90
- name: rake
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- version: '0'
103
- - !ruby/object:Gem::Dependency
104
- name: simplecov
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - ">="
115
- - !ruby/object:Gem::Version
116
- version: '0'
32
+ version: '5'
117
33
  description: " Extends puppet-lint to ensure that your manifests follow a strict
118
34
  indentation pattern.\n"
119
35
  email: voxpupuli@groups.io
@@ -134,7 +50,7 @@ files:
134
50
  - spec/spec_helper.rb
135
51
  homepage: https://github.com/voxpupuli/puppet-lint-strict_indent-check
136
52
  licenses:
137
- - Mozilla 2.0
53
+ - MPL-2.0
138
54
  metadata: {}
139
55
  post_install_message:
140
56
  rdoc_options: []
@@ -144,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
60
  requirements:
145
61
  - - ">="
146
62
  - !ruby/object:Gem::Version
147
- version: '0'
63
+ version: 2.7.0
148
64
  required_rubygems_version: !ruby/object:Gem::Requirement
149
65
  requirements:
150
66
  - - ">="
@@ -155,11 +71,4 @@ rubygems_version: 3.2.33
155
71
  signing_key:
156
72
  specification_version: 4
157
73
  summary: puppet-lint strict indent check
158
- test_files:
159
- - spec/fixtures/fail/1.pp
160
- - spec/fixtures/fail/heredoc_extra.pp
161
- - spec/fixtures/fail/heredoc_unsuficient.pp
162
- - spec/fixtures/pass/1.pp
163
- - spec/fixtures/pass/heredoc.pp
164
- - spec/puppet-lint/plugins/check_strict_indent_spec.rb
165
- - spec/spec_helper.rb
74
+ test_files: []