-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f634529
commit f3e60be
Showing
5 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,42 @@ | ||
# SublimeLinter-contrib-cloudformation | ||
SublimeLinter plugin for Cloudformation files | ||
SublimeLinter-contrib-cloudformation | ||
================================ | ||
This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to [cfn-lint](https://github.com/awslabs/cfn-python-lint). This plugin lints `yaml` and `json` CloudFormation templates. | ||
|
||
|
||
## Installation | ||
SublimeLinter must be installed in order to use this plugin. | ||
|
||
Please use [Package Control](https://packagecontrol.io) to install the linter plugin. | ||
|
||
Before installing this plugin, you must ensure that `cfn-lint` is installed on your system. | ||
|
||
``` | ||
pip install cfn-lint | ||
``` | ||
|
||
**Note**: This plugin requires cfn-lint 0.2.2 or later. | ||
|
||
## Settings | ||
For general information on how SublimeLinter works with settings, please see [Settings]. For information on generic linter settings, please see [Linter Settings][linter-settings]. | ||
|
||
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 | ||
|
||
Example: | ||
|
||
```json | ||
{ | ||
"linters": { | ||
"cfnlint": { | ||
"ignore_rules": ["W2507", "W2508"], | ||
"append_rules": ["/path/to/custom/rules"], | ||
"override_spec": "/path/to/override.json" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
For details about these settings, check the [cfn-lint documentation](https://github.com/awslabs/cfn-python-lint#parameters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# | ||
# linter.py | ||
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3 | ||
# | ||
# Written by Markus Liljedahl | ||
# Copyright (c) 2017 Markus Liljedahl | ||
# | ||
# License: MIT | ||
# | ||
|
||
from SublimeLinter.lint import Linter, util | ||
|
||
import re | ||
|
||
class CfnLint(Linter): | ||
"""Provides an interface to cfn-lint.""" | ||
|
||
cmd = ('cfn-lint', '--template', '${file}', '--format', 'parseable') | ||
executable = None | ||
version_args = '--version' | ||
version_re = r'(?P<version>\d+\.\d+\.\d+)' | ||
version_requirement = '>= 3.0.1' | ||
regex = r'^.+?:(?P<line>\d+):(?P<col>\d+):\d+:\d+:((?P<warning>W)|(?P<error>E))(?P<code>.{4}):(?P<message>.+)' | ||
multiline = True | ||
line_col_base = (1, 1) | ||
tempfile_suffix = '-' | ||
error_stream = util.STREAM_STDOUT | ||
word_re = None | ||
comment_re = r'\s*#' | ||
|
||
defaults = { | ||
'selector': 'source.yaml, source.json', | ||
'strict': True | ||
} | ||
|
||
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; | ||
|
||
# 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; | ||
|
||
if is_cfn: | ||
settings = self.get_view_settings() | ||
|
||
# Add ignore rules | ||
ignore_rules = settings.get('ignore_rules', []) | ||
if len(ignore_rules) > 0: | ||
|
||
cmd.append('--ignore-checks') | ||
|
||
for ignore_rule in ignore_rules: | ||
cmd.append(ignore_rule) | ||
|
||
# Add apprent rules paths | ||
append_rules = 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') | ||
|
||
if override_spec: | ||
cmd.append('--override-spec') | ||
cmd.append(override_spec) | ||
|
||
return super().communicate(cmd, code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"install": "messages/install.txt" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SublimeLinter-contrib-cloudormation | ||
------------------------------- | ||
This linter plugin for SublimeLinter provides an interface to `cfn-lint`, | ||
a linter for CloudFormation templates (both `yaml` and `json` files). | ||
|
||
For more information, please see: | ||
https://github.com/fatbasstard/SublimeLinter-contrib-cloudformation |