puppet-lint-manifest_whitespace-check 0.1.2 → 0.1.4

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: d6c95fdd92713473387e0cb780ba993b73aac14c1b8a31ac3605cb211cb34413
4
- data.tar.gz: 51b93e74f8b2ce71082873f4023efabc673fd8a6144710341695efdc80c102cc
3
+ metadata.gz: 82fd48a0b533bc6357b7e250f945f8ab3f0ba80625a19fa060fde543bf854dae
4
+ data.tar.gz: 5289f75f1e16b08fb0b18c6798326017625d6a9b71cb061e9f020e4267630a45
5
5
  SHA512:
6
- metadata.gz: 1940d7236fab0350b6cf217c41a88228f50de795f8e68ca3b3d0da03289578fc83ffc4708c86d37ffd71f9c8b0b254be75121c6c311e43aef7d4acfc89950170
7
- data.tar.gz: e5cb33fa8ee74bb757fcab7cb333090b3e9770e909274ce313a51e5e1a382c60799893235f8a40d31fac1b21cf9c39b6ba4479765f75bd92e0a2563dc9e47bf9
6
+ metadata.gz: 4ff960cc339885dfbfa62823058381bb609ca8de39f1047837f2882efb325e176251dcec6f9786907b5fa14145e4f8ad0dfea52e942eadc6909ebc1f8f8f3dd1
7
+ data.tar.gz: 9a4f2cd1929e5ca731efb25894730e0ec793d4f2ebc9f3a46baa045deb9d6891e092402afe42acdd8cb83e6cfa808d7033fdb515d60360a4be1a7452e83f54dd
data/README.md CHANGED
@@ -19,9 +19,17 @@ gem 'puppet-lint-manifest_whitespace-check'
19
19
 
20
20
  This plugin provides a number of new checks to `puppet-lint`.
21
21
 
22
- ### manifest_whitespace_class_opening_curly_brace
22
+ ### manifest_whitespace_opening_bracket_after
23
23
 
24
- > There should be a single space before the opening curly brace of a class body.
24
+ > There should be a single space or single newline after an opening curly brace
25
+
26
+ Exceptions: other brackets or comma's
27
+
28
+ ### manifest_whitespace_opening_bracket_before
29
+
30
+ > There should be a single space before an opening bracket
31
+
32
+ Exceptions: other brackets
25
33
 
26
34
  Good examples:
27
35
 
@@ -35,6 +43,14 @@ class myclass (
35
43
  class myclass {
36
44
  # the body
37
45
  }
46
+
47
+ class myclass {
48
+ $value = [{ 'key' => 'value' }]
49
+
50
+ if somecondition {
51
+ class { 'someclass': }
52
+ }
53
+ }
38
54
  ```
39
55
 
40
56
  Bad examples:
@@ -57,6 +73,12 @@ class myclass
57
73
  {
58
74
  # the body
59
75
  }
76
+
77
+ class myclass {
78
+ if somecondition{
79
+ class{ 'someclass': }
80
+ }
81
+ }
60
82
  ```
61
83
 
62
84
  ### manifest_whitespace_missing_newline_end_of_file
@@ -26,46 +26,3 @@ PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_before) do
26
26
  problem[:token].value = ' '
27
27
  end
28
28
  end
