From 3a03e11dd5cb7b72c4009704064dac8890170214 Mon Sep 17 00:00:00 2001 From: Pat Gaffney Date: Wed, 20 Nov 2019 12:17:27 -0600 Subject: [PATCH 1/5] Remove cls.executable This property has no effect, and its removal silences the following warning: WARNING: cfnlint: Defining 'cls.executable' has no effect. Please cleanup and remove this setting. --- linter.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linter.py b/linter.py index 5d1624c..d57a6b3 100644 --- a/linter.py +++ b/linter.py @@ -12,11 +12,11 @@ import re + class CfnLint(Linter): """Provides an interface to cfn-lint.""" cmd = ('cfn-lint', '--template', '${file}', '--format', 'parseable') - executable = None regex = r'^.+?:(?P\d+):(?P\d+):\d+:\d+:((?PW)|(?PE))(?P.{4}):(?P.+)' multiline = True line_col_base = (1, 1) @@ -33,7 +33,7 @@ def communicate(self, cmd, code=None): """Run an external executable using stdin to pass code and return its output.""" relfilename = self.filename - is_cfn = False; + is_cfn = False # Check if we're processing a CloudFormation file with open(relfilename, 'r', encoding='utf8') as file: @@ -41,7 +41,7 @@ def communicate(self, cmd, code=None): regex = re.compile(r'"?AWSTemplateFormatVersion"?\s*') if regex.search(content): - is_cfn = True; + is_cfn = True if is_cfn: settings = self.get_view_settings() From ad7d289c492803fc090aeb5b2a02a1b43ae0c635 Mon Sep 17 00:00:00 2001 From: Pat Gaffney Date: Wed, 20 Nov 2019 12:55:19 -0600 Subject: [PATCH 2/5] Update how the linter setttings are fetched Previously we used self.get_view_settings(), which has been deprecated. Moving to using self.settings directly silences this warning: WARNING: cfnlint: `self.get_view_settings()` has been deprecated. Just use the member `self.settings` which is the same thing. --- linter.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/linter.py b/linter.py index d57a6b3..0166498 100644 --- a/linter.py +++ b/linter.py @@ -44,10 +44,8 @@ def communicate(self, cmd, code=None): is_cfn = True if is_cfn: - settings = self.get_view_settings() - # Add ignore rules - ignore_rules = settings.get('ignore_rules', []) + ignore_rules = self.settings.get('ignore_rules', []) if len(ignore_rules) > 0: cmd.append('--ignore-checks') @@ -56,7 +54,7 @@ def communicate(self, cmd, code=None): cmd.append(ignore_rule) # Add apprent rules paths - append_rules = settings.get('append_rules', []) + append_rules = self.settings.get('append_rules', []) if len(append_rules) > 0: cmd.append('--append-rules') @@ -64,9 +62,8 @@ def communicate(self, cmd, code=None): for append_rule in append_rules: cmd.append(append_rule) - # Add override spdcificaton file - override_spec = settings.get('override_spec') - + # Add override specification file + override_spec = self.settings.get('override_spec') if override_spec: cmd.append('--override-spec') cmd.append(override_spec) From 08eae227e2715e74cc09a4bb9e0c969cf40efaec Mon Sep 17 00:00:00 2001 From: Pat Gaffney Date: Wed, 20 Nov 2019 12:56:56 -0600 Subject: [PATCH 3/5] Allow for "informational" checks These checks we're added in v0.8.0, they warn about best practices. --- linter.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linter.py b/linter.py index 0166498..2268330 100644 --- a/linter.py +++ b/linter.py @@ -17,7 +17,7 @@ class CfnLint(Linter): """Provides an interface to cfn-lint.""" cmd = ('cfn-lint', '--template', '${file}', '--format', 'parseable') - regex = r'^.+?:(?P\d+):(?P\d+):\d+:\d+:((?PW)|(?PE))(?P.{4}):(?P.+)' + regex = r'^.+?:(?P\d+):(?P\d+):\d+:\d+:((?PW|I)|(?PE))(?P.{4}):(?P.+)' multiline = True line_col_base = (1, 1) tempfile_suffix = '-' @@ -68,4 +68,14 @@ def communicate(self, cmd, code=None): cmd.append('--override-spec') cmd.append(override_spec) + include_checks = self.settings.get('include_checks', []) + if len(include_checks) > 0: + + cmd.append('--include-checks') + + for include_rule in include_checks: + cmd.append(include_rule) + + print(cmd) + return super().communicate(cmd, code) From f54bfbbc2a0dfe9c247b2ccc8be72b64617b2985 Mon Sep 17 00:00:00 2001 From: Pat Gaffney Date: Wed, 20 Nov 2019 16:28:23 -0600 Subject: [PATCH 4/5] Update README with include_checks setting --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 853fae2..3ef4145 100644 --- a/README.md +++ b/README.md @@ -25,21 +25,24 @@ For general information on how SublimeLinter works with settings, please see [Se You can configure `cfn-lint` by adding the following options to the Sublime Linter User Settings: -* ignore_rules: Array of rules that should be ignored when testing the file -* append_rules: Array of paths containing additional rules to be applied -* override_spec: Path the a Specification Override file +* `ignore_rules`: Array of rules that should be ignored when testing the file +* `append_rules`: Array of paths containing additional rules to be applied +* `override_spec`: Path the a Specification Override file +* `include_checks`: Array of rules that should be included when testing the file + * This setting requires v0.8.0 or later. Example: ```json { "linters": { - "cfnlint": { - "ignore_rules": ["W2507", "W2508"], - "append_rules": ["/path/to/custom/rules"], - "override_spec": "/path/to/override.json" - } - } + "cfnlint": { + "ignore_rules": ["W2507", "W2508"], + "append_rules": ["/path/to/custom/rules"], + "override_spec": "/path/to/override.json", + "include_checks": ["I"] + } + } } ``` From 2649a28b7f0d7a2ff614d672257e29f7fcf82916 Mon Sep 17 00:00:00 2001 From: Pat Gaffney Date: Sun, 24 Nov 2019 14:13:50 -0600 Subject: [PATCH 5/5] Create the regex over multiple lines for readability --- linter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/linter.py b/linter.py index 2268330..1ddafac 100644 --- a/linter.py +++ b/linter.py @@ -17,7 +17,11 @@ class CfnLint(Linter): """Provides an interface to cfn-lint.""" cmd = ('cfn-lint', '--template', '${file}', '--format', 'parseable') - regex = r'^.+?:(?P\d+):(?P\d+):\d+:\d+:((?PW|I)|(?PE))(?P.{4}):(?P.+)' + regex = ( + r'^.+?:(?P\d+):(?P\d+):\d+:\d+:' + r'((?PW|I)|(?PE))(?P.{4})' + r':(?P.+)' + ) multiline = True line_col_base = (1, 1) tempfile_suffix = '-' @@ -68,6 +72,7 @@ def communicate(self, cmd, code=None): cmd.append('--override-spec') cmd.append(override_spec) + # Add additional checks include_checks = self.settings.get('include_checks', []) if len(include_checks) > 0: @@ -76,6 +81,4 @@ def communicate(self, cmd, code=None): for include_rule in include_checks: cmd.append(include_rule) - print(cmd) - return super().communicate(cmd, code)