Skip to content

Commit

Permalink
Merge pull request #1 from patrickrgaffney/fixes
Browse files Browse the repository at this point in the history
Add Setting for --include-checks
  • Loading branch information
fatbasstard committed Nov 25, 2019
2 parents 0c8dbf2 + 2649a28 commit 4a85247
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
}
```

Expand Down
32 changes: 21 additions & 11 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<line>\d+):(?P<col>\d+):\d+:\d+:((?P<warning>W)|(?P<error>E))(?P<code>.{4}):(?P<message>.+)'
regex = (
r'^.+?:(?P<line>\d+):(?P<col>\d+):\d+:\d+:'
r'((?P<warning>W|I)|(?P<error>E))(?P<code>.{4})'
r':(?P<message>.+)'
)
multiline = True
line_col_base = (1, 1)
tempfile_suffix = '-'
Expand All @@ -33,21 +37,19 @@ 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:
content = file.read()
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')
Expand All @@ -56,19 +58,27 @@ 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')

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)

0 comments on commit 4a85247

Please sign in to comment.