salt-lint 0.1.1 → 0.1.2
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 +4 -4
- data/.gitignore +2 -1
- data/Gemfile +4 -2
- data/README.md +5 -2
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +7 -0
- data/doc/list_tests.md +47 -0
- data/lib/salt-lint/actions.rb +2 -1
- data/lib/salt-lint/tests.rb +26 -12
- data/lib/salt-lint/version.rb +1 -1
- data/shippable.yml +4 -0
- data/spec/spec_helper.rb +3 -2
- data/spec/tests_spec.rb +8 -0
- data/tests/file_with_multiple_errors.sls +4 -1
- data/tests/well_formatted_top.sls +2 -0
- metadata +4 -2
- data/tests/.well_formatted_top.sls.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fe2637de60ccfaa599fdacd992bc4a82a52f9fb
|
4
|
+
data.tar.gz: a4c720a812c7a64c6f3ada177c1db9ec11e1af15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04d2acece330ecdae9ae4d7cd677891a5fc1cccf8be3166b7523d2b1f9ec1a5a8b5f017a4405ebfc013df0ddcbc8ec70c29153c123675644db9d47d6f915c459
|
7
|
+
data.tar.gz: 82c711e2eef7ff31ef8bf39b354a716b11d9f76391e4492ea885496642d8d89746ad2d869329be275a7f960b0848f79b3512b160c9be6ffee374210b665a7e3a
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
Linter for Salt configuration management.
|
4
4
|
|
5
|
-
[](https://app.shippable.com/projects/551cfc825ab6cc1352b491b3/builds/latest)
|
6
|
-
[](https://app.shippable.com/projects/551cfc825ab6cc1352b491b3/builds/latest)
|
5
|
+
Master: [](https://app.shippable.com/projects/551cfc825ab6cc1352b491b3/builds/latest)
|
6
|
+
Development: [](https://app.shippable.com/projects/551cfc825ab6cc1352b491b3/builds/latest)
|
7
7
|
|
8
8
|
|
9
9
|
[](http://badge.fury.io/rb/salt-lint)
|
10
10
|
[](https://codeclimate.com/github/lukaszraczylo/salt-lint)
|
11
11
|
[](https://gratipay.com/lukaszraczylo/)
|
12
12
|
|
13
|
+
## Documentation:
|
14
|
+
Please see [documentation](doc/list_tests.md) to interpret any results returned.
|
15
|
+
|
13
16
|
## Do not use it until version >= 0.5
|
data/doc/list_tests.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Salt-lint tests
|
2
|
+
|
3
|
+
* [Using double quotes with no variables](#Using double quotes with no variables)
|
4
|
+
* [Line length above 80 characters](#Line length above 80 characters)
|
5
|
+
* [Found single line declaration](#Found single line declaration)
|
6
|
+
* [No newline at the end of the file](#No newline at the end of the file)
|
7
|
+
* [Trailing whitespace character found](#Trailing whitespace character found)
|
8
|
+
|
9
|
+
### Using double quotes with no variables
|
10
|
+
In general - it's a bad idea. All the strings which does not contain dynamic content ( variables ) should use single quote instead of double.
|
11
|
+
|
12
|
+
##### Bad
|
13
|
+
```
|
14
|
+
dev:
|
15
|
+
"*"
|
16
|
+
```
|
17
|
+
|
18
|
+
##### Correct
|
19
|
+
```
|
20
|
+
dev:
|
21
|
+
'*'
|
22
|
+
```
|
23
|
+
|
24
|
+
### Line length above 80 characters
|
25
|
+
As a 'standard code width limit' and for historical reasons - [IBM punch card](http://en.wikipedia.org/wiki/Punched_card) had exactly 80 columns.
|
26
|
+
|
27
|
+
### Found single line declaration
|
28
|
+
Avoid extending your code by adding single-line declarations. It makes your code much cleaner and easier to parse / grep while searching for those declarations.
|
29
|
+
|
30
|
+
##### Bad
|
31
|
+
```
|
32
|
+
python:
|
33
|
+
pkg:
|
34
|
+
- installed
|
35
|
+
```
|
36
|
+
|
37
|
+
##### Correct
|
38
|
+
```
|
39
|
+
python:
|
40
|
+
pkg.installed
|
41
|
+
```
|
42
|
+
|
43
|
+
### No newline at the end of the file
|
44
|
+
Each line should be terminated in a newline character, including the last one. Some programs have problems processing the last line of a file if it isn't newline terminated. [Stackoverflow thread](http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline)
|
45
|
+
|
46
|
+
### Trailing whitespace character found
|
47
|
+
Trailing whitespaces take more spaces than necessary, any regexp based searches won't return lines as a result due to trailing whitespace(s).
|
data/lib/salt-lint/actions.rb
CHANGED
@@ -6,10 +6,11 @@ module SaltLint
|
|
6
6
|
def self.check_rules(f)
|
7
7
|
$invalid_yaml = Hash.new
|
8
8
|
$invalid_newline = Hash.new
|
9
|
+
$invalid_oneword = Hash.new
|
9
10
|
|
10
11
|
checks_went_fine = true
|
11
12
|
Printer.print('debug', "Checking file: #{f}", 5)
|
12
|
-
test_suite_methods = SaltLint::Tests.methods(false).sort
|
13
|
+
test_suite_methods = SaltLint::Tests.methods(false).sort - [ :check_for_regexp ]
|
13
14
|
line_counter = 1
|
14
15
|
File.readlines(f).each do |l|
|
15
16
|
test_suite_methods.each do |m|
|
data/lib/salt-lint/tests.rb
CHANGED
@@ -4,13 +4,28 @@ module SaltLint
|
|
4
4
|
# Main class for all the tests.
|
5
5
|
class Tests
|
6
6
|
|
7
|
-
#
|
8
|
-
def self.
|
7
|
+
# Helper: Checking for whitespaces
|
8
|
+
def self.check_for_regexp(line_number, line, file, regex, debug_msg, warning_msg)
|
9
9
|
is_ok = true
|
10
|
-
Printer.print('debug',
|
11
|
-
line.match(
|
10
|
+
Printer.print('debug', debug_msg, 5)
|
11
|
+
line.match(regex) ? is_ok = false : nil
|
12
12
|
if ! is_ok
|
13
|
-
Printer.print('warning',
|
13
|
+
Printer.print('warning', warning_msg)
|
14
|
+
end
|
15
|
+
return is_ok
|
16
|
+
end
|
17
|
+
|
18
|
+
# Test content: Check context and block all the single-word declarations
|
19
|
+
def self.check_if_single_word_declaration(line_number, line, file)
|
20
|
+
is_ok = true
|
21
|
+
Printer.print('debug', "Looking for single word declarations in #{file}", 5)
|
22
|
+
if line =~ /(pkg|file|service):\n/
|
23
|
+
f = File.readlines(file)[line_number-1..line_number+2]
|
24
|
+
( f[2] =~ /^\n$/ && f[1] =~ /- \w+\n$/ ) ? is_ok = true : is_ok = false
|
25
|
+
if ! $invalid_oneword.has_key?(file) && is_ok == false
|
26
|
+
Printer.print('warning', "Found single line declaration in #{file}:#{line_number-1}-#{line_number+2}")
|
27
|
+
$invalid_oneword[file] = is_ok
|
28
|
+
end
|
14
29
|
end
|
15
30
|
return is_ok
|
16
31
|
end
|
@@ -54,16 +69,15 @@ module SaltLint
|
|
54
69
|
return is_ok
|
55
70
|
end
|
56
71
|
|
72
|
+
# Test content: Checking given line for trailing whitespaces.
|
73
|
+
def self.check_trailing_whitespace(line_number, line, file)
|
74
|
+
check_for_regexp(line_number, line, file, /[ \t]+$/, "Checking for trailing whitespaces: #{line_number}", "Trailing whitespace character found: #{file}:#{line_number}")
|
75
|
+
end
|
76
|
+
|
57
77
|
# Test content: Checking if given line contains double quoted content without
|
58
78
|
# variable.
|
59
79
|
def self.check_double_quotes(line_number, line, file)
|
60
|
-
|
61
|
-
Printer.print('debug', "Checking for double quotes: #{line_number}", 5)
|
62
|
-
line.match(/\"(?!{+).*(?!}+)\"/) ? is_ok = false : nil
|
63
|
-
if ! is_ok
|
64
|
-
Printer.print('warning', "Using double quotes with no variables: #{file}:#{line_number}")
|
65
|
-
end
|
66
|
-
return is_ok
|
80
|
+
check_for_regexp(line_number, line, file, /\"(?!{+).*(?!}+)\"/, "Checking for double quotes: #{line_number}", "Using double quotes with no variables: #{file}:#{line_number}")
|
67
81
|
end
|
68
82
|
end
|
69
83
|
end
|
data/lib/salt-lint/version.rb
CHANGED
data/shippable.yml
CHANGED
@@ -2,6 +2,10 @@ language: ruby
|
|
2
2
|
install:
|
3
3
|
- bundle install
|
4
4
|
|
5
|
+
env:
|
6
|
+
global:
|
7
|
+
- secure: bFWu5rjnllXLSI7EqWqlvOQZ6mpKMv3RnFgq9DFM9aeCmkrd5tr5hH+SQDuX9W5okJDoytJX60xPcDtVShabgtTPcadEl4bSjgRgG+1Uof33TmNzhlLRBpiZ6auOtWxW3wHqUt9g7YNuj4/wFstdVnud7c8zBvClsy32V4KNrrUdhLl0Qyb2ULv82V1yBdgQ2wESdAa0La5OoP43+qTkD3lm8Z9D/X3qDJcKT59ylolnBwi25XQUDa+4v5YbC2zUK+HUyayNLgH7Rqc1tLYrQv6a1qogwE0yPRChd7Ig+y73MqRkWmCts6kTpkpOpKLaFW3sMxrwsftOhkZ4ns2GnQ==
|
8
|
+
|
5
9
|
notifications:
|
6
10
|
email:
|
7
11
|
recipients:
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
|
4
|
-
|
4
|
+
|
5
5
|
require 'rspec'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'salt-lint'
|
6
8
|
require 'aruba/rspec'
|
7
9
|
require 'pathname'
|
8
|
-
require 'ostruct'
|
9
10
|
|
10
11
|
require 'salt-lint/printer'
|
11
12
|
require 'salt-lint/actions'
|
data/spec/tests_spec.rb
CHANGED
@@ -29,4 +29,12 @@ describe 'Tests suite checks if' do
|
|
29
29
|
it 'won\'t allow to forget about newline at the end of the file' do
|
30
30
|
expect(SaltLint::Tests.check_for_no_newline(0, 0, test_file_bad)).to eq false
|
31
31
|
end
|
32
|
+
|
33
|
+
it 'won\'t allow to single word declarations' do
|
34
|
+
expect(SaltLint::Tests.check_if_single_word_declaration(5, "pkg:\n", test_file_bad)).to eq false
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'will allow condensed declarations' do
|
38
|
+
expect(SaltLint::Tests.check_if_single_word_declaration(5, "pkg.installed\n", test_file_good)).to eq true
|
39
|
+
end
|
32
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salt-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukasz Raczylo
|
@@ -112,6 +112,9 @@ files:
|
|
112
112
|
- README.md
|
113
113
|
- Rakefile
|
114
114
|
- bin/salt-lint
|
115
|
+
- coverage/.last_run.json
|
116
|
+
- coverage/.resultset.json
|
117
|
+
- doc/list_tests.md
|
115
118
|
- lib/salt-lint.rb
|
116
119
|
- lib/salt-lint/actions.rb
|
117
120
|
- lib/salt-lint/options.rb
|
@@ -125,7 +128,6 @@ files:
|
|
125
128
|
- spec/files_spec.rb
|
126
129
|
- spec/spec_helper.rb
|
127
130
|
- spec/tests_spec.rb
|
128
|
-
- tests/.well_formatted_top.sls.swp
|
129
131
|
- tests/file_with_multiple_errors.sls
|
130
132
|
- tests/non_yaml_file.sls
|
131
133
|
- tests/well_formatted_top.sls
|
Binary file
|