29
-
30
- PuppetLint.new_check(:manifest_whitespace_inherits_name_single_space_after) do
31
- def check
32
- tokens.select { |token| token.type == :INHERITS }.each do |inherits_token|
33
- name_token = inherits_token.next_token_of(%i[NAME FUNCTION_NAME])
34
- next unless name_token
35
-
36
- next_token = name_token.next_token
37
- brace_token = name_token.next_token_of(%i[LPAREN LBRACE])
38
- next unless tokens.index(name_token) != tokens.index(brace_token) - 2 ||
39
- !is_single_space(next_token)
40
-
41
- notify(
42
- :error,
43
- message: 'there should be a single space between the class or resource name and the first brace',
44
- line: next_token.line,
45
- column: next_token.column,
46
- token: next_token,
47
- )
48
- end
49
- end
50
-
51
- def fix(problem)
52
- token = problem[:token]
53
- brace_token = token.prev_token.next_token_of(%i[LPAREN LBRACE])
54
-
55
- if token == brace_token
56
- add_token(tokens.index(brace_token), new_single_space)
57
- return
58
- end
59
-
60
- while token != brace_token
61
- unless %i[WHITESPACE INDENT NEWLINE].include?(token.type)
62
- raise PuppetLint::NoFix
63
- end
64
-
65
- remove_token(token)
66
- token = token.next_token
67
- end
68
-
69
- add_token(tokens.index(brace_token), new_single_space)
70
- end
71
- end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ PuppetLint.new_check(:manifest_whitespace_closing_brace_before) do
4
+ def check
5
+ tokens.select { |token| token.type == :RBRACE }.each do |brace_token|
6
+ prev_token = brace_token.prev_token
7
+ prev_code_token = brace_token.prev_code_token
8
+
9
+ next unless prev_token && prev_code_token
10
+ next if %i[LBRACE RBRACK RBRACE].include?(prev_token.type)
11
+
12
+ unless %i[LBRACE RBRACK RBRACE].include?(prev_code_token.type)
13
+ if is_single_space(prev_token) && tokens.index(prev_code_token) == tokens.index(brace_token) - 2
14
+ next
15
+ end
16
+ end
17
+
18
+ if prev_token.type == :INDENT
19
+ next if tokens.index(prev_code_token) == tokens.index(brace_token) - 3
20
+ end
21
+
22
+ if prev_token.type == :NEWLINE
23
+ next if tokens.index(prev_code_token) == tokens.index(brace_token) - 2
24
+ end
25
+
26
+ notify(
27
+ :error,
28
+ message: 'there should be a bracket or a single newline before a closing brace',
29
+ line: prev_code_token.next_token.line,
30
+ column: prev_code_token.next_token.column,
31
+ token: prev_code_token.next_token,
32
+ )
33
+ end
34
+ end
35
+
36
+ def fix(problem)
37
+ token = problem[:token]
38
+
39
+ next_token = token
40
+
41
+ until next_token.type == :RBRACE
42
+ if tokens[tokens.index(next_token)..-1].first(2).collect(&:type) == %i[NEWLINE RBRACE]
43
+ break
44
+ end
45
+
46
+ if tokens[tokens.index(next_token)..-1].first(3).collect(&:type) == %i[NEWLINE INDENT RBRACE]
47
+ break
48
+ end
49
+
50
+ remove_token(next_token)
51
+ next_token = next_token.next_token
52
+ end
53
+
54
+ if next_token.type == :RBRACE && !%i[LBRACE RBRACE RBRACK NEWLINE INDENT].include?(next_token.prev_token.type)
55
+ add_token(tokens.index(next_token), new_single_space)
56
+ end
57
+ end
58
+ end
59
+
60
+ PuppetLint.new_check(:manifest_whitespace_closing_brace_after) do
61
+ def check
62
+ tokens.select { |token| token.type == :RBRACE }.each do |brace_token|
63
+ next_token = brace_token.next_token
64
+
65
+ next unless next_token
66
+ next if after_bracket_tokens.include?(next_token.type)
67
+
68
+ if next_token.type == :WHITESPACE
69
+ next_code_token = brace_token.next_code_token
70
+ next unless next_code_token
71
+ next unless after_bracket_tokens.include?(next_code_token.type)
72
+ end
73
+
74
+ notify(
75
+ :error,
76
+ message: 'there should be either a bracket, comma, colon, closing quote or a newline after a closing brace, or whitespace and none of the aforementioned',
77
+ line: next_token.line,
78
+ column: next_token.column,
79
+ token: next_token,
80
+ )
81
+ end
82
+ end
83
+
84
+ def fix(problem)
85
+ token = problem[:token]
86
+
87
+ next_token = token
88
+
89
+ until %i[RBRACE RBRACK RPAREN COMMA NEWLINE].include?(next_token.type)
90
+ raise PuppetLint::NoFix if next_token.type != :WHITESPACE
91
+
92
+ remove_token(next_token)
93
+ next_token = next_token.next_token
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ PuppetLint.new_check(:manifest_whitespace_closing_bracket_before) do
4
+ def check
5
+ tokens.select { |token| token.type == :RBRACK }.each do |bracket_token|
6
+ prev_token = bracket_token.prev_token
7
+ next unless prev_token
8
+
9
+ prev_code_token = bracket_token.prev_code_token
10
+ next unless prev_code_token
11
+
12
+ next unless %i[NEWLINE INDENT WHITESPACE].include?(prev_token.type)
13
+
14
+ if prev_token.type == :INDENT
15
+ next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 3
16
+ end
17
+ if prev_token.type == :NEWLINE
18
+ next if tokens.index(prev_code_token) == tokens.index(bracket_token) - 2
19
+ end
20
+
21
+ notify(
22
+ :error,
23
+ message: 'there should be no whitespace or a single newline before a closing bracket',
24
+ line: prev_code_token.next_token.line,
25
+ column: prev_code_token.next_token.column,
26
+ token: prev_code_token.next_token,
27
+ )
28
+ end
29
+ end
30
+
31
+ def fix(problem)
32
+ token = problem[:token]
33
+ if token.type == :WHITESPACE
34
+ remove_token(token)
35
+ return
36
+ end
37
+
38
+ next_token = token.next_token
39
+ until next_token.type == :RBRACK
40
+ if next_token.type == :INDENT && next_token.next_token.type == :RBRACK
41
+ break
42
+ end
43
+
44
+ remove_token(next_token)
45
+ next_token = next_token.next_token
46
+ end
47
+ end
48
+ end
49
+
50
+ PuppetLint.new_check(:manifest_whitespace_closing_bracket_after) do
51
+ def check
52
+ tokens.select { |token| token.type == :RBRACK }.each do |bracket_token|
53
+ next_token = bracket_token.next_token
54
+
55
+ next unless next_token
56
+ next if after_bracket_tokens.include?(next_token.type)
57
+
58
+ if next_token.type == :WHITESPACE
59
+ next_code_token = bracket_token.next_code_token
60
+ next unless next_code_token
61
+ next unless after_bracket_tokens.include?(next_code_token.type)
62
+ end
63
+
64
+ notify(
65
+ :error,
66
+ message: 'there should be either a bracket, comma, colon, closing quote or a newline after a closing bracket, or whitespace and none of the aforementioned',
67
+ line: next_token.line,
68
+ column: next_token.column,
69
+ token: next_token,
70
+ )
71
+ end
72
+ end
73
+
74
+ def fix(problem)
75
+ token = problem[:token]
76
+
77
+ next_token = token
78
+
79
+ until %i[RBRACE RBRACK RPAREN COMMA NEWLINE].include?(next_token.type)
80
+ raise PuppetLint::NoFix if next_token.type != :WHITESPACE
81
+
82
+ remove_token(next_token)
83
+ next_token = next_token.next_token
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ PuppetLint.new_check(:manifest_whitespace_opening_brace_before) do
4
+ def check
5
+ tokens.select { |token| token.type == :LBRACE }.each do |brace_token|
6
+ prev_token = brace_token.prev_token
7
+ prev_code_token = brace_token.prev_code_token
8
+
9
+ next unless prev_token && prev_code_token
10
+ next if %i[LBRACK LBRACE COMMA].include?(prev_code_token.type)
11
+ next unless tokens.index(prev_code_token) != tokens.index(brace_token) - 2 ||
12
+ !is_single_space(prev_token)
13
+
14
+ notify(
15
+ :error,
16
+ message: 'there should be a single space before an opening brace',
17
+ line: brace_token.line,
18
+ column: brace_token.column,
19
+ token: brace_token,
20
+ )
21
+ end
22
+ end
23
+
24
+ def fix(problem)
25
+ token = problem[:token]
26
+ prev_token = token.prev_token
27
+ prev_code_token = token.prev_code_token
28
+
29
+ while prev_code_token != prev_token
30
+ unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
31
+ raise PuppetLint::NoFix
32
+ end
33
+
34
+ remove_token(prev_token)
35
+ prev_token = prev_token.prev_token
36
+ end
37
+
38
+ add_token(tokens.index(token), new_single_space)
39
+ end
40
+ end
41
+
42
+ PuppetLint.new_check(:manifest_whitespace_opening_brace_after) do
43
+ def check
44
+ tokens.select { |token| token.type == :LBRACE }.each do |brace_token|
45
+ next_token = brace_token.next_token
46
+
47
+ next unless next_token && !is_single_space(next_token)
48
+ next if %i[LBRACK LBRACE RBRACE].include?(next_token.type)
49
+
50
+ if next_token.type == :NEWLINE
51
+ next_token = next_token.next_token
52
+ next if next_token.type != :NEWLINE
53
+ end
54
+
55
+ notify(
56
+ :error,
57
+ message: 'there should be a single space or single newline after an opening brace',
58
+ line: next_token.line,
59
+ column: next_token.column,
60
+ token: next_token,
61
+ )
62
+ end
63
+ end
64
+
65
+ def fix(problem)
66
+ token = problem[:token]
67
+
68
+ if token.type == :WHITESPACE
69
+ token.value = ' '
70
+ return
71
+ end
72
+
73
+ if token.type == :NEWLINE
74
+ while token && token.type == :NEWLINE
75
+ remove_token(token)
76
+ token = token.next_token
77
+ end
78
+ return
79
+ end
80
+
81
+ add_token(tokens.index(token), new_single_space)
82
+ end
83
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ PuppetLint.new_check(:manifest_whitespace_opening_bracket_before) do
4
+ def check
5
+ tokens.select { |token| token.type == :LBRACK }.each do |bracket_token|
6
+ prev_token = bracket_token.prev_token
7
+ prev_code_token = bracket_token.prev_code_token
8
+
9
+ next unless prev_token && prev_code_token
10
+ next if %i[LBRACK LBRACE COMMA SEMIC].include?(prev_code_token.type)
11
+ next unless %i[WHITESPACE NEWLINE INDENT].include?(prev_token.type)
12
+ next unless tokens.index(prev_code_token) != tokens.index(bracket_token) - 2 ||
13
+ !is_single_space(prev_token)
14
+
15
+ notify(
16
+ :error,
17
+ message: 'there should be a single space before an opening bracket',
18
+ line: bracket_token.line,
19
+ column: bracket_token.column,
20
+ token: bracket_token,
21
+ )
22
+ end
23
+ end
24
+
25
+ def fix(problem)
26
+ token = problem[:token]
27
+ prev_token = token.prev_token
28
+ prev_code_token = token.prev_code_token
29
+
30
+ while prev_code_token != prev_token
31
+ unless %i[WHITESPACE INDENT NEWLINE].include?(prev_token.type)
32
+ raise PuppetLint::NoFix
33
+ end
34
+
35
+ remove_token(prev_token)
36
+ prev_token = prev_token.prev_token
37
+ end
38
+
39
+ add_token(tokens.index(token), new_single_space)
40
+ end
41
+ end
42
+
43
+ PuppetLint.new_check(:manifest_whitespace_opening_bracket_after) do
44
+ def check
45
+ tokens.select { |token| token.type == :LBRACK }.each do |bracket_token|
46
+ next_token = bracket_token.next_token
47
+
48
+ next unless next_token
49
+ next unless %i[WHITESPACE NEWLINE INDENT].include?(next_token.type)
50
+
51
+ if next_token.type == :NEWLINE
52
+ next_token = next_token.next_token
53
+ next if next_token.type != :NEWLINE
54
+ end
55
+
56
+ notify(
57
+ :error,
58
+ message: 'there should be no whitespace or a single newline after an opening bracket',
59
+ line: next_token.line,
60
+ column: next_token.column,
61
+ token: next_token,
62
+ )
63
+ end
64
+ end
65
+
66
+ def fix(problem)
67
+ token = problem[:token]
68
+
69
+ if token.type == :WHITESPACE
70
+ remove_token(token)
71
+ return
72
+ end
73
+
74
+ while token.next_token.type == :NEWLINE || (token.next_token.type == :INDENT && token.next_token.next_token.type != :NEWLINE)
75
+ remove_token(token)
76
+ token = token.next_token
77
+ end
78
+ end
79
+ end