Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 210 to skip non-number values #69

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion saltlint/rules/YamlHasOctalValueRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class YamlHasOctalValueRule(SaltLintRule):
tags = ['formatting']
version_added = 'v0.0.6'

bracket_regex = re.compile(r": (?<!['\"])0+[0-9]\d*(?!['\"])")
bracket_regex = re.compile(r"(?<=:)\s{0,}0[0-9]{1,}\s{0,}((?={#)|(?=#)|(?=$))")

def match(self, file, line):
return self.bracket_regex.search(line)
34 changes: 24 additions & 10 deletions tests/unit/TestYamlHasOctalValueRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests import RunFromText


GOOD_NUMBER_LINE = '''
GOOD_NUMBER_STATE = '''
testdirectory:
file.recurse:
- name: /tmp/directory
Expand All @@ -22,29 +22,43 @@
- name: /tmp/directory02
- file_mode: 0
- dir_mode: "0775"

# Non-number values should be skipped, for more information see:
# https://github.com/warpnet/salt-lint/issues/68
apache_disable_default_site:
apache_site.disabled:
- name: 000-default
'''

BAD_NUMBER_LINE = '''
BAD_NUMBER_STATE = '''
# Unquoted octal values with leading zero's.
testdirectory:
file.recurse:
- name: /tmp/directory
- file_mode: 00
- dir_mode: 0700

# Unquoted octal values with leading zero's followed by a YAML of Jinja
# comment.
testdirectory:
file.recurse:
- name: /tmp/directory001 # shouldn't fail
- mode: 0 # shouldn't fail
- file_mode: 00 # should fail
- dir_mode: 0700 # should fail
- name: /tmp/directory
- file_mode: 00 # COMMENT
- dir_mode:0700{# JINJA COMMENT #}
'''

class TestFileModeLeadingZeroRule(unittest.TestCase):
class TestYamlHasOctalValueRule(unittest.TestCase):
collection = RulesCollection()

def setUp(self):
self.collection.register(YamlHasOctalValueRule())

def test_statement_positive(self):
runner = RunFromText(self.collection)
results = runner.run_state(GOOD_NUMBER_LINE)
results = runner.run_state(GOOD_NUMBER_STATE)
self.assertEqual(0, len(results))

def test_statement_negative(self):
runner = RunFromText(self.collection)
results = runner.run_state(BAD_NUMBER_LINE)
self.assertEqual(2, len(results))
results = runner.run_state(BAD_NUMBER_STATE)
self.assertEqual(4, len(results))