Skip to content

Commit

Permalink
fix #7 #14 add "strict" setting
Browse files Browse the repository at this point in the history
  • Loading branch information
braver committed Dec 13, 2017
1 parent 2d9f092 commit 8698ee8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
34 changes: 11 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,23 @@ SublimeLinter-json

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.

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).
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).

## Installation
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).

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.

To install via Package Control, do the following:

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.

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.
Please use [Package Control](https://sublime.wbond.net/installation) to install the linter plugin.

## Settings
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).

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

1. Fork the plugin repository.
1. Hack on a separate topic branch created from the latest `master`.
1. Commit and push the topic branch.
1. Make a pull request.
1. Be patient. ;-)
```json
"linters": {
"json": {
"strict": false
}
}
```

Please note that modications should follow these coding guidelines:

- Indent is 4 spaces.
- Code should pass flake8 and pep257 linters.
- Vertical whitespace helps readability, don’t be afraid to use it.

Thank you for helping out!
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).
15 changes: 12 additions & 3 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,19 @@ class JSON(Linter):
]

def run(self, cmd, code):
"""Attempt to parse code as JSON, return '' if it succeeds, the error message if it fails."""
"""
Attempt to parse code as JSON
Returns '' if it succeeds, the error message if it fails.
# Use ST's loose parser for its setting files.
strict = os.path.splitext(self.filename)[1] not in self.extensions
Use ST's loose parser for its setting files, or when specified.
"""

is_sublime_file = os.path.splitext(self.filename)[1] in self.extensions

if Linter.get_view_settings(self).get('strict') and not is_sublime_file:
strict = True
else:
strict = False

try:
if strict:
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"install": "messages/install.txt",
"1.0.2": "messages/1.0.2.txt",
"1.2.0": "messages/1.2.0.txt"
"1.2.0": "messages/1.2.0.txt",
"1.3.0": "messages/1.3.0.txt"
}
5 changes: 5 additions & 0 deletions messages/1.3.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SublimeLinter-json 1.3.0
-------------------------

Now accepts a "strict" setting, which if false uses Sublime Text's "loose"
parser so that trailing comma's and comments are accepted.

0 comments on commit 8698ee8

Please sign in to comment.