puppet-lint 2.3.5 → 2.3.6

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
  SHA1:
3
- metadata.gz: c2f7f4e8237599a2215c6e0b7b80126c6ed43cc2
4
- data.tar.gz: 91aa136ffbc1370e60d999d9d0f591df2fbbb0f3
3
+ metadata.gz: 299ce7a01574b87c32ac76798f691800ef27fc2c
4
+ data.tar.gz: 4f3f73a44040dbfc0d6f3b2bfb6535b000d3bdf1
5
5
  SHA512:
6
- metadata.gz: e109be5cd7d30e0660fbc0b839d69e1bcd19870b12a31889076999deb2a0d7fe8519e28e874be556c6ebe9345a5df6a968acbf0c87ba1438d14f63bbb836264e
7
- data.tar.gz: 8d65ef648c28a084e13b2450f0bebb69e2ee9ca937a6fee09ad5762c309da27f2496fbb7adf5b6bcc3117e3a2b4a65b790681073ab3956661a508d7586503fcf
6
+ metadata.gz: 920ee6f31d30184faf6c288902f53387bba45df38976a854c7e837647520e8162e140303fad43a6b7de70be4c1b3efd1cede9fc2f93b377e0773442f66fe239d
7
+ data.tar.gz: ab9bb35509a161c70c73b4880b737e39416884d6709c166df95817b3fd6f6efce5329ca856f50644705907c776b631c61f658ecfa2bae1c7972e79310fc45cb4
@@ -1,5 +1,25 @@
1
1
  # Change Log
2
2
 
