Find file
Fetching contributors…
Cannot retrieve contributors at this time
103 lines (85 sloc) 3.69 KB
;;; flymake-jslint.el --- A flymake handler for javascript using jslint
;; Copyright (c) 2011-2017 Steve Purcell
;; Author: Steve Purcell <>
;; Homepage:
;; Package-Version: 0
;; Package-Requires: ((flymake-easy "0.1"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <>.
;;; Commentary:
;; References:
;; Works with either "jslint" from, or "jsl" from
;; The default is "jsl", if that executable is
;; found at load-time. Otherwise, "jslint" is the default. If you want
;; to use the non-default checker, you can customize the values of
;; `flymake-jslint-command' and `flymake-jslint-args' accordingly.
;; Usage:
;; (require 'flymake-jslint)
;; (add-hook 'js-mode-hook 'flymake-jslint-load)
;; Uses flymake-easy, from
;;; Code:
(require 'flymake-easy)
(defgroup flymake-jslint nil
"Flymake checking of Javascript using jslint"
:group 'programming
:prefix "flymake-jslint-")
(defcustom flymake-jslint-detect-trailing-comma t
"Whether or not to report warnings about trailing commas."
:type 'boolean :group 'flymake-jslint)
(defcustom flymake-jslint-command
(if (executable-find "jsl") "jsl" "jslint")
"Name (and optionally full path) of jslint executable."
:type 'string :group 'flymake-jslint)
(defcustom flymake-jslint-args
(unless (string-equal "jsl" flymake-jslint-command)
'(--white --undef --nomen --regexp --plusplus --bitwise --newcap --sloppy --vars --eqeq)))
"Command-line args for jslint executable."
:type '(repeat string) :group 'flymake-jslint)
(defconst flymake-jslint-err-line-patterns
'(("^ *#[0-9]+ \\(.*?\\)\n.*?// Line \\([0-9]+\\), Pos \\([0-9]+\\)$" nil 2 3 1)
;; jsl
("^\\(.+\\)\:\\([0-9]+\\)\: \\(SyntaxError\:.+\\)\:$" nil 2 nil 3)
("^\\(.+\\)(\\([0-9]+\\)): \\(SyntaxError:.+\\)$" nil 2 nil 3)
("^\\(.+\\)(\\([0-9]+\\)): \\(lint \\)?\\(warning:.+\\)$" nil 2 nil 4)))
(defconst flymake-jslint-trailing-comma-err-line-pattern
'("^\\(.+\\)\:\\([0-9]+\\)\: strict \\(warning: trailing comma.+\\)\:$" nil 2 nil 3))
(defun flymake-jslint-command (filename)
"Construct a command that flymake can use to check javascript source in FILENAME."
(list flymake-jslint-command)
(unless (string-match "jslint" flymake-jslint-command)
;; jsl required option
(list "-process"))
(list filename)))
(defun flymake-jslint-load ()
"Configure flymake mode to check the current buffer's javascript syntax."
(flymake-easy-load 'flymake-jslint-command
(append flymake-jslint-err-line-patterns
(when flymake-jslint-detect-trailing-comma
(list flymake-jslint-trailing-comma-err-line-pattern)))
(provide 'flymake-jslint)
;;; flymake-jslint.el ends here