Skip to content

Commit 4740af8

Browse files
authored
Merge pull request #318 from SublimeLinter/auto-eslint_d
2 parents 2bbb711 + cc320fa commit 4740af8

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ For [Svelte](https://svelte.dev/) `.svelte` files, using [`eslint-plugin-svelte3
6868

6969
To find the `selector` value for a particular file type, place the cursor at the start of the file and use the command **Tools** ➡️ **Developer** ➡️ **Show Scope Name**.
7070

71+
## Using eslint_d
72+
73+
This plugin will automatically prefer a `eslint_d` installation if present.
74+
You can change this behavior by setting `prefer_eslint_d` to `false` either
75+
globally or per project. E.g. for the global setting:
76+
77+
```json
78+
"linters": {
79+
"eslint": {
80+
"prefer_eslint_d": false
81+
}
82+
}
83+
```
84+
7185
## Settings
7286

7387
- SublimeLinter settings: http://sublimelinter.com/en/latest/settings.html

linter.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@
1414
import logging
1515
import os
1616
import re
17+
import shutil
1718
from SublimeLinter.lint import LintMatch, NodeLinter, PermanentError
1819

1920
from SublimeLinter.lint.base_linter.node_linter import read_json_file
2021

2122

23+
MYPY = False
24+
if MYPY:
25+
from typing import List, Union
26+
27+
2228
logger = logging.getLogger('SublimeLinter.plugin.eslint')
2329

2430

@@ -47,7 +53,8 @@ class ESLint(NodeLinter):
4753
line_col_base = (1, 1)
4854
defaults = {
4955
'selector': OPTIMISTIC_SELECTOR,
50-
'--stdin-filename': '${file}'
56+
'--stdin-filename': '${file}',
57+
'prefer_eslint_d': True,
5158
}
5259

5360
def run(self, cmd, code):
@@ -113,6 +120,21 @@ def ensure_plugin_installed(self) -> bool:
113120
self.notify_unassign() # Abort linting without popping error dialog
114121
raise PermanentError()
115122

123+
def find_local_executable(self, start_dir, npm_name):
124+
# type: (str, str) -> Union[None, str, List[str]]
125+
"""Automatically switch to `eslint_d` if available (and wanted)."""
126+
executable = super().find_local_executable(start_dir, npm_name)
127+
if self.settings.get('prefer_eslint_d') and isinstance(executable, str):
128+
basedir = os.path.dirname(executable)
129+
daemonized_name = '{}_d'.format(npm_name)
130+
return (
131+
(shutil.which(daemonized_name, path=basedir) if basedir else None) # local
132+
or self.which(daemonized_name) # global
133+
or executable # keep it
134+
)
135+
136+
return executable
137+
116138
def on_stderr(self, stderr):
117139
# Demote 'annoying' config is missing error to a warning.
118140
if self.missing_config_regex.match(stderr):

messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"install": "messages/install.txt",
3-
"4.2.0": "messages/4.2.0.txt"
3+
"4.2.0": "messages/4.2.0.txt",
4+
"4.3.0": "messages/4.3.0.txt"
45
}

messages/4.3.0.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SublimeLinter-eslint 4.3.0
2+
--------------------------
3+
4+
SublimeLinter will now prefer a possible `eslint_d` installation (globally or
5+
locally) over the slower `eslint` binary automatically.
6+
7+
You can control this behavior with the `prefer_eslint_d` setting. For example,
8+
to turn this off in the global SublimeLinter settings:
9+
10+
```json
11+
"linters": {
12+
"eslint": {
13+
"prefer_eslint_d": false
14+
}
15+
}
16+
```

0 commit comments

Comments
 (0)