├── .gitignore ├── .python-version ├── .travis.yml ├── LICENSE ├── README.md ├── linter.py ├── messages.json └── messages └── install.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.6" 4 | install: 5 | - pip install flake8 6 | script: 7 | - flake8 . --max-line-length=120 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-json 2 | ========================= 3 | 4 | [![Build Status](https://travis-ci.org/SublimeLinter/SublimeLinter-json.svg?branch=master)](https://travis-ci.org/SublimeLinter/SublimeLinter-json) 5 | 6 | This linter plugin for [SublimeLinter](https://github.com/SublimeLinter/SublimeLinter) provides an interface to the [JSON parser](http://docs.python.org/3/library/json.html?highlight=json.loads#json.loads) built into Sublime Text. 7 | It will be used with files that have the "JSON" syntax. 8 | 9 | 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). 10 | 11 | 12 | ## Installation 13 | 14 | SublimeLinter must be installed in order to use this plugin. 15 | 16 | Please use [Package Control](https://packagecontrol.io) to install the linter plugin. 17 | 18 | 19 | ## Settings 20 | 21 | This linter accepts a `"strict"` setting, which if false uses Sublime Text's "loose" parser so that trailing comma's and comments are accepted. 22 | 23 | ```json 24 | "linters": { 25 | "json": { 26 | "strict": false 27 | } 28 | } 29 | ``` 30 | 31 | - SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html 32 | - Linter settings: http://sublimelinter.com/en/latest/linter_settings.html 33 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os.path 3 | import re 4 | import sublime 5 | 6 | from SublimeLinter.lint import Linter 7 | 8 | 9 | class JSON(Linter): 10 | cmd = None 11 | loose_regex = re.compile(r'^.+: (?P.+) in \(data\):(?P\d+):(?P\d+)') 12 | strict_regex = re.compile(r'^(?P.+):\s*line (?P\d+) column (?P\d+)') 13 | regex = loose_regex 14 | defaults = { 15 | 'selector': 'source.json', 16 | 'strict': True 17 | } 18 | 19 | def run(self, cmd, code): 20 | """ 21 | Attempt to parse code as JSON. 22 | 23 | Returns '' if it succeeds, the error message if it fails. 24 | Use ST's loose parser for its setting files, or when specified. 25 | """ 26 | is_sublime_file = os.path.splitext(self.filename)[1].startswith('.sublime-') 27 | 28 | if self.settings.get('strict') and not is_sublime_file: 29 | strict = True 30 | else: 31 | strict = False 32 | 33 | try: 34 | if strict: 35 | self.regex = self.strict_regex 36 | json.loads(code) 37 | else: 38 | self.regex = self.loose_regex 39 | sublime.decode_value(code) 40 | 41 | return '' 42 | except ValueError as err: 43 | return str(err) 44 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt" 3 | } 4 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-json 2 | ------------------------------- 3 | This linter plugin for SublimeLinter provides an interface to json. 4 | 5 | For more information, please see https://github.com/SublimeLinter/SublimeLinter-json. 6 | --------------------------------------------------------------------------------