Skip to content

Commit

Permalink
Porting SublimeLinter-eslint stdin logic to SublimeLinter-contrib-esl…
Browse files Browse the repository at this point in the history
…int_d. Depends on mantoni/eslint_d.js#15
  • Loading branch information
doctyper committed Nov 8, 2015
1 parent 5fa22b0 commit 18209dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ install:
# command to run tests
script:
- flake8 . --max-line-length=120
- pep257 . --ignore=D202
- pep257 . --ignore=D202,D211
28 changes: 26 additions & 2 deletions linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

"""This module exports the Eslint_d plugin class."""

import sublime
import os
import re
from SublimeLinter.lint import NodeLinter

Expand All @@ -20,7 +22,7 @@ class Eslint_d(NodeLinter):

syntax = ('javascript', 'html', 'javascriptnext', 'javascript (babel)', 'javascript (jsx)', 'jsx-real')
npm_name = 'eslint_d'
cmd = ('eslint_d', '--no-ignore', '--format', 'compact', '@')
cmd = ('eslint_d', '--no-ignore', '--format', 'compact', '--stdin', '--stdin-filename', '__RELATIVE_TO_FOLDER__')
executable = None
version_args = '--version'
version_re = r'eslint_d v(?P<version>\d+\.\d+\.\d+)'
Expand All @@ -39,7 +41,6 @@ class Eslint_d(NodeLinter):
selectors = {
'html': 'source.js.embedded.html'
}
tempfile_suffix = 'js'
config_file = ('--config', '.eslintrc', '~')

def find_errors(self, output):
Expand All @@ -59,3 +60,26 @@ def find_errors(self, output):
return [(match, 0, None, "Error", "", msg, None)]

return super().find_errors(output)

def communicate(self, cmd, code=None):
"""Run an external executable using stdin to pass code and return its output."""

if '__RELATIVE_TO_FOLDER__' in cmd:

relfilename = self.filename
window = self.view.window()

# can't get active folder, it will work only if there is one folder in project
if int(sublime.version()) >= 3080 and len(window.folders()) < 2:

vars = window.extract_variables()

if 'folder' in vars:
relfilename = os.path.relpath(self.filename, vars['folder'])

cmd[cmd.index('__RELATIVE_TO_FOLDER__')] = relfilename

elif not code:
cmd.append(self.filename)

return super().communicate(cmd, code)

0 comments on commit 18209dc

Please sign in to comment.