3
+ ## [2.3.6](https://github.com/rodjek/puppet-lint/tree/2.3.6) (2018-07-09)
4
+ [Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.3.5...2.3.6)
5
+
6
+ **Fixed bugs:**
7
+
8
+ - --fix does not work with require arrows in certain situations [\#799](https://github.com/rodjek/puppet-lint/issues/799)
9
+ - Error with --fix when no whitespace before hashrocket in resource attribute list [\#798](https://github.com/rodjek/puppet-lint/issues/798)
10
+ - puppet-lint --fix strips comments when fixing arrow\_on\_right\_operand\_line [\#792](https://github.com/rodjek/puppet-lint/issues/792)
11
+ - Crash report, reason unclear [\#781](https://github.com/rodjek/puppet-lint/issues/781)
12
+ - crash in fix mode with multiple trailing arrows [\#776](https://github.com/rodjek/puppet-lint/issues/776)
13
+ - Error negative argument if opening brace on the same line and following element longer [\#771](https://github.com/rodjek/puppet-lint/issues/771)
14
+ - ArgumentError: negative argument [\#723](https://github.com/rodjek/puppet-lint/issues/723)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - \(\#771\) Handle arrow alignment when arrow column \< opening brace column... [\#819](https://github.com/rodjek/puppet-lint/pull/819) ([rodjek](https://github.com/rodjek))
19
+ - Less aggressive fix method for arrow\_on\_right\_operand\_line [\#817](https://github.com/rodjek/puppet-lint/pull/817) ([rodjek](https://github.com/rodjek))
20
+ - Check if token still exists before fixing trailing\_whitespace [\#816](https://github.com/rodjek/puppet-lint/pull/816) ([rodjek](https://github.com/rodjek))
21
+ - Run all the checks before fixing problems [\#815](https://github.com/rodjek/puppet-lint/pull/815) ([rodjek](https://github.com/rodjek))
22
+
3
23
  ## [2.3.5](https://github.com/rodjek/puppet-lint/tree/2.3.5) (2018-03-27)
4
24
  [Full Changelog](https://github.com/rodjek/puppet-lint/compare/2.3.4...2.3.5)
5
25
 
@@ -14,6 +14,10 @@ environment:
14
14
  - RUBY_VERSION: 23-x64
15
15
  - RUBY_VERSION: 24-x64
16
16
 
17
+ matrix:
18
+ allow_failures:
19
+ - RUBY_VERSION: 193
20
+
17
21
  install:
18
22
  - SET PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
19
23
  - SET LOG_SPEC_ORDER=true
@@ -54,11 +54,15 @@ class PuppetLint::Checks
54
54
  def run(fileinfo, data)
55
55
  load_data(fileinfo, data)
56
56
 
57
+ checks_run = []
57
58
  enabled_checks.each do |check|
58
59
  klass = PuppetLint.configuration.check_object[check].new
59
60
  # FIXME: shadowing #problems
60
61
  problems = klass.run
62
+ checks_run << [klass, problems]
63
+ end
61
64
 
65
+ checks_run.each do |klass, problems|
62
66
  if PuppetLint.configuration.fix
63
67
  @problems.concat(klass.fix_problems)
64
68
  else
@@ -9,7 +9,7 @@ PuppetLint.new_check(:arrow_on_right_operand_line) do
9
9
 
10
10
  notify(
11
11
  :warning,
12
- :message => 'arrow should be on the right operand\'s line',
12
+ :message => "arrow should be on the right operand's line",
13
13
  :line => token.line,
14
14
  :column => token.column,
15
15
  :token => token
@@ -18,27 +18,22 @@ PuppetLint.new_check(:arrow_on_right_operand_line) do
18
18
  end
19
19
 
20
20
  def fix(problem)
21
- token = problem[:token]
21
+ return if problem[:token].nil?
22
22
 
23
- prev_code_token = token.prev_code_token
24
- next_code_token = token.next_code_token
25
- indent_token = prev_code_token.prev_token_of(:INDENT)
23
+ arrow_token = problem[:token]
24
+ left_operand_token = arrow_token.prev_code_token
25
+ right_operand_token = arrow_token.next_code_token
26
26
 
27
- # Delete all tokens between the two code tokens the anchor is between
28
- temp_token = prev_code_token
29
- while (temp_token = temp_token.next_token) && (temp_token != next_code_token)
30
- remove_token(temp_token) unless temp_token == token
31
- end
32
-
33
- # Insert a newline and an indent before the arrow
34
- index = tokens.index(token)
35
- newline_token = PuppetLint::Lexer::Token.new(:NEWLINE, "\n", token.line, 0)
36
- add_token(index, newline_token)
37
- add_token(index + 1, indent_token) if indent_token
27
+ # Move arrow token to just before the right operand
28
+ remove_token(arrow_token)
29
+ right_operand_index = tokens.index(right_operand_token)
30
+ add_token(right_operand_index, arrow_token)
31
+ whitespace_token = PuppetLint::Lexer::Token.new(:WHITESPACE, ' ', right_operand_token.line, 3)
32
+ add_token(right_operand_index + 1, whitespace_token)
38
33
 
39
- # Insert a space between the arrow and the following code token
40
- index = tokens.index(token)
41
- whitespace_token = PuppetLint::Lexer::Token.new(:WHITESPACE, ' ', token.line, 3)
42
- add_token(index + 1, whitespace_token)
34
+ # Remove trailing whitespace after left operand (if it exists)
35
+ return unless left_operand_token.next_token.type == :WHITESPACE
36
+ trailing_whitespace_token = left_operand_token.next_token
37
+ remove_token(trailing_whitespace_token) if [:NEWLINE, :WHITESPACE].include?(trailing_whitespace_token.next_token.type)
43
38
  end
44
39
  end
@@ -25,7 +25,6 @@ PuppetLint.new_check(:arrow_alignment) do
25
25
 
26
26
  resource_tokens.each do |token|
27
27
  if token.type == :FARROW
28
- (level_tokens[level_idx] ||= []) << token
29
28
  param_token = token.prev_code_token
30
29
 
31
30
  if param_token.type == :DQPOST
@@ -48,12 +47,18 @@ PuppetLint.new_check(:arrow_alignment) do
48
47
  end
49
48
  end
50
49
 
51
- this_arrow_column = param_column[level_idx] + param_length + 1
50
+ if (level_tokens[level_idx] ||= []).any? { |t| t.line == token.line }
51
+ this_arrow_column = param_column[level_idx] + param_length + 1
52
+ else
53
+ this_arrow_column = param_token.column + param_token.to_manifest.length
54
+ this_arrow_column += 1 unless param_token.type == :DQPOST
55
+ end
52
56
 
53
57
  if arrow_column[level_idx] < this_arrow_column
54
58
  arrow_column[level_idx] = this_arrow_column
55
59
  end
56
60
 
61
+ (level_tokens[level_idx] ||= []) << token
57
62
  elsif token.type == :LBRACE
58
63
  level_idx += 1
59
64
  arrow_column << 0
@@ -96,12 +101,21 @@ PuppetLint.new_check(:arrow_alignment) do
96
101
  # indent the parameter to the correct depth
97
102
  problem[:token].prev_code_token.prev_token.type = :INDENT
98
103
  problem[:token].prev_code_token.prev_token.value = ' ' * problem[:newline_indent]
104
+
105
+ end_param_idx = tokens.index(problem[:token].prev_code_token)
106
+ start_param_idx = tokens.index(problem[:token].prev_token_of([:INDENT, :NEWLINE]))
107
+ param_length = tokens[start_param_idx..end_param_idx].map { |r| r.to_manifest.length }.reduce(0) { |sum, x| sum + x } + 1
108
+ new_ws_len = problem[:arrow_column] - param_length
109
+ else
110
+ new_ws_len = if problem[:token].prev_token.type == :WHITESPACE
111
+ problem[:token].prev_token.to_manifest.length
112
+ else
113
+ 0
114
+ end
115
+ new_ws_len += (problem[:arrow_column] - problem[:token].column)
99
116
  end
100
117
 
101
- end_param_idx = tokens.index(problem[:token].prev_code_token)
102
- start_param_idx = tokens.index(problem[:token].prev_token_of([:INDENT, :NEWLINE])) + 1
103
- param_length = tokens[start_param_idx..end_param_idx].map { |r| r.to_manifest.length }.reduce(0) { |sum, x| sum + x }
104
- new_ws_len = (problem[:arrow_column] - (problem[:newline_indent] + param_length + 1))
118
+ raise PuppetLint::NoFix if new_ws_len < 0
105
119
  new_ws = ' ' * new_ws_len
106
120
 
107
121
  if problem[:token].prev_token.type == :WHITESPACE
@@ -20,6 +20,8 @@ PuppetLint.new_check(:trailing_whitespace) do
20
20
  end
21
21
 
22
22
  def fix(problem)
23
+ return if problem[:token].nil?
24
+
23
25
  prev_token = problem[:token].prev_token
24
26
  next_token = problem[:token].next_token
25
27
  prev_token.next_token = next_token
@@ -1,3 +1,3 @@
1
1
  class PuppetLint
2
- VERSION = '2.3.5'.freeze
2
+ VERSION = '2.3.6'.freeze
3
3
  end
@@ -1,22 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'arrow_on_right_operand_line' do
4
+ msg = "arrow should be on the right operand's line"
5
+
4
6
  { 'chain' => '->', 'subscribe chain' => '~>' }.each do |name, operator|
5
7
  context "#{name} operator" do
6
8
  context 'both operands on same line' do
7
- let(:code) { "Package['httpd'] #{operator} Service['httpd']" }
9
+ let(:code) do
10
+ <<-END
11
+ Package['httpd'] #{operator} Service['httpd']
12
+ END
13
+ end
8
14
 
9
- it { expect(problems).to have(0).problems }
15
+ it 'should not detect any problems' do
16
+ expect(problems).to have(0).problems
17
+ end
10
18
  end
11
19
 
12
20
  context 'arrow on the line of left operand' do
13
21
  let(:code) do
14
- "
22
+ <<-END
15
23
  Package['httpd'] #{operator}
16
- Service['httpd']"
24
+ Service['httpd']
25
+ END
17
26
  end
18
27
 
19
- it { expect(problems).to have(1).problems }
28
+ it 'should detect a problem' do
29
+ expect(problems).to have(1).problem
30
+ end
31
+
32
+ it 'should create a warning' do
33
+ expect(problems).to contain_warning(msg).on_line(1).in_column(31)
34
+ end
20
35
 
21
36
  context 'with fix enabled' do
22
37
  before do
@@ -28,12 +43,19 @@ describe 'arrow_on_right_operand_line' do
28
43
  end
29
44
 
30
45
  let(:fixed) do
31
- "
32
- Package['httpd']
33
- #{operator} Service['httpd']"
46
+ <<-END.gsub(%r{^ {2}}, '')
47
+ Package['httpd']
48
+ #{operator} Service['httpd']
49
+ END
50
+ end
51
+
52
+ it 'should fix the problem' do
53
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(31)
34
54
  end
35
55
 
36
- it { expect(manifest).to eq(fixed) }
56
+ it 'should move the arrow to before the right operand' do
57
+ expect(manifest).to eq(fixed)
58
+ end
37
59
  end
38
60
  end
39
61
 
@@ -45,7 +67,99 @@ describe 'arrow_on_right_operand_line' do
45
67
  END
46
68
  end
47
69
 
48
- it { expect(problems).to have(0).problems }
70
+ it 'should not detect any problems' do
71
+ expect(problems).to have(0).problems
72
+ end
73
+ end
74
+
75
+ context 'arrow on the line of left operand with comment in between' do
76
+ let(:code) do
77
+ <<-END
78
+ Package['httpd'] #{operator}
79
+
80
+ # a comment
81
+ # another comment
82
+ Service['httpd']
83
+ END
84
+ end
85
+
86
+ it 'should detect a problem' do
87
+ expect(problems).to have(1).problem
88
+ end
89
+
90
+ it 'should create a warning' do
91
+ expect(problems).to contain_warning(msg).on_line(1).in_column(30)
92
+ end
93
+
94
+ context 'with fix enabled' do
95
+ before(:each) do
96
+ PuppetLint.configuration.fix = true
97
+ end
98
+
99
+ after(:each) do
100
+ PuppetLint.configuration.fix = false
101
+ end
102
+
103
+ let(:fixed) do
104
+ <<-END.gsub(%r{^ {2}}, '')
105
+ Package['httpd']
106
+
107
+ # a comment
108
+ # another comment
109
+ #{operator} Service['httpd']
110
+ END
111
+ end
112
+
113
+ it 'should fix the problem' do
114
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(30)
115
+ end
116
+
117
+ it 'should move the arrow to before the right operand' do
118
+ expect(manifest).to eq(fixed)
119
+ end
120
+ end
121
+ end
122
+
123
+ context 'arrow on the line of the left operand with a comment following the arrow' do
124
+ let(:code) do
125
+ <<-END
126
+ Package['httpd'] #{operator} # something
127
+ Service['httpd']
128
+ END
129
+ end
130
+
131
+ it 'should detect a problem' do
132
+ expect(problems).to have(1).problem
133
+ end
134
+
135
+ it 'should create a warning' do
136
+ expect(problems).to contain_warning(msg).on_line(1).in_column(30)
137
+ end
138
+
139
+ context 'with fix enabled' do
140
+ before(:each) do
141
+ PuppetLint.configuration.fix = true
142
+ end
143
+
144
+ after(:each) do
145
+ PuppetLint.configuration.fix = false
146
+ end
147
+
148
+ let(:fixed) do
149
+ <<-END.gsub(%r{^ {2}}, '')
150
+ Package['httpd'] # something
151
+ #{operator} Service['httpd']
152
+ END
153
+ end
154
+
155
+ it 'should fix the problem' do
156
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(30)
157
+ end
158
+
159
+ it 'should move the arrow to before the right operand' do
160
+ expect(manifest).to eq(fixed)
161
+ end
162
+ end
49
163
  end
50
164
  end
51
165
  end
@@ -967,5 +967,42 @@ describe 'arrow_alignment' do
967
967
  expect(manifest).to eq(fixed)
968
968
  end
969
969
  end
970
+
971
+ context 'negative argument' do
972
+ let(:code) do
973
+ <<-END
974
+ res { 'a':
975
+ x => { 'a' => '',
976
+ 'ab' => '',
977
+ }
978
+ }
979
+ END
980
+ end
981
+
982
+ # TODO: This is not the desired behaviour, but adjusting the check to
983
+ # properly format the hashes will need to wait until a major version
984
+ # bump.
985
+ let(:fixed) do
986
+ <<-END
987
+ res { 'a':
988
+ x => { 'a' => '',
989
+ 'ab' => '',
990
+ }
991
+ }
992
+ END
993
+ end
994
+
995
+ it 'should detect a problem' do
996
+ expect(problems).to have(1).problem
997
+ end
998
+
999
+ it 'should fix the problems' do
1000
+ expect(problems).to contain_fixed(format(msg, 24, 20)).on_line(3).in_column(20)
1001
+ end
1002
+
1003
+ it 'should realign the arrows' do
1004
+ expect(manifest).to eq(fixed)
1005
+ end
1006
+ end
970
1007
  end
971
1008
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.5
4
+ version: 2.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-27 00:00:00.000000000 Z
11
+ date: 2018-07-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Checks your Puppet manifests against the Puppetlabs