Skip to content

Commit f3e60be

Browse files
committed
Initial Commit
1 parent f634529 commit f3e60be

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

LICENSE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Permission is hereby granted, free of charge, to any person obtaining a copy
2+
of this software and associated documentation files (the "Software"), to deal
3+
in the Software without restriction, including without limitation the rights
4+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5+
copies of the Software, and to permit persons to whom the Software is
6+
furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in
9+
all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17+
THE SOFTWARE.

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
1-
# SublimeLinter-contrib-cloudformation
2-
SublimeLinter plugin for Cloudformation files
1+
SublimeLinter-contrib-cloudformation
2+
================================
3+
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.
4+
5+
6+
## Installation
7+
SublimeLinter must be installed in order to use this plugin.
8+
9+
Please use [Package Control](https://packagecontrol.io) to install the linter plugin.
10+
11+
Before installing this plugin, you must ensure that `cfn-lint` is installed on your system.
12+
13+
```
14+
pip install cfn-lint
15+
```
16+
17+
**Note**: This plugin requires cfn-lint 0.2.2 or later.
18+
19+
## Settings
20+
For general information on how SublimeLinter works with settings, please see [Settings]. For information on generic linter settings, please see [Linter Settings][linter-settings].
21+
22+
You can configure `cfn-lint` by adding the following options to the Sublime Linter User Settings:
23+
24+
* ignore_rules: Array of rules that should be ignored when testing the file
25+
* append_rules: Array of paths containing additional rules to be applied
26+
* override_spec: Path the a Specification Override file
27+
28+
Example:
29+
30+
```json
31+
{
32+
"linters": {
33+
"cfnlint": {
34+
"ignore_rules": ["W2507", "W2508"],
35+
"append_rules": ["/path/to/custom/rules"],
36+
"override_spec": "/path/to/override.json"
37+
}
38+
}
39+
}
40+
```
41+
42+
For details about these settings, check the [cfn-lint documentation](https://github.com/awslabs/cfn-python-lint#parameters)

linter.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#
2+
# linter.py
3+
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
4+
#
5+
# Written by Markus Liljedahl
6+
# Copyright (c) 2017 Markus Liljedahl
7+
#
8+
# License: MIT
9+
#
10+
11+
from SublimeLinter.lint import Linter, util
12+
13+
import re
14+
15+
class CfnLint(Linter):
16+
"""Provides an interface to cfn-lint."""
17+
18+
cmd = ('cfn-lint', '--template', '${file}', '--format', 'parseable')
19+
executable = None
20+
version_args = '--version'
21+
version_re = r'(?P<version>\d+\.\d+\.\d+)'
22+
version_requirement = '>= 3.0.1'
23+
regex = r'^.+?:(?P<line>\d+):(?P<col>\d+):\d+:\d+:((?P<warning>W)|(?P<error>E))(?P<code>.{4}):(?P<message>.+)'
24+
multiline = True
25+
line_col_base = (1, 1)
26+
tempfile_suffix = '-'
27+
error_stream = util.STREAM_STDOUT
28+
word_re = None
29+
comment_re = r'\s*#'
30+
31+
defaults = {
32+
'selector': 'source.yaml, source.json',
33+
'strict': True
34+
}
35+
36+
def communicate(self, cmd, code=None):
37+
"""Run an external executable using stdin to pass code and return its output."""
38+
relfilename = self.filename
39+
40+
is_cfn = False;
41+
42+
# Check if we're processing a CloudFormation file
43+
with open(relfilename, 'r', encoding='utf8') as file:
44+
content = file.read()
45+
regex = re.compile(r'"?AWSTemplateFormatVersion"?\s*')
46+
47+
if regex.search(content):
48+
is_cfn = True;
49+
50+
if is_cfn:
51+
settings = self.get_view_settings()
52+
53+
# Add ignore rules
54+
ignore_rules = settings.get('ignore_rules', [])
55+
if len(ignore_rules) > 0:
56+
57+
cmd.append('--ignore-checks')
58+
59+
for ignore_rule in ignore_rules:
60+
cmd.append(ignore_rule)
61+
62+
# Add apprent rules paths
63+
append_rules = settings.get('append_rules', [])
64+
if len(append_rules) > 0:
65+
66+
cmd.append('--append-rules')
67+
68+
for append_rule in append_rules:
69+
cmd.append(append_rule)
70+
71+
# Add override spdcificaton file
72+
override_spec = settings.get('override_spec')
73+
74+
if override_spec:
75+
cmd.append('--override-spec')
76+
cmd.append(override_spec)
77+
78+
return super().communicate(cmd, code)

messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"install": "messages/install.txt"
3+
}

messages/install.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SublimeLinter-contrib-cloudormation
2+
-------------------------------
3+
This linter plugin for SublimeLinter provides an interface to `cfn-lint`,
4+
a linter for CloudFormation templates (both `yaml` and `json` files).
5+
6+
For more information, please see:
7+
https://github.com/fatbasstard/SublimeLinter-contrib-cloudformation

0 commit comments

Comments
 (0)