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"] + } + } } ``` diff --git a/linter.py b/linter.py index 5d1624c..1ddafac 100644 --- a/linter.py +++ b/linter.py @@ -12,12 +12,16 @@ 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.+)' + 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 = '-' @@ -33,7 +37,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,13 +45,11 @@ 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() - # 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 +58,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,11 +66,19 @@ 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) + # Add additional checks + 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) + return super().communicate(cmd, code)