From ec4e8ffd1516783c146b145efcb2f131971dc1ae Mon Sep 17 00:00:00 2001 From: nicholasmhughes Date: Sun, 5 Feb 2023 13:13:03 -0500 Subject: [PATCH 1/3] fix octal rule for time format --- saltlint/rules/YamlHasOctalValueRule.py | 9 ++++++++- tests/unit/TestYamlHasOctalValueRule.py | 13 ++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/saltlint/rules/YamlHasOctalValueRule.py b/saltlint/rules/YamlHasOctalValueRule.py index 2001e49..389b96d 100644 --- a/saltlint/rules/YamlHasOctalValueRule.py +++ b/saltlint/rules/YamlHasOctalValueRule.py @@ -19,5 +19,12 @@ class YamlHasOctalValueRule(Rule): bracket_regex = re.compile(r"^[^:]+:\s{0,}0[0-9]{1,}\s{0,}((?={#)|(?=#)|(?=$))") + exclude_regex = re.compile(r"[ T]\d\d:\d\d(?:[: ]|$)") + def match(self, file, line): - return self.bracket_regex.search(line) + found = self.bracket_regex.search(line) + if found: + exc = self.exclude_regex.search(found.group(0)) + if exc: + return None + return found diff --git a/tests/unit/TestYamlHasOctalValueRule.py b/tests/unit/TestYamlHasOctalValueRule.py index e03fc44..604d64c 100644 --- a/tests/unit/TestYamlHasOctalValueRule.py +++ b/tests/unit/TestYamlHasOctalValueRule.py @@ -31,9 +31,20 @@ # MAC addresses shouldn't be matched, for more information see: # https://github.com/warpnet/salt-lint/issues/202 -infoblox_remove_record: +infoblox_remove_record1: infoblox_host_record.absent: - mac: 4c:f2:d3:1b:2e:05 + +infoblox_remove_record2: + infoblox_host_record.absent: + - mac: 05:f2:d3:1b:2e:4c + +# time values should not trigger this rule +some_calendar_entry: + file.managed: + - name: /tmp/my_unit_file + - contents: | + oncalendar=Sun 18:00 ''' BAD_NUMBER_STATE = ''' From f738ccda8eff24170c72d015329a225d88c9b83d Mon Sep 17 00:00:00 2001 From: Roald Nefs Date: Wed, 3 Jan 2024 18:54:34 +0100 Subject: [PATCH 2/3] docs: add changelog entry Signed-off-by: Roald Nefs --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 979daca..f031905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added - Add Python 3.12 support ([#315](https://github.com/warpnet/salt-lint/pull/315)). +### Fixed +- Ignore false positive result in rule 210 ([#303](https://github.com/warpnet/salt-lint/pull/303)). + ## [0.9.2] (2023-02-09) ### Fixed - Ensure version identification adheres to [PEP440](https://peps.python.org/pep-0440/) ([!304](https://github.com/warpnet/salt-lint/issues/304)) From ee39608cdf56242d92ca684c24fd7a2c63a5685e Mon Sep 17 00:00:00 2001 From: Roald Nefs Date: Wed, 3 Jan 2024 19:01:16 +0100 Subject: [PATCH 3/3] feat: simplify YamlHasOctalValueRule rule Signed-off-by: Roald Nefs --- saltlint/rules/YamlHasOctalValueRule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/saltlint/rules/YamlHasOctalValueRule.py b/saltlint/rules/YamlHasOctalValueRule.py index 389b96d..6207251 100644 --- a/saltlint/rules/YamlHasOctalValueRule.py +++ b/saltlint/rules/YamlHasOctalValueRule.py @@ -24,7 +24,7 @@ class YamlHasOctalValueRule(Rule): def match(self, file, line): found = self.bracket_regex.search(line) if found: - exc = self.exclude_regex.search(found.group(0)) - if exc: + # Skip false positive result if the exclude_regex matches. + if self.exclude_regex.search(found.group(0)): return None return found