Skip to content

Commit

Permalink
Disable eslint if no config is found
Browse files Browse the repository at this point in the history
Fixes and closes GH-1085
  • Loading branch information
Simplify committed Sep 26, 2016
1 parent d7b664d commit 724bc28
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Expand Up @@ -9,6 +9,8 @@
no longer used [GH-1057]
- ``:modes`` is now mandatory for syntax checker definitions [GH-1071]
- Remove jade checker [GH-951] [GH-1084]
- Remove ``javascript-eslintrc`` and instead rely on eslint's own configuration file
search [GH-1085]

- New syntax checkers:

Expand All @@ -22,6 +24,10 @@
subcommand [GH-1079]
- Add ``:enabled`` property to ``flycheck-define-checker`` [GH-1089]

- Improvements:

- Do not use ``javascript-eslint`` if eslint cannot find a valid configuration [GH-1085]

29 (Aug 28, 2016)
=================

Expand Down
7 changes: 5 additions & 2 deletions doc/languages.rst
Expand Up @@ -549,12 +549,15 @@ to view the docstring of the syntax checker. Likewise, you may use

Check syntax and lint with `ESLint <http://eslint.org/>`_.

.. note::

Flycheck does not use this syntax checker if eslint cannot find a valid
configuration file.

.. defcustom:: flycheck-eslint-rules-directories

A list of directories with custom rules.

.. syntax-checker-config-file:: flycheck-eslintrc

.. syntax-checker:: javascript-jshint

Check syntax and lint with `JSHint <http://jshint.com/>`_.
Expand Down
13 changes: 8 additions & 5 deletions flycheck.el
Expand Up @@ -7489,16 +7489,11 @@ for more information about the custom directories."
:safe #'flycheck-string-list-p
:package-version '(flycheck . "29"))

(flycheck-def-config-file-var flycheck-eslintrc javascript-eslint nil
:safe #'stringp
:package-version '(flycheck . "0.20"))

(flycheck-define-checker javascript-eslint
"A Javascript syntax and style checker using eslint.

See URL `https://github.com/eslint/eslint'."
:command ("eslint" "--format=checkstyle"
(config-file "--config" flycheck-eslintrc)
(option-list "--rulesdir" flycheck-eslint-rules-directories)
"--stdin" "--stdin-filename" source-original)
:standard-input t
Expand All @@ -7518,6 +7513,14 @@ See URL `https://github.com/eslint/eslint'."
(flycheck-error-message err))))
(flycheck-sanitize-errors errors))
errors)
:enabled (lambda (checker)
(let* ((directory (concat
(flycheck-compute-working-directory checker)
"."))
(executable (flycheck-find-checker-executable checker))
(exitcode (call-process executable nil nil nil
"--print-config" directory)))
(eq exitcode 0)))
:modes (js-mode js-jsx-mode js2-mode js2-jsx-mode js3-mode)
:next-checkers ((warning . javascript-jscs)))

Expand Down
9 changes: 4 additions & 5 deletions test/flycheck-test.el
Expand Up @@ -3321,17 +3321,16 @@ Why not:
(let ((flycheck-disabled-checkers '(javascript-jshint)))
(flycheck-ert-should-syntax-check
"language/javascript/syntax-error.js" flycheck-test-javascript-modes
'(3 26 error "Parsing error: Unexpected token )" :checker javascript-eslint))))
'(3 25 error "Parsing error: Unexpected token )" :checker javascript-eslint))))

(flycheck-ert-def-checker-test javascript-eslint javascript warning
:tags '(checkstyle-xml)
(let ((flycheck-eslintrc "eslint.json")
(flycheck-disabled-checkers '(javascript-jshint javascript-jscs)))
(let ((flycheck-disabled-checkers '(javascript-jshint javascript-jscs)))
(flycheck-ert-should-syntax-check
"language/javascript/warnings.js" flycheck-test-javascript-modes
'(3 2 warning "Use the function form of \"use strict\"." :id "strict"
'(3 2 warning "Use the function form of 'use strict'." :id "strict"
:checker javascript-eslint)
'(4 9 warning "\"foo\" is defined but never used" :id "no-unused-vars"
'(4 9 warning "'foo' is defined but never used." :id "no-unused-vars"
:checker javascript-eslint))))

(flycheck-ert-def-checker-test javascript-gjslint javascript nil
Expand Down
6 changes: 6 additions & 0 deletions test/resources/language/javascript/.eslintrc.json
@@ -0,0 +1,6 @@
{
"rules" : {
"strict": 1,
"no-unused-vars": 1
}
}

0 comments on commit 724bc28

Please sign in to comment.