Skip to content

Commit 1371749

Browse files
committed
better handle eslint not found on PATH
1 parent 7c8aa8d commit 1371749

5 files changed

Lines changed: 28 additions & 4 deletions

File tree

Commands/Automatically Fix Problems (ESLint).tmCommand

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
set -f
1313
1414
TPY=${TM_PYTHON:-python}
15-
"${TPY}" "${TM_BUNDLE_SUPPORT}/main.py" --fix
15+
OUTPUT=$("${TPY}" "${TM_BUNDLE_SUPPORT}/main.py" --fix)
16+
17+
if [[ ${OUTPUT} == *"!DOCTYPE html"* ]]; then
18+
exit_show_html "${OUTPUT}"
19+
fi
20+
1621
</string>
1722
<key>input</key>
1823
<string>document</string>

Commands/Save & Validate with ESLint.tmCommand

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ set -f
1313
1414
TPY=${TM_PYTHON:-python}
1515
OUTPUT=$("${TPY}" "${TM_BUNDLE_SUPPORT}/main.py")
16+
17+
if [[ ${OUTPUT} == *"!DOCTYPE html"* ]]; then
18+
exit_show_html "${OUTPUT}"
19+
fi
20+
1621
if [[ "${OUTPUT}" = "" ]]; then
1722
exit_discard
1823
else

Support/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,21 @@ def fix():
197197
filename = os.environ['TM_FILEPATH']
198198
cwd = get_cwd()
199199

200-
the_validator.fix(filename, cwd)
200+
try:
201+
the_validator.fix(filename, cwd)
202+
except validator.ValidateError as err:
203+
context = {
204+
'BASE_PATH': BASE_PATH,
205+
'timestamp': time.strftime('%c'),
206+
'errorMessage': err.message,
207+
}
208+
if err.path:
209+
context['searchPath'] = err.path
210+
html = ASHES_ENV.render('error_eslint_path.html', context)
211+
else:
212+
html = ASHES_ENV.render('error_eslint_other.html', context)
213+
print(html)
214+
sys.exit()
201215

202216
mate = os.environ['TM_MATE']
203217
subprocess.call([mate, '--clear-mark=warning', filename])

Support/templates/error_eslint_path.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h4>How to fix it</h4><br>
2828
location of your <code>eslint</code> and <code>node</code> commands.
2929
</li>
3030
</ol><br>
31-
The path currently used by TextMate bundles is:<br>
31+
The path currently used to search for ESLint is:<br>
3232
<br>
3333
<div style="overflow:auto"><code>{searchPath|h}</code></div><br>
3434
<h4>How to disable validation</h4><br>

Support/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def fix(self, filename, cwd):
5151
try:
5252
subprocess.call(args, env=env, cwd=cwd)
5353
except OSError as err:
54-
raise ValidateError(err.message, env['PATH'])
54+
raise ValidateError(err.__str__(), env['PATH'])
5555

5656

5757
def run(self, input_iterable=sys.stdin, filename=None, input_is_html=False,

0 commit comments

Comments
 (0)