├── .gitignore ├── messages.json ├── .travis.yml ├── .sublimelinterrc ├── messages └── install.txt ├── LICENSE ├── linter.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt" 3 | } 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.3" 4 | # command to install dependencies 5 | install: 6 | - pip install flake8 7 | - pip install pep257 8 | # command to run tests 9 | script: 10 | - flake8 . --max-line-length=120 11 | - pep257 . --ignore=D202,D211 12 | -------------------------------------------------------------------------------- /.sublimelinterrc: -------------------------------------------------------------------------------- 1 | { 2 | "@python": 3, 3 | "linters": { 4 | "flake8": { 5 | "max-line-length": 120 6 | }, 7 | "pep257": { 8 | "ignore": ["D202", "D211"] 9 | }, 10 | "pep8": { 11 | "max-line-length": 120 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | SublimeLinter-contrib-eslint_d 2 | ------------------------------- 3 | This linter plugin for SublimeLinter provides an interface to eslint_d. 4 | 5 | ** IMPORTANT! ** 6 | 7 | Before this plugin will activate, you *must* 8 | follow the installation instructions here: 9 | 10 | https://github.com/roadhump/SublimeLinter-contrib-eslint_d 11 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /linter.py: -------------------------------------------------------------------------------- 1 | # 2 | # linter.py 3 | # Linter for SublimeLinter3, a code checking framework for Sublime Text 3 4 | # 5 | # Written by roadhump 6 | # Copyright (c) 2015 roadhump 7 | # 8 | # License: MIT 9 | # 10 | 11 | """This module exports the Eslint_d plugin class.""" 12 | 13 | import sublime 14 | import os 15 | import re 16 | from SublimeLinter.lint import NodeLinter 17 | 18 | 19 | class Eslint_d(NodeLinter): 20 | 21 | """Provides an interface to eslint_d.""" 22 | 23 | syntax = ('javascript', 'html', 'javascriptnext', 'javascript (babel)', 'javascript (jsx)', 'jsx-real') 24 | npm_name = 'eslint_d' 25 | cmd = ('eslint_d', '--format', 'compact', '--stdin', '--stdin-filename', '@') 26 | executable = None 27 | version_args = '--version' 28 | version_re = r'eslint_d v(?P\d+\.\d+\.\d+)' 29 | version_requirement = '>= 2.3.1' 30 | regex = ( 31 | r'^.+?: line (?P\d+), col (?P\d+), ' 32 | r'(?:(?PError)|(?PWarning)) - ' 33 | r'(?P.+)' 34 | ) 35 | config_fail_regex = re.compile(r'^Cannot read config file: .*\r?\n') 36 | crash_regex = re.compile( 37 | r'^(.*?)\r?\n\w*Error: \1', 38 | re.MULTILINE 39 | ) 40 | line_col_base = (1, 1) 41 | selectors = { 42 | 'html': 'source.js.embedded.html' 43 | } 44 | config_file = ('--config', '.eslintrc', '~') 45 | 46 | def find_errors(self, output): 47 | """ 48 | Parse errors from linter's output. 49 | 50 | We override this method to handle parsing eslint crashes. 51 | """ 52 | 53 | match = self.config_fail_regex.match(output) 54 | if match: 55 | return [(match, 0, None, "Error", "", match.group(0), None)] 56 | 57 | match = self.crash_regex.match(output) 58 | if match: 59 | msg = "ESLint crashed: %s" % match.group(1) 60 | return [(match, 0, None, "Error", "", msg, None)] 61 | 62 | return super().find_errors(output) 63 | 64 | def communicate(self, cmd, code=None): 65 | """Run an external executable using stdin to pass code and return its output.""" 66 | 67 | if '__RELATIVE_TO_FOLDER__' in cmd: 68 | 69 | relfilename = self.filename 70 | window = self.view.window() 71 | 72 | # can't get active folder, it will work only if there is one folder in project 73 | if int(sublime.version()) >= 3080 and len(window.folders()) < 2: 74 | 75 | vars = window.extract_variables() 76 | 77 | if 'folder' in vars: 78 | relfilename = os.path.relpath(self.filename, vars['folder']) 79 | 80 | cmd[cmd.index('__RELATIVE_TO_FOLDER__')] = relfilename 81 | 82 | elif not code: 83 | cmd.append(self.filename) 84 | 85 | return super().communicate(cmd, code) 86 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SublimeLinter-contrib-eslint_d 2 | ================================ 3 | 4 | [![Build Status](https://travis-ci.org/roadhump/SublimeLinter-contrib-eslint_d.svg?branch=master)](https://travis-ci.org/roadhump/SublimeLinter-contrib-eslint_d) 5 | 6 | This linter plugin for [SublimeLinter][docs] provides an interface to [eslint_d][linter-homepage]. It will be used with files that have the “JavaScript” syntax. 7 | 8 | ## Installation 9 | SublimeLinter 3 must be installed in order to use this plugin. If SublimeLinter 3 is not installed, please follow the instructions [here][installation]. 10 | 11 | ### Linter installation 12 | Before using this plugin, you must ensure that `eslint_d` is installed on your system. To install `eslint_d`, do the following: 13 | 14 | 1. Install [Node.js](http://nodejs.org) (and [npm](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) on Linux). 15 | 16 | 1. Install `eslint_d` by typing the following in a terminal: 17 | ``` 18 | npm install -g eslint_d 19 | ``` 20 | Or install `eslint_d` locally in your project folder (**you must have package.json file there**): 21 | ``` 22 | npm init -f 23 | npm install eslint_d 24 | ``` 25 | 26 | 1. If you are using `nvm` and `zsh`, ensure that the line to load `nvm` is in `.zshenv` and not `.zshrc`. 27 | 28 | 1. If you are using `zsh` and `oh-my-zsh`, do not load the `nvm` plugin for `oh-my-zsh`. 29 | 30 | 31 | **Note:** This plugin requires `eslint_d` 2.3.1 or later. 32 | 33 | ### Linter configuration 34 | In order for `eslint_d` to be executed by SublimeLinter, you must ensure that its path is available to SublimeLinter. Before going any further, please read and follow the steps in [“Finding a linter executable”](http://sublimelinter.readthedocs.org/en/latest/troubleshooting.html#finding-a-linter-executable) through “Validating your PATH” in the documentation. 35 | 36 | Once you have installed and configured `eslint_d`, you can proceed to install the SublimeLinter-contrib-eslint_d plugin if it is not yet installed. 37 | 38 | ### Plugin installation 39 | Please use [Package Control][pc] 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. 40 | 41 | To install via Package Control, do the following: 42 | 43 | 1. Within Sublime Text, bring up the [Command Palette][cmd] 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. 44 | 45 | 1. When the plugin list appears, type `eslint_d`. Among the entries you should see `SublimeLinter-contrib-eslint_d`. If that entry is not highlighted, use the keyboard or mouse to select it. 46 | 47 | ## Settings 48 | For general information on how SublimeLinter works with settings, please see [Settings][settings]. For information on generic linter settings, please see [Linter Settings][linter-settings]. 49 | 50 | You can configure `eslint` options in the way you would from the command line, with `.eslintrc` files. For more information, see the [eslint docs](https://github.com/nzakas/eslint/wiki). 51 | 52 | ## FAQ and Troubleshooting 53 | 54 | This plugin is almost similar to [SublimeLinter-contrib-eslint](https://github.com/roadhump/SublimeLinter-eslint#faq-and-troubleshooting), so you can use its [documentation](https://github.com/roadhump/SublimeLinter-eslint#faq-and-troubleshooting), just replace `eslint` with `eslint_d`. 55 | 56 | ## Contributing 57 | If you would like to contribute enhancements or fixes, please do the following: 58 | 59 | 1. Fork the plugin repository. 60 | 1. Hack on a separate topic branch created from the latest `master`. 61 | 1. Commit and push the topic branch. 62 | 1. Make a pull request. 63 | 1. Be patient. ;-) 64 | 65 | Please note that modifications should follow these coding guidelines: 66 | 67 | - Indent is 4 spaces. 68 | - Code should pass flake8 and pep257 linters. 69 | - Vertical whitespace helps readability, don’t be afraid to use it. 70 | - Please use descriptive variable names, no abbreviations unless they are very well known. 71 | 72 | Thank you for helping out! 73 | 74 | [docs]: http://sublimelinter.readthedocs.org 75 | [installation]: http://sublimelinter.readthedocs.org/en/latest/installation.html 76 | [locating-executables]: http://sublimelinter.readthedocs.org/en/latest/usage.html#how-linter-executables-are-located 77 | [pc]: https://sublime.wbond.net/installation 78 | [cmd]: http://docs.sublimetext.info/en/sublime-text-3/extensibility/command_palette.html 79 | [settings]: http://sublimelinter.readthedocs.org/en/latest/settings.html 80 | [linter-settings]: http://sublimelinter.readthedocs.org/en/latest/linter_settings.html 81 | [inline-settings]: http://sublimelinter.readthedocs.org/en/latest/settings.html#inline-settings 82 | [linter-homepage]: https://github.com/mantoni/eslint_d.js 83 | --------------------------------------------------------------------------------