Skip to content

Commit 8698ee8

Browse files
committed
fix #7 #14 add "strict" setting
1 parent 2d9f092 commit 8698ee8

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,23 @@ SublimeLinter-json
55

66
This linter plugin for [SublimeLinter](http://sublimelinter.readthedocs.org) provides an interface to the [JSON parser](http://docs.python.org/3/library/json.html?highlight=json.loads#json.loads) built into Sublime Text. It will be used with files that have the “JSON” syntax.
77

8-
To facilitate editing Sublime Text settings files, which may contain comments, this linter allows line comments (//) and multiline block comments (/* */), but they may not appear at the end of a line (after JSON data).
8+
To facilitate editing Sublime Text settings files, which may contain comments, this linter allows line comments (//) and multiline block comments (`/* */`), but they may not appear at the end of a line (after JSON data).
99

1010
## Installation
1111
SublimeLinter 3 must be installed in order to use this plugin. If SublimeLinter 3 is not installed, please follow the instructions [here](http://sublimelinter.readthedocs.org/en/latest/installation.html).
1212

13-
Please use [Package Control](https://sublime.wbond.net/installation) to install the linter plugin. This will ensure that the plugin will be updated when new versions are available. If you want to install from source so you can modify the source code, you probably know what you are doing so we won’t cover that here.
14-
15-
To install via Package Control, do the following:
16-
17-
1. Within Sublime Text, bring up the [Command Palette](http://docs.sublimetext.info/en/sublime-text-3/extensibility/command_palette.html) and type `install`. Among the commands you should see `Package Control: Install Package`. If that command is not highlighted, use the keyboard or mouse to select it. There will be a pause of a few seconds while Package Control fetches the list of available plugins.
18-
19-
1. When the plugin list appears, type `json`. Among the entries you should see `SublimeLinter-json`. If that entry is not highlighted, use the keyboard or mouse to select it.
13+
Please use [Package Control](https://sublime.wbond.net/installation) to install the linter plugin.
2014

2115
## Settings
22-
For general information on how SublimeLinter works with settings, please see [Settings](http://sublimelinter.readthedocs.org/en/latest/settings.html). For information on generic linter settings, please see [Linter Settings](http://sublimelinter.readthedocs.org/en/latest/linter_settings.html).
2316

24-
## Contributing
25-
If you would like to contribute enhancements or fixes, please do the following:
17+
This linter accepts a `"strict"` setting, which if false uses Sublime Text's "loose" parser so that trailing comma's and comments are accepted.
2618

27-
1. Fork the plugin repository.
28-
1. Hack on a separate topic branch created from the latest `master`.
29-
1. Commit and push the topic branch.
30-
1. Make a pull request.
31-
1. Be patient. ;-)
19+
```json
20+
"linters": {
21+
"json": {
22+
"strict": false
23+
}
24+
}
25+
```
3226

33-
Please note that modications should follow these coding guidelines:
34-
35-
- Indent is 4 spaces.
36-
- Code should pass flake8 and pep257 linters.
37-
- Vertical whitespace helps readability, don’t be afraid to use it.
38-
39-
Thank you for helping out!
27+
For general information on how SublimeLinter works with settings, please see [Settings](http://sublimelinter.readthedocs.org/en/latest/settings.html). For information on generic linter settings, please see [Linter Settings](http://sublimelinter.readthedocs.org/en/latest/linter_settings.html).

linter.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,19 @@ class JSON(Linter):
4848
]
4949

5050
def run(self, cmd, code):
51-
"""Attempt to parse code as JSON, return '' if it succeeds, the error message if it fails."""
51+
"""
52+
Attempt to parse code as JSON
53+
Returns '' if it succeeds, the error message if it fails.
5254
53-
# Use ST's loose parser for its setting files.
54-
strict = os.path.splitext(self.filename)[1] not in self.extensions
55+
Use ST's loose parser for its setting files, or when specified.
56+
"""
57+
58+
is_sublime_file = os.path.splitext(self.filename)[1] in self.extensions
59+
60+
if Linter.get_view_settings(self).get('strict') and not is_sublime_file:
61+
strict = True
62+
else:
63+
strict = False
5564

5665
try:
5766
if strict:

messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"install": "messages/install.txt",
33
"1.0.2": "messages/1.0.2.txt",
4-
"1.2.0": "messages/1.2.0.txt"
4+
"1.2.0": "messages/1.2.0.txt",
5+
"1.3.0": "messages/1.3.0.txt"
56
}

messages/1.3.0.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SublimeLinter-json 1.3.0
2+
-------------------------
3+
4+
Now accepts a "strict" setting, which if false uses Sublime Text's "loose"
5+
parser so that trailing comma's and comments are accepted.

0 commit comments

Comments
 (0)