Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10002 lines
383 KiB

  1. ;;; flycheck.el --- On-the-fly syntax checking -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017 Flycheck contributors
  3. ;; Copyright (C) 2012-2016 Sebastian Wiesner and Flycheck contributors
  4. ;; Copyright (C) 2013, 2014 Free Software Foundation, Inc.
  5. ;;
  6. ;; Author: Sebastian Wiesner <swiesner@lunaryorn.com>
  7. ;; Maintainer: Clément Pit-Claudel <clement.pitclaudel@live.com>
  8. ;; fmdkdd <fmdkdd@gmail.com>
  9. ;; URL: http://www.flycheck.org
  10. ;; Keywords: convenience, languages, tools
  11. ;; Version: 31
  12. ;; Package-Requires: ((dash "2.12.1") (pkg-info "0.4") (let-alist "1.0.4") (seq "1.11") (emacs "24.3"))
  13. ;; This file is not part of GNU Emacs.
  14. ;; This program is free software: you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation, either version 3 of the License, or
  17. ;; (at your option) any later version.
  18. ;; This program is distributed in the hope that it will be useful,
  19. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;; GNU General Public License for more details.
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. ;;; Commentary:
  25. ;; On-the-fly syntax checking for GNU Emacs 24.
  26. ;;
  27. ;; Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs,
  28. ;; intended as replacement for the older Flymake extension which is part of GNU
  29. ;; Emacs.
  30. ;;
  31. ;; Flycheck automatically checks buffers for errors while you type, and reports
  32. ;; warnings and errors directly in the buffer and in an optional IDE-like error
  33. ;; list.
  34. ;;
  35. ;; It comes with a rich interface for custom syntax checkers and other
  36. ;; extensions, and has already many 3rd party extensions adding new features.
  37. ;;
  38. ;; Please read the online manual at http://www.flycheck.org for more
  39. ;; information. You can open the manual directly from Emacs with `M-x
  40. ;; flycheck-manual'.
  41. ;;
  42. ;; # Setup
  43. ;;
  44. ;; Flycheck works best on Unix systems. It does not officially support Windows,
  45. ;; but tries to maintain Windows compatibility and should generally work fine on
  46. ;; Windows, too.
  47. ;;
  48. ;; To enable Flycheck add the following to your init file:
  49. ;;
  50. ;; (add-hook 'after-init-hook #'global-flycheck-mode)
  51. ;;
  52. ;; Flycheck will then automatically check buffers in supported languages, as
  53. ;; long as all necessary tools are present. Use `flycheck-verify-setup' to
  54. ;; troubleshoot your Flycheck setup.
  55. ;;; Code:
  56. (eval-when-compile
  57. (require 'let-alist) ; `let-alist'
  58. (require 'compile) ; Compile Mode integration
  59. (require 'jka-compr) ; To inhibit compression of temp files
  60. (require 'pcase) ; `pcase-dolist' (`pcase' itself is autoloaded)
  61. )
  62. (require 'dash)
  63. (require 'seq) ; Sequence functions
  64. (require 'subr-x nil 'no-error) ; Additional utilities, Emacs 24.4 and upwards
  65. (require 'cl-lib) ; `cl-defstruct' and CL utilities
  66. (require 'tabulated-list) ; To list errors
  67. (require 'easymenu) ; Flycheck Mode menu definition
  68. (require 'rx) ; Regexp fanciness in `flycheck-define-checker'
  69. (require 'help-mode) ; `define-button-type'
  70. (require 'find-func) ; `find-function-regexp-alist'
  71. (require 'json) ; `flycheck-parse-tslint'
  72. ;; Declare a bunch of dynamic variables that we need from other modes
  73. (defvar sh-shell) ; For shell script checker predicates
  74. (defvar ess-language) ; For r-lintr predicate
  75. ;; Tell the byte compiler about autoloaded functions from packages
  76. (declare-function pkg-info-version-info "pkg-info" (package))
  77. ;;; Compatibility
  78. (eval-and-compile
  79. (unless (fboundp 'string-suffix-p)
  80. ;; TODO: Remove when dropping support for Emacs 24.3 and earlier
  81. (defun string-suffix-p (suffix string &optional ignore-case)
  82. "Return non-nil if SUFFIX is a suffix of STRING.
  83. If IGNORE-CASE is non-nil, the comparison is done without paying
  84. attention to case differences."
  85. (let ((start-pos (- (length string) (length suffix))))
  86. (and (>= start-pos 0)
  87. (eq t (compare-strings suffix nil nil
  88. string start-pos nil ignore-case))))))
  89. ;; TODO: Remove when dropping support for Emacs 24.3 and earlier
  90. (unless (featurep 'subr-x)
  91. ;; `subr-x' function for Emacs 24.3 and below
  92. (defsubst string-join (strings &optional separator)
  93. "Join all STRINGS using SEPARATOR."
  94. (mapconcat 'identity strings separator))
  95. (defsubst string-trim-left (string)
  96. "Remove leading whitespace from STRING."
  97. (if (string-match "\\`[ \t\n\r]+" string)
  98. (replace-match "" t t string)
  99. string))
  100. (defsubst string-trim-right (string)
  101. "Remove trailing whitespace from STRING."
  102. (if (string-match "[ \t\n\r]+\\'" string)
  103. (replace-match "" t t string)
  104. string))
  105. (defsubst string-trim (string)
  106. "Remove leading and trailing whitespace from STRING."
  107. (string-trim-left (string-trim-right string)))
  108. (defsubst string-empty-p (string)
  109. "Check whether STRING is empty."
  110. (string= string ""))))
  111. ;;; Customization
  112. (defgroup flycheck nil
  113. "Modern on-the-fly syntax checking for GNU Emacs."
  114. :prefix "flycheck-"
  115. :group 'tools
  116. :link '(url-link :tag "Website" "http://www.flycheck.org")
  117. :link '(url-link :tag "Github" "https://github.com/flycheck/flycheck"))
  118. (defgroup flycheck-config-files nil
  119. "Configuration files for on-the-fly syntax checkers."
  120. :prefix "flycheck-"
  121. :group 'flycheck)
  122. (defgroup flycheck-options nil
  123. "Options for on-the-fly syntax checkers."
  124. :prefix "flycheck-"
  125. :group 'flycheck)
  126. (defgroup flycheck-executables nil
  127. "Executables of syntax checkers."
  128. :prefix "flycheck-"
  129. :group 'flycheck)
  130. (defgroup flycheck-faces nil
  131. "Faces used by on-the-fly syntax checking."
  132. :prefix "flycheck-"
  133. :group 'flycheck)
  134. (defcustom flycheck-checkers
  135. '(ada-gnat
  136. asciidoctor
  137. asciidoc
  138. c/c++-clang
  139. c/c++-gcc
  140. c/c++-cppcheck
  141. cfengine
  142. chef-foodcritic
  143. coffee
  144. coffee-coffeelint
  145. coq
  146. css-csslint
  147. css-stylelint
  148. d-dmd
  149. dockerfile-hadolint
  150. elixir-dogma
  151. emacs-lisp
  152. emacs-lisp-checkdoc
  153. erlang-rebar3
  154. erlang
  155. eruby-erubis
  156. fortran-gfortran
  157. go-gofmt
  158. go-golint
  159. go-vet
  160. go-build
  161. go-test
  162. go-errcheck
  163. go-unconvert
  164. go-megacheck
  165. groovy
  166. haml
  167. handlebars
  168. haskell-stack-ghc
  169. haskell-ghc
  170. haskell-hlint
  171. html-tidy
  172. javascript-eslint
  173. javascript-jshint
  174. javascript-jscs
  175. javascript-standard
  176. json-jsonlint
  177. json-python-json
  178. less
  179. less-stylelint
  180. llvm-llc
  181. lua-luacheck
  182. lua
  183. perl
  184. perl-perlcritic
  185. php
  186. php-phpmd
  187. php-phpcs
  188. processing
  189. proselint
  190. protobuf-protoc
  191. pug
  192. puppet-parser
  193. puppet-lint
  194. python-flake8
  195. python-pylint
  196. python-pycompile
  197. r-lintr
  198. racket
  199. rpm-rpmlint
  200. markdown-mdl
  201. nix
  202. rst-sphinx
  203. rst
  204. ruby-rubocop
  205. ruby-reek
  206. ruby-rubylint
  207. ruby
  208. ruby-jruby
  209. rust-cargo
  210. rust
  211. scala
  212. scala-scalastyle
  213. scheme-chicken
  214. scss-lint
  215. scss-stylelint
  216. sass/scss-sass-lint
  217. sass
  218. scss
  219. sh-bash
  220. sh-posix-dash
  221. sh-posix-bash
  222. sh-zsh
  223. sh-shellcheck
  224. slim
  225. slim-lint
  226. sql-sqlint
  227. systemd-analyze
  228. tex-chktex
  229. tex-lacheck
  230. texinfo
  231. typescript-tslint
  232. verilog-verilator
  233. xml-xmlstarlet
  234. xml-xmllint
  235. yaml-jsyaml
  236. yaml-ruby)
  237. "Syntax checkers available for automatic selection.
  238. A list of Flycheck syntax checkers to choose from when syntax
  239. checking a buffer. Flycheck will automatically select a suitable
  240. syntax checker from this list, unless `flycheck-checker' is set,
  241. either directly or with `flycheck-select-checker'.
  242. You should not need to change this variable normally. In order
  243. to disable syntax checkers, please use
  244. `flycheck-disabled-checkers'. This variable is intended for 3rd
  245. party extensions to tell Flycheck about new syntax checkers.
  246. Syntax checkers in this list must be defined with
  247. `flycheck-define-checker'."
  248. :group 'flycheck
  249. :type '(repeat (symbol :tag "Checker"))
  250. :risky t)
  251. (defcustom flycheck-disabled-checkers nil
  252. "Syntax checkers excluded from automatic selection.
  253. A list of Flycheck syntax checkers to exclude from automatic
  254. selection. Flycheck will never automatically select a syntax
  255. checker in this list, regardless of the value of
  256. `flycheck-checkers'.
  257. However, syntax checkers in this list are still available for
  258. manual selection with `flycheck-select-checker'.
  259. Use this variable to disable syntax checkers, instead of removing
  260. the syntax checkers from `flycheck-checkers'. You may also use
  261. this option as a file or directory local variable to disable
  262. specific checkers in individual files and directories
  263. respectively."
  264. :group 'flycheck
  265. :type '(repeat (symbol :tag "Checker"))
  266. :package-version '(flycheck . "0.16")
  267. :safe #'flycheck-symbol-list-p)
  268. (make-variable-buffer-local 'flycheck-disabled-checkers)
  269. (defvar-local flycheck-checker nil
  270. "Syntax checker to use for the current buffer.
  271. If unset or nil, automatically select a suitable syntax checker
  272. from `flycheck-checkers' on every syntax check.
  273. If set to a syntax checker only use this syntax checker and never
  274. select one from `flycheck-checkers' automatically. The syntax
  275. checker is used regardless of whether it is contained in
  276. `flycheck-checkers' or `flycheck-disabled-checkers'. If the
  277. syntax checker is unusable in the current buffer an error is
  278. signaled.
  279. A syntax checker assigned to this variable must be defined with
  280. `flycheck-define-checker'.
  281. Use the command `flycheck-select-checker' to select a syntax
  282. checker for the current buffer, or set this variable as file
  283. local variable to always use a specific syntax checker for a
  284. file. See Info Node `(emacs)Specifying File Variables' for more
  285. information about file variables.")
  286. (put 'flycheck-checker 'safe-local-variable 'flycheck-registered-checker-p)
  287. (defcustom flycheck-locate-config-file-functions nil
  288. "Functions to locate syntax checker configuration files.
  289. Each function in this hook must accept two arguments: The value
  290. of the configuration file variable, and the syntax checker
  291. symbol. It must return either a string with an absolute path to
  292. the configuration file, or nil, if it cannot locate the
  293. configuration file.
  294. The functions in this hook are called in order of appearance, until a
  295. function returns non-nil. The configuration file returned by that
  296. function is then given to the syntax checker if it exists.
  297. This variable is an abnormal hook. See Info
  298. node `(elisp)Hooks'."
  299. :group 'flycheck
  300. :type 'hook
  301. :risky t)
  302. (defcustom flycheck-checker-error-threshold 400
  303. "Maximum errors allowed per syntax checker.
  304. The value of this variable is either an integer denoting the
  305. maximum number of errors per syntax checker and buffer, or nil to
  306. not limit the errors reported from a syntax checker.
  307. If this variable is a number and a syntax checker reports more
  308. errors than the value of this variable, its errors are not
  309. discarded, and not highlighted in the buffer or available in the
  310. error list. The affected syntax checker is also disabled for
  311. future syntax checks of the buffer."
  312. :group 'flycheck
  313. :type '(choice (const :tag "Do not limit reported errors" nil)
  314. (integer :tag "Maximum number of errors"))
  315. :risky t
  316. :package-version '(flycheck . "0.22"))
  317. (defcustom flycheck-process-error-functions nil
  318. "Functions to process errors.
  319. Each function in this hook must accept a single argument: A
  320. Flycheck error to process.
  321. All functions in this hook are called in order of appearance,
  322. until a function returns non-nil. Thus, a function in this hook
  323. may return nil, to allow for further processing of the error, or
  324. any non-nil value, to indicate that the error was fully processed
  325. and inhibit any further processing.
  326. The functions are called for each newly parsed error immediately
  327. after the corresponding syntax checker finished. At this stage,
  328. the overlays from the previous syntax checks are still present,
  329. and there may be further syntax checkers in the chain.
  330. This variable is an abnormal hook. See Info
  331. node `(elisp)Hooks'."
  332. :group 'flycheck
  333. :type 'hook
  334. :package-version '(flycheck . "0.13")
  335. :risky t)
  336. (defcustom flycheck-display-errors-delay 0.9
  337. "Delay in seconds before displaying errors at point.
  338. Use floating point numbers to express fractions of seconds."
  339. :group 'flycheck
  340. :type 'number
  341. :package-version '(flycheck . "0.15")
  342. :safe #'numberp)
  343. (defcustom flycheck-display-errors-function #'flycheck-display-error-messages
  344. "Function to display error messages.
  345. If set to a function, call the function with the list of errors
  346. to display as single argument. Each error is an instance of the
  347. `flycheck-error' struct.
  348. If set to nil, do not display errors at all."
  349. :group 'flycheck
  350. :type '(choice (const :tag "Display error messages"
  351. flycheck-display-error-messages)
  352. (const :tag "Display error messages only if no error list"
  353. flycheck-display-error-messages-unless-error-list)
  354. (function :tag "Error display function"))
  355. :package-version '(flycheck . "0.13")
  356. :risky t)
  357. (defcustom flycheck-help-echo-function #'flycheck-help-echo-all-error-messages
  358. "Function to compute the contents of the error tooltips.
  359. If set to a function, call the function with the list of errors
  360. to display as single argument. Each error is an instance of the
  361. `flycheck-error' struct. The function is used to set the
  362. help-echo property of flycheck error overlays. It should return
  363. a string, which is displayed when the user hovers over an error
  364. or presses \\[display-local-help].
  365. If set to nil, do not show error tooltips."
  366. :group 'flycheck
  367. :type '(choice (const :tag "Concatenate error messages to form a tooltip"
  368. flycheck-help-echo-all-error-messages)
  369. (function :tag "Help echo function"))
  370. :package-version '(flycheck . "0.25")
  371. :risky t)
  372. (defcustom flycheck-command-wrapper-function #'identity
  373. "Function to modify checker commands before execution.
  374. The value of this option is a function which is given a list
  375. containing the full command of a syntax checker after
  376. substitution through `flycheck-substitute-argument' but before
  377. execution. The function may return a new command for Flycheck to
  378. execute.
  379. The default value is `identity' which does not change the
  380. command. You may provide your own function to run Flycheck
  381. commands through `bundle exec', `nix-shell' or similar wrappers."
  382. :group 'flycheck
  383. :type '(choice (const :tag "Do not modify commands" identity)
  384. (function :tag "Modify command with a custom function"))
  385. :package-version '(flycheck . "0.25")
  386. :risky t)
  387. (defcustom flycheck-executable-find #'executable-find
  388. "Function to search for executables.
  389. The value of this option is a function which is given the name or
  390. path of an executable and shall return the full path to the
  391. executable, or nil if the executable does not exit.
  392. The default is the standard `executable-find' function which
  393. searches `exec-path'. You can customize this option to search
  394. for checkers in other environments such as bundle or NixOS
  395. sandboxes."
  396. :group 'flycheck
  397. :type '(choice (const :tag "Search executables in `exec-path'" executable-find)
  398. (function :tag "Search executables with a custom function"))
  399. :package-version '(flycheck . "0.25")
  400. :risky t)
  401. (defcustom flycheck-indication-mode 'left-fringe
  402. "The indication mode for Flycheck errors and warnings.
  403. This variable controls how Flycheck indicates errors in buffers.
  404. May either be `left-fringe', `right-fringe', or nil.
  405. If set to `left-fringe' or `right-fringe', indicate errors and
  406. warnings via icons in the left and right fringe respectively.
  407. If set to nil, do not indicate errors and warnings, but just
  408. highlight them according to `flycheck-highlighting-mode'."
  409. :group 'flycheck
  410. :type '(choice (const :tag "Indicate in the left fringe" left-fringe)
  411. (const :tag "Indicate in the right fringe" right-fringe)
  412. (const :tag "Do not indicate" nil))
  413. :safe #'symbolp)
  414. (defcustom flycheck-highlighting-mode 'symbols
  415. "The highlighting mode for Flycheck errors and warnings.
  416. The highlighting mode controls how Flycheck highlights errors in
  417. buffers. The following modes are known:
  418. `columns'
  419. Highlight the error column. If the error does not have a column,
  420. highlight the whole line.
  421. `symbols'
  422. Highlight the symbol at the error column, if there is any,
  423. otherwise behave like `columns'. This is the default.
  424. `sexps'
  425. Highlight the expression at the error column, if there is
  426. any, otherwise behave like `columns'. Note that this mode
  427. can be *very* slow in some major modes.
  428. `lines'
  429. Highlight the whole line.
  430. nil
  431. Do not highlight errors at all. However, errors will still
  432. be reported in the mode line and in error message popups,
  433. and indicated according to `flycheck-indication-mode'."
  434. :group 'flycheck
  435. :type '(choice (const :tag "Highlight columns only" columns)
  436. (const :tag "Highlight symbols" symbols)
  437. (const :tag "Highlight expressions" sexps)
  438. (const :tag "Highlight whole lines" lines)
  439. (const :tag "Do not highlight errors" nil))
  440. :package-version '(flycheck . "0.14")
  441. :safe #'symbolp)
  442. (defcustom flycheck-check-syntax-automatically '(save
  443. idle-change
  444. new-line
  445. mode-enabled)
  446. "When Flycheck should check syntax automatically.
  447. This variable is a list of events that may trigger syntax checks.
  448. The following events are known:
  449. `save'
  450. Check syntax immediately after the buffer was saved.
  451. `idle-change'
  452. Check syntax a short time (see `flycheck-idle-change-delay')
  453. after the last change to the buffer.
  454. `new-line'
  455. Check syntax immediately after a new line was inserted into
  456. the buffer.
  457. `mode-enabled'
  458. Check syntax immediately when variable `flycheck-mode' is
  459. non-nil.
  460. Flycheck performs a syntax checks only on events, which are
  461. contained in this list. For instance, if the value of this
  462. variable is `(mode-enabled save)', Flycheck will only check if
  463. the mode is enabled or the buffer was saved, but never after
  464. changes to the buffer contents.
  465. If nil, never check syntax automatically. In this case, use
  466. `flycheck-buffer' to start a syntax check manually."
  467. :group 'flycheck
  468. :type '(set (const :tag "After the buffer was saved" save)
  469. (const :tag "After the buffer was changed and idle" idle-change)
  470. (const :tag "After a new line was inserted" new-line)
  471. (const :tag "After `flycheck-mode' was enabled" mode-enabled))
  472. :package-version '(flycheck . "0.12")
  473. :safe #'flycheck-symbol-list-p)
  474. (defcustom flycheck-idle-change-delay 0.5
  475. "How many seconds to wait before checking syntax automatically.
  476. After the buffer was changed, Flycheck will wait as many seconds
  477. as the value of this variable before starting a syntax check. If
  478. the buffer is modified during this time, Flycheck will wait
  479. again.
  480. This variable has no effect, if `idle-change' is not contained in
  481. `flycheck-check-syntax-automatically'."
  482. :group 'flycheck
  483. :type 'number
  484. :package-version '(flycheck . "0.13")
  485. :safe #'numberp)
  486. (defcustom flycheck-standard-error-navigation t
  487. "Whether to support error navigation with `next-error'.
  488. If non-nil, enable navigation of Flycheck errors with
  489. `next-error', `previous-error' and `first-error'. Otherwise,
  490. these functions just navigate errors from compilation modes.
  491. Flycheck error navigation with `flycheck-next-error',
  492. `flycheck-previous-error' and `flycheck-first-error' is always
  493. enabled, regardless of the value of this variable.
  494. Note that this setting only takes effect when variable
  495. `flycheck-mode' is non-nil. Changing it will not affect buffers
  496. where variable `flycheck-mode' is already non-nil."
  497. :group 'flycheck
  498. :type 'boolean
  499. :package-version '(flycheck . "0.15")
  500. :safe #'booleanp)
  501. (define-widget 'flycheck-minimum-level 'lazy
  502. "A radio-type choice of minimum error levels.
  503. See `flycheck-navigation-minimum-level' and
  504. `flycheck-error-list-minimum-level'."
  505. :type '(radio (const :tag "All locations" nil)
  506. (const :tag "Informational messages" info)
  507. (const :tag "Warnings" warning)
  508. (const :tag "Errors" error)
  509. (symbol :tag "Custom error level")))
  510. (defcustom flycheck-navigation-minimum-level nil
  511. "The minimum level of errors to navigate.
  512. If set to an error level, only navigate errors whose error level
  513. is at least as severe as this one. If nil, navigate all errors."
  514. :group 'flycheck
  515. :type 'flycheck-minimum-level
  516. :safe #'flycheck-error-level-p
  517. :package-version '(flycheck . "0.21"))
  518. (defcustom flycheck-error-list-minimum-level nil
  519. "The minimum level of errors to display in the error list.
  520. If set to an error level, only display errors whose error level
  521. is at least as severe as this one in the error list. If nil,
  522. display all errors.
  523. This is the default level, used when the error list is opened.
  524. You can temporarily change the level using
  525. \\[flycheck-error-list-set-filter], or reset it to this value
  526. using \\[flycheck-error-list-reset-filter]."
  527. :group 'flycheck
  528. :type 'flycheck-minimum-level
  529. :safe #'flycheck-error-level-p
  530. :package-version '(flycheck . "0.24"))
  531. (defcustom flycheck-completing-read-function #'completing-read
  532. "Function to read from minibuffer with completion.
  533. The function must be compatible to the built-in `completing-read'
  534. function."
  535. :group 'flycheck
  536. :type '(choice (const :tag "Default" completing-read)
  537. (const :tag "IDO" ido-completing-read)
  538. (function :tag "Custom function"))
  539. :risky t
  540. :package-version '(flycheck . "26"))
  541. (defcustom flycheck-temp-prefix "flycheck"
  542. "Prefix for temporary files created by Flycheck."
  543. :group 'flycheck
  544. :type 'string
  545. :package-version '(flycheck . "0.19")
  546. :risky t)
  547. (defcustom flycheck-mode-hook nil
  548. "Hooks to run after command `flycheck-mode' is toggled."
  549. :group 'flycheck
  550. :type 'hook
  551. :risky t)
  552. (defcustom flycheck-after-syntax-check-hook nil
  553. "Functions to run after each syntax check.
  554. This hook is run after a syntax check was finished.
  555. At this point, *all* chained checkers were run, and all errors
  556. were parsed, highlighted and reported. The variable
  557. `flycheck-current-errors' contains all errors from all syntax
  558. checkers run during the syntax check, so you can apply any error
  559. analysis functions.
  560. Note that this hook does *not* run after each individual syntax
  561. checker in the syntax checker chain, but only after the *last
  562. checker*.
  563. This variable is a normal hook. See Info node `(elisp)Hooks'."
  564. :group 'flycheck
  565. :type 'hook
  566. :risky t)
  567. (defcustom flycheck-before-syntax-check-hook nil
  568. "Functions to run before each syntax check.
  569. This hook is run right before a syntax check starts.
  570. Error information from the previous syntax check is *not*
  571. cleared before this hook runs.
  572. Note that this hook does *not* run before each individual syntax
  573. checker in the syntax checker chain, but only before the *first
  574. checker*.
  575. This variable is a normal hook. See Info node `(elisp)Hooks'."
  576. :group 'flycheck
  577. :type 'hook
  578. :risky t)
  579. (defcustom flycheck-syntax-check-failed-hook nil
  580. "Functions to run if a syntax check failed.
  581. This hook is run whenever an error occurs during Flycheck's
  582. internal processing. No information about the error is given to
  583. this hook.
  584. You should use this hook to conduct additional cleanup actions
  585. when Flycheck failed.
  586. This variable is a normal hook. See Info node `(elisp)Hooks'."
  587. :group 'flycheck
  588. :type 'hook
  589. :risky t)
  590. (defcustom flycheck-status-changed-functions nil
  591. "Functions to run if the Flycheck status changed.
  592. This hook is run whenever the status of Flycheck changes. Each
  593. hook function takes the status symbol as single argument, as
  594. given to `flycheck-report-status', which see.
  595. This variable is a abnormal hook. See Info
  596. node `(elisp)Hooks'."
  597. :group 'flycheck
  598. :type 'hook
  599. :risky t
  600. :package-version '(flycheck . "0.20"))
  601. (defcustom flycheck-error-list-after-refresh-hook nil
  602. "Functions to run after the error list was refreshed.
  603. This hook is run whenever the error list is refreshed.
  604. This variable is a normal hook. See Info node `(elisp)Hooks'."
  605. :group 'flycheck
  606. :type 'hook
  607. :risky t
  608. :package-version '(flycheck . "0.21"))
  609. (defface flycheck-error
  610. '((((supports :underline (:style wave)))
  611. :underline (:style wave :color "Red1"))
  612. (t
  613. :underline t :inherit error))
  614. "Flycheck face for errors."
  615. :package-version '(flycheck . "0.13")
  616. :group 'flycheck-faces)
  617. (defface flycheck-warning
  618. '((((supports :underline (:style wave)))
  619. :underline (:style wave :color "DarkOrange"))
  620. (t
  621. :underline t :inherit warning))
  622. "Flycheck face for warnings."
  623. :package-version '(flycheck . "0.13")
  624. :group 'flycheck-faces)
  625. (defface flycheck-info
  626. '((((supports :underline (:style wave)))
  627. :underline (:style wave :color "ForestGreen"))
  628. (t
  629. :underline t :inherit success))
  630. "Flycheck face for informational messages."
  631. :package-version '(flycheck . "0.15")
  632. :group 'flycheck-faces)
  633. (defface flycheck-fringe-error
  634. '((t :inherit error))
  635. "Flycheck face for fringe error indicators."
  636. :package-version '(flycheck . "0.13")
  637. :group 'flycheck-faces)
  638. (defface flycheck-fringe-warning
  639. '((t :inherit warning))
  640. "Flycheck face for fringe warning indicators."
  641. :package-version '(flycheck . "0.13")
  642. :group 'flycheck-faces)
  643. (defface flycheck-fringe-info
  644. ;; Semantically `success' is probably not the right face, but it looks nice as
  645. ;; a base face
  646. '((t :inherit success))
  647. "Flycheck face for fringe info indicators."
  648. :package-version '(flycheck . "0.15")
  649. :group 'flycheck-faces)
  650. (defface flycheck-error-list-error
  651. '((t :inherit error))
  652. "Flycheck face for error messages in the error list."
  653. :package-version '(flycheck . "0.16")
  654. :group 'flycheck-faces)
  655. (defface flycheck-error-list-warning
  656. '((t :inherit warning))
  657. "Flycheck face for warning messages in the error list."
  658. :package-version '(flycheck . "0.16")
  659. :group 'flycheck-faces)
  660. (defface flycheck-error-list-info
  661. '((t :inherit success))
  662. "Flycheck face for info messages in the error list."
  663. :package-version '(flycheck . "0.16")
  664. :group 'flycheck-faces)
  665. ;; The base faces for the following two faces are inspired by Compilation Mode
  666. (defface flycheck-error-list-line-number
  667. '((t :inherit font-lock-constant-face))
  668. "Face for line numbers in the error list."
  669. :group 'flycheck-faces
  670. :package-version '(flycheck . "0.16"))
  671. (defface flycheck-error-list-column-number
  672. '((t :inherit font-lock-constant-face))
  673. "Face for line numbers in the error list."
  674. :group 'flycheck-faces
  675. :package-version '(flycheck . "0.16"))
  676. (defface flycheck-error-list-id
  677. '((t :inherit font-lock-type-face))
  678. "Face for the error ID in the error list."
  679. :group 'flycheck-faces
  680. :package-version '(flycheck . "0.22"))
  681. (defface flycheck-error-list-id-with-explainer
  682. '((t :inherit flycheck-error-list-id
  683. :box (:style released-button)))
  684. "Face for the error ID in the error list, for errors that have an explainer."
  685. :group 'flycheck-faces
  686. :package-version '(flycheck . "30"))
  687. (defface flycheck-error-list-checker-name
  688. '((t :inherit font-lock-function-name-face))
  689. "Face for the syntax checker name in the error list."
  690. :group 'flycheck-faces
  691. :package-version '(flycheck . "0.21"))
  692. (defface flycheck-error-list-highlight
  693. '((t :inherit highlight))
  694. "Flycheck face to highlight errors in the error list."
  695. :package-version '(flycheck . "0.15")
  696. :group 'flycheck-faces)
  697. (defvar flycheck-command-map
  698. (let ((map (make-sparse-keymap)))
  699. (define-key map "c" #'flycheck-buffer)
  700. (define-key map "C" #'flycheck-clear)
  701. (define-key map (kbd "C-c") #'flycheck-compile)
  702. (define-key map "n" #'flycheck-next-error)
  703. (define-key map "p" #'flycheck-previous-error)
  704. (define-key map "l" #'flycheck-list-errors)
  705. (define-key map (kbd "C-w") #'flycheck-copy-errors-as-kill)
  706. (define-key map "s" #'flycheck-select-checker)
  707. (define-key map "?" #'flycheck-describe-checker)
  708. (define-key map "h" #'flycheck-display-error-at-point)
  709. (define-key map "e" #'flycheck-explain-error-at-point)
  710. (define-key map "H" #'display-local-help)
  711. (define-key map "i" #'flycheck-manual)
  712. (define-key map "V" #'flycheck-version)
  713. (define-key map "v" #'flycheck-verify-setup)
  714. (define-key map "x" #'flycheck-disable-checker)
  715. map)
  716. "Keymap of Flycheck interactive commands.")
  717. (defcustom flycheck-keymap-prefix (kbd "C-c !")
  718. "Prefix for key bindings of Flycheck.
  719. Changing this variable outside Customize does not have any
  720. effect. To change the keymap prefix from Lisp, you need to
  721. explicitly re-define the prefix key:
  722. (define-key flycheck-mode-map flycheck-keymap-prefix nil)
  723. (setq flycheck-keymap-prefix (kbd \"C-c f\"))
  724. (define-key flycheck-mode-map flycheck-keymap-prefix
  725. flycheck-command-map)
  726. Please note that Flycheck's manual documents the default
  727. keybindings. Changing this variable is at your own risk."
  728. :group 'flycheck
  729. :package-version '(flycheck . "0.19")
  730. :type 'string
  731. :risky t
  732. :set
  733. (lambda (variable key)
  734. (when (and (boundp variable) (boundp 'flycheck-mode-map))
  735. (define-key flycheck-mode-map (symbol-value variable) nil)
  736. (define-key flycheck-mode-map key flycheck-command-map))
  737. (set-default variable key)))
  738. (defcustom flycheck-mode-line '(:eval (flycheck-mode-line-status-text))
  739. "Mode line lighter for Flycheck.
  740. The value of this variable is a mode line template as in
  741. `mode-line-format'. See Info Node `(elisp)Mode Line Format' for
  742. more information. Note that it should contain a _single_ mode
  743. line construct only.
  744. Customize this variable to change how Flycheck reports its status
  745. in the mode line. You may use `flycheck-mode-line-status-text'
  746. to obtain a human-readable status text, including an
  747. error/warning count.
  748. You may also assemble your own status text. The current status
  749. of Flycheck is available in `flycheck-last-status-change'. The
  750. errors in the current buffer are stored in
  751. `flycheck-current-errors', and the function
  752. `flycheck-count-errors' may be used to obtain the number of
  753. errors grouped by error level.
  754. Set this variable to nil to disable the mode line completely."
  755. :group 'flycheck
  756. :type 'sexp
  757. :risky t
  758. :package-version '(flycheck . "0.20"))
  759. (defcustom flycheck-mode-line-prefix "FlyC"
  760. "Base mode line lighter for Flycheck.
  761. This will have an effect only with the default
  762. `flycheck-mode-line'.
  763. If you've customized `flycheck-mode-line' then the customized
  764. function must be updated to use this variable."
  765. :group 'flycheck
  766. :type 'string
  767. :package-version '(flycheck . "26"))
  768. (defcustom flycheck-error-list-mode-line
  769. `(,(propertized-buffer-identification "%12b")
  770. " for buffer "
  771. (:eval (flycheck-error-list-propertized-source-name))
  772. (:eval (flycheck-error-list-mode-line-filter-indicator)))
  773. "Mode line construct for Flycheck error list.
  774. The value of this variable is a mode line template as in
  775. `mode-line-format', to be used as
  776. `mode-line-buffer-identification' in `flycheck-error-list-mode'.
  777. See Info Node `(elisp)Mode Line Format' for more information.
  778. Customize this variable to change how the error list appears in
  779. the mode line. The default shows the name of the buffer and the
  780. name of the source buffer, i.e. the buffer whose errors are
  781. currently listed."
  782. :group 'flycheck
  783. :type 'sexp
  784. :risky t
  785. :package-version '(flycheck . "0.20"))
  786. (defcustom flycheck-global-modes t
  787. "Modes for which option `flycheck-mode' is turned on.
  788. If t, Flycheck Mode is turned on for all major modes. If a list,
  789. Flycheck Mode is turned on for all `major-mode' symbols in that
  790. list. If the `car' of the list is `not', Flycheck Mode is turned
  791. on for all `major-mode' symbols _not_ in that list. If nil,
  792. Flycheck Mode is never turned on by command
  793. `global-flycheck-mode'.
  794. Note that Flycheck is never turned on for modes whose
  795. `mode-class' property is `special' (see Info node `(elisp)Major
  796. Mode Conventions'), regardless of the value of this option.
  797. Only has effect when variable `global-flycheck-mode' is non-nil."
  798. :group 'flycheck
  799. :type '(choice (const :tag "none" nil)
  800. (const :tag "all" t)
  801. (set :menu-tag "mode specific" :tag "modes"
  802. :value (not)
  803. (const :tag "Except" not)
  804. (repeat :inline t (symbol :tag "mode"))))
  805. :risky t
  806. :package-version '(flycheck . "0.23"))
  807. ;; Add built-in functions to our hooks, via `add-hook', to make sure that our
  808. ;; functions are really present, even if the variable was implicitly defined by
  809. ;; another call to `add-hook' that occurred before Flycheck was loaded. See
  810. ;; http://lists.gnu.org/archive/html/emacs-devel/2015-02/msg01271.html for why
  811. ;; we don't initialize the hook variables right away. We append our own
  812. ;; functions, because a user likely expects that their functions come first,
  813. ;; even if the added them before Flycheck was loaded.
  814. (dolist (hook (list #'flycheck-locate-config-file-by-path
  815. #'flycheck-locate-config-file-ancestor-directories
  816. #'flycheck-locate-config-file-home))
  817. (add-hook 'flycheck-locate-config-file-functions hook 'append))
  818. (add-hook 'flycheck-process-error-functions #'flycheck-add-overlay 'append)
  819. ;;; Global Flycheck menu
  820. (defvar flycheck-mode-menu-map
  821. (easy-menu-create-menu
  822. "Syntax Checking"
  823. '(["Enable on-the-fly syntax checking" flycheck-mode
  824. :style toggle :selected flycheck-mode
  825. :enable (or flycheck-mode
  826. ;; Don't let users toggle the mode if there is no syntax
  827. ;; checker for this buffer
  828. (seq-find #'flycheck-checker-supports-major-mode-p
  829. flycheck-checkers))]
  830. ["Check current buffer" flycheck-buffer flycheck-mode]
  831. ["Clear errors in buffer" flycheck-clear t]
  832. "---"
  833. ["Go to next error" flycheck-next-error flycheck-mode]
  834. ["Go to previous error" flycheck-previous-error flycheck-mode]
  835. ["Show all errors" flycheck-list-errors flycheck-mode]
  836. "---"
  837. ["Copy messages at point" flycheck-copy-errors-as-kill
  838. (flycheck-overlays-at (point))]
  839. ["Explain error at point" flycheck-explain-error-at-point]
  840. "---"
  841. ["Select syntax checker" flycheck-select-checker flycheck-mode]
  842. ["Disable syntax checker" flycheck-disable-checker flycheck-mode]
  843. ["Set executable of syntax checker" flycheck-set-checker-executable
  844. flycheck-mode]
  845. "---"
  846. ["Describe syntax checker" flycheck-describe-checker t]
  847. ["Show Flycheck version" flycheck-version t]
  848. ["Read the Flycheck manual" flycheck-info t]))
  849. "Menu of command `flycheck-mode'.")
  850. (easy-menu-add-item nil '("Tools") flycheck-mode-menu-map "Spell Checking")
  851. ;;; Version information, manual and loading of Flycheck
  852. (defun flycheck-version (&optional show-version)
  853. "Get the Flycheck version as string.
  854. If called interactively or if SHOW-VERSION is non-nil, show the
  855. version in the echo area and the messages buffer.
  856. The returned string includes both, the version from package.el
  857. and the library version, if both a present and different.
  858. If the version number could not be determined, signal an error,
  859. if called interactively, or if SHOW-VERSION is non-nil, otherwise
  860. just return nil."
  861. (interactive (list t))
  862. (let ((version (pkg-info-version-info 'flycheck)))
  863. (when show-version
  864. (message "Flycheck version: %s" version))
  865. version))
  866. (defun flycheck-unload-function ()
  867. "Unload function for Flycheck."
  868. (global-flycheck-mode -1)
  869. (easy-menu-remove-item nil '("Tools") (cadr flycheck-mode-menu-map))
  870. (remove-hook 'kill-emacs-hook #'flycheck-global-teardown)
  871. (setq find-function-regexp-alist
  872. (assq-delete-all 'flycheck-checker find-function-regexp-alist)))
  873. ;;;###autoload
  874. (defun flycheck-manual ()
  875. "Open the Flycheck manual."
  876. (interactive)
  877. (browse-url "http://www.flycheck.org"))
  878. (define-obsolete-function-alias 'flycheck-info
  879. 'flycheck-manual "26" "Open the Flycheck manual.")
  880. ;;; Utility functions
  881. (defun flycheck-sexp-to-string (sexp)
  882. "Convert SEXP to a string.
  883. Like `prin1-to-string' but ensure that the returned string
  884. is loadable."
  885. (let ((print-quoted t)
  886. (print-length nil)
  887. (print-level nil))
  888. (prin1-to-string sexp)))
  889. (defun flycheck-string-to-number-safe (string)
  890. "Safely convert STRING to a number.
  891. If STRING is of string type and a numeric string, convert STRING
  892. to a number and return it. Otherwise return nil."
  893. (let ((number-re (rx string-start (one-or-more (any digit)) string-end)))
  894. (when (and (stringp string) (string-match-p number-re string))
  895. (string-to-number string))))
  896. (defun flycheck-string-list-p (obj)
  897. "Determine if OBJ is a list of strings."
  898. (and (listp obj) (seq-every-p #'stringp obj)))
  899. (defun flycheck-symbol-list-p (obj)
  900. "Determine if OBJ is a list of symbols."
  901. (and (listp obj) (seq-every-p #'symbolp obj)))
  902. (defun flycheck-same-files-p (file-a file-b)
  903. "Determine whether FILE-A and FILE-B refer to the same file."
  904. (let ((file-a (expand-file-name file-a))
  905. (file-b (expand-file-name file-b)))
  906. ;; We must resolve symbolic links here, since some syntax checker always
  907. ;; output canonical file names with all symbolic links resolved. However,
  908. ;; we still do a simple path compassion first, to avoid the comparatively
  909. ;; expensive file system call if possible. See
  910. ;; https://github.com/flycheck/flycheck/issues/561
  911. (or (string= (directory-file-name file-a) (directory-file-name file-b))
  912. (string= (directory-file-name (file-truename file-a))
  913. (directory-file-name (file-truename file-b))))))
  914. (defvar-local flycheck-temporaries nil
  915. "Temporary files and directories created by Flycheck.")
  916. (defun flycheck-temp-dir-system ()
  917. "Create a unique temporary directory.
  918. Use `flycheck-temp-prefix' as prefix, and add the directory to
  919. `flycheck-temporaries'.
  920. Return the path of the directory"
  921. (let* ((tempdir (make-temp-file flycheck-temp-prefix 'directory)))
  922. (push tempdir flycheck-temporaries)
  923. tempdir))
  924. (defun flycheck-temp-file-system (filename)
  925. "Create a temporary file named after FILENAME.
  926. If FILENAME is non-nil, this function creates a temporary
  927. directory with `flycheck-temp-dir-system', and creates a file
  928. with the same name as FILENAME in this directory.
  929. Otherwise this function creates a temporary file with
  930. `flycheck-temp-prefix' and a random suffix. The path of the file
  931. is added to `flycheck-temporaries'.
  932. Add the path of the file to `flycheck-temporaries'.
  933. Return the path of the file."
  934. (let ((tempfile (convert-standard-filename
  935. (if filename
  936. (expand-file-name (file-name-nondirectory filename)
  937. (flycheck-temp-dir-system))
  938. (make-temp-file flycheck-temp-prefix)))))
  939. (push tempfile flycheck-temporaries)
  940. tempfile))
  941. (defun flycheck-temp-file-inplace (filename)
  942. "Create an in-place copy of FILENAME.
  943. Prefix the file with `flycheck-temp-prefix' and add the path of
  944. the file to `flycheck-temporaries'.
  945. If FILENAME is nil, fall back to `flycheck-temp-file-system'.
  946. Return the path of the file."
  947. (if filename
  948. (let* ((tempname (format "%s_%s"
  949. flycheck-temp-prefix
  950. (file-name-nondirectory filename)))
  951. (tempfile (convert-standard-filename
  952. (expand-file-name tempname
  953. (file-name-directory filename)))))
  954. (push tempfile flycheck-temporaries)
  955. tempfile)
  956. (flycheck-temp-file-system filename)))
  957. (defun flycheck-save-buffer-to-file (file-name)
  958. "Save the contents of the current buffer to FILE-NAME."
  959. (make-directory (file-name-directory file-name) t)
  960. (let ((jka-compr-inhibit t))
  961. (write-region nil nil file-name nil 0)))
  962. (defun flycheck-save-buffer-to-temp (temp-file-fn)
  963. "Save buffer to temp file returned by TEMP-FILE-FN.
  964. Return the name of the temporary file."
  965. (let ((filename (funcall temp-file-fn (buffer-file-name))))
  966. ;; Do not flush short-lived temporary files onto disk
  967. (let ((write-region-inhibit-fsync t))
  968. (flycheck-save-buffer-to-file filename))
  969. filename))
  970. (defun flycheck-prepend-with-option (option items &optional prepend-fn)
  971. "Prepend OPTION to each item in ITEMS, using PREPEND-FN.
  972. Prepend OPTION to each item in ITEMS.
  973. ITEMS is a list of strings to pass to the syntax checker. OPTION
  974. is the option, as string. PREPEND-FN is a function called to
  975. prepend OPTION to each item in ITEMS. It receives the option and
  976. a single item from ITEMS as argument, and must return a string or
  977. a list of strings with OPTION prepended to the item. If
  978. PREPEND-FN is nil or omitted, use `list'.
  979. Return a list of strings where OPTION is prepended to each item
  980. in ITEMS using PREPEND-FN. If PREPEND-FN returns a list, it is
  981. spliced into the resulting list."
  982. (unless (stringp option)
  983. (error "Option %S is not a string" option))
  984. (unless prepend-fn
  985. (setq prepend-fn #'list))
  986. (let ((prepend
  987. (lambda (item)
  988. (let ((result (funcall prepend-fn option item)))
  989. (cond
  990. ((and (listp result) (seq-every-p #'stringp result)) result)
  991. ((stringp result) (list result))
  992. (t (error "Invalid result type for option: %S" result)))))))
  993. (apply #'append (seq-map prepend items))))
  994. (defun flycheck-find-in-buffer (pattern)
  995. "Find PATTERN in the current buffer.
  996. Return the result of the first matching group of PATTERN, or nil,
  997. if PATTERN did not match."
  998. (save-restriction
  999. (widen)
  1000. (save-excursion
  1001. (goto-char (point-min))
  1002. (when (re-search-forward pattern nil 'no-error)
  1003. (match-string-no-properties 1)))))
  1004. (defun flycheck-buffer-empty-p (&optional buffer)
  1005. "Whether a BUFFER is empty.
  1006. If buffer is nil or omitted check the current buffer.
  1007. Return non-nil if so, or nil if the buffer has content."
  1008. (<= (buffer-size buffer) 0))
  1009. (defun flycheck-ephemeral-buffer-p ()
  1010. "Determine whether the current buffer is an ephemeral buffer.
  1011. See Info node `(elisp)Buffer Names' for information about
  1012. ephemeral buffers."
  1013. (string-prefix-p " " (buffer-name)))
  1014. (defun flycheck-encrypted-buffer-p ()
  1015. "Determine whether the current buffer is an encrypted file.
  1016. See Info node `(epa)Top' for Emacs' interface to encrypted
  1017. files."
  1018. ;; The EPA file handler sets this variable locally to remember the recipients
  1019. ;; of the encrypted file for re-encryption. Hence, a local binding of this
  1020. ;; variable is a good indication that the buffer is encrypted. I haven't
  1021. ;; found any better indicator anyway.
  1022. (local-variable-p 'epa-file-encrypt-to))
  1023. (defun flycheck-autoloads-file-p ()
  1024. "Determine whether the current buffer is a autoloads file.
  1025. Autoloads are generated by package.el during installation."
  1026. (string-suffix-p "-autoloads.el" (buffer-name)))
  1027. (defun flycheck-in-user-emacs-directory-p (filename)
  1028. "Whether FILENAME is in `user-emacs-directory'."
  1029. (string-prefix-p (file-name-as-directory (file-truename user-emacs-directory))
  1030. (file-truename filename)))
  1031. (defun flycheck-safe-delete (file-or-dir)
  1032. "Safely delete FILE-OR-DIR."
  1033. (ignore-errors
  1034. (if (file-directory-p file-or-dir)
  1035. (delete-directory file-or-dir 'recursive)
  1036. (delete-file file-or-dir))))
  1037. (defun flycheck-safe-delete-temporaries ()
  1038. "Safely delete all temp files and directories of Flycheck.
  1039. Safely delete all files and directories listed in
  1040. `flycheck-temporaries' and set the variable's value to nil."
  1041. (seq-do #'flycheck-safe-delete flycheck-temporaries)
  1042. (setq flycheck-temporaries nil))
  1043. (defun flycheck-rx-file-name (form)
  1044. "Translate the `(file-name)' FORM into a regular expression."
  1045. (let ((body (or (cdr form) '((minimal-match
  1046. (one-or-more not-newline))))))
  1047. (rx-submatch-n `(group-n 1 ,@body))))
  1048. (defun flycheck-rx-message (form)
  1049. "Translate the `(message)' FORM into a regular expression."
  1050. (let ((body (or (cdr form) '((one-or-more not-newline)))))
  1051. (rx-submatch-n `(group-n 4 ,@body))))
  1052. (defun flycheck-rx-id (form)
  1053. "Translate the `(id)' FORM into a regular expression."
  1054. (rx-submatch-n `(group-n 5 ,@(cdr form))))
  1055. (defun flycheck-rx-to-string (form &optional no-group)
  1056. "Like `rx-to-string' for FORM, but with special keywords:
  1057. `line'
  1058. matches the line number.
  1059. `column'
  1060. matches the column number.
  1061. `(file-name SEXP ...)'
  1062. matches the file name. SEXP describes the file name. If no
  1063. SEXP is given, use a default body of `(minimal-match
  1064. (one-or-more not-newline))'.
  1065. `(message SEXP ...)'
  1066. matches the message. SEXP constitutes the body of the
  1067. message. If no SEXP is given, use a default body
  1068. of `(one-or-more not-newline)'.
  1069. `(id SEXP ...)'
  1070. matches an error ID. SEXP describes the ID.
  1071. NO-GROUP is passed to `rx-to-string'.
  1072. See `rx' for a complete list of all built-in `rx' forms."
  1073. (let ((rx-constituents
  1074. (append
  1075. `((line . ,(rx (group-n 2 (one-or-more digit))))
  1076. (column . ,(rx (group-n 3 (one-or-more digit))))
  1077. (file-name flycheck-rx-file-name 0 nil)
  1078. (message flycheck-rx-message 0 nil)
  1079. (id flycheck-rx-id 0 nil))
  1080. rx-constituents nil)))
  1081. (rx-to-string form no-group)))
  1082. (defun flycheck-current-load-file ()
  1083. "Get the source file currently being loaded.
  1084. Always return the name of the corresponding source file, never
  1085. any byte-compiled file.
  1086. Return nil, if the currently loaded file cannot be determined."
  1087. (-when-let* ((this-file (cond
  1088. (load-in-progress load-file-name)
  1089. ((bound-and-true-p byte-compile-current-file))
  1090. (t (buffer-file-name))))
  1091. ;; A best guess for the source file of a compiled library. Works
  1092. ;; well in most cases, and especially for ELPA packages
  1093. (source-file (concat (file-name-sans-extension this-file)
  1094. ".el")))
  1095. (when (file-exists-p source-file)
  1096. source-file)))
  1097. (defun flycheck-module-root-directory (module &optional file-name)
  1098. "Get the root directory for a MODULE in FILE-NAME.
  1099. MODULE is a qualified module name, either a string with
  1100. components separated by a dot, or as list of components.
  1101. FILE-NAME is the name of the file or directory containing the
  1102. module as string. When nil or omitted, defaults to the return
  1103. value of function `buffer-file-name'.
  1104. Return the root directory of the module, that is, the directory,
  1105. from which FILE-NAME can be reached by descending directories
  1106. along each part of MODULE.
  1107. If the MODULE name does not match the directory hierarchy upwards
  1108. from FILE-NAME, return the directory containing FILE-NAME. When
  1109. FILE-NAME is nil, return `default-directory'."
  1110. (let ((file-name (or file-name (buffer-file-name)))
  1111. (module-components (if (stringp module)
  1112. (split-string module (rx "."))
  1113. (copy-sequence module))))
  1114. (if (and module-components file-name)
  1115. (let ((parts (nreverse module-components))
  1116. (base-directory (directory-file-name
  1117. (file-name-sans-extension file-name))))
  1118. (while (and parts
  1119. (string= (file-name-nondirectory base-directory)
  1120. (car parts)))
  1121. (pop parts)
  1122. (setq base-directory (directory-file-name
  1123. (file-name-directory base-directory))))
  1124. (file-name-as-directory base-directory))
  1125. (if file-name
  1126. (file-name-directory file-name)
  1127. (expand-file-name default-directory)))))
  1128. ;;; Minibuffer tools
  1129. (defvar read-flycheck-checker-history nil
  1130. "`completing-read' history of `read-flycheck-checker'.")
  1131. (defun flycheck-completing-read (prompt candidates default &optional history)
  1132. "Read a value from the minibuffer.
  1133. Use `flycheck-completing-read-function' to read input from the
  1134. minibuffer with completion.
  1135. Show PROMPT and read one of CANDIDATES, defaulting to DEFAULT.
  1136. HISTORY is passed to `flycheck-completing-read-function'."
  1137. (funcall flycheck-completing-read-function
  1138. prompt candidates nil 'require-match nil history default))
  1139. (defun read-flycheck-checker (prompt &optional default property candidates)
  1140. "Read a flycheck checker from minibuffer with PROMPT and DEFAULT.
  1141. PROMPT is a string to show in the minibuffer as prompt. It
  1142. should end with a single space. DEFAULT is a symbol denoting the
  1143. default checker to use, if the user did not select any checker.
  1144. PROPERTY is a symbol denoting a syntax checker property. If
  1145. non-nil, only complete syntax checkers which have a non-nil value
  1146. for PROPERTY. CANDIDATES is an optional list of all syntax
  1147. checkers available for completion, defaulting to all defined
  1148. checkers. If given, PROPERTY is ignored.
  1149. Return the checker as symbol, or DEFAULT if no checker was
  1150. chosen. If DEFAULT is nil and no checker was chosen, signal a
  1151. `user-error' if the underlying completion system does not provide
  1152. a default on its own."
  1153. (when (and default (not (flycheck-valid-checker-p default)))
  1154. (error "%S is no valid Flycheck checker" default))
  1155. (let* ((candidates (seq-map #'symbol-name
  1156. (or candidates
  1157. (flycheck-defined-checkers property))))
  1158. (default (and default (symbol-name default)))
  1159. (input (flycheck-completing-read
  1160. prompt candidates default
  1161. 'read-flycheck-checker-history)))
  1162. (when (string-empty-p input)
  1163. (unless default
  1164. (user-error "No syntax checker selected"))
  1165. (setq input default))
  1166. (let ((checker (intern input)))
  1167. (unless (flycheck-valid-checker-p checker)
  1168. (error "%S is not a valid Flycheck syntax checker" checker))
  1169. checker)))
  1170. (defun read-flycheck-error-level (prompt)
  1171. "Read an error level from the user with PROMPT.
  1172. Only offers level for which errors currently exist, in addition
  1173. to the default levels."
  1174. (let* ((levels (seq-map #'flycheck-error-level
  1175. (flycheck-error-list-current-errors)))
  1176. (levels-with-defaults (append '(info warning error) levels))
  1177. (uniq-levels (seq-uniq levels-with-defaults))
  1178. (level (flycheck-completing-read prompt uniq-levels nil)))
  1179. (and (stringp level) (intern level))))
  1180. ;;; Checker API
  1181. (defun flycheck-defined-checkers (&optional property)
  1182. "Find all defined syntax checkers, optionally with PROPERTY.
  1183. PROPERTY is a symbol. If given, only return syntax checkers with
  1184. a non-nil value for PROPERTY.
  1185. The returned list is sorted alphapetically by the symbol name of
  1186. the syntax checkers."
  1187. (let (defined-checkers)
  1188. (mapatoms (lambda (symbol)
  1189. (when (and (flycheck-valid-checker-p symbol)
  1190. (or (null property)
  1191. (flycheck-checker-get symbol property)))
  1192. (push symbol defined-checkers))))
  1193. (sort defined-checkers #'string<)))
  1194. (defun flycheck-registered-checker-p (checker)
  1195. "Determine whether CHECKER is registered.
  1196. A checker is registered if it is contained in
  1197. `flycheck-checkers'."
  1198. (and (flycheck-valid-checker-p checker)
  1199. (memq checker flycheck-checkers)))
  1200. (defun flycheck-disabled-checker-p (checker)
  1201. "Determine whether CHECKER is disabled.
  1202. A checker is disabled if it is contained in
  1203. `flycheck-disabled-checkers'."
  1204. (memq checker flycheck-disabled-checkers))
  1205. ;;; Generic syntax checkers
  1206. (defconst flycheck-generic-checker-version 2
  1207. "The internal version of generic syntax checker declarations.
  1208. Flycheck will not use syntax checkers whose generic version is
  1209. less than this constant.")
  1210. (defsubst flycheck--checker-property-name (property)
  1211. "Return the SYMBOL property for checker PROPERTY."
  1212. (intern (concat "flycheck-" (symbol-name property))))
  1213. (defun flycheck-checker-get (checker property)
  1214. "Get the value of CHECKER's PROPERTY."
  1215. (get checker (flycheck--checker-property-name property)))
  1216. (gv-define-setter flycheck-checker-get (value checker property)
  1217. `(setf (get ,checker (flycheck--checker-property-name ,property)) ,value))
  1218. (defun flycheck-validate-next-checker (next &optional strict)
  1219. "Validate NEXT checker.
  1220. With STRICT non-nil, also check whether the syntax checker and
  1221. the error level in NEXT are valid. Otherwise just check whether
  1222. these are symbols.
  1223. Signal an error if NEXT is not a valid entry for
  1224. `:next-checkers'."
  1225. (when (symbolp next)
  1226. (setq next (cons t next)))
  1227. (pcase next
  1228. (`(,level . ,checker)
  1229. (if strict
  1230. (progn
  1231. (unless (or (eq level t) (flycheck-error-level-p level))
  1232. (error "%S is not a valid Flycheck error level" level))
  1233. (unless (flycheck-valid-checker-p checker)
  1234. (error "%s is not a valid Flycheck syntax checker" checker)))
  1235. (unless (symbolp level)
  1236. (error "Error level %S must be a symbol" level))
  1237. (unless (symbolp checker)
  1238. (error "Checker %S must be a symbol" checker))))
  1239. (_ (error "%S must be a symbol or cons cell" next)))
  1240. t)
  1241. (defun flycheck-define-generic-checker (symbol docstring &rest properties)
  1242. "Define SYMBOL as generic syntax checker.
  1243. Any syntax checker defined with this macro is eligible for manual
  1244. syntax checker selection with `flycheck-select-checker'. To make
  1245. the new syntax checker available for automatic selection, it must
  1246. be registered in `flycheck-checkers'.
  1247. DOCSTRING is the documentation of the syntax checker, for
  1248. `flycheck-describe-checker'. The following PROPERTIES constitute
  1249. a generic syntax checker. Unless otherwise noted, all properties
  1250. are mandatory.
  1251. `:start FUNCTION'
  1252. A function to start the syntax checker.
  1253. FUNCTION shall take two arguments and return a context
  1254. object if the checker is started successfully. Otherwise it
  1255. shall signal an error.
  1256. The first argument is the syntax checker being started. The
  1257. second is a callback function to report state changes to
  1258. Flycheck. The callback takes two arguments STATUS DATA,
  1259. where STATUS is a symbol denoting the syntax checker status
  1260. and DATA an optional argument with additional data for the
  1261. status report. See `flycheck-report-buffer-checker-status'
  1262. for more information about STATUS and DATA.
  1263. FUNCTION may be synchronous or asynchronous, i.e. it may
  1264. call the given callback either immediately, or at some later
  1265. point (e.g. from a process sentinel).
  1266. A syntax checker _must_ call CALLBACK at least once with a
  1267. STATUS that finishes the current syntax checker. Otherwise
  1268. Flycheck gets stuck at the current syntax check with this
  1269. syntax checker.
  1270. The context object returned by FUNCTION is passed to
  1271. `:interrupt'.
  1272. `:interrupt FUNCTION'
  1273. A function to interrupt the syntax check.
  1274. FUNCTION is called with the syntax checker and the context
  1275. object returned by the `:start' function and shall try to
  1276. interrupt the syntax check. The context may be nil, if the
  1277. syntax check is interrupted before actually started.
  1278. FUNCTION should handle this situation.
  1279. If it cannot interrupt the syntax check, it may either
  1280. signal an error or silently ignore the attempt to interrupt
  1281. the syntax checker, depending on the severity of the
  1282. situation.
  1283. If interrupting the syntax check failed, Flycheck will let
  1284. the syntax check continue, but ignore any status reports.
  1285. Notably, it won't highlight any errors reported by the
  1286. syntax check in the buffer.
  1287. This property is optional. If omitted, Flycheck won't
  1288. attempt to interrupt syntax checks wit this syntax checker,
  1289. and simply ignore their results.
  1290. `:print-doc FUNCTION'
  1291. A function to print additional documentation into the Help
  1292. buffer of this checker.
  1293. FUNCTION is called when creating the Help buffer for the
  1294. syntax checker, with the syntax checker as single argument,
  1295. after printing the name of the syntax checker and its modes
  1296. and predicate, but before printing DOCSTRING. It may insert
  1297. additional documentation into the current buffer.
  1298. The call occurs within `with-help-window'. Hence
  1299. `standard-output' points to the current buffer, so you may
  1300. use `princ' and friends to add content. Also, the current
  1301. buffer is put into Help mode afterwards, which automatically
  1302. turns symbols into references, if possible.
  1303. This property is optional. If omitted, no additional
  1304. documentation is printed for this syntax checker.
  1305. :verify FUNCTION
  1306. A function to verify the checker for the current buffer.
  1307. FUNCTION is called with the syntax checker as single
  1308. argument, and shall return a list of
  1309. `flycheck-verification-result' objects indicating whether
  1310. the syntax checker could be used in the current buffer, and
  1311. highlighting potential setup problems.
  1312. This property is optional. If omitted, no additional
  1313. verification occurs for this syntax checker. It is however
  1314. absolutely recommended that you add a `:verify' function to
  1315. your syntax checker, because it will help users to spot
  1316. potential setup problems.
  1317. `:modes MODES'
  1318. A major mode symbol or a list thereof, denoting major modes
  1319. to use this syntax checker in.
  1320. This syntax checker will only be used in buffers whose
  1321. `major-mode' is contained in MODES.
  1322. If `:predicate' is also given the syntax checker will only
  1323. be used in buffers for which the `:predicate' returns
  1324. non-nil.
  1325. `:predicate FUNCTION'
  1326. A function to determine whether to use the syntax checker in
  1327. the current buffer.
  1328. FUNCTION is called without arguments and shall return
  1329. non-nil if this syntax checker shall be used to check the
  1330. current buffer. Otherwise it shall return nil.
  1331. If this checker has a `:working-directory' FUNCTION is
  1332. called with `default-directory' bound to the checker's
  1333. working directory.
  1334. FUNCTION is only called in matching major modes.
  1335. This property is optional.
  1336. `:enabled FUNCTION'
  1337. A function to determine whether to use the syntax checker in
  1338. the current buffer.
  1339. This property behaves as `:predicate', except that it's only
  1340. called the first time a syntax checker is to be used in a buffer.
  1341. FUNCTION is called without arguments and shall return
  1342. non-nil if this syntax checker shall be used to check the
  1343. current buffer. Otherwise it shall return nil.
  1344. If FUNCTION returns a non-nil value the checker is put in a
  1345. whitelist in `flycheck-enabled-checkers' to prevent further
  1346. invocations of `:enabled'. Otherwise it is disabled via
  1347. `flycheck-disabled-checkers' to prevent any further use of
  1348. it.
  1349. If this checker has a `:working-directory' FUNCTION is
  1350. called with `default-directory' bound to the checker's
  1351. working directory.
  1352. FUNCTION is only called in matching major modes.
  1353. This property is optional.
  1354. `:error-filter FUNCTION'
  1355. A function to filter the errors returned by this checker.
  1356. FUNCTION is called with the list of `flycheck-error' objects
  1357. returned by the syntax checker and shall return another list
  1358. of `flycheck-error' objects, which is considered the final
  1359. result of this syntax checker.
  1360. FUNCTION is free to add, remove or modify errors, whether in
  1361. place or by copying.
  1362. This property is optional. The default filter is
  1363. `identity'.
  1364. `:error-explainer FUNCTION'
  1365. A function to return an explanation text for errors
  1366. generated by this checker.
  1367. FUNCTION is called with a `flycheck-error' object and shall
  1368. return an explanation message for this error as a string, or
  1369. nil if there is no explanation for this error.
  1370. This property is optional.
  1371. `:next-checkers NEXT-CHECKERS'
  1372. A list denoting syntax checkers to apply after this syntax
  1373. checker, in what we call \"chaining\" of syntax checkers.
  1374. Each ITEM is a cons cell `(LEVEL . CHECKER)'. CHECKER is a
  1375. syntax checker to run after this syntax checker. LEVEL is
  1376. an error level. CHECKER will only be used if there are no
  1377. current errors of at least LEVEL. LEVEL may also be t, in
  1378. which case CHECKER is used regardless of the current errors.
  1379. ITEM may also be a syntax checker symbol, which is
  1380. equivalent to `(t . ITEM)'.
  1381. Flycheck tries all items in order of declaration, and uses
  1382. the first whose LEVEL matches and whose CHECKER is
  1383. registered and can be used for the current buffer.
  1384. This feature is typically used to apply more than one syntax
  1385. checker to a buffer. For instance, you might first use a
  1386. compiler to check a buffer for syntax and type errors, and
  1387. then run a linting tool that checks for insecure code, or
  1388. questionable style.
  1389. This property is optional. If omitted, it defaults to the
  1390. nil, i.e. no other syntax checkers are applied after this
  1391. syntax checker.
  1392. `:working-directory FUNCTION'
  1393. The value of `default-directory' when invoking `:start'.
  1394. FUNCTION is a function taking the syntax checker as sole
  1395. argument. It shall return the absolute path to an existing
  1396. directory to use as `default-directory' for `:start' or
  1397. nil to fall back to the `default-directory' of the current
  1398. buffer.
  1399. This property is optional. If omitted invoke `:start'
  1400. from the `default-directory' of the buffer being checked.
  1401. Signal an error, if any property has an invalid value."
  1402. (declare (indent 1)
  1403. (doc-string 2))
  1404. (let ((start (plist-get properties :start))
  1405. (interrupt (plist-get properties :interrupt))
  1406. (print-doc (plist-get properties :print-doc))
  1407. (modes (plist-get properties :modes))
  1408. (predicate (plist-get properties :predicate))
  1409. (verify (plist-get properties :verify))
  1410. (enabled (plist-get properties :enabled))
  1411. (filter (or (plist-get properties :error-filter) #'identity))
  1412. (explainer (plist-get properties :error-explainer))
  1413. (next-checkers (plist-get properties :next-checkers))
  1414. (file (flycheck-current-load-file))
  1415. (working-directory (plist-get properties :working-directory)))
  1416. (unless (listp modes)
  1417. (setq modes (list modes)))
  1418. (unless (functionp start)
  1419. (error ":start %S of syntax checker %s is not a function" start symbol))
  1420. (unless (or (null interrupt) (functionp interrupt))
  1421. (error ":interrupt %S of syntax checker %s is not a function"
  1422. interrupt symbol))
  1423. (unless (or (null print-doc) (functionp print-doc))
  1424. (error ":print-doc %S of syntax checker %s is not a function"
  1425. print-doc symbol))
  1426. (unless (or (null verify) (functionp verify))
  1427. (error ":verify %S of syntax checker %S is not a function"
  1428. verify symbol))
  1429. (unless (or (null enabled) (functionp enabled))
  1430. (error ":enabled %S of syntax checker %S is not a function"
  1431. enabled symbol))
  1432. (unless modes
  1433. (error "Missing :modes in syntax checker %s" symbol))
  1434. (dolist (mode modes)
  1435. (unless (symbolp mode)
  1436. (error "Invalid :modes %s in syntax checker %s, %s must be a symbol"
  1437. modes symbol mode)))
  1438. (unless (or (null predicate) (functionp predicate))
  1439. (error ":predicate %S of syntax checker %s is not a function"
  1440. predicate symbol))
  1441. (unless (functionp filter)
  1442. (error ":error-filter %S of syntax checker %s is not a function"
  1443. filter symbol))
  1444. (unless (or (null explainer) (functionp explainer))
  1445. (error ":error-explainer %S of syntax checker %S is not a function"
  1446. explainer symbol))
  1447. (dolist (checker next-checkers)
  1448. (flycheck-validate-next-checker checker))
  1449. (let ((real-predicate
  1450. (and predicate
  1451. (lambda ()
  1452. ;; Run predicate in the checker's default directory
  1453. (let ((default-directory
  1454. (flycheck-compute-working-directory symbol)))
  1455. (funcall predicate)))))
  1456. (real-enabled
  1457. (lambda ()
  1458. (if (flycheck-valid-checker-p symbol)
  1459. (or (null enabled)
  1460. ;; Run enabled in the checker's default directory
  1461. (let ((default-directory
  1462. (flycheck-compute-working-directory symbol)))
  1463. (funcall enabled)))
  1464. (lwarn 'flycheck :warning "%S is no valid Flycheck syntax checker.
  1465. Try to reinstall the package defining this syntax checker." symbol)
  1466. nil))))
  1467. (pcase-dolist (`(,prop . ,value)
  1468. `((start . ,start)
  1469. (interrupt . ,interrupt)
  1470. (print-doc . ,print-doc)
  1471. (modes . ,modes)
  1472. (predicate . ,real-predicate)
  1473. (verify . ,verify)
  1474. (enabled . ,real-enabled)
  1475. (error-filter . ,filter)
  1476. (error-explainer . ,explainer)
  1477. (next-checkers . ,next-checkers)
  1478. (documentation . ,docstring)
  1479. (file . ,file)
  1480. (working-directory . ,working-directory)))
  1481. (setf (flycheck-checker-get symbol prop) value)))
  1482. ;; Track the version, to avoid breakage if the internal format changes
  1483. (setf (flycheck-checker-get symbol 'generic-checker-version)
  1484. flycheck-generic-checker-version)))
  1485. (defun flycheck-valid-checker-p (checker)
  1486. "Check whether a CHECKER is valid.
  1487. A valid checker is a symbol defined as syntax checker with
  1488. `flycheck-define-checker'."
  1489. (and (symbolp checker)
  1490. (= (or (get checker 'flycheck-generic-checker-version) 0)
  1491. flycheck-generic-checker-version)))
  1492. (defun flycheck-checker-supports-major-mode-p (checker &optional mode)
  1493. "Whether CHECKER supports the given major MODE.
  1494. CHECKER is a syntax checker symbol and MODE a major mode symbol.
  1495. Look at the `modes' property of CHECKER to determine whether
  1496. CHECKER supports buffers in the given major MODE.
  1497. MODE defaults to the value of `major-mode' if omitted or nil.
  1498. Return non-nil if CHECKER supports MODE and nil otherwise."
  1499. (let ((mode (or mode major-mode)))
  1500. (memq mode (flycheck-checker-get checker 'modes))))
  1501. (defvar-local flycheck-enabled-checkers nil
  1502. "Syntax checkers included in automatic selection.
  1503. A list of Flycheck syntax checkers included in automatic
  1504. selection for current buffer.")
  1505. (defun flycheck-may-enable-checker (checker)
  1506. "Whether a generic CHECKER may be enabled for current buffer.
  1507. Return non-nil if CHECKER may be used for the current buffer, and
  1508. nil otherwise."
  1509. (let* ((enabled (flycheck-checker-get checker 'enabled))
  1510. (shall-enable (and (not (flycheck-disabled-checker-p checker))
  1511. (or (memq checker flycheck-enabled-checkers)
  1512. (null enabled)
  1513. (funcall enabled)))))
  1514. (if shall-enable
  1515. (cl-pushnew checker flycheck-enabled-checkers)
  1516. (cl-pushnew checker flycheck-disabled-checkers))
  1517. shall-enable))
  1518. (defun flycheck-may-use-checker (checker)
  1519. "Whether a generic CHECKER may be used.
  1520. Return non-nil if CHECKER may be used for the current buffer, and
  1521. nil otherwise."
  1522. (let ((predicate (flycheck-checker-get checker 'predicate)))
  1523. (and (flycheck-valid-checker-p checker)
  1524. (flycheck-checker-supports-major-mode-p checker)
  1525. (flycheck-may-enable-checker checker)
  1526. (or (null predicate) (funcall predicate)))))
  1527. (defun flycheck-may-use-next-checker (next-checker)
  1528. "Determine whether NEXT-CHECKER may be used."
  1529. (when (symbolp next-checker)
  1530. (push t next-checker))
  1531. (let ((level (car next-checker))
  1532. (next-checker (cdr next-checker)))
  1533. (and (or (eq level t)
  1534. (flycheck-has-max-current-errors-p level))
  1535. (flycheck-registered-checker-p next-checker)
  1536. (flycheck-may-use-checker next-checker))))
  1537. ;;; Help for generic syntax checkers
  1538. (define-button-type 'help-flycheck-checker-def
  1539. :supertype 'help-xref
  1540. 'help-function #'flycheck-goto-checker-definition
  1541. 'help-echo "mouse-2, RET: find Flycheck checker definition")
  1542. (defconst flycheck-find-checker-regexp
  1543. (rx line-start (zero-or-more (syntax whitespace))
  1544. "(" symbol-start "flycheck-define-checker" symbol-end
  1545. (eval (list 'regexp find-function-space-re))
  1546. symbol-start
  1547. "%s"
  1548. symbol-end
  1549. (or (syntax whitespace) line-end))
  1550. "Regular expression to find a checker definition.")
  1551. (add-to-list 'find-function-regexp-alist
  1552. '(flycheck-checker . flycheck-find-checker-regexp))
  1553. (defun flycheck-goto-checker-definition (checker file)
  1554. "Go to to the definition of CHECKER in FILE."
  1555. (let ((location (find-function-search-for-symbol
  1556. checker 'flycheck-checker file)))
  1557. (pop-to-buffer (car location))
  1558. (if (cdr location)
  1559. (goto-char (cdr location))
  1560. (message "Unable to find checker location in file"))))
  1561. (defun flycheck-checker-at-point ()
  1562. "Return the Flycheck checker found at or before point.
  1563. Return nil if there is no checker."
  1564. (let ((symbol (variable-at-point 'any-symbol)))
  1565. (when (flycheck-valid-checker-p symbol)
  1566. symbol)))
  1567. (defun flycheck-describe-checker (checker)
  1568. "Display the documentation of CHECKER.
  1569. CHECKER is a checker symbol.
  1570. Pop up a help buffer with the documentation of CHECKER."
  1571. (interactive
  1572. (let* ((enable-recursive-minibuffers t)
  1573. (default (or (flycheck-checker-at-point)
  1574. (ignore-errors (flycheck-get-checker-for-buffer))))
  1575. (prompt (if default
  1576. (format "Describe syntax checker (default %s): " default)
  1577. "Describe syntax checker: ")))
  1578. (list (read-flycheck-checker prompt default))))
  1579. (unless (flycheck-valid-checker-p checker)
  1580. (user-error "You didn't specify a Flycheck syntax checker"))
  1581. (help-setup-xref (list #'flycheck-describe-checker checker)
  1582. (called-interactively-p 'interactive))
  1583. (save-excursion
  1584. (with-help-window (help-buffer)
  1585. (let ((filename (flycheck-checker-get checker 'file))
  1586. (modes (flycheck-checker-get checker 'modes))
  1587. (predicate (flycheck-checker-get checker 'predicate))
  1588. (print-doc (flycheck-checker-get checker 'print-doc))
  1589. (next-checkers (flycheck-checker-get checker 'next-checkers)))
  1590. (princ (format "%s is a Flycheck syntax checker" checker))
  1591. (when filename
  1592. (princ (format " in `%s'" (file-name-nondirectory filename)))
  1593. (with-current-buffer standard-output
  1594. (save-excursion
  1595. (re-search-backward "`\\([^`']+\\)'" nil t)
  1596. (help-xref-button 1 'help-flycheck-checker-def checker filename))))
  1597. (princ ".\n\n")
  1598. (let ((modes-start (with-current-buffer standard-output (point-max))))
  1599. ;; Track the start of the modes documentation, to properly re-fill
  1600. ;; it later
  1601. (princ " This syntax checker checks syntax in the major mode(s) ")
  1602. (princ (string-join
  1603. (seq-map (apply-partially #'format "`%s'") modes)
  1604. ", "))
  1605. (when predicate
  1606. (princ ", and uses a custom predicate"))
  1607. (princ ".")
  1608. (when next-checkers
  1609. (princ " It runs the following checkers afterwards:"))
  1610. (with-current-buffer standard-output
  1611. (save-excursion
  1612. (fill-region-as-paragraph modes-start (point-max))))
  1613. (princ "\n")
  1614. ;; Print the list of next checkers
  1615. (when next-checkers
  1616. (princ "\n")
  1617. (let ((beg-checker-list (with-current-buffer standard-output
  1618. (point))))
  1619. (dolist (next-checker next-checkers)
  1620. (if (symbolp next-checker)
  1621. (princ (format " * `%s'\n" next-checker))
  1622. (princ (format " * `%s' (maximum level `%s')\n"
  1623. (cdr next-checker) (car next-checker)))))
  1624. ;;
  1625. (with-current-buffer standard-output
  1626. (save-excursion
  1627. (while (re-search-backward "`\\([^`']+\\)'"
  1628. beg-checker-list t)
  1629. (when (flycheck-valid-checker-p
  1630. (intern-soft (match-string 1)))
  1631. (help-xref-button 1 'help-flycheck-checker-def checker
  1632. filename))))))))
  1633. ;; Call the custom print-doc function of the checker, if present
  1634. (when print-doc
  1635. (funcall print-doc checker))
  1636. ;; Ultimately, print the docstring
  1637. (princ "\nDocumentation:\n")
  1638. (princ (flycheck-checker-get checker 'documentation))))))
  1639. ;;; Syntax checker verification
  1640. (cl-defstruct (flycheck-verification-result
  1641. (:constructor flycheck-verification-result-new))
  1642. "Structure for storing a single verification result.
  1643. Slots:
  1644. `label'
  1645. A label for this result, as string
  1646. `message'
  1647. A message for this result, as string
  1648. `face'
  1649. The face to use for the `message'.
  1650. You can either use a face symbol, or a list of face symbols."
  1651. label message face)
  1652. (defun flycheck-verify-generic-checker (checker)
  1653. "Verify a generic CHECKER in the current buffer.
  1654. Return a list of `flycheck-verification-result' objects."
  1655. (let (results
  1656. (predicate (flycheck-checker-get checker 'predicate))
  1657. (enabled (flycheck-checker-get checker 'enabled))
  1658. (verify (flycheck-checker-get checker 'verify)))
  1659. (when enabled
  1660. (let ((result (funcall enabled)))
  1661. (push (flycheck-verification-result-new
  1662. :label "may enable"
  1663. :message (if result "yes" "Automatically disabled!")
  1664. :face (if result 'success '(bold warning)))
  1665. results)))
  1666. (when predicate
  1667. (let ((result (funcall predicate)))
  1668. (push (flycheck-verification-result-new
  1669. :label "predicate"
  1670. :message (prin1-to-string (not (null result)))
  1671. :face (if result 'success '(bold warning)))
  1672. results)))
  1673. (append (nreverse results)
  1674. (and verify (funcall verify checker)))))
  1675. (define-button-type 'help-flycheck-checker-doc
  1676. :supertype 'help-xref
  1677. 'help-function #'flycheck-describe-checker
  1678. 'help-echo "mouse-2, RET: describe Flycheck checker")
  1679. (defun flycheck--verify-princ-checker (checker buffer &optional with-mm)
  1680. "Print verification result of CHECKER for BUFFER.
  1681. When WITH-MM is given and non-nil, also include the major mode
  1682. into the verification results."
  1683. (princ " ")
  1684. (insert-button (symbol-name checker)
  1685. 'type 'help-flycheck-checker-doc
  1686. 'help-args (list checker))
  1687. (when (with-current-buffer buffer (flycheck-disabled-checker-p checker))
  1688. (insert (propertize " (disabled)" 'face '(bold error))))
  1689. (princ "\n")
  1690. (let ((results (with-current-buffer buffer
  1691. (flycheck-verify-generic-checker checker))))
  1692. (when with-mm
  1693. (with-current-buffer buffer
  1694. (let ((message-and-face
  1695. (if (flycheck-checker-supports-major-mode-p checker)
  1696. (cons (format "`%s' supported" major-mode) 'success)
  1697. (cons (format "`%s' not supported" major-mode) 'error))))
  1698. (push (flycheck-verification-result-new
  1699. :label "major mode"
  1700. :message (car message-and-face)
  1701. :face (cdr message-and-face))
  1702. results))))
  1703. (let* ((label-length
  1704. (seq-max (mapcar
  1705. (lambda (res)
  1706. (length (flycheck-verification-result-label res)))
  1707. results)))
  1708. (message-column (+ 8 label-length)))
  1709. (dolist (result results)
  1710. (princ " - ")
  1711. (princ (flycheck-verification-result-label result))
  1712. (princ ": ")
  1713. (princ (make-string (- message-column (current-column)) ?\ ))
  1714. (let ((message (flycheck-verification-result-message result))
  1715. (face (flycheck-verification-result-face result)))
  1716. (insert (propertize message 'face face)))
  1717. (princ "\n"))))
  1718. (princ "\n"))
  1719. (defun flycheck--verify-print-header (desc buffer)
  1720. "Print a title with DESC for BUFFER in the current buffer.
  1721. DESC is an arbitrary string containing a description, and BUFFER
  1722. is the buffer being verified. The name and the major mode mode
  1723. of BUFFER are printed.
  1724. DESC and information about BUFFER are printed in the current
  1725. buffer."
  1726. (princ desc)
  1727. (insert (propertize (buffer-name buffer) 'face 'bold))
  1728. (princ " in ")
  1729. (let ((mode (buffer-local-value 'major-mode buffer)))
  1730. (insert-button (symbol-name mode)
  1731. 'type 'help-function
  1732. 'help-args (list mode)))
  1733. (princ ":\n\n"))
  1734. (defun flycheck--verify-print-footer (buffer)
  1735. "Print a footer for BUFFER in the current buffer.
  1736. BUFFER is the buffer being verified."
  1737. (princ "Flycheck Mode is ")
  1738. (let ((enabled (buffer-local-value 'flycheck-mode buffer)))
  1739. (insert (propertize (if enabled "enabled" "disabled")
  1740. 'face (if enabled 'success '(warning bold)))))
  1741. (princ
  1742. (with-current-buffer buffer
  1743. ;; Use key binding state in the verified buffer to print the help.
  1744. (substitute-command-keys
  1745. ". Use \\[universal-argument] \\[flycheck-disable-checker] to enable disabled checkers.")))
  1746. (save-excursion
  1747. (let ((end (point)))
  1748. (backward-paragraph)
  1749. (fill-region-as-paragraph (point) end)))
  1750. (princ "\n\n--------------------\n\n")
  1751. (princ (format "Flycheck version: %s\n" (flycheck-version)))
  1752. (princ (format "Emacs version: %s\n" emacs-version))
  1753. (princ (format "System: %s\n" system-configuration))
  1754. (princ (format "Window system: %S\n" window-system)))
  1755. (defun flycheck-verify-checker (checker)
  1756. "Check whether a CHECKER can be used in this buffer.
  1757. Show a buffer listing possible problems that prevent CHECKER from
  1758. being used for the current buffer.
  1759. Note: Do not use this function to check whether a syntax checker
  1760. is applicable from Emacs Lisp code. Use
  1761. `flycheck-may-use-checker' instead."
  1762. (interactive (list (read-flycheck-checker "Checker to verify: ")))
  1763. (unless (flycheck-valid-checker-p checker)
  1764. (user-error "%s is not a syntax checker" checker))
  1765. ;; Save the buffer to make sure that all predicates are good
  1766. (when (and (buffer-file-name) (buffer-modified-p))
  1767. (save-buffer))
  1768. (let ((buffer (current-buffer)))
  1769. (with-help-window (get-buffer-create " *Flycheck checker*")
  1770. (with-current-buffer standard-output
  1771. (flycheck--verify-print-header "Syntax checker in buffer " buffer)
  1772. (flycheck--verify-princ-checker checker buffer 'with-mm)
  1773. (if (with-current-buffer buffer (flycheck-may-use-checker checker))
  1774. (insert (propertize "Flycheck can use this syntax checker for this buffer.\n"
  1775. 'face 'success))
  1776. (insert (propertize "Flycheck cannot use this syntax checker for this buffer.\n"
  1777. 'face 'error)))
  1778. (insert "\n")
  1779. (flycheck--verify-print-footer buffer)))))
  1780. (defun flycheck-verify-setup ()
  1781. "Check whether Flycheck can be used in this buffer.
  1782. Display a new buffer listing all syntax checkers that could be
  1783. applicable in the current buffer. For each syntax checkers,
  1784. possible problems are shown."
  1785. (interactive)
  1786. (when (and (buffer-file-name) (buffer-modified-p))
  1787. ;; Save the buffer
  1788. (save-buffer))
  1789. (let ((buffer (current-buffer))
  1790. ;; Get all checkers that support the current major mode
  1791. (checkers (seq-filter #'flycheck-checker-supports-major-mode-p
  1792. flycheck-checkers))
  1793. (help-buffer (get-buffer-create " *Flycheck checkers*")))
  1794. ;; Now print all applicable checkers
  1795. (with-help-window help-buffer
  1796. (with-current-buffer standard-output
  1797. (flycheck--verify-print-header "Syntax checkers for buffer " buffer)
  1798. (unless checkers
  1799. (insert (propertize "There are no syntax checkers for this buffer!\n\n"
  1800. 'face '(bold error))))
  1801. (dolist (checker checkers)
  1802. (flycheck--verify-princ-checker checker buffer))
  1803. (-when-let (selected-checker (buffer-local-value 'flycheck-checker buffer))
  1804. (insert (propertize "The following checker is explicitly selected for this buffer:\n\n"
  1805. 'face 'bold))
  1806. (flycheck--verify-princ-checker selected-checker buffer 'with-mm))
  1807. (let ((unregistered-checkers (seq-difference (flycheck-defined-checkers)
  1808. flycheck-checkers)))
  1809. (when unregistered-checkers
  1810. (insert (propertize "\nThe following syntax checkers are not registered:\n\n"
  1811. 'face '(bold warning)))
  1812. (dolist (checker unregistered-checkers)
  1813. (princ " - ")
  1814. (princ checker)
  1815. (princ "\n"))
  1816. (princ "\nTry adding these syntax checkers to `flycheck-checkers'.\n")))
  1817. (flycheck--verify-print-footer buffer)))
  1818. (with-current-buffer help-buffer
  1819. (setq-local revert-buffer-function
  1820. (lambda (_ignore-auto _noconfirm)
  1821. (with-current-buffer buffer (flycheck-verify-setup)))))))
  1822. ;;; Predicates for generic syntax checkers
  1823. (defun flycheck-buffer-saved-p (&optional buffer)
  1824. "Determine whether BUFFER is saved to a file.
  1825. BUFFER is the buffer to check. If omitted or nil, use the
  1826. current buffer as BUFFER.
  1827. Return non-nil if the BUFFER is backed by a file, and not
  1828. modified, or nil otherwise."
  1829. (let ((file-name (buffer-file-name buffer)))
  1830. (and file-name (file-exists-p file-name) (not (buffer-modified-p buffer)))))
  1831. ;;; Extending generic checkers
  1832. (defun flycheck-add-next-checker (checker next &optional append)
  1833. "After CHECKER add a NEXT checker.
  1834. CHECKER is a syntax checker symbol, to which to add NEXT checker.
  1835. NEXT is a cons cell `(LEVEL . NEXT-CHECKER)'. NEXT-CHECKER is a
  1836. symbol denoting the syntax checker to run after CHECKER. LEVEL
  1837. is an error level. NEXT-CHECKER will only be used if there is no
  1838. current error whose level is more severe than LEVEL. LEVEL may
  1839. also be t, in which case NEXT-CHECKER is used regardless of the
  1840. current errors.
  1841. NEXT can also be a syntax checker symbol only, which is
  1842. equivalent to `(t . NEXT)'.
  1843. NEXT-CHECKER is prepended before other next checkers, unless
  1844. APPEND is non-nil."
  1845. (unless (flycheck-valid-checker-p checker)
  1846. (error "%s is not a valid syntax checker" checker))
  1847. (flycheck-validate-next-checker next 'strict)
  1848. (if append
  1849. (setf (flycheck-checker-get checker 'next-checkers)
  1850. (append (flycheck-checker-get checker 'next-checkers) (list next)))
  1851. (push next (flycheck-checker-get checker 'next-checkers))))
  1852. (defun flycheck-add-mode (checker mode)
  1853. "To CHECKER add a new major MODE.
  1854. CHECKER and MODE are symbols denoting a syntax checker and a
  1855. major mode respectively.
  1856. Add MODE to the `:modes' property of CHECKER, so that CHECKER
  1857. will be used in buffers with MODE."
  1858. (unless (flycheck-valid-checker-p checker)
  1859. (error "%s is not a valid syntax checker" checker))
  1860. (unless (symbolp mode)
  1861. (error "%s is not a symbol" mode))
  1862. (push mode (flycheck-checker-get checker 'modes)))
  1863. ;;; Generic syntax checks
  1864. (cl-defstruct (flycheck-syntax-check
  1865. (:constructor flycheck-syntax-check-new))
  1866. "Structure for storing syntax check state.
  1867. Slots:
  1868. `buffer'
  1869. The buffer being checked.
  1870. `checker'
  1871. The syntax checker being used.
  1872. `context'
  1873. The context object.
  1874. `working-directory'
  1875. Working directory for the syntax checker. Serve as a value for
  1876. `default-directory' for a checker."
  1877. buffer checker context working-directory)
  1878. (defun flycheck-syntax-check-start (syntax-check callback)
  1879. "Start a SYNTAX-CHECK with CALLBACK."
  1880. (let ((checker (flycheck-syntax-check-checker syntax-check))
  1881. (default-directory (flycheck-syntax-check-working-directory syntax-check)))
  1882. (setf (flycheck-syntax-check-context syntax-check)
  1883. (funcall (flycheck-checker-get checker 'start) checker callback))))
  1884. (defun flycheck-syntax-check-interrupt (syntax-check)
  1885. "Interrupt a SYNTAX-CHECK."
  1886. (let* ((checker (flycheck-syntax-check-checker syntax-check))
  1887. (interrupt-fn (flycheck-checker-get checker 'interrupt))
  1888. (context (flycheck-syntax-check-context syntax-check)))
  1889. (when interrupt-fn
  1890. (funcall interrupt-fn checker context))))
  1891. ;;; Syntax checking mode
  1892. (defvar flycheck-mode-map
  1893. (let ((map (make-sparse-keymap)))
  1894. (define-key map flycheck-keymap-prefix flycheck-command-map)
  1895. ;; We place the menu under a custom menu key. Since this menu key is not
  1896. ;; present in the menu of the global map, no top-level menu entry is added
  1897. ;; to the global menu bar. However, it still appears on the mode line
  1898. ;; lighter.
  1899. (define-key map [menu-bar flycheck] flycheck-mode-menu-map)
  1900. map)
  1901. "Keymap of command `flycheck-mode'.")
  1902. (defvar-local flycheck-old-next-error-function nil
  1903. "Remember the old `next-error-function'.")
  1904. (defconst flycheck-hooks-alist
  1905. '(
  1906. ;; Handle events that may start automatic syntax checks
  1907. (after-save-hook . flycheck-handle-save)
  1908. (after-change-functions . flycheck-handle-change)
  1909. ;; Handle events that may triggered pending deferred checks
  1910. (window-configuration-change-hook . flycheck-perform-deferred-syntax-check)
  1911. (post-command-hook . flycheck-perform-deferred-syntax-check)
  1912. ;; Teardown Flycheck whenever the buffer state is about to get lost, to
  1913. ;; clean up temporary files and directories.
  1914. (kill-buffer-hook . flycheck-teardown)
  1915. (change-major-mode-hook . flycheck-teardown)
  1916. (before-revert-hook . flycheck-teardown)
  1917. ;; Update the error list if necessary
  1918. (post-command-hook . flycheck-error-list-update-source)
  1919. (post-command-hook . flycheck-error-list-highlight-errors)
  1920. ;; Display errors. Show errors at point after commands (like movements) and
  1921. ;; when Emacs gets focus. Cancel the display timer when Emacs looses focus
  1922. ;; (as there's no need to display errors if the user can't see them), and
  1923. ;; hide the error buffer (for large error messages) if necessary. Note that
  1924. ;; the focus hooks only work on Emacs 24.4 and upwards, but since undefined
  1925. ;; hooks are perfectly ok we don't need a version guard here. They'll just
  1926. ;; not work silently.
  1927. (post-command-hook . flycheck-display-error-at-point-soon)
  1928. (focus-in-hook . flycheck-display-error-at-point-soon)
  1929. (focus-out-hook . flycheck-cancel-error-display-error-at-point-timer)
  1930. (post-command-hook . flycheck-hide-error-buffer)
  1931. ;; Immediately show error popups when navigating to an error
  1932. (next-error-hook . flycheck-display-error-at-point))
  1933. "Hooks which Flycheck needs to hook in.
  1934. The `car' of each pair is a hook variable, the `cdr' a function
  1935. to be added or removed from the hook variable if Flycheck mode is
  1936. enabled and disabled respectively.")
  1937. ;;;###autoload
  1938. (define-minor-mode flycheck-mode
  1939. "Minor mode for on-the-fly syntax checking.
  1940. When called interactively, toggle `flycheck-mode'. With prefix
  1941. ARG, enable `flycheck-mode' if ARG is positive, otherwise disable
  1942. it.
  1943. When called from Lisp, enable `flycheck-mode' if ARG is omitted,
  1944. nil or positive. If ARG is `toggle', toggle `flycheck-mode'.
  1945. Otherwise behave as if called interactively.
  1946. In `flycheck-mode' the buffer is automatically syntax-checked
  1947. using the first suitable syntax checker from `flycheck-checkers'.
  1948. Use `flycheck-select-checker' to select a checker for the current
  1949. buffer manually.
  1950. \\{flycheck-mode-map}"
  1951. :init-value nil
  1952. :keymap flycheck-mode-map
  1953. :lighter flycheck-mode-line
  1954. :after-hook (flycheck-buffer-automatically 'mode-enabled 'force-deferred)
  1955. (cond
  1956. (flycheck-mode
  1957. (flycheck-clear)
  1958. (pcase-dolist (`(,hook . ,fn) flycheck-hooks-alist)
  1959. (add-hook hook fn nil 'local))
  1960. (setq flycheck-old-next-error-function (if flycheck-standard-error-navigation
  1961. next-error-function
  1962. :unset))
  1963. (when flycheck-standard-error-navigation
  1964. (setq next-error-function #'flycheck-next-error-function)))
  1965. (t
  1966. (unless (eq flycheck-old-next-error-function :unset)
  1967. (setq next-error-function flycheck-old-next-error-function))
  1968. (pcase-dolist (`(,hook . ,fn) flycheck-hooks-alist)
  1969. (remove-hook hook fn 'local))
  1970. (flycheck-teardown))))
  1971. ;;; Syntax checker selection for the current buffer
  1972. (defun flycheck-get-checker-for-buffer ()
  1973. "Find the checker for the current buffer.
  1974. Use the selected checker for the current buffer, if any,
  1975. otherwise search for the best checker from `flycheck-checkers'.
  1976. Return checker if there is a checker for the current buffer, or
  1977. nil otherwise."
  1978. (if flycheck-checker
  1979. (if (flycheck-may-use-checker flycheck-checker)
  1980. flycheck-checker
  1981. (error "Flycheck cannot use %s in this buffer, type M-x flycheck-verify-setup for more details"
  1982. flycheck-checker))
  1983. (seq-find #'flycheck-may-use-checker flycheck-checkers)))
  1984. (defun flycheck-get-next-checker-for-buffer (checker)
  1985. "Get the checker to run after CHECKER for the current buffer."
  1986. (let ((next (seq-find #'flycheck-may-use-next-checker
  1987. (flycheck-checker-get checker 'next-checkers))))
  1988. (when next
  1989. (if (symbolp next) next (cdr next)))))
  1990. (defun flycheck-select-checker (checker)
  1991. "Select CHECKER for the current buffer.
  1992. CHECKER is a syntax checker symbol (see `flycheck-checkers') or
  1993. nil. In the former case, use CHECKER for the current buffer,
  1994. otherwise deselect the current syntax checker (if any) and use
  1995. automatic checker selection via `flycheck-checkers'.
  1996. If called interactively prompt for CHECKER. With prefix arg
  1997. deselect the current syntax checker and enable automatic
  1998. selection again.
  1999. Set `flycheck-checker' to CHECKER and automatically start a new
  2000. syntax check if the syntax checker changed.
  2001. CHECKER will be used, even if it is not contained in
  2002. `flycheck-checkers', or if it is disabled via
  2003. `flycheck-disabled-checkers'."
  2004. (interactive
  2005. (if current-prefix-arg
  2006. (list nil)
  2007. (list (read-flycheck-checker "Select checker: "
  2008. (flycheck-get-checker-for-buffer)))))
  2009. (when (not (eq checker flycheck-checker))
  2010. (unless (or (not checker) (flycheck-may-use-checker checker))
  2011. (flycheck-verify-checker checker)
  2012. (user-error "Can't use syntax checker %S in this buffer" checker))
  2013. (setq flycheck-checker checker)
  2014. (when flycheck-mode
  2015. (flycheck-buffer))))
  2016. (defun flycheck-disable-checker (checker &optional enable)
  2017. "Interactively disable CHECKER for the current buffer.
  2018. Interactively, prompt for a syntax checker to disable, and add
  2019. the syntax checker to the buffer-local value of
  2020. `flycheck-disabled-checkers'.
  2021. With non-nil ENABLE or with prefix arg, prompt for a disabled
  2022. syntax checker and re-enable it by removing it from the
  2023. buffer-local value of `flycheck-disabled-checkers'."
  2024. (declare (interactive-only "Directly set `flycheck-disabled-checkers' instead"))
  2025. (interactive
  2026. (let* ((enable current-prefix-arg)
  2027. (candidates (if enable flycheck-disabled-checkers flycheck-checkers))
  2028. (prompt (if enable "Enable syntax checker: "
  2029. "Disable syntax checker: ")))
  2030. (when (and enable (not candidates))
  2031. (user-error "No syntax checkers disabled in this buffer"))
  2032. (list (read-flycheck-checker prompt nil nil candidates) enable)))
  2033. (unless checker
  2034. (user-error "No syntax checker given"))
  2035. (if enable
  2036. ;; We must use `remq' instead of `delq', because we must _not_ modify the
  2037. ;; list. Otherwise we could potentially modify the global default value,
  2038. ;; in case the list is the global default.
  2039. (when (memq checker flycheck-disabled-checkers)
  2040. (setq flycheck-disabled-checkers
  2041. (remq checker flycheck-disabled-checkers))
  2042. (flycheck-buffer))
  2043. (unless (memq checker flycheck-disabled-checkers)
  2044. (push checker flycheck-disabled-checkers)
  2045. (flycheck-buffer))))
  2046. ;;; Syntax checks for the current buffer
  2047. (defvar-local flycheck-current-syntax-check nil
  2048. "The current syntax check in the this buffer.")
  2049. (put 'flycheck-current-syntax-check 'permanent-local t)
  2050. (defun flycheck-start-current-syntax-check (checker)
  2051. "Start a syntax check in the current buffer with CHECKER.
  2052. Set `flycheck-current-syntax-check' accordingly."
  2053. ;; Allocate the current syntax check *before* starting it. This allows for
  2054. ;; synchronous checks, which call the status callback immediately in their
  2055. ;; start function.
  2056. (let* ((check (flycheck-syntax-check-new
  2057. :buffer (current-buffer)
  2058. :checker checker
  2059. :context nil
  2060. :working-directory (flycheck-compute-working-directory checker)))
  2061. (callback (flycheck-buffer-status-callback check)))
  2062. (setq flycheck-current-syntax-check check)
  2063. (flycheck-report-status 'running)
  2064. (flycheck-syntax-check-start check callback)))
  2065. (defun flycheck-running-p ()
  2066. "Determine whether a syntax check is running in the current buffer."
  2067. (not (null flycheck-current-syntax-check)))
  2068. (defun flycheck-stop ()
  2069. "Stop any ongoing syntax check in the current buffer."
  2070. (when (flycheck-running-p)
  2071. (flycheck-syntax-check-interrupt flycheck-current-syntax-check)
  2072. ;; Remove the current syntax check, to reset Flycheck into a non-running
  2073. ;; state, and to make `flycheck-report-buffer-checker-status' ignore any
  2074. ;; status reports from the current syntax check.
  2075. (setq flycheck-current-syntax-check nil)
  2076. (flycheck-report-status 'interrupted)))
  2077. (defun flycheck-buffer-status-callback (syntax-check)
  2078. "Create a status callback for SYNTAX-CHECK in the current buffer."
  2079. (lambda (&rest args)
  2080. (apply #'flycheck-report-buffer-checker-status
  2081. syntax-check args)))
  2082. (defun flycheck-buffer ()
  2083. "Start checking syntax in the current buffer.
  2084. Get a syntax checker for the current buffer with
  2085. `flycheck-get-checker-for-buffer', and start it."
  2086. (interactive)
  2087. (flycheck-clean-deferred-check)
  2088. (if flycheck-mode
  2089. (unless (flycheck-running-p)
  2090. ;; Clear error list and mark all overlays for deletion. We do not
  2091. ;; delete all overlays immediately to avoid excessive re-displays and
  2092. ;; flickering, if the same errors gets highlighted again after the check
  2093. ;; completed.
  2094. (run-hooks 'flycheck-before-syntax-check-hook)
  2095. (flycheck-clear-errors)
  2096. (flycheck-mark-all-overlays-for-deletion)
  2097. (condition-case err
  2098. (let* ((checker (flycheck-get-checker-for-buffer)))
  2099. (if checker
  2100. (flycheck-start-current-syntax-check checker)
  2101. (flycheck-clear)
  2102. (flycheck-report-status 'no-checker)))
  2103. (error
  2104. (flycheck-report-failed-syntax-check)
  2105. (signal (car err) (cdr err)))))
  2106. (user-error "Flycheck mode disabled")))
  2107. (defun flycheck-report-buffer-checker-status
  2108. (syntax-check status &optional data)
  2109. "In BUFFER, report a SYNTAX-CHECK STATUS with DATA.
  2110. SYNTAX-CHECK is the `flycheck-syntax-check' which reported
  2111. STATUS. STATUS denotes the status of CHECKER, with an optional
  2112. DATA. STATUS may be one of the following symbols:
  2113. `errored'
  2114. The syntax checker has errored. DATA is an optional error
  2115. message.
  2116. This report finishes the current syntax check.
  2117. `interrupted'
  2118. The syntax checker was interrupted. DATA is ignored.
  2119. This report finishes the current syntax check.
  2120. `finished'
  2121. The syntax checker has finished with a proper error report
  2122. for the current buffer. DATA is the (potentially empty)
  2123. list of `flycheck-error' objects reported by the syntax
  2124. check.
  2125. This report finishes the current syntax check.
  2126. `suspicious'
  2127. The syntax checker encountered a suspicious state, which the
  2128. user needs to be informed about. DATA is an optional
  2129. message.
  2130. A syntax checker _must_ report a status at least once with any
  2131. symbol that finishes the current syntax checker. Otherwise
  2132. Flycheck gets stuck with the current syntax check.
  2133. If CHECKER is not the currently used syntax checker in
  2134. `flycheck-current-syntax-check', the status report is largely
  2135. ignored. Notably, any errors reported by the checker are
  2136. discarded."
  2137. (let ((buffer (flycheck-syntax-check-buffer syntax-check)))
  2138. ;; Ignore the status report if the buffer is gone, or if this syntax check
  2139. ;; isn't the current one in buffer (which can happen if this is an old
  2140. ;; report of an interrupted syntax check, and a new syntax check was started
  2141. ;; since this check was interrupted)
  2142. (when (and (buffer-live-p buffer)
  2143. (eq syntax-check
  2144. (buffer-local-value 'flycheck-current-syntax-check buffer)))
  2145. (with-current-buffer buffer
  2146. (let ((checker (flycheck-syntax-check-checker syntax-check)))
  2147. (pcase status
  2148. ((or `errored `interrupted)
  2149. (flycheck-report-failed-syntax-check status)
  2150. (when (eq status 'errored)
  2151. ;; In case of error, show the error message
  2152. (message "Error from syntax checker %s: %s"
  2153. checker (or data "UNKNOWN!"))))
  2154. (`suspicious
  2155. (when flycheck-mode
  2156. (message "Suspicious state from syntax checker %s: %s"
  2157. checker (or data "UNKNOWN!")))
  2158. (flycheck-report-status 'suspicious))
  2159. (`finished
  2160. (when flycheck-mode
  2161. ;; Only report errors from the checker if Flycheck Mode is
  2162. ;; still enabled.
  2163. (flycheck-finish-current-syntax-check
  2164. data
  2165. (flycheck-syntax-check-working-directory syntax-check))))
  2166. (_
  2167. (error "Unknown status %s from syntax checker %s"
  2168. status checker))))))))
  2169. (defun flycheck-finish-current-syntax-check (errors working-dir)
  2170. "Finish the current syntax-check in the current buffer with ERRORS.
  2171. ERRORS is a list of `flycheck-error' objects reported by the
  2172. current syntax check in `flycheck-current-syntax-check'.
  2173. Report all ERRORS and potentially start any next syntax checkers.
  2174. If the current syntax checker reported excessive errors, it is
  2175. disabled via `flycheck-disable-excessive-checker' for subsequent
  2176. syntax checks.
  2177. Relative file names in ERRORS will be expanded relative to
  2178. WORKING-DIR."
  2179. (let* ((syntax-check flycheck-current-syntax-check)
  2180. (checker (flycheck-syntax-check-checker syntax-check))
  2181. (errors (flycheck-relevant-errors
  2182. (flycheck-fill-and-expand-error-file-names
  2183. (flycheck-filter-errors
  2184. (flycheck-assert-error-list-p errors) checker)
  2185. working-dir))))
  2186. (unless (flycheck-disable-excessive-checker checker errors)
  2187. (flycheck-report-current-errors errors))
  2188. (let ((next-checker (flycheck-get-next-checker-for-buffer checker)))
  2189. (if next-checker
  2190. (flycheck-start-current-syntax-check next-checker)
  2191. (setq flycheck-current-syntax-check nil)
  2192. (flycheck-report-status 'finished)
  2193. ;; Delete overlays only after the very last checker has run, to avoid
  2194. ;; flickering on intermediate re-displays
  2195. (flycheck-delete-marked-overlays)
  2196. (flycheck-error-list-refresh)
  2197. (run-hooks 'flycheck-after-syntax-check-hook)
  2198. (when (eq (current-buffer) (window-buffer))
  2199. (flycheck-display-error-at-point))
  2200. ;; Immediately try to run any pending deferred syntax check, which
  2201. ;; were triggered by intermediate automatic check event, to make sure
  2202. ;; that we quickly refine outdated error information
  2203. (flycheck-perform-deferred-syntax-check)))))
  2204. (defun flycheck-disable-excessive-checker (checker errors)
  2205. "Disable CHECKER if it reported excessive ERRORS.
  2206. If ERRORS has more items than `flycheck-checker-error-threshold',
  2207. add CHECKER to `flycheck-disabled-checkers', and show a warning.
  2208. Return t when CHECKER was disabled, or nil otherwise."
  2209. (when (and flycheck-checker-error-threshold
  2210. (> (length errors) flycheck-checker-error-threshold))
  2211. ;; Disable CHECKER for this buffer (`flycheck-disabled-checkers' is a local
  2212. ;; variable).
  2213. (lwarn '(flycheck syntax-checker) :warning
  2214. "Syntax checker %s reported too many errors (%s) and is disabled."
  2215. checker (length errors))
  2216. (push checker flycheck-disabled-checkers)
  2217. t))
  2218. (defun flycheck-clear (&optional shall-interrupt)
  2219. "Clear all errors in the current buffer.
  2220. With prefix arg or SHALL-INTERRUPT non-nil, also interrupt the
  2221. current syntax check."
  2222. (interactive "P")
  2223. (when shall-interrupt
  2224. (flycheck-stop))
  2225. (flycheck-delete-all-overlays)
  2226. (flycheck-clear-errors)
  2227. (flycheck-error-list-refresh)
  2228. (flycheck-hide-error-buffer))
  2229. (defun flycheck-teardown ()
  2230. "Teardown Flycheck in the current buffer..
  2231. Completely clear the whole Flycheck state. Remove overlays, kill
  2232. running checks, and empty all variables used by Flycheck."
  2233. (flycheck-safe-delete-temporaries)
  2234. (flycheck-stop)
  2235. (flycheck-clean-deferred-check)
  2236. (flycheck-clear)
  2237. (flycheck-cancel-error-display-error-at-point-timer))
  2238. ;;; Automatic syntax checking in a buffer
  2239. (defun flycheck-may-check-automatically (&optional condition)
  2240. "Determine whether the buffer may be checked under CONDITION.
  2241. Read-only buffers may never be checked automatically.
  2242. If CONDITION is non-nil, determine whether syntax may checked
  2243. automatically according to
  2244. `flycheck-check-syntax-automatically'."
  2245. (and (not (or buffer-read-only (flycheck-ephemeral-buffer-p)))
  2246. (file-exists-p default-directory)
  2247. (or (not condition)
  2248. (memq condition flycheck-check-syntax-automatically))))
  2249. (defun flycheck-buffer-automatically (&optional condition force-deferred)
  2250. "Automatically check syntax at CONDITION.
  2251. Syntax is not checked if `flycheck-may-check-automatically'
  2252. returns nil for CONDITION.
  2253. The syntax check is deferred if FORCE-DEFERRED is non-nil, or if
  2254. `flycheck-must-defer-check' returns t."
  2255. (when (and flycheck-mode (flycheck-may-check-automatically condition))
  2256. (if (or force-deferred (flycheck-must-defer-check))
  2257. (flycheck-buffer-deferred)
  2258. (with-demoted-errors "Error while checking syntax automatically: %S"
  2259. (flycheck-buffer)))))
  2260. (defvar-local flycheck-idle-change-timer nil
  2261. "Timer to mark the idle time since the last change.")
  2262. (defun flycheck-clear-idle-change-timer ()
  2263. "Clear the idle change timer."
  2264. (when flycheck-idle-change-timer
  2265. (cancel-timer flycheck-idle-change-timer)
  2266. (setq flycheck-idle-change-timer nil)))
  2267. (defun flycheck-handle-change (beg end _len)
  2268. "Handle a buffer change between BEG and END.
  2269. BEG and END mark the beginning and end of the change text. _LEN
  2270. is ignored.
  2271. Start a syntax check if a new line has been inserted into the
  2272. buffer."
  2273. ;; Save and restore the match data, as recommended in (elisp)Change Hooks
  2274. (save-match-data
  2275. (when flycheck-mode
  2276. ;; The buffer was changed, thus clear the idle timer
  2277. (flycheck-clear-idle-change-timer)
  2278. (if (string-match-p (rx "\n") (buffer-substring beg end))
  2279. (flycheck-buffer-automatically 'new-line 'force-deferred)
  2280. (setq flycheck-idle-change-timer
  2281. (run-at-time flycheck-idle-change-delay nil
  2282. #'flycheck--handle-idle-change-in-buffer
  2283. (current-buffer)))))))
  2284. (defun flycheck--handle-idle-change-in-buffer (buffer)
  2285. "Handle an expired idle timer in BUFFER since the last change.
  2286. This thin wrapper around `flycheck-handle-idle-change' is needed
  2287. because some users override that function, as described in URL
  2288. `https://github.com/flycheck/flycheck/pull/1305'."
  2289. (when (buffer-live-p buffer)
  2290. (with-current-buffer buffer
  2291. (flycheck-handle-idle-change))))
  2292. (defun flycheck-handle-idle-change ()
  2293. "Handle an expired idle timer since the last change."
  2294. (flycheck-clear-idle-change-timer)
  2295. (flycheck-buffer-automatically 'idle-change))
  2296. (defun flycheck-handle-save ()
  2297. "Handle a save of the buffer."
  2298. (flycheck-buffer-automatically 'save))
  2299. ;;; Deferred syntax checking
  2300. (defvar-local flycheck-deferred-syntax-check nil
  2301. "If non-nil, a deferred syntax check is pending.")
  2302. (defun flycheck-must-defer-check ()
  2303. "Determine whether the syntax check has to be deferred.
  2304. A check has to be deferred if the buffer is not visible, or if the buffer is
  2305. currently being reverted.
  2306. Return t if the check is to be deferred, or nil otherwise."
  2307. (or (not (get-buffer-window))
  2308. ;; We defer the syntax check if Flycheck is already running, to
  2309. ;; immediately start a new syntax check after the current one finished,
  2310. ;; because the result of the current check will most likely be outdated by
  2311. ;; the time it is finished.
  2312. (flycheck-running-p)
  2313. ;; We must defer checks while a buffer is being reverted, to avoid race
  2314. ;; conditions while the buffer contents are being restored.
  2315. revert-buffer-in-progress-p))
  2316. (defun flycheck-deferred-check-p ()
  2317. "Determine whether the current buffer has a deferred check.
  2318. Return t if so, or nil otherwise."
  2319. flycheck-deferred-syntax-check)
  2320. (defun flycheck-buffer-deferred ()
  2321. "Defer syntax check for the current buffer."
  2322. (setq flycheck-deferred-syntax-check t))
  2323. (defun flycheck-clean-deferred-check ()
  2324. "Clean an deferred syntax checking state."
  2325. (setq flycheck-deferred-syntax-check nil))
  2326. (defun flycheck-perform-deferred-syntax-check ()
  2327. "Perform the deferred syntax check."
  2328. (when (flycheck-deferred-check-p)
  2329. (flycheck-clean-deferred-check)
  2330. (flycheck-buffer-automatically)))
  2331. ;;; Syntax checking in all buffers
  2332. (defun flycheck-may-enable-mode ()
  2333. "Determine whether Flycheck mode may be enabled.
  2334. Flycheck mode is not enabled for
  2335. - the minibuffer,
  2336. - `fundamental-mode'
  2337. - major modes whose `mode-class' property is `special',
  2338. - ephemeral buffers (see `flycheck-ephemeral-buffer-p'),
  2339. - encrypted buffers (see `flycheck-encrypted-buffer-p'),
  2340. - remote files (see `file-remote-p'),
  2341. - and major modes excluded by `flycheck-global-modes'.
  2342. Return non-nil if Flycheck mode may be enabled, and nil
  2343. otherwise."
  2344. (and (pcase flycheck-global-modes
  2345. ;; Whether `major-mode' is disallowed by `flycheck-global-modes'
  2346. (`t t)
  2347. (`(not . ,modes) (not (memq major-mode modes)))
  2348. (modes (memq major-mode modes)))
  2349. (not (or (minibufferp)
  2350. (eq major-mode 'fundamental-mode)
  2351. (eq (get major-mode 'mode-class) 'special)
  2352. (flycheck-ephemeral-buffer-p)
  2353. (flycheck-encrypted-buffer-p)
  2354. (and (buffer-file-name)
  2355. (file-remote-p (buffer-file-name) 'method))))))
  2356. (defun flycheck-mode-on-safe ()
  2357. "Enable command `flycheck-mode' if it is safe to do so.
  2358. Command `flycheck-mode' is only enabled if
  2359. `flycheck-may-enable-mode' returns a non-nil result."
  2360. (when (flycheck-may-enable-mode)
  2361. (flycheck-mode)))
  2362. ;;;###autoload
  2363. (define-globalized-minor-mode global-flycheck-mode flycheck-mode
  2364. flycheck-mode-on-safe
  2365. :init-value nil
  2366. ;; Do not expose Global Flycheck Mode on customize interface, because the
  2367. ;; interaction between package.el and customize is currently broken. See
  2368. ;; https://github.com/flycheck/flycheck/issues/595
  2369. ;; :require 'flycheck :group
  2370. ;; 'flycheck
  2371. )
  2372. (defun flycheck-global-teardown ()
  2373. "Teardown Flycheck in all buffers.
  2374. Completely clear the whole Flycheck state in all buffers, stop
  2375. all running checks, remove all temporary files, and empty all
  2376. variables of Flycheck."
  2377. (dolist (buffer (buffer-list))
  2378. (with-current-buffer buffer
  2379. (when flycheck-mode
  2380. (flycheck-teardown)))))
  2381. ;; Clean up the entire state of Flycheck when Emacs is killed, to get rid of any
  2382. ;; pending temporary files.
  2383. (add-hook 'kill-emacs-hook #'flycheck-global-teardown)
  2384. ;;; Errors from syntax checks
  2385. (cl-defstruct (flycheck-error
  2386. (:constructor flycheck-error-new)
  2387. (:constructor flycheck-error-new-at (line column
  2388. &optional level message
  2389. &key checker id group
  2390. (filename (buffer-file-name))
  2391. (buffer (current-buffer)))))
  2392. "Structure representing an error reported by a syntax checker.
  2393. Slots:
  2394. `buffer'
  2395. The buffer that the error was reported for, as buffer object.
  2396. `checker'
  2397. The syntax checker which reported this error, as symbol.
  2398. `filename'
  2399. The file name the error refers to, as string.
  2400. `line'
  2401. The line number the error refers to, as number.
  2402. `column' (optional)
  2403. The column number the error refers to, as number.
  2404. For compatibility with external tools and unlike Emacs
  2405. itself (e.g. in Compile Mode) Flycheck uses _1-based_
  2406. columns: The first character on a line is column 1.
  2407. Occasionally some tools try to proactively adapt to Emacs
  2408. and emit 0-based columns automatically. In these cases, the
  2409. columns must be adjusted for Flycheck, see
  2410. `flycheck-increment-error-columns'.
  2411. `message' (optional)
  2412. The error message as a string, if any.
  2413. `level'
  2414. The error level, as either `info', `warning' or `error'.
  2415. `id' (optional)
  2416. An ID identifying the kind of error.
  2417. `group` (optional)
  2418. A symbol identifying the group the error belongs to.
  2419. Some tools will emit multiple errors that relate to the same
  2420. issue (e.g., lifetime errors in Rust). All related errors
  2421. collected by a checker should have the same `group` value,
  2422. in order to be able to present them to the user.
  2423. See `flycheck-errors-from-group`."
  2424. buffer checker filename line column message level id group)
  2425. (defmacro flycheck-error-with-buffer (err &rest forms)
  2426. "Switch to the buffer of ERR and evaluate FORMS.
  2427. If the buffer of ERR is not live, FORMS are not evaluated."
  2428. (declare (indent 1) (debug t))
  2429. `(when (buffer-live-p (flycheck-error-buffer ,err))
  2430. (with-current-buffer (flycheck-error-buffer ,err)
  2431. ,@forms)))
  2432. (defun flycheck-error-line-region (err)
  2433. "Get the line region of ERR.
  2434. ERR is a Flycheck error whose region to get.
  2435. Return a cons cell `(BEG . END)' where BEG is the first
  2436. non-whitespace character on the line ERR refers to, and END the
  2437. end of the line."
  2438. (flycheck-error-with-buffer err
  2439. (save-restriction
  2440. (save-excursion
  2441. (widen)
  2442. (goto-char (point-min))
  2443. (forward-line (- (flycheck-error-line err) 1))
  2444. ;; We are at the beginning of the line now, so move to the beginning of
  2445. ;; its indentation, similar to `back-to-indentation'
  2446. (let ((end (line-end-position)))
  2447. (skip-syntax-forward " " end)
  2448. (backward-prefix-chars)
  2449. ;; If the current line is empty, include the previous line break
  2450. ;; character(s) to have any region at all. When called with 0,
  2451. ;; `line-end-position' gives us the end of the previous line
  2452. (cons (if (eolp) (line-end-position 0) (point)) end))))))
  2453. (defun flycheck-error-column-region (err)
  2454. "Get the error column region of ERR.
  2455. ERR is a Flycheck error whose region to get.
  2456. Return a cons cell `(BEG . END)' where BEG is the character
  2457. before the error column, and END the actual error column, or nil
  2458. if ERR has no column."
  2459. (flycheck-error-with-buffer err
  2460. (save-restriction
  2461. (save-excursion
  2462. (-when-let (column (flycheck-error-column err))
  2463. (widen)
  2464. (goto-char (point-min))
  2465. (forward-line (- (flycheck-error-line err) 1))
  2466. (cond
  2467. ((eobp) ; Line beyond EOF
  2468. ;; If we are at the end of the file (i.e. the line was beyond the
  2469. ;; end of the file), use the very last column in the file.
  2470. (cons (- (point-max) 1) (point-max)))
  2471. ((eolp) ; Empty line
  2472. ;; If the target line is empty, there's no column to highlight on
  2473. ;; this line, so return the last column of the previous line.
  2474. (cons (line-end-position 0) (point)))
  2475. (t
  2476. ;; The end is either the column offset of the line, or the end of
  2477. ;; the line, if the column offset points beyond the end of the
  2478. ;; line.
  2479. (let ((end (min (+ (point) column)
  2480. (+ (line-end-position) 1))))
  2481. (cons (- end 1) end)))))))))
  2482. (defun flycheck-error-thing-region (thing err)
  2483. "Get the region of THING at the column of ERR.
  2484. ERR is a Flycheck error whose region to get. THING is a
  2485. understood by `thing-at-point'.
  2486. Return a cons cell `(BEG . END)' where BEG is the beginning of
  2487. the THING at the error column, and END the end of the symbol. If
  2488. ERR has no error column, or if there is no THING at this column,
  2489. return nil."
  2490. (-when-let (column (car (flycheck-error-column-region err)))
  2491. (flycheck-error-with-buffer err
  2492. (save-excursion
  2493. (save-restriction
  2494. (widen)
  2495. (goto-char column)
  2496. (bounds-of-thing-at-point thing))))))
  2497. (defun flycheck-error-region-for-mode (err mode)
  2498. "Get the region of ERR for the highlighting MODE.
  2499. ERR is a Flycheck error. MODE may be one of the following symbols:
  2500. `columns'
  2501. Get the column region of ERR, or the line region if ERR
  2502. has no column.
  2503. `symbols'
  2504. Get the symbol region of ERR, or the result of `columns', if
  2505. there is no sexp at the error column.
  2506. `sexps'
  2507. Get the sexp region of ERR, or the result of `columns', if
  2508. there is no sexp at the error column.
  2509. `lines'
  2510. Return the line region.
  2511. Otherwise signal an error."
  2512. ;; Ignoring fields speeds up calls to `line-end-position' in
  2513. ;; `flycheck-error-column-region' and `flycheck-error-line-region'.
  2514. (let ((inhibit-field-text-motion t))
  2515. (pcase mode
  2516. (`columns (or (flycheck-error-column-region err)
  2517. (flycheck-error-line-region err)))
  2518. (`symbols (or (flycheck-error-thing-region 'symbol err)
  2519. (flycheck-error-region-for-mode err 'columns)))
  2520. (`sexps (or (flycheck-error-thing-region 'sexp err)
  2521. (flycheck-error-region-for-mode err 'columns)))
  2522. (`lines (flycheck-error-line-region err))
  2523. (_ (error "Invalid mode %S" mode)))))
  2524. (defun flycheck-error-pos (err)
  2525. "Get the buffer position of ERR.
  2526. ERR is a Flycheck error whose position to get.
  2527. The error position is the error column, or the first
  2528. non-whitespace character of the error line, if ERR has no error column."
  2529. (car (or (flycheck-error-column-region err)
  2530. (flycheck-error-line-region err))))
  2531. (defun flycheck-error-format-message-and-id (err)
  2532. "Format the message and id of ERR as human-readable string."
  2533. (let ((id (flycheck-error-id err))
  2534. (message (flycheck-error-message err)))
  2535. (if id (format "%s [%s]" message id) message)))
  2536. (defun flycheck-error-format (err &optional with-file-name)
  2537. "Format ERR as human-readable string, optionally WITH-FILE-NAME.
  2538. Return a string that represents the given ERR. If WITH-FILE-NAME
  2539. is given and non-nil, include the file-name as well, otherwise
  2540. omit it."
  2541. (let* ((line (flycheck-error-line err))
  2542. (column (flycheck-error-column err))
  2543. (level (symbol-name (flycheck-error-level err)))
  2544. (checker (symbol-name (flycheck-error-checker err)))
  2545. (format `(,@(when with-file-name
  2546. (list (flycheck-error-filename err) ":"))
  2547. ,(number-to-string line) ":"
  2548. ,@(when column (list (number-to-string column) ":"))
  2549. ,level ": "
  2550. ,(flycheck-error-format-message-and-id err)
  2551. " (" ,checker ")")))
  2552. (apply #'concat format)))
  2553. (defun flycheck-error-< (err1 err2)
  2554. "Determine whether ERR1 is less than ERR2 by location.
  2555. Compare by line numbers and then by column numbers."
  2556. (let ((line1 (flycheck-error-line err1))
  2557. (line2 (flycheck-error-line err2)))
  2558. (if (= line1 line2)
  2559. (let ((col1 (flycheck-error-column err1))
  2560. (col2 (flycheck-error-column err2)))
  2561. (and col2
  2562. ;; Sort errors for the whole line first
  2563. (or (not col1) (< col1 col2))))
  2564. (< line1 line2))))
  2565. (defun flycheck-error-level-< (err1 err2)
  2566. "Determine whether ERR1 is less than ERR2 by error level.
  2567. Like `flycheck-error-<', but compares by error level severity
  2568. first. Levels of the same severity are compared by name."
  2569. (let* ((level1 (flycheck-error-level err1))
  2570. (level2 (flycheck-error-level err2))
  2571. (severity1 (flycheck-error-level-severity level1))
  2572. (severity2 (flycheck-error-level-severity level2)))
  2573. (cond
  2574. ((= severity1 severity2)
  2575. (if (string= level1 level2)
  2576. (flycheck-error-< err1 err2)
  2577. (string< level1 level2)))
  2578. (t (< severity1 severity2)))))
  2579. (defun flycheck-assert-error-list-p (errors)
  2580. "Assert that all items in ERRORS are of `flycheck-error' type.
  2581. Signal an error if any item in ERRORS is not a `flycheck-error'
  2582. object, as by `flycheck-error-p'. Otherwise return ERRORS
  2583. again."
  2584. (unless (listp errors)
  2585. (signal 'wrong-type-argument (list 'listp errors)))
  2586. (dolist (err errors)
  2587. (unless (flycheck-error-p err)
  2588. (signal 'wrong-type-argument (list 'flycheck-error-p err))))
  2589. errors)
  2590. ;;; Errors in the current buffer
  2591. (defvar-local flycheck-current-errors nil
  2592. "A list of all errors and warnings in the current buffer.")
  2593. (defun flycheck-report-current-errors (errors)
  2594. "Report ERRORS in the current buffer.
  2595. Add ERRORS to `flycheck-current-errors' and process each error
  2596. with `flycheck-process-error-functions'."
  2597. (setq flycheck-current-errors (sort (append errors flycheck-current-errors)
  2598. #'flycheck-error-<))
  2599. (overlay-recenter (point-max))
  2600. (seq-do (lambda (err)
  2601. (run-hook-with-args-until-success 'flycheck-process-error-functions
  2602. err))
  2603. errors))
  2604. (defun flycheck-clear-errors ()
  2605. "Remove all error information from the current buffer."
  2606. (setq flycheck-current-errors nil)
  2607. (flycheck-report-status 'not-checked))
  2608. (defun flycheck-fill-and-expand-error-file-names (errors directory)
  2609. "Fill and expand file names in ERRORS relative to DIRECTORY.
  2610. Expand all file names of ERRORS against DIRECTORY. If the file
  2611. name of an error is nil fill in the result of function
  2612. `buffer-file-name' in the current buffer.
  2613. Return ERRORS, modified in-place."
  2614. (seq-do (lambda (err)
  2615. (setf (flycheck-error-filename err)
  2616. (-if-let (filename (flycheck-error-filename err))
  2617. (expand-file-name filename directory)
  2618. (buffer-file-name))))
  2619. errors)
  2620. errors)
  2621. (defun flycheck-relevant-error-p (err)
  2622. "Determine whether ERR is relevant for the current buffer.
  2623. Return t if ERR may be shown for the current buffer, or nil
  2624. otherwise."
  2625. (flycheck-error-with-buffer err
  2626. (let ((file-name (flycheck-error-filename err))
  2627. (message (flycheck-error-message err)))
  2628. (and
  2629. ;; The error is relevant for the current buffer if it's got no file-name
  2630. ;; and the current buffer has no file name, too, or if it refers to the
  2631. ;; same file as the current buffer.
  2632. (or (and (not file-name) (not buffer-file-name))
  2633. (and buffer-file-name file-name
  2634. (flycheck-same-files-p file-name buffer-file-name)))
  2635. message
  2636. (not (string-empty-p message))
  2637. (flycheck-error-line err)))))
  2638. (defun flycheck-relevant-errors (errors)
  2639. "Filter the relevant errors from ERRORS.
  2640. Return a list of all errors that are relevant for their
  2641. corresponding buffer."
  2642. (seq-filter #'flycheck-relevant-error-p errors))
  2643. (defun flycheck-related-errors (err)
  2644. "Get all the errors that are in the same group as ERR.
  2645. Return a list of all errors (in `flycheck-current-errors') that
  2646. have the same `flycheck-error-group' as ERR, including ERR
  2647. itself."
  2648. (-if-let (group (flycheck-error-group err))
  2649. (seq-filter (lambda (e)
  2650. (eq (flycheck-error-group e) group))
  2651. flycheck-current-errors)
  2652. (list err)))
  2653. ;;; Status reporting for the current buffer
  2654. (defvar-local flycheck-last-status-change 'not-checked
  2655. "The last status change in the current buffer.")
  2656. (defun flycheck-report-failed-syntax-check (&optional status)
  2657. "Report a failed Flycheck syntax check with STATUS.
  2658. STATUS is a status symbol for `flycheck-report-status',
  2659. defaulting to `errored'.
  2660. Clear Flycheck state, run `flycheck-syntax-check-failed-hook' and
  2661. report an error STATUS."
  2662. (flycheck-clear)
  2663. (setq flycheck-current-syntax-check nil)
  2664. (run-hooks 'flycheck-syntax-check-failed-hook)
  2665. (flycheck-report-status (or status 'errored)))
  2666. (defun flycheck-report-status (status)
  2667. "Report Flycheck STATUS.
  2668. STATUS is one of the following symbols:
  2669. `not-checked'
  2670. The current buffer was not checked.
  2671. `no-checker'
  2672. Automatic syntax checker selection did not find a suitable
  2673. syntax checker.
  2674. `running'
  2675. A syntax check is now running in the current buffer.
  2676. `errored'
  2677. The current syntax check has errored.
  2678. `finished'
  2679. The current syntax check was finished normally.
  2680. `interrupted'
  2681. The current syntax check was interrupted.
  2682. `suspicious'
  2683. The last syntax check had a suspicious result.
  2684. Set `flycheck-last-status-change' and call
  2685. `flycheck-status-changed-functions' with STATUS. Afterwards
  2686. refresh the mode line."
  2687. (setq flycheck-last-status-change status)
  2688. (run-hook-with-args 'flycheck-status-changed-functions status)
  2689. (force-mode-line-update))
  2690. (defun flycheck-mode-line-status-text (&optional status)
  2691. "Get a text describing STATUS for use in the mode line.
  2692. STATUS defaults to `flycheck-last-status-change' if omitted or
  2693. nil."
  2694. (let ((text (pcase (or status flycheck-last-status-change)
  2695. (`not-checked "")
  2696. (`no-checker "-")
  2697. (`running "*")
  2698. (`errored "!")
  2699. (`finished
  2700. (let-alist (flycheck-count-errors flycheck-current-errors)
  2701. (if (or .error .warning)
  2702. (format ":%s/%s" (or .error 0) (or .warning 0))
  2703. "")))
  2704. (`interrupted ".")
  2705. (`suspicious "?"))))
  2706. (concat " " flycheck-mode-line-prefix text)))
  2707. ;;; Error levels
  2708. ;;;###autoload
  2709. (defun flycheck-define-error-level (level &rest properties)
  2710. "Define a new error LEVEL with PROPERTIES.
  2711. The following PROPERTIES constitute an error level:
  2712. `:severity SEVERITY'
  2713. A number denoting the severity of this level. The higher
  2714. the number, the more severe is this level compared to other
  2715. levels. Defaults to 0.
  2716. The severity is used by `flycheck-error-level-<' to
  2717. determine the ordering of errors according to their levels.
  2718. `:compilation-level LEVEL'
  2719. A number indicating the broad class of messages that errors
  2720. at this level belong to: one of 0 (info), 1 (warning), or
  2721. 2 or nil (error). Defaults to nil.
  2722. This is used by `flycheck-checker-pattern-to-error-regexp'
  2723. to map error levels into `compilation-mode''s hierarchy and
  2724. to get proper highlighting of errors in `compilation-mode'.
  2725. `:overlay-category CATEGORY'
  2726. A symbol denoting the overlay category to use for error
  2727. highlight overlays for this level. See Info
  2728. node `(elisp)Overlay Properties' for more information about
  2729. overlay categories.
  2730. A category for an error level overlay should at least define
  2731. the `face' property, for error highlighting. Another useful
  2732. property for error level categories is `priority', to
  2733. influence the stacking of multiple error level overlays.
  2734. `:fringe-bitmap BITMAP'
  2735. A fringe bitmap symbol denoting the bitmap to use for fringe
  2736. indicators for this level. See Info node `(elisp)Fringe
  2737. Bitmaps' for more information about fringe bitmaps,
  2738. including a list of built-in fringe bitmaps.
  2739. `:fringe-face FACE'
  2740. A face symbol denoting the face to use for fringe indicators
  2741. for this level.
  2742. `:error-list-face FACE'
  2743. A face symbol denoting the face to use for messages of this
  2744. level in the error list. See `flycheck-list-errors'."
  2745. (declare (indent 1))
  2746. (setf (get level 'flycheck-error-level) t)
  2747. (setf (get level 'flycheck-error-severity)
  2748. (or (plist-get properties :severity) 0))
  2749. (setf (get level 'flycheck-compilation-level)
  2750. (plist-get properties :compilation-level))
  2751. (setf (get level 'flycheck-overlay-category)
  2752. (plist-get properties :overlay-category))
  2753. (setf (get level 'flycheck-fringe-bitmap-double-arrow)
  2754. (plist-get properties :fringe-bitmap))
  2755. (setf (get level 'flycheck-fringe-face)
  2756. (plist-get properties :fringe-face))
  2757. (setf (get level 'flycheck-error-list-face)
  2758. (plist-get properties :error-list-face)))
  2759. (defun flycheck-error-level-p (level)
  2760. "Determine whether LEVEL is a Flycheck error level."
  2761. (get level 'flycheck-error-level))
  2762. (defun flycheck-error-level-severity (level)
  2763. "Get the numeric severity of LEVEL."
  2764. (or (get level 'flycheck-error-severity) 0))
  2765. (defun flycheck-error-level-compilation-level (level)
  2766. "Get the compilation level for LEVEL."
  2767. (get level 'flycheck-compilation-level))
  2768. (defun flycheck-error-level-overlay-category (level)
  2769. "Get the overlay category for LEVEL."
  2770. (get level 'flycheck-overlay-category))
  2771. (defun flycheck-error-level-fringe-bitmap (level)
  2772. "Get the fringe bitmap for LEVEL."
  2773. (get level 'flycheck-fringe-bitmap-double-arrow))
  2774. (defun flycheck-error-level-fringe-face (level)
  2775. "Get the fringe face for LEVEL."
  2776. (get level 'flycheck-fringe-face))
  2777. (defun flycheck-error-level-error-list-face (level)
  2778. "Get the error list face for LEVEL."
  2779. (get level 'flycheck-error-list-face))
  2780. (defun flycheck-error-level-make-fringe-icon (level side)
  2781. "Create the fringe icon for LEVEL at SIDE.
  2782. Return a propertized string that shows a fringe bitmap according
  2783. to LEVEL and the given fringe SIDE.
  2784. LEVEL is a Flycheck error level defined with
  2785. `flycheck-define-error-level', and SIDE is either `left-fringe'
  2786. or `right-fringe'.
  2787. Return a propertized string representing the fringe icon,
  2788. intended for use as `before-string' of an overlay to actually
  2789. show the icon."
  2790. (unless (memq side '(left-fringe right-fringe))
  2791. (error "Invalid fringe side: %S" side))
  2792. (propertize "!" 'display
  2793. (list side
  2794. (flycheck-error-level-fringe-bitmap level)
  2795. (flycheck-error-level-fringe-face level))))
  2796. ;;; Built-in error levels
  2797. (when (fboundp 'define-fringe-bitmap)
  2798. (define-fringe-bitmap 'flycheck-fringe-bitmap-double-arrow
  2799. (vector #b00000000
  2800. #b00000000
  2801. #b00000000
  2802. #b00000000
  2803. #b00000000
  2804. #b10011000
  2805. #b01101100
  2806. #b00110110
  2807. #b00011011
  2808. #b00110110
  2809. #b01101100
  2810. #b10011000
  2811. #b00000000
  2812. #b00000000
  2813. #b00000000
  2814. #b00000000
  2815. #b00000000)))
  2816. (setf (get 'flycheck-error-overlay 'face) 'flycheck-error)
  2817. (setf (get 'flycheck-error-overlay 'priority) 110)
  2818. (flycheck-define-error-level 'error
  2819. :severity 100
  2820. :compilation-level 2
  2821. :overlay-category 'flycheck-error-overlay
  2822. :fringe-bitmap 'flycheck-fringe-bitmap-double-arrow
  2823. :fringe-face 'flycheck-fringe-error
  2824. :error-list-face 'flycheck-error-list-error)
  2825. (setf (get 'flycheck-warning-overlay 'face) 'flycheck-warning)
  2826. (setf (get 'flycheck-warning-overlay 'priority) 100)
  2827. (flycheck-define-error-level 'warning
  2828. :severity 10
  2829. :compilation-level 1
  2830. :overlay-category 'flycheck-warning-overlay
  2831. :fringe-bitmap 'flycheck-fringe-bitmap-double-arrow
  2832. :fringe-face 'flycheck-fringe-warning
  2833. :error-list-face 'flycheck-error-list-warning)
  2834. (setf (get 'flycheck-info-overlay 'face) 'flycheck-info)
  2835. (setf (get 'flycheck-info-overlay 'priority) 90)
  2836. (flycheck-define-error-level 'info
  2837. :severity -10
  2838. :compilation-level 0
  2839. :overlay-category 'flycheck-info-overlay
  2840. :fringe-bitmap 'flycheck-fringe-bitmap-double-arrow
  2841. :fringe-face 'flycheck-fringe-info
  2842. :error-list-face 'flycheck-error-list-info)
  2843. ;;; Error filtering
  2844. (defun flycheck-filter-errors (errors checker)
  2845. "Filter ERRORS from CHECKER.
  2846. Apply the error filter of CHECKER to ERRORs and return the
  2847. result. If CHECKER has no error filter, fall back to
  2848. `flycheck-sanitize-errors'."
  2849. (let ((filter (or (flycheck-checker-get checker 'error-filter)
  2850. #'flycheck-sanitize-errors)))
  2851. (funcall filter errors)))
  2852. (defun flycheck-sanitize-errors (errors)
  2853. "Sanitize ERRORS.
  2854. Sanitize ERRORS by trimming leading and trailing whitespace in
  2855. all error messages, and by replacing 0 columns and empty error
  2856. messages with nil.
  2857. Returns sanitized ERRORS."
  2858. (dolist (err errors)
  2859. (flycheck-error-with-buffer err
  2860. (let ((message (flycheck-error-message err))
  2861. (column (flycheck-error-column err))
  2862. (id (flycheck-error-id err)))
  2863. (when message
  2864. (setq message (string-trim message))
  2865. (setf (flycheck-error-message err)
  2866. (if (string-empty-p message) nil message)))
  2867. (when (and id (string-empty-p id))
  2868. (setf (flycheck-error-id err) nil))
  2869. (when (eq column 0)
  2870. (setf (flycheck-error-column err) nil)))))
  2871. errors)
  2872. (defun flycheck-remove-error-file-names (file-name errors)
  2873. "Remove matching FILE-NAME from ERRORS.
  2874. Use as `:error-filter' for syntax checkers that output faulty
  2875. filenames. Flycheck will later fill in the buffer file name.
  2876. Return ERRORS."
  2877. (seq-do (lambda (err)
  2878. (when (and (flycheck-error-filename err)
  2879. (string= (flycheck-error-filename err) file-name))
  2880. (setf (flycheck-error-filename err) nil)))
  2881. errors)
  2882. errors)
  2883. (defun flycheck-increment-error-columns (errors &optional offset)
  2884. "Increment all columns of ERRORS by OFFSET.
  2885. Use this as `:error-filter' if a syntax checker outputs 0-based
  2886. columns."
  2887. (seq-do (lambda (err)
  2888. (let ((column (flycheck-error-column err)))
  2889. (when column
  2890. (setf (flycheck-error-column err)
  2891. (+ column (or offset 1))))))
  2892. errors)
  2893. errors)
  2894. (defun flycheck-collapse-error-message-whitespace (errors)
  2895. "Collapse whitespace in all messages of ERRORS.
  2896. Return ERRORS."
  2897. (dolist (err errors)
  2898. (-when-let (message (flycheck-error-message err))
  2899. (setf (flycheck-error-message err)
  2900. (replace-regexp-in-string (rx (one-or-more (any space "\n" "\r")))
  2901. " " message 'fixed-case 'literal))))
  2902. errors)
  2903. (defun flycheck-dedent-error-messages (errors)
  2904. "Dedent all messages of ERRORS.
  2905. For each error in ERRORS, determine the indentation offset from
  2906. the leading whitespace of the first line, and dedent all further
  2907. lines accordingly.
  2908. Return ERRORS, with in-place modifications."
  2909. (dolist (err errors)
  2910. (-when-let (message (flycheck-error-message err))
  2911. (with-temp-buffer
  2912. (insert message)
  2913. ;; Determine the indentation offset
  2914. (goto-char (point-min))
  2915. (back-to-indentation)
  2916. (let* ((indent-offset (- (point) (point-min))))
  2917. ;; Now iterate over all lines and dedent each according to
  2918. ;; `indent-offset'
  2919. (while (not (eobp))
  2920. (back-to-indentation)
  2921. ;; If the current line starts with sufficient whitespace, delete the
  2922. ;; indendation offset. Otherwise keep the line intact, as we might
  2923. ;; loose valuable information
  2924. (when (>= (- (point) (line-beginning-position)) indent-offset)
  2925. (delete-char (- indent-offset)))
  2926. (forward-line 1)))
  2927. (delete-trailing-whitespace (point-min) (point-max))
  2928. (setf (flycheck-error-message err)
  2929. (buffer-substring-no-properties (point-min) (point-max))))))
  2930. errors)
  2931. (defun flycheck-fold-include-levels (errors sentinel-message)
  2932. "Fold levels of ERRORS from included files.
  2933. ERRORS is a list of `flycheck-error' objects. SENTINEL-MESSAGE
  2934. is a regular expression matched against the error message to
  2935. determine whether the errror denotes errors from an included
  2936. file. Alternatively, it is a function that is given an error and
  2937. shall return non-nil, if the error denotes errors from an
  2938. included file."
  2939. (unless (or (stringp sentinel-message) (functionp sentinel-message))
  2940. (error "Sentinel must be string or function: %S" sentinel-message))
  2941. (let ((sentinel (if (functionp sentinel-message)
  2942. sentinel-message
  2943. (lambda (err)
  2944. (string-match-p sentinel-message
  2945. (flycheck-error-message err)))))
  2946. (remaining-errors errors))
  2947. (while remaining-errors
  2948. (let* ((current-error (pop remaining-errors)))
  2949. (when (funcall sentinel current-error)
  2950. ;; We found an error denoting errors in the included file:
  2951. ;; 1. process all subsequent errors until faulty include file is found
  2952. ;; 2. process again all subsequent errors until an error has the
  2953. ;; current file name again
  2954. ;; 3. find the most severe error level
  2955. (let ((current-filename (flycheck-error-filename current-error))
  2956. (current-level nil)
  2957. (faulty-include-filename nil)
  2958. (filename nil)
  2959. (done (null remaining-errors)))
  2960. (while (not done)
  2961. (setq filename (flycheck-error-filename (car remaining-errors)))
  2962. (unless faulty-include-filename
  2963. (unless (string= filename current-filename)
  2964. (setq faulty-include-filename filename)))
  2965. (let* ((error-in-include (pop remaining-errors))
  2966. (in-include-level (flycheck-error-level error-in-include)))
  2967. (unless (funcall sentinel error-in-include)
  2968. ;; Ignore nested "included file" errors, we are only
  2969. ;; interested in real errors because these define our level
  2970. (when (or (not current-level)
  2971. (> (flycheck-error-level-severity in-include-level)
  2972. (flycheck-error-level-severity current-level)))
  2973. (setq current-level in-include-level))))
  2974. (setq done (or (null remaining-errors)
  2975. (and faulty-include-filename
  2976. (string= filename current-filename)))))
  2977. (setf (flycheck-error-level current-error) current-level
  2978. (flycheck-error-message current-error)
  2979. (format "In include %s" faulty-include-filename))))))
  2980. errors))
  2981. (defun flycheck-dequalify-error-ids (errors)
  2982. "De-qualify error ids in ERRORS.
  2983. Remove all qualifications from error ids in ERRORS, by stripping
  2984. all leading dotted components from error IDs. For instance, if
  2985. the error ID is com.foo.E100, replace it with E100.
  2986. This error filter is mainly useful to simplify error IDs obtained
  2987. from parsing Checkstyle XML, which frequently has very verbose
  2988. IDs, that include the name of the tool."
  2989. (seq-do (lambda (err)
  2990. (let ((id (flycheck-error-id err)))
  2991. (when id
  2992. (setf (flycheck-error-id err)
  2993. (replace-regexp-in-string
  2994. (rx string-start
  2995. (group
  2996. (optional (zero-or-more not-newline) "."))
  2997. (one-or-more (not (any ".")))
  2998. string-end)
  2999. "" id 'fixedcase 'literal 1)))))
  3000. errors)
  3001. errors)
  3002. (defun flycheck-remove-error-ids (errors)
  3003. "Remove all error ids from ERRORS."
  3004. (seq-do (lambda (err) (setf (flycheck-error-id err) nil)) errors)
  3005. errors)
  3006. (defun flycheck-fill-empty-line-numbers (errors)
  3007. "Set ERRORS without lines to line 0.
  3008. Use as `:error-filter' for syntax checkers that output errors
  3009. without line numbers.
  3010. Return ERRORS."
  3011. (seq-do (lambda (err)
  3012. (unless (flycheck-error-line err)
  3013. (setf (flycheck-error-line err) 0)))
  3014. errors)
  3015. errors)
  3016. ;;; Error analysis
  3017. (defun flycheck-count-errors (errors)
  3018. "Count the number of ERRORS, grouped by level..
  3019. Return an alist, where each ITEM is a cons cell whose `car' is an
  3020. error level, and whose `cdr' is the number of errors of that
  3021. level."
  3022. (let (counts-by-level)
  3023. (dolist (err errors)
  3024. (let* ((level (flycheck-error-level err))
  3025. (item (assq level counts-by-level)))
  3026. (if item
  3027. (cl-incf (cdr item))
  3028. (push (cons level 1) counts-by-level))))
  3029. counts-by-level))
  3030. (defun flycheck-has-max-errors-p (errors level)
  3031. "Check if there is no error in ERRORS more severe than LEVEL."
  3032. (let ((severity (flycheck-error-level-severity level)))
  3033. (seq-every-p (lambda (e) (<= (flycheck-error-level-severity
  3034. (flycheck-error-level e))
  3035. severity))
  3036. errors)))
  3037. (defun flycheck-has-max-current-errors-p (level)
  3038. "Check if there is no current error more severe than LEVEL."
  3039. (flycheck-has-max-errors-p flycheck-current-errors level))
  3040. (defun flycheck-has-errors-p (errors level)
  3041. "Determine if there are any ERRORS with LEVEL."
  3042. (seq-some (lambda (e) (eq (flycheck-error-level e) level)) errors))
  3043. (defun flycheck-has-current-errors-p (&optional level)
  3044. "Determine if the current buffer has errors with LEVEL.
  3045. If LEVEL is omitted if the current buffer has any errors at all."
  3046. (if level
  3047. (flycheck-has-errors-p flycheck-current-errors level)
  3048. (and flycheck-current-errors t)))
  3049. ;;; Error overlays in the current buffer
  3050. (defun flycheck-add-overlay (err)
  3051. "Add overlay for ERR.
  3052. Return the created overlay."
  3053. ;; We must have a proper error region for the sake of fringe indication,
  3054. ;; error display and error navigation, even if the highlighting is disabled.
  3055. ;; We erase the highlighting later on in this case
  3056. (pcase-let* ((`(,beg . ,end) (flycheck-error-region-for-mode
  3057. err (or flycheck-highlighting-mode 'lines)))
  3058. (overlay (make-overlay beg end))
  3059. (level (flycheck-error-level err))
  3060. (category (flycheck-error-level-overlay-category level)))
  3061. (unless (flycheck-error-level-p level)
  3062. (error "Undefined error level: %S" level))
  3063. (setf (overlay-get overlay 'flycheck-overlay) t)
  3064. (setf (overlay-get overlay 'flycheck-error) err)
  3065. (setf (overlay-get overlay 'category) category)
  3066. (unless flycheck-highlighting-mode
  3067. ;; Erase the highlighting from the overlay if requested by the user
  3068. (setf (overlay-get overlay 'face) nil))
  3069. (when flycheck-indication-mode
  3070. (setf (overlay-get overlay 'before-string)
  3071. (flycheck-error-level-make-fringe-icon
  3072. level flycheck-indication-mode)))
  3073. (setf (overlay-get overlay 'help-echo) #'flycheck-help-echo)
  3074. overlay))
  3075. (defun flycheck-help-echo (_window object pos)
  3076. "Construct a tooltip message.
  3077. Most of the actual work is done by calling
  3078. `flycheck-help-echo-function' with the appropriate list of
  3079. errors. Arguments WINDOW, OBJECT and POS are as described in
  3080. info node `(elisp)Special properties', as this function is
  3081. intended to be used as the 'help-echo property of flycheck error
  3082. overlays."
  3083. (-when-let (buf (cond ((bufferp object) object)
  3084. ((overlayp object) (overlay-buffer object))))
  3085. (with-current-buffer buf
  3086. (-when-let* ((fn flycheck-help-echo-function)
  3087. (errs (flycheck-overlay-errors-at pos)))
  3088. (funcall fn errs)))))
  3089. (defun flycheck-help-echo-all-error-messages (errs)
  3090. "Concatenate error messages and ids from ERRS."
  3091. (mapconcat
  3092. (lambda (err)
  3093. (when err
  3094. (if (flycheck-error-message err)
  3095. (flycheck-error-format-message-and-id err)
  3096. (format "Unknown %s" (flycheck-error-level err)))))
  3097. (reverse errs) "\n\n"))
  3098. (defun flycheck-filter-overlays (overlays)
  3099. "Get all Flycheck overlays from OVERLAYS."
  3100. (seq-filter (lambda (o) (overlay-get o 'flycheck-overlay)) overlays))
  3101. (defun flycheck-overlays-at (pos)
  3102. "Get all Flycheck overlays at POS."
  3103. (flycheck-filter-overlays (overlays-at pos)))
  3104. (defun flycheck-overlays-in (beg end)
  3105. "Get all Flycheck overlays between BEG and END."
  3106. (flycheck-filter-overlays (overlays-in beg end)))
  3107. (defun flycheck-overlay-errors-at (pos)
  3108. "Return a list of all flycheck errors overlayed at POS."
  3109. (seq-map (lambda (o) (overlay-get o 'flycheck-error))
  3110. (flycheck-overlays-at pos)))
  3111. (defun flycheck-overlay-errors-in (beg end)
  3112. "Return a list of all flycheck errors overlayed between BEG and END."
  3113. (seq-map (lambda (o) (overlay-get o 'flycheck-error))
  3114. (flycheck-overlays-in beg end)))
  3115. (defvar-local flycheck-overlays-to-delete nil
  3116. "Overlays mark for deletion after all syntax checks completed.")
  3117. (put 'flycheck-overlays-to-delete 'permanent-local t)
  3118. (defun flycheck-delete-all-overlays ()
  3119. "Remove all flycheck overlays in the current buffer."
  3120. (overlay-recenter (point-max))
  3121. (flycheck-delete-marked-overlays)
  3122. (save-restriction
  3123. (widen)
  3124. (seq-do #'delete-overlay (flycheck-overlays-in (point-min) (point-max)))))
  3125. (defun flycheck-mark-all-overlays-for-deletion ()
  3126. "Mark all current overlays for deletion."
  3127. (setq flycheck-overlays-to-delete
  3128. (append (flycheck-overlays-in (point-min) (point-max))
  3129. flycheck-overlays-to-delete)))
  3130. (defun flycheck-delete-marked-overlays ()
  3131. "Delete all overlays marked for deletion."
  3132. (overlay-recenter (point-max))
  3133. (seq-do #'delete-overlay flycheck-overlays-to-delete)
  3134. (setq flycheck-overlays-to-delete nil))
  3135. ;;; Error navigation in the current buffer
  3136. (defun flycheck-error-level-interesting-at-pos-p (pos)
  3137. "Check if error severity at POS passes `flycheck-error-level-interesting-p'."
  3138. (flycheck-error-level-interesting-p (get-char-property pos 'flycheck-error)))
  3139. (defun flycheck-error-level-interesting-p (err)
  3140. "Check if ERR severity is >= `flycheck-navigation-minimum-level'."
  3141. (when (flycheck-error-p err)
  3142. (-if-let (min-level flycheck-navigation-minimum-level)
  3143. (<= (flycheck-error-level-severity min-level)
  3144. (flycheck-error-level-severity (flycheck-error-level err)))
  3145. t)))
  3146. (defun flycheck-next-error-pos (n &optional reset)
  3147. "Get the position of the N-th next error.
  3148. With negative N, get the position of the (-N)-th previous error
  3149. instead. With non-nil RESET, search from `point-min', otherwise
  3150. search from the current point.
  3151. Return the position of the next or previous error, or nil if
  3152. there is none."
  3153. (let ((n (or n 1))
  3154. (pos (if reset (point-min) (point))))
  3155. (if (>= n 0)
  3156. ;; Search forwards
  3157. (while (and pos (> n 0))
  3158. (setq n (1- n))
  3159. (when (get-char-property pos 'flycheck-error)
  3160. ;; Move beyond from the current error if any
  3161. (setq pos (next-single-char-property-change pos 'flycheck-error)))
  3162. (while (not (or (= pos (point-max))
  3163. (flycheck-error-level-interesting-at-pos-p pos)))
  3164. ;; Scan for the next error
  3165. (setq pos (next-single-char-property-change pos 'flycheck-error)))
  3166. (when (and (= pos (point-max))
  3167. (not (flycheck-error-level-interesting-at-pos-p pos)))
  3168. ;; If we reached the end of the buffer, but no error, we didn't find
  3169. ;; any
  3170. (setq pos nil)))
  3171. ;; Search backwards
  3172. (while (and pos (< n 0))
  3173. (setq n (1+ n))
  3174. ;; Loop until we find an error. We need to check the position *before*
  3175. ;; the current one, because `previous-single-char-property-change'
  3176. ;; always moves to the position *of* the change.
  3177. (while (not (or (= pos (point-min))
  3178. (flycheck-error-level-interesting-at-pos-p (1- pos))))
  3179. (setq pos (previous-single-char-property-change pos 'flycheck-error)))
  3180. (when (and (= pos (point-min))
  3181. (not (flycheck-error-level-interesting-at-pos-p pos)))
  3182. ;; We didn't find any error.
  3183. (setq pos nil))
  3184. (when pos
  3185. ;; We found an error, so move to its beginning
  3186. (setq pos (previous-single-char-property-change pos
  3187. 'flycheck-error)))))
  3188. pos))
  3189. (defun flycheck-next-error-function (n reset)
  3190. "Visit the N-th error from the current point.
  3191. N is the number of errors to advance by, where a negative N
  3192. advances backwards. With non-nil RESET, advance from the
  3193. beginning of the buffer, otherwise advance from the current
  3194. position.
  3195. Intended for use with `next-error-function'."
  3196. (let ((pos (flycheck-next-error-pos n reset)))
  3197. (if pos
  3198. (goto-char pos)
  3199. (user-error "No more Flycheck errors"))))
  3200. (defun flycheck-next-error (&optional n reset)
  3201. "Visit the N-th error from the current point.
  3202. N is the number of errors to advance by, where a negative N
  3203. advances backwards. With non-nil RESET, advance from the
  3204. beginning of the buffer, otherwise advance from the current
  3205. position."
  3206. (interactive "P")
  3207. (when (consp n)
  3208. ;; Universal prefix argument means reset
  3209. (setq reset t n nil))
  3210. (flycheck-next-error-function n reset)
  3211. (flycheck-display-error-at-point))
  3212. (defun flycheck-previous-error (&optional n)
  3213. "Visit the N-th previous error.
  3214. If given, N specifies the number of errors to move backwards by.
  3215. If N is negative, move forwards instead."
  3216. (interactive "P")
  3217. (flycheck-next-error (- (or n 1))))
  3218. (defun flycheck-first-error (&optional n)
  3219. "Visit the N-th error from beginning of the buffer.
  3220. If given, N specifies the number of errors to move forward from
  3221. the beginning of the buffer."
  3222. (interactive "P")
  3223. (flycheck-next-error n 'reset))
  3224. ;;; Listing errors in buffers
  3225. (defconst flycheck-error-list-buffer "*Flycheck errors*"
  3226. "The name of the buffer to show error lists.")
  3227. (defvar flycheck-error-list-mode-map
  3228. (let ((map (make-sparse-keymap)))
  3229. (define-key map (kbd "f") #'flycheck-error-list-set-filter)
  3230. (define-key map (kbd "F") #'flycheck-error-list-reset-filter)
  3231. (define-key map (kbd "n") #'flycheck-error-list-next-error)
  3232. (define-key map (kbd "p") #'flycheck-error-list-previous-error)
  3233. (define-key map (kbd "g") #'flycheck-error-list-check-source)
  3234. (define-key map (kbd "e") #'flycheck-error-list-explain-error)
  3235. (define-key map (kbd "RET") #'flycheck-error-list-goto-error)
  3236. map)
  3237. "The keymap of `flycheck-error-list-mode'.")
  3238. (defun flycheck-error-list-make-last-column (message checker)
  3239. "Compute contents of the last error list cell.
  3240. MESSAGE and CHECKER are displayed in a single column to allow the
  3241. message to stretch arbitrarily far."
  3242. (let ((checker-name (propertize (symbol-name checker)
  3243. 'face 'flycheck-error-list-checker-name)))
  3244. (format (propertize "%s (%s)" 'face 'default)
  3245. message checker-name)))
  3246. (defconst flycheck-error-list-format
  3247. `[("Line" 5 flycheck-error-list-entry-< :right-align t)
  3248. ("Col" 3 nil :right-align t)
  3249. ("Level" 8 flycheck-error-list-entry-level-<)
  3250. ("ID" 6 t)
  3251. (,(flycheck-error-list-make-last-column "Message" 'Checker) 0 t)]
  3252. "Table format for the error list.")
  3253. (defconst flycheck-error-list-padding 1
  3254. "Padding used in error list.")
  3255. (defconst flycheck--error-list-msg-offset
  3256. (seq-reduce
  3257. (lambda (offset fmt)
  3258. (pcase-let* ((`(,_ ,width ,_ . ,props) fmt)
  3259. (padding (or (plist-get props :pad-right) 1)))
  3260. (+ offset width padding)))
  3261. (seq-subseq flycheck-error-list-format 0 -1)
  3262. flycheck-error-list-padding)
  3263. "Amount of space to use in `flycheck-flush-multiline-message'.")
  3264. (define-derived-mode flycheck-error-list-mode tabulated-list-mode "Flycheck errors"
  3265. "Major mode for listing Flycheck errors.
  3266. \\{flycheck-error-list-mode-map}"
  3267. (setq tabulated-list-format flycheck-error-list-format
  3268. ;; Sort by location initially
  3269. tabulated-list-sort-key (cons "Line" nil)
  3270. tabulated-list-padding flycheck-error-list-padding
  3271. tabulated-list-entries #'flycheck-error-list-entries
  3272. ;; `revert-buffer' updates the mode line for us, so all we need to do is
  3273. ;; set the corresponding mode line construct.
  3274. mode-line-buffer-identification flycheck-error-list-mode-line)
  3275. ;; Guard `truncate-string-ellipsis' for Emacs 24.
  3276. ;; TODO: Remove when dropping Emacs 24 compatibility
  3277. (when (boundp 'truncate-string-ellipsis)
  3278. ;; See https://github.com/flycheck/flycheck/issues/1101
  3279. (setq-local truncate-string-ellipsis ""))
  3280. (tabulated-list-init-header))
  3281. (defvar-local flycheck-error-list-source-buffer nil
  3282. "The current source buffer of the error list.")
  3283. ;; Needs to permanently local to preserve the source buffer across buffer
  3284. ;; reversions
  3285. (put 'flycheck-error-list-source-buffer 'permanent-local t)
  3286. (defun flycheck-error-list-set-source (buffer)
  3287. "Set BUFFER as the source buffer of the error list."
  3288. (when (get-buffer flycheck-error-list-buffer)
  3289. (with-current-buffer flycheck-error-list-buffer
  3290. ;; Only update the source when required
  3291. (unless (eq buffer flycheck-error-list-source-buffer)
  3292. (setq flycheck-error-list-source-buffer buffer)
  3293. (flycheck-error-list-refresh)))))
  3294. (defun flycheck-error-list-update-source ()
  3295. "Update the source buffer of the error list."
  3296. (when (not (eq (current-buffer) (get-buffer flycheck-error-list-buffer)))
  3297. ;; We must not update the source buffer, if the current buffer is the error
  3298. ;; list itself.
  3299. (flycheck-error-list-set-source (current-buffer))))
  3300. (defun flycheck-error-list-check-source ()
  3301. "Trigger a syntax check in the source buffer of the error list."
  3302. (interactive)
  3303. (let ((buffer (get-buffer flycheck-error-list-source-buffer)))
  3304. (when (buffer-live-p buffer)
  3305. (with-current-buffer buffer
  3306. (flycheck-buffer)))))
  3307. (define-button-type 'flycheck-error-list
  3308. 'action #'flycheck-error-list-button-goto-error
  3309. 'help-echo "mouse-2, RET: goto error")
  3310. (defun flycheck-error-list-button-goto-error (button)
  3311. "Go to the error at BUTTON."
  3312. (flycheck-error-list-goto-error (button-start button)))
  3313. (define-button-type 'flycheck-error-list-explain-error
  3314. 'action #'flycheck-error-list-button-explain-error
  3315. 'help-echo "mouse-2, RET: explain error")
  3316. (defun flycheck-error-list-button-explain-error (button)
  3317. "Explain the error at BUTTON."
  3318. (flycheck-error-list-explain-error (button-start button)))
  3319. (defsubst flycheck-error-list-make-cell (text &optional face help-echo type)
  3320. "Make an error list cell with TEXT and FACE.
  3321. If FACE is nil don't set a FACE on TEXT. If TEXT already has
  3322. face properties, do not specify a FACE. Note though, that if
  3323. TEXT gets truncated it will not inherit any previous face
  3324. properties. If you expect TEXT to be truncated in the error
  3325. list, do specify a FACE explicitly!
  3326. If HELP-ECHO is non-nil, set a help-echo property on TEXT, with
  3327. value HELP-ECHO. This is convenient if you expect TEXT to be
  3328. truncated.
  3329. The cell will have the type TYPE unless TYPE is nil, and the
  3330. default type `flycheck-error-list' will be used instead."
  3331. (append (list text 'type (if type type
  3332. 'flycheck-error-list))
  3333. (and face (list 'face face))
  3334. (and help-echo (list 'help-echo help-echo))))
  3335. (defsubst flycheck-error-list-make-number-cell (number face)
  3336. "Make a table cell for a NUMBER with FACE.
  3337. Convert NUMBER to string, fontify it with FACE and return the
  3338. string with attached text properties."
  3339. (flycheck-error-list-make-cell
  3340. (if (numberp number) (number-to-string number) "")
  3341. face))
  3342. (defun flycheck-error-list-make-entry (error)
  3343. "Make a table cell for the given ERROR.
  3344. Return a list with the contents of the table cell."
  3345. (let* ((level (flycheck-error-level error))
  3346. (level-face (flycheck-error-level-error-list-face level))
  3347. (line (flycheck-error-line error))
  3348. (column (flycheck-error-column error))
  3349. (message (or (flycheck-error-message error)
  3350. (format "Unknown %s" (symbol-name level))))
  3351. (flushed-msg (flycheck-flush-multiline-message message))
  3352. (id (flycheck-error-id error))
  3353. (id-str (if id (format "%s" id) ""))
  3354. (checker (flycheck-error-checker error))
  3355. (msg-and-checker (flycheck-error-list-make-last-column flushed-msg checker))
  3356. (explainer (flycheck-checker-get checker 'error-explainer)))
  3357. (list error
  3358. (vector (flycheck-error-list-make-number-cell
  3359. line 'flycheck-error-list-line-number)
  3360. (flycheck-error-list-make-number-cell
  3361. column 'flycheck-error-list-column-number)
  3362. (flycheck-error-list-make-cell
  3363. (symbol-name (flycheck-error-level error)) level-face)
  3364. ;; Error ID use a different face when an error-explainer is present
  3365. (flycheck-error-list-make-cell
  3366. id-str (if explainer 'flycheck-error-list-id-with-explainer
  3367. 'flycheck-error-list-id)
  3368. id-str 'flycheck-error-list-explain-error)
  3369. (flycheck-error-list-make-cell
  3370. msg-and-checker nil msg-and-checker)))))
  3371. (defun flycheck-flush-multiline-message (msg)
  3372. "Prepare error message MSG for display in the error list.
  3373. Prepend all lines of MSG except the first with enough space to
  3374. ensure that they line up properly once the message is displayed."
  3375. (let* ((spc-spec `(space . (:width ,flycheck--error-list-msg-offset)))
  3376. (spc (propertize " " 'display spc-spec))
  3377. (rep (concat "\\1" spc "\\2")))
  3378. (replace-regexp-in-string "\\([\r\n]+\\)\\(.\\)" rep msg)))
  3379. (defun flycheck-error-list-current-errors ()
  3380. "Read the list of errors in `flycheck-error-list-source-buffer'."
  3381. (when (buffer-live-p flycheck-error-list-source-buffer)
  3382. (buffer-local-value 'flycheck-current-errors
  3383. flycheck-error-list-source-buffer)))
  3384. (defun flycheck-error-list-entries ()
  3385. "Create the entries for the error list."
  3386. (-when-let* ((errors (flycheck-error-list-current-errors))
  3387. (filtered (flycheck-error-list-apply-filter errors)))
  3388. (seq-map #'flycheck-error-list-make-entry filtered)))
  3389. (defun flycheck-error-list-entry-< (entry1 entry2)
  3390. "Determine whether ENTRY1 is before ENTRY2 by location.
  3391. See `flycheck-error-<'."
  3392. (flycheck-error-< (car entry1) (car entry2)))
  3393. (defun flycheck-error-list-entry-level-< (entry1 entry2)
  3394. "Determine whether ENTRY1 is before ENTRY2 by level.
  3395. See `flycheck-error-level-<'."
  3396. (not (flycheck-error-level-< (car entry1) (car entry2))))
  3397. (defvar flycheck-error-list-mode-line-map
  3398. (let ((map (make-sparse-keymap)))
  3399. (define-key map [mode-line mouse-1]
  3400. #'flycheck-error-list-mouse-switch-to-source)
  3401. map)
  3402. "Keymap for error list mode line.")
  3403. (defun flycheck-error-list-propertized-source-name ()
  3404. "Get the name of the current source buffer for the mode line.
  3405. Propertize the name of the current source buffer for use in the
  3406. mode line indication of `flycheck-error-list-mode'."
  3407. (let ((name (replace-regexp-in-string
  3408. (rx "%") "%%"
  3409. (buffer-name flycheck-error-list-source-buffer)
  3410. 'fixed-case 'literal)))
  3411. (propertize name 'face 'mode-line-buffer-id
  3412. 'mouse-face 'mode-line-highlight
  3413. 'help-echo "mouse-1: switch to source"
  3414. 'local-map flycheck-error-list-mode-line-map)))
  3415. (defun flycheck-error-list-mouse-switch-to-source (event)
  3416. "Switch to the error list source buffer of the EVENT window."
  3417. (interactive "e")
  3418. (save-selected-window
  3419. (when (eventp event)
  3420. (select-window (posn-window (event-start event))))
  3421. (when (buffer-live-p flycheck-error-list-source-buffer)
  3422. (switch-to-buffer flycheck-error-list-source-buffer))))
  3423. (defun flycheck-get-error-list-window-list (&optional all-frames)
  3424. "Get all windows displaying the error list.
  3425. ALL-FRAMES specifies the frames to consider, as in
  3426. `get-buffer-window-list'."
  3427. (-when-let (buf (get-buffer flycheck-error-list-buffer))
  3428. (get-buffer-window-list buf nil all-frames)))
  3429. (defun flycheck-get-error-list-window (&optional all-frames)
  3430. "Get a window displaying the error list, or nil if none.
  3431. ALL-FRAMES specifies the frames to consider, as in
  3432. `get-buffer-window'."
  3433. (-when-let (buf (get-buffer flycheck-error-list-buffer))
  3434. (get-buffer-window buf all-frames)))
  3435. (defun flycheck-error-list-recenter-at (pos)
  3436. "Recenter the error list at POS."
  3437. (dolist (window (flycheck-get-error-list-window-list t))
  3438. (with-selected-window window
  3439. (goto-char pos)
  3440. (recenter))))
  3441. (defun flycheck-error-list-refresh ()
  3442. "Refresh the current error list.
  3443. Add all errors currently reported for the current
  3444. `flycheck-error-list-source-buffer', and recenter the error
  3445. list."
  3446. ;; We only refresh the error list, when it is visible in a window, and we
  3447. ;; select this window while reverting, because Tabulated List mode attempts to
  3448. ;; recenter the error at the old location, so it must have the proper window
  3449. ;; selected.
  3450. (-when-let (window (flycheck-get-error-list-window t))
  3451. (with-selected-window window
  3452. (revert-buffer))
  3453. (run-hooks 'flycheck-error-list-after-refresh-hook)
  3454. (let ((preserve-pos (eq (current-buffer)
  3455. (get-buffer flycheck-error-list-buffer))))
  3456. ;; If the error list is the current buffer, don't recenter when
  3457. ;; highlighting
  3458. (flycheck-error-list-highlight-errors preserve-pos))))
  3459. (defun flycheck-error-list-mode-line-filter-indicator ()
  3460. "Create a string representing the current error list filter."
  3461. (if flycheck-error-list-minimum-level
  3462. (format " [>= %s]" flycheck-error-list-minimum-level)
  3463. ""))
  3464. (defun flycheck-error-list-set-filter (level)
  3465. "Restrict the error list to errors at level LEVEL or higher.
  3466. LEVEL is either an error level symbol, or nil, to remove the filter."
  3467. (interactive
  3468. (list (read-flycheck-error-level
  3469. "Minimum error level (errors at lower levels will be hidden): ")))
  3470. (when (and level (not (flycheck-error-level-p level)))
  3471. (user-error "Invalid level: %s" level))
  3472. (-when-let (buf (get-buffer flycheck-error-list-buffer))
  3473. (with-current-buffer buf
  3474. (setq-local flycheck-error-list-minimum-level level))
  3475. (flycheck-error-list-refresh)
  3476. (flycheck-error-list-recenter-at (point-min))))
  3477. (defun flycheck-error-list-reset-filter ()
  3478. "Remove filters and show all errors in the error list."
  3479. (interactive)
  3480. (kill-local-variable 'flycheck-error-list-minimum-level))
  3481. (defun flycheck-error-list-apply-filter (errors)
  3482. "Filter ERRORS according to `flycheck-error-list-minimum-level'."
  3483. (-if-let* ((min-level flycheck-error-list-minimum-level)
  3484. (min-severity (flycheck-error-level-severity min-level)))
  3485. (seq-filter (lambda (err) (>= (flycheck-error-level-severity
  3486. (flycheck-error-level err))
  3487. min-severity))
  3488. errors)
  3489. errors))
  3490. (defun flycheck-error-list-goto-error (&optional pos)
  3491. "Go to the location of the error at POS in the error list.
  3492. POS defaults to `point'."
  3493. (interactive)
  3494. (-when-let* ((error (tabulated-list-get-id pos))
  3495. (buffer (flycheck-error-buffer error)))
  3496. (when (buffer-live-p buffer)
  3497. (if (eq (window-buffer) (get-buffer flycheck-error-list-buffer))
  3498. ;; When called from within the error list, keep the error list,
  3499. ;; otherwise replace the current buffer.
  3500. (pop-to-buffer buffer 'other-window)
  3501. (switch-to-buffer buffer))
  3502. (let ((pos (flycheck-error-pos error)))
  3503. (unless (eq (goto-char pos) (point))
  3504. ;; If widening gets in the way of moving to the right place, remove it
  3505. ;; and try again
  3506. (widen)
  3507. (goto-char pos)))
  3508. ;; Re-highlight the errors
  3509. (flycheck-error-list-highlight-errors 'preserve-pos))))
  3510. (defun flycheck-error-list-explain-error (&optional pos)
  3511. "Explain the error at POS in the error list.
  3512. POS defaults to `point'."
  3513. (interactive)
  3514. (-when-let* ((error (tabulated-list-get-id pos))
  3515. (explainer (flycheck-checker-get (flycheck-error-checker error)
  3516. 'error-explainer))
  3517. (explanation (funcall explainer error)))
  3518. (flycheck-display-error-explanation explanation)))
  3519. (defun flycheck-error-list-next-error-pos (pos &optional n)
  3520. "Starting from POS get the N'th next error in the error list.
  3521. N defaults to 1. If N is negative, search for the previous error
  3522. instead.
  3523. Get the beginning position of the N'th next error from POS, or
  3524. nil, if there is no next error."
  3525. (let ((n (or n 1)))
  3526. (if (>= n 0)
  3527. ;; Search forward
  3528. (while (and pos (/= n 0))
  3529. (setq n (1- n))
  3530. (setq pos (next-single-property-change pos 'tabulated-list-id)))
  3531. ;; Search backwards
  3532. (while (/= n 0)
  3533. (setq n (1+ n))
  3534. ;; We explicitly give the limit here to explicitly have the minimum
  3535. ;; point returned, to be able to move to the first error (which starts
  3536. ;; at `point-min')
  3537. (setq pos (previous-single-property-change pos 'tabulated-list-id
  3538. nil (point-min)))))
  3539. pos))
  3540. (defun flycheck-error-list-previous-error (n)
  3541. "Go to the N'th previous error in the error list."
  3542. (interactive "P")
  3543. (flycheck-error-list-next-error (- (or n 1))))
  3544. (defun flycheck-error-list-next-error (n)
  3545. "Go to the N'th next error in the error list."
  3546. (interactive "P")
  3547. (let ((pos (flycheck-error-list-next-error-pos (point) n)))
  3548. (when (and pos (/= pos (point)))
  3549. (goto-char pos)
  3550. (save-selected-window
  3551. ;; Keep the error list selected, so that the user can navigate errors by
  3552. ;; repeatedly pressing n/p, without having to re-select the error list
  3553. ;; window.
  3554. (flycheck-error-list-goto-error)))))
  3555. (defvar-local flycheck-error-list-highlight-overlays nil
  3556. "Error highlight overlays in the error list buffer.")
  3557. (put 'flycheck-error-list-highlight-overlays 'permanent-local t)
  3558. (defun flycheck-error-list-highlight-errors (&optional preserve-pos)
  3559. "Highlight errors in the error list.
  3560. Highlight all errors in the error lists that are at point in the
  3561. source buffer, and on the same line as point. Then recenter the
  3562. error list to the highlighted error, unless PRESERVE-POS is
  3563. non-nil."
  3564. (when (get-buffer flycheck-error-list-buffer)
  3565. (let ((current-errors (flycheck-overlay-errors-in (line-beginning-position)
  3566. (line-end-position))))
  3567. (with-current-buffer flycheck-error-list-buffer
  3568. (let ((old-overlays flycheck-error-list-highlight-overlays)
  3569. (min-point (point-max))
  3570. (max-point (point-min)))
  3571. ;; Display the new overlays first, to avoid re-display flickering
  3572. (setq flycheck-error-list-highlight-overlays nil)
  3573. (when current-errors
  3574. (let ((next-error-pos (point-min)))
  3575. (while next-error-pos
  3576. (let* ((beg next-error-pos)
  3577. (end (flycheck-error-list-next-error-pos beg))
  3578. (err (tabulated-list-get-id beg)))
  3579. (when (member err current-errors)
  3580. (setq min-point (min min-point beg)
  3581. max-point (max max-point beg))
  3582. (let ((ov (make-overlay beg
  3583. ;; Extend overlay to the beginning of
  3584. ;; the next line, to highlight the
  3585. ;; whole line
  3586. (or end (point-max)))))
  3587. (push ov flycheck-error-list-highlight-overlays)
  3588. (setf (overlay-get ov 'flycheck-error-highlight-overlay)
  3589. t)
  3590. (setf (overlay-get ov 'face)
  3591. 'flycheck-error-list-highlight)))
  3592. (setq next-error-pos end)))))
  3593. ;; Delete the old overlays
  3594. (seq-do #'delete-overlay old-overlays)
  3595. (when (and (not preserve-pos) current-errors)
  3596. ;; Move point to the middle error
  3597. (goto-char (+ min-point (/ (- max-point min-point) 2)))
  3598. (beginning-of-line)
  3599. ;; And recenter the error list at this position
  3600. (flycheck-error-list-recenter-at (point))))))))
  3601. (defun flycheck-list-errors ()
  3602. "Show the error list for the current buffer."
  3603. (interactive)
  3604. (unless flycheck-mode
  3605. (user-error "Flycheck mode not enabled"))
  3606. ;; Create and initialize the error list
  3607. (unless (get-buffer flycheck-error-list-buffer)
  3608. (with-current-buffer (get-buffer-create flycheck-error-list-buffer)
  3609. (flycheck-error-list-mode)))
  3610. (flycheck-error-list-set-source (current-buffer))
  3611. ;; Reset the error filter
  3612. (flycheck-error-list-reset-filter)
  3613. ;; Show the error list in a window, and re-select the old window
  3614. (display-buffer flycheck-error-list-buffer)
  3615. ;; Finally, refresh the error list to show the most recent errors
  3616. (flycheck-error-list-refresh))
  3617. (defalias 'list-flycheck-errors 'flycheck-list-errors)
  3618. ;;; Displaying errors in the current buffer
  3619. (defun flycheck-display-errors (errors)
  3620. "Display ERRORS using `flycheck-display-errors-function'."
  3621. (when flycheck-display-errors-function
  3622. (funcall flycheck-display-errors-function errors)))
  3623. (defvar-local flycheck-display-error-at-point-timer nil
  3624. "Timer to automatically show the error at point in minibuffer.")
  3625. (defun flycheck-cancel-error-display-error-at-point-timer ()
  3626. "Cancel the error display timer for the current buffer."
  3627. (when flycheck-display-error-at-point-timer
  3628. (cancel-timer flycheck-display-error-at-point-timer)
  3629. (setq flycheck-display-error-at-point-timer nil)))
  3630. (defun flycheck-display-error-at-point ()
  3631. "Display the all error messages at point in minibuffer."
  3632. (interactive)
  3633. ;; This function runs from a timer, so we must take care to not ignore any
  3634. ;; errors
  3635. (with-demoted-errors "Flycheck error display error: %s"
  3636. (flycheck-cancel-error-display-error-at-point-timer)
  3637. (when flycheck-mode
  3638. (-when-let (errors (flycheck-overlay-errors-at (point)))
  3639. (flycheck-display-errors errors)))))
  3640. (defun flycheck-display-error-at-point-soon ()
  3641. "Display the first error message at point in minibuffer delayed."
  3642. (flycheck-cancel-error-display-error-at-point-timer)
  3643. (when (flycheck-overlays-at (point))
  3644. (setq flycheck-display-error-at-point-timer
  3645. (run-at-time flycheck-display-errors-delay nil 'flycheck-display-error-at-point))))
  3646. ;;; Functions to display errors
  3647. (defconst flycheck-error-message-buffer "*Flycheck error messages*"
  3648. "The name of the buffer to show long error messages in.")
  3649. (defun flycheck-error-message-buffer ()
  3650. "Get the buffer object to show long error messages in.
  3651. Get the buffer named by variable `flycheck-error-message-buffer',
  3652. or nil if the buffer does not exist."
  3653. (get-buffer flycheck-error-message-buffer))
  3654. (defun flycheck-may-use-echo-area-p ()
  3655. "Determine whether the echo area may be used.
  3656. The echo area may be used if the cursor is not in the echo area,
  3657. and if the echo area is not occupied by minibuffer input."
  3658. (not (or cursor-in-echo-area (active-minibuffer-window))))
  3659. (defun flycheck-display-error-messages (errors)
  3660. "Display the messages of ERRORS.
  3661. Concatenate all non-nil messages of ERRORS separated by empty
  3662. lines, and display them with `display-message-or-buffer', which
  3663. shows the messages either in the echo area or in a separate
  3664. buffer, depending on the number of lines. See Info
  3665. node `(elisp)Displaying Messages' for more information.
  3666. In the latter case, show messages in the buffer denoted by
  3667. variable `flycheck-error-message-buffer'."
  3668. (when (and errors (flycheck-may-use-echo-area-p))
  3669. (let ((messages (seq-map #'flycheck-error-format-message-and-id errors)))
  3670. (display-message-or-buffer (string-join messages "\n\n")
  3671. flycheck-error-message-buffer
  3672. 'not-this-window))))
  3673. (defun flycheck-display-error-messages-unless-error-list (errors)
  3674. "Show messages of ERRORS unless the error list is visible.
  3675. Like `flycheck-display-error-messages', but only if the error
  3676. list (see `flycheck-list-errors') is not visible in any window in
  3677. the current frame."
  3678. (unless (flycheck-get-error-list-window 'current-frame)
  3679. (flycheck-display-error-messages errors)))
  3680. (defun flycheck-hide-error-buffer ()
  3681. "Hide the Flycheck error buffer if necessary.
  3682. Hide the error buffer if there is no error under point."
  3683. (-when-let* ((buffer (flycheck-error-message-buffer))
  3684. (window (get-buffer-window buffer)))
  3685. (unless (flycheck-overlays-at (point))
  3686. ;; save-selected-window prevents `quit-window' from changing the current
  3687. ;; buffer (see https://github.com/flycheck/flycheck/issues/648).
  3688. (save-selected-window
  3689. (quit-window nil window)))))
  3690. ;;; Working with errors
  3691. (defun flycheck-copy-errors-as-kill (pos &optional formatter)
  3692. "Copy each error at POS into kill ring, using FORMATTER.
  3693. FORMATTER is a function to turn an error into a string,
  3694. defaulting to `flycheck-error-message'.
  3695. Interactively, use `flycheck-error-format-message-and-id' as
  3696. FORMATTER with universal prefix arg, and `flycheck-error-id' with
  3697. normal prefix arg, i.e. copy the message and the ID with
  3698. universal prefix arg, and only the id with normal prefix arg."
  3699. (interactive (list (point)
  3700. (pcase current-prefix-arg
  3701. ((pred not) #'flycheck-error-message)
  3702. ((pred consp) #'flycheck-error-format-message-and-id)
  3703. (_ #'flycheck-error-id))))
  3704. (let ((messages (delq nil (seq-map (or formatter #'flycheck-error-message)
  3705. (flycheck-overlay-errors-at pos)))))
  3706. (when messages
  3707. (seq-do #'kill-new (reverse messages))
  3708. (message (string-join messages "\n")))))
  3709. (defun flycheck-explain-error-at-point ()
  3710. "Display an explanation for the first explainable error at point.
  3711. The first explainable error at point is the first error at point
  3712. with a non-nil `:error-explainer' function defined in its
  3713. checker. The `:error-explainer' function is then called with
  3714. this error to produce the explanation to display."
  3715. (interactive)
  3716. (-when-let* ((first-error
  3717. ;; Get the first error at point that has an `error-explainer'.
  3718. (seq-find (lambda (error)
  3719. (flycheck-checker-get
  3720. (flycheck-error-checker error) 'error-explainer))
  3721. (flycheck-overlay-errors-at (point))))
  3722. (explainer
  3723. (flycheck-checker-get (flycheck-error-checker first-error)
  3724. 'error-explainer))
  3725. (explanation (funcall explainer first-error)))
  3726. (flycheck-display-error-explanation explanation)))
  3727. (defconst flycheck-explain-error-buffer "*Flycheck error explanation*"
  3728. "The name of the buffer to show error explanations.")
  3729. (defun flycheck-display-error-explanation (explanation)
  3730. "Display the EXPLANATION string in a help buffer."
  3731. (with-help-window (get-buffer-create flycheck-explain-error-buffer)
  3732. (princ explanation)))
  3733. ;;; Syntax checkers using external commands
  3734. (defun flycheck-command-argument-p (arg)
  3735. "Check whether ARG is a valid command argument."
  3736. (pcase arg
  3737. ((pred stringp) t)
  3738. ((or `source `source-inplace `source-original) t)
  3739. ((or `temporary-directory `temporary-file-name) t)
  3740. (`null-device t)
  3741. (`(config-file ,option-name ,config-file-var)
  3742. (and (stringp option-name)
  3743. (symbolp config-file-var)))
  3744. (`(config-file ,option-name ,config-file-var ,prepender)
  3745. (and (stringp option-name)
  3746. (symbolp config-file-var)
  3747. (symbolp prepender)))
  3748. (`(,(or `option `option-list) ,option-name ,option-var)
  3749. (and (stringp option-name)
  3750. (symbolp option-var)))
  3751. (`(,(or `option `option-list) ,option-name ,option-var ,prepender)
  3752. (and (stringp option-name)
  3753. (symbolp option-var)
  3754. (symbolp prepender)))
  3755. (`(,(or `option `option-list) ,option-name ,option-var ,prepender ,filter)
  3756. (and (stringp option-name)
  3757. (symbolp option-var)
  3758. (symbolp prepender)
  3759. (symbolp filter)))
  3760. (`(option-flag ,option-name ,option-var)
  3761. (and (stringp option-name)
  3762. (symbolp option-var)))
  3763. (`(eval ,_) t)
  3764. (_ nil)))
  3765. (defun flycheck-compute-working-directory (checker)
  3766. "Get the default working directory for CHECKER.
  3767. Compute the value of `default-directory' for the invocation of
  3768. the syntax checker command, by calling the function in the
  3769. `working-directory' property of CHECKER, with CHECKER as sole
  3770. argument, and returning its value. Signal an error if the
  3771. function returns a non-existing working directory.
  3772. If the property is undefined or if the function returns nil
  3773. return the `default-directory' of the current buffer."
  3774. (let* ((def-directory-fn (flycheck-checker-get checker 'working-directory))
  3775. (directory (or (and def-directory-fn
  3776. (funcall def-directory-fn checker))
  3777. ;; Default to the `default-directory' of the current
  3778. ;; buffer
  3779. default-directory)))
  3780. (unless (file-exists-p directory)
  3781. (error ":working-directory %s of syntax checker %S does not exist"
  3782. directory checker))
  3783. directory))
  3784. ;;;###autoload
  3785. (defun flycheck-define-command-checker (symbol docstring &rest properties)
  3786. "Define SYMBOL as syntax checker to run a command.
  3787. Define SYMBOL as generic syntax checker via
  3788. `flycheck-define-generic-checker', which uses an external command
  3789. to check the buffer. SYMBOL and DOCSTRING are the same as for
  3790. `flycheck-define-generic-checker'.
  3791. In addition to the properties understood by
  3792. `flycheck-define-generic-checker', the following PROPERTIES
  3793. constitute a command syntax checker. Unless otherwise noted, all
  3794. properties are mandatory. Note that the default `:error-filter'
  3795. of command checkers is `flycheck-sanitize-errors'.
  3796. `:command COMMAND'
  3797. The command to run for syntax checking.
  3798. COMMAND is a list of the form `(EXECUTABLE [ARG ...])'.
  3799. EXECUTABLE is a string with the executable of this syntax
  3800. checker. It can be overridden with the variable
  3801. `flycheck-SYMBOL-executable'. Note that this variable is
  3802. NOT implicitly defined by this function. Use
  3803. `flycheck-def-executable-var' to define this variable.
  3804. Each ARG is an argument to the executable, either as string,
  3805. or as special symbol or form for
  3806. `flycheck-substitute-argument', which see.
  3807. `:error-patterns PATTERNS'
  3808. A list of patterns to parse the output of the `:command'.
  3809. Each ITEM in PATTERNS is a list `(LEVEL SEXP ...)', where
  3810. LEVEL is a Flycheck error level (see
  3811. `flycheck-define-error-level'), followed by one or more RX
  3812. `SEXP's which parse an error of that level and extract line,
  3813. column, file name and the message.
  3814. See `rx' for general information about RX, and
  3815. `flycheck-rx-to-string' for some special RX forms provided
  3816. by Flycheck.
  3817. All patterns are applied in the order of declaration to the
  3818. whole output of the syntax checker. Output already matched
  3819. by a pattern will not be matched by subsequent patterns. In
  3820. other words, the first pattern wins.
  3821. This property is optional. If omitted, however, an
  3822. `:error-parser' is mandatory.
  3823. `:error-parser FUNCTION'
  3824. A function to parse errors with.
  3825. The function shall accept three arguments OUTPUT CHECKER
  3826. BUFFER. OUTPUT is the syntax checker output as string,
  3827. CHECKER the syntax checker that was used, and BUFFER a
  3828. buffer object representing the checked buffer. The function
  3829. must return a list of `flycheck-error' objects parsed from
  3830. OUTPUT.
  3831. This property is optional. If omitted, it defaults to
  3832. `flycheck-parse-with-patterns'. In this case,
  3833. `:error-patterns' is mandatory.
  3834. `:standard-input t'
  3835. Whether to send the buffer contents on standard input.
  3836. If this property is given and has a non-nil value, send the
  3837. contents of the buffer on standard input.
  3838. Defaults to nil.
  3839. Note that you may not give `:start', `:interrupt', and
  3840. `:print-doc' for a command checker. You can give a custom
  3841. `:verify' function, though, whose results will be appended to the
  3842. default `:verify' function of command checkers."
  3843. (declare (indent 1)
  3844. (doc-string 2))
  3845. (dolist (prop '(:start :interrupt :print-doc))
  3846. (when (plist-get properties prop)
  3847. (error "%s not allowed in definition of command syntax checker %s"
  3848. prop symbol)))
  3849. (unless (plist-get properties :error-filter)
  3850. ;; Default to `flycheck-sanitize-errors' as error filter
  3851. (setq properties (plist-put properties :error-filter
  3852. #'flycheck-sanitize-errors)))
  3853. (let ((verify-fn (plist-get properties :verify)))
  3854. (setq properties
  3855. (plist-put properties :verify
  3856. (lambda (checker)
  3857. (append (flycheck-verify-command-checker checker)
  3858. (and verify-fn
  3859. (funcall verify-fn checker)))))))
  3860. (let ((command (plist-get properties :command))
  3861. (patterns (plist-get properties :error-patterns))
  3862. (parser (or (plist-get properties :error-parser)
  3863. #'flycheck-parse-with-patterns))
  3864. (enabled (plist-get properties :enabled))
  3865. (standard-input (plist-get properties :standard-input)))
  3866. (unless command
  3867. (error "Missing :command in syntax checker %s" symbol))
  3868. (unless (stringp (car command))
  3869. (error "Command executable for syntax checker %s must be a string: %S"
  3870. symbol (car command)))
  3871. (dolist (arg (cdr command))
  3872. (unless (flycheck-command-argument-p arg)
  3873. (error "Invalid command argument %S in syntax checker %s" arg symbol)))
  3874. (when (and (eq parser 'flycheck-parse-with-patterns)
  3875. (not patterns))
  3876. (error "Missing :error-patterns in syntax checker %s" symbol))
  3877. (setq properties
  3878. ;; Automatically disable command checkers if the executable does not
  3879. ;; exist.
  3880. (plist-put properties :enabled
  3881. (lambda ()
  3882. (and (flycheck-find-checker-executable symbol)
  3883. (or (not enabled) (funcall enabled))))))
  3884. (apply #'flycheck-define-generic-checker symbol docstring
  3885. :start #'flycheck-start-command-checker
  3886. :interrupt #'flycheck-interrupt-command-checker
  3887. :print-doc #'flycheck-command-checker-print-doc
  3888. properties)
  3889. ;; Pre-compile all errors patterns into strings, so that we don't need to do
  3890. ;; that on each error parse
  3891. (let ((patterns (seq-map (lambda (p)
  3892. (cons (flycheck-rx-to-string `(and ,@(cdr p))
  3893. 'no-group)
  3894. (car p)))
  3895. patterns)))
  3896. (pcase-dolist (`(,prop . ,value)
  3897. `((command . ,command)
  3898. (error-parser . ,parser)
  3899. (error-patterns . ,patterns)
  3900. (standard-input . ,standard-input)))
  3901. (setf (flycheck-checker-get symbol prop) value)))))
  3902. (eval-and-compile
  3903. ;; Make this function available during byte-compilation, since we need it
  3904. ;; at macro expansion of `flycheck-def-executable-var'.
  3905. (defun flycheck-checker-executable-variable (checker)
  3906. "Get the executable variable of CHECKER.
  3907. The executable variable is named `flycheck-CHECKER-executable'."
  3908. (intern (format "flycheck-%s-executable" checker))))
  3909. (defun flycheck-checker-default-executable (checker)
  3910. "Get the default executable of CHECKER."
  3911. (car (flycheck-checker-get checker 'command)))
  3912. (defun flycheck-checker-executable (checker)
  3913. "Get the command executable of CHECKER.
  3914. The executable is either the value of the variable
  3915. `flycheck-CHECKER-executable', or the default executable given in
  3916. the syntax checker definition, if the variable is nil."
  3917. (let ((var (flycheck-checker-executable-variable checker)))
  3918. (or (and (boundp var) (symbol-value var))
  3919. (flycheck-checker-default-executable checker))))
  3920. (defun flycheck-find-checker-executable (checker)
  3921. "Get the full path of the executbale of CHECKER.
  3922. Return the full absolute path to the executable of CHECKER, or
  3923. nil if the executable does not exist."
  3924. (funcall flycheck-executable-find (flycheck-checker-executable checker)))
  3925. (defun flycheck-checker-arguments (checker)
  3926. "Get the command arguments of CHECKER."
  3927. (cdr (flycheck-checker-get checker 'command)))
  3928. (defun flycheck-substitute-argument (arg checker)
  3929. "Substitute ARG for CHECKER.
  3930. Return a list of real arguments for the executable of CHECKER,
  3931. substituted for the symbolic argument ARG. Single arguments,
  3932. e.g. if ARG is a literal strings, are wrapped in a list.
  3933. ARG may be one of the following forms:
  3934. STRING
  3935. Return ARG unchanged.
  3936. `source', `source-inplace'
  3937. Create a temporary file to check and return its path. With
  3938. `source-inplace' create the temporary file in the same
  3939. directory as the original file. The value of
  3940. `flycheck-temp-prefix' is used as prefix of the file name.
  3941. With `source', try to retain the non-directory component of
  3942. the buffer's file name in the temporary file.
  3943. `source' is the preferred way to pass the input file to a
  3944. syntax checker. `source-inplace' should only be used if the
  3945. syntax checker needs other files from the source directory,
  3946. such as include files in C.
  3947. `source-original'
  3948. Return the path of the actual file to check, or an empty
  3949. string if the buffer has no file name.
  3950. Note that the contents of the file may not be up to date
  3951. with the contents of the buffer to check. Do not use this
  3952. as primary input to a checker, unless absolutely necessary.
  3953. When using this symbol as primary input to the syntax
  3954. checker, add `flycheck-buffer-saved-p' to the `:predicate'.
  3955. `temporary-directory'
  3956. Create a unique temporary directory and return its path.
  3957. `temporary-file-name'
  3958. Return a unique temporary filename. The file is *not*
  3959. created.
  3960. To ignore the output of syntax checkers, try `null-device'
  3961. first.
  3962. `null-device'
  3963. Return the value of `null-device', i.e the system null
  3964. device.
  3965. Use this option to ignore the output of a syntax checker.
  3966. If the syntax checker cannot handle the null device, or
  3967. won't write to an existing file, try `temporary-file-name'
  3968. instead.
  3969. `(config-file OPTION VARIABLE [PREPEND-FN])'
  3970. Search the configuration file bound to VARIABLE with
  3971. `flycheck-locate-config-file' and return a list of arguments
  3972. that pass this configuration file to the syntax checker, or
  3973. nil if the configuration file was not found.
  3974. PREPEND-FN is called with the OPTION and the located
  3975. configuration file, and should return OPTION prepended
  3976. before the file, either a string or as list. If omitted,
  3977. PREPEND-FN defaults to `list'.
  3978. `(option OPTION VARIABLE [PREPEND-FN [FILTER]])'
  3979. Retrieve the value of VARIABLE and return a list of
  3980. arguments that pass this value as value for OPTION to the
  3981. syntax checker.
  3982. PREPEND-FN is called with the OPTION and the value of
  3983. VARIABLE, and should return OPTION prepended before the
  3984. file, either a string or as list. If omitted, PREPEND-FN
  3985. defaults to `list'.
  3986. FILTER is an optional function to be applied to the value of
  3987. VARIABLE before prepending. This function must return nil
  3988. or a string. In the former case, return nil. In the latter
  3989. case, return a list of arguments as described above.
  3990. `(option-list OPTION VARIABLE [PREPEND-FN [FILTER]])'
  3991. Retrieve the value of VARIABLE, which must be a list,
  3992. and prepend OPTION before each item in this list, using
  3993. PREPEND-FN.
  3994. PREPEND-FN is called with the OPTION and each item of the
  3995. list as second argument, and should return OPTION prepended
  3996. before the item, either as string or as list. If omitted,
  3997. PREPEND-FN defaults to `list'.
  3998. FILTER is an optional function to be applied to each item in
  3999. the list before prepending OPTION. It shall return the
  4000. option value for each item as string, or nil, if the item is
  4001. to be ignored.
  4002. `(option-flag OPTION VARIABLE)'
  4003. Retrieve the value of VARIABLE and return OPTION, if the
  4004. value is non-nil. Otherwise return nil.
  4005. `(eval FORM)'
  4006. Return the result of evaluating FORM in the buffer to be
  4007. checked. FORM must either return a string or a list of
  4008. strings, or nil to indicate that nothing should be
  4009. substituted for CELL. For all other return types, signal an
  4010. error
  4011. _No_ further substitutions are performed, neither in FORM
  4012. before it is evaluated, nor in the result of evaluating
  4013. FORM.
  4014. In all other cases, signal an error.
  4015. Note that substitution is *not* recursive. No symbols or cells
  4016. are substituted within the body of cells!"
  4017. (pcase arg
  4018. ((pred stringp) (list arg))
  4019. (`source
  4020. (list (flycheck-save-buffer-to-temp #'flycheck-temp-file-system)))
  4021. (`source-inplace
  4022. (list (flycheck-save-buffer-to-temp #'flycheck-temp-file-inplace)))
  4023. (`source-original (list (or (buffer-file-name) "")))
  4024. (`temporary-directory (list (flycheck-temp-dir-system)))
  4025. (`temporary-file-name
  4026. (let ((directory (flycheck-temp-dir-system)))
  4027. (list (make-temp-name (expand-file-name "flycheck" directory)))))
  4028. (`null-device (list null-device))
  4029. (`(config-file ,option-name ,file-name-var)
  4030. (-when-let* ((value (symbol-value file-name-var))
  4031. (file-name (flycheck-locate-config-file value checker)))
  4032. (flycheck-prepend-with-option option-name (list file-name))))
  4033. (`(config-file ,option-name ,file-name-var ,prepend-fn)
  4034. (-when-let* ((value (symbol-value file-name-var))
  4035. (file-name (flycheck-locate-config-file value checker)))
  4036. (flycheck-prepend-with-option option-name (list file-name) prepend-fn)))
  4037. (`(option ,option-name ,variable)
  4038. (-when-let (value (symbol-value variable))
  4039. (unless (stringp value)
  4040. (error "Value %S of %S for option %s is not a string"
  4041. value variable option-name))
  4042. (flycheck-prepend-with-option option-name (list value))))
  4043. (`(option ,option-name ,variable ,prepend-fn)
  4044. (-when-let (value (symbol-value variable))
  4045. (unless (stringp value)
  4046. (error "Value %S of %S for option %s is not a string"
  4047. value variable option-name))
  4048. (flycheck-prepend-with-option option-name (list value) prepend-fn)))
  4049. (`(option ,option-name ,variable ,prepend-fn ,filter)
  4050. (-when-let (value (funcall filter (symbol-value variable)))
  4051. (unless (stringp value)
  4052. (error "Value %S of %S (filter: %S) for option %s is not a string"
  4053. value variable filter option-name))
  4054. (flycheck-prepend-with-option option-name (list value) prepend-fn)))
  4055. (`(option-list ,option-name ,variable)
  4056. (let ((value (symbol-value variable)))
  4057. (unless (and (listp value) (seq-every-p #'stringp value))
  4058. (error "Value %S of %S for option %S is not a list of strings"
  4059. value variable option-name))
  4060. (flycheck-prepend-with-option option-name value)))
  4061. (`(option-list ,option-name ,variable ,prepend-fn)
  4062. (let ((value (symbol-value variable)))
  4063. (unless (and (listp value) (seq-every-p #'stringp value))
  4064. (error "Value %S of %S for option %S is not a list of strings"
  4065. value variable option-name))
  4066. (flycheck-prepend-with-option option-name value prepend-fn)))
  4067. (`(option-list ,option-name ,variable ,prepend-fn ,filter)
  4068. (let ((value (delq nil (seq-map filter (symbol-value variable)))))
  4069. (unless (and (listp value) (seq-every-p #'stringp value))
  4070. (error "Value %S of %S for option %S is not a list of strings"
  4071. value variable option-name))
  4072. (flycheck-prepend-with-option option-name value prepend-fn)))
  4073. (`(option-flag ,option-name ,variable)
  4074. (when (symbol-value variable)
  4075. (list option-name)))
  4076. (`(eval ,form)
  4077. (let ((result (eval form)))
  4078. (cond
  4079. ((and (listp result) (seq-every-p #'stringp result)) result)
  4080. ((stringp result) (list result))
  4081. (t (error "Invalid result from evaluation of %S: %S" form result)))))
  4082. (_ (error "Unsupported argument %S" arg))))
  4083. (defun flycheck-checker-substituted-arguments (checker)
  4084. "Get the substituted arguments of a CHECKER.
  4085. Substitute each argument of CHECKER using
  4086. `flycheck-substitute-argument'. This replaces any special
  4087. symbols in the command."
  4088. (apply #'append
  4089. (seq-map (lambda (arg) (flycheck-substitute-argument arg checker))
  4090. (flycheck-checker-arguments checker))))
  4091. (defun flycheck--process-send-buffer-contents-chunked (process)
  4092. "Send contents of current buffer to PROCESS in small batches.
  4093. Send the entire buffer to the standard input of PROCESS in chunks
  4094. of 4096 characters. Chunking is done in Emacs Lisp, hence this
  4095. function is probably far less efficient than
  4096. `send-process-region'. Use only when required."
  4097. (let ((from (point-min)))
  4098. (while (< from (point-max))
  4099. (let ((to (min (+ from 4096) (point-max))))
  4100. (process-send-region process from to)
  4101. (setq from to)))))
  4102. (defvar flycheck-chunked-process-input
  4103. ;; Chunk process output on Windows to work around
  4104. ;; https://github.com/flycheck/flycheck/issues/794 and
  4105. ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22344. The presence of
  4106. ;; `w32-pipe-buffer-size' denotes an Emacs version (> Emacs 25.1 )where pipe
  4107. ;; writes on Windows are fixed.
  4108. ;;
  4109. ;; TODO: Remove option and chunking when dropping Emacs 24 support, see
  4110. ;; https://github.com/flycheck/flycheck/issues/856
  4111. (and (eq system-type 'windows-nt) (not (boundp 'w32-pipe-buffer-size)))
  4112. "If non-nil send process input in small chunks.
  4113. If this variable is non-nil `flycheck-process-send-buffer' sends
  4114. buffer contents in small chunks.
  4115. Defaults to nil, except on Windows to work around Emacs bug
  4116. #22344.")
  4117. (defun flycheck-process-send-buffer (process)
  4118. "Send all contents of current buffer to PROCESS.
  4119. Sends all contents of the current buffer to the standard input of
  4120. PROCESS, and terminates standard input with EOF.
  4121. If `flycheck-chunked-process-input' is non-nil, send buffer
  4122. contents in chunks via
  4123. `flycheck--process-send-buffer-contents-chunked', which see.
  4124. Otherwise use `process-send-region' to send all contents at once
  4125. and rely on Emacs' own buffering and chunking."
  4126. (save-restriction
  4127. (widen)
  4128. (if flycheck-chunked-process-input
  4129. (flycheck--process-send-buffer-contents-chunked process)
  4130. (process-send-region process (point-min) (point-max))))
  4131. (process-send-eof process))
  4132. (defun flycheck-start-command-checker (checker callback)
  4133. "Start a command CHECKER with CALLBACK."
  4134. (let (process)
  4135. (condition-case err
  4136. (let* ((program (flycheck-find-checker-executable checker))
  4137. (args (flycheck-checker-substituted-arguments checker))
  4138. (command (funcall flycheck-command-wrapper-function
  4139. (cons program args)))
  4140. ;; Use pipes to receive output from the syntax checker. They are
  4141. ;; more efficient and more robust than PTYs, which Emacs uses by
  4142. ;; default, and since we don't need any job control features, we
  4143. ;; can easily use pipes.
  4144. (process-connection-type nil))
  4145. ;; We pass do not associate the process with any buffer, by
  4146. ;; passing nil for the BUFFER argument of `start-process'.
  4147. ;; Instead, we just remember the buffer being checked in a
  4148. ;; process property (see below). This neatly avoids all
  4149. ;; side-effects implied by attached a process to a buffer, which
  4150. ;; may cause conflicts with other packages.
  4151. ;;
  4152. ;; See https://github.com/flycheck/flycheck/issues/298 for an
  4153. ;; example for such a conflict.
  4154. (setq process (apply 'start-process (format "flycheck-%s" checker)
  4155. nil command))
  4156. (setf (process-sentinel process) #'flycheck-handle-signal)
  4157. (setf (process-filter process) #'flycheck-receive-checker-output)
  4158. (set-process-query-on-exit-flag process nil)
  4159. ;; Remember the syntax checker, the buffer and the callback
  4160. (process-put process 'flycheck-checker checker)
  4161. (process-put process 'flycheck-callback callback)
  4162. (process-put process 'flycheck-buffer (current-buffer))
  4163. ;; The default directory is bound in the `flycheck-syntax-check-start' function.
  4164. (process-put process 'flycheck-working-directory default-directory)
  4165. ;; Track the temporaries created by argument substitution in the
  4166. ;; process itself, to get rid of the global state ASAP.
  4167. (process-put process 'flycheck-temporaries flycheck-temporaries)
  4168. (setq flycheck-temporaries nil)
  4169. ;; Send the buffer to the process on standard input, if enabled.
  4170. (when (flycheck-checker-get checker 'standard-input)
  4171. (flycheck-process-send-buffer process))
  4172. ;; Return the process.
  4173. process)
  4174. (error
  4175. ;; In case of error, clean up our resources, and report the error back to
  4176. ;; Flycheck.
  4177. (flycheck-safe-delete-temporaries)
  4178. (when process
  4179. ;; No need to explicitly delete the temporary files of the process,
  4180. ;; because deleting runs the sentinel, which will delete them anyway.
  4181. (delete-process process))
  4182. (signal (car err) (cdr err))))))
  4183. (defun flycheck-interrupt-command-checker (_checker process)
  4184. "Interrupt a PROCESS."
  4185. ;; Deleting the process always triggers the sentinel, which does the cleanup
  4186. (when process
  4187. (delete-process process)))
  4188. (defun flycheck-command-checker-print-doc (checker)
  4189. "Print additional documentation for a command CHECKER."
  4190. (let ((executable (flycheck-checker-default-executable checker))
  4191. (config-file-var (flycheck-checker-get checker 'config-file-var))
  4192. (option-vars (seq-sort #'string<
  4193. (flycheck-checker-get checker 'option-vars))))
  4194. (princ "\n")
  4195. (let ((doc-start (with-current-buffer standard-output (point-max))))
  4196. ;; Track the start of our documentation so that we can re-indent it
  4197. ;; properly
  4198. (princ " This syntax checker executes \"")
  4199. (princ executable)
  4200. (princ "\"")
  4201. (when config-file-var
  4202. (princ ", using a configuration file from `")
  4203. (princ (symbol-name config-file-var))
  4204. (princ "'"))
  4205. (princ ". The executable can be overridden with `")
  4206. (princ (symbol-name (flycheck-checker-executable-variable checker)))
  4207. (princ "'.")
  4208. (with-current-buffer standard-output
  4209. (save-excursion
  4210. (fill-region-as-paragraph doc-start (point-max)))))
  4211. (princ "\n")
  4212. (when option-vars
  4213. (princ "\n This syntax checker can be configured with these options:\n\n")
  4214. (dolist (var option-vars)
  4215. (princ (format " * `%s'\n" var))))))
  4216. (defun flycheck-verify-command-checker (checker)
  4217. "Verify a command CHECKER in the current buffer.
  4218. Return a list of `flycheck-verification-result' objects for
  4219. CHECKER."
  4220. (let ((executable (flycheck-find-checker-executable checker))
  4221. (config-file-var (flycheck-checker-get checker 'config-file-var)))
  4222. `(
  4223. ,(flycheck-verification-result-new
  4224. :label "executable"
  4225. :message (if executable (format "Found at %s" executable) "Not found")
  4226. :face (if executable 'success '(bold error)))
  4227. ,@(when config-file-var
  4228. (let* ((value (symbol-value config-file-var))
  4229. (path (and value (flycheck-locate-config-file value checker))))
  4230. (list (flycheck-verification-result-new
  4231. :label "configuration file"
  4232. :message (if path (format "Found at %S" path) "Not found")
  4233. :face (if path 'success 'warning))))))))
  4234. ;;; Process management for command syntax checkers
  4235. (defun flycheck-receive-checker-output (process output)
  4236. "Receive a syntax checking PROCESS OUTPUT."
  4237. (push output (process-get process 'flycheck-pending-output)))
  4238. (defun flycheck-get-output (process)
  4239. "Get the complete output of PROCESS."
  4240. (with-demoted-errors "Error while retrieving process output: %S"
  4241. (let ((pending-output (process-get process 'flycheck-pending-output)))
  4242. (apply #'concat (nreverse pending-output)))))
  4243. (defun flycheck-handle-signal (process _event)
  4244. "Handle a signal from the syntax checking PROCESS.
  4245. _EVENT is ignored."
  4246. (when (memq (process-status process) '(signal exit))
  4247. (let ((files (process-get process 'flycheck-temporaries))
  4248. (buffer (process-get process 'flycheck-buffer))
  4249. (callback (process-get process 'flycheck-callback))
  4250. (cwd (process-get process 'flycheck-working-directory)))
  4251. ;; Delete the temporary files
  4252. (seq-do #'flycheck-safe-delete files)
  4253. (when (buffer-live-p buffer)
  4254. (with-current-buffer buffer
  4255. (condition-case err
  4256. (pcase (process-status process)
  4257. (`signal
  4258. (funcall callback 'interrupted))
  4259. (`exit
  4260. (flycheck-finish-checker-process
  4261. (process-get process 'flycheck-checker)
  4262. (process-exit-status process)
  4263. files
  4264. (flycheck-get-output process) callback cwd)))
  4265. ((debug error)
  4266. (funcall callback 'errored (error-message-string err)))))))))
  4267. (defun flycheck-finish-checker-process
  4268. (checker exit-status files output callback cwd)
  4269. "Finish a checker process from CHECKER with EXIT-STATUS.
  4270. FILES is a list of files given as input to the checker. OUTPUT
  4271. is the output of the syntax checker. CALLBACK is the status
  4272. callback to use for reporting.
  4273. Parse the OUTPUT and report an appropriate error status.
  4274. Resolve all errors in OUTPUT using CWD as working directory."
  4275. (let ((errors (flycheck-parse-output output checker (current-buffer))))
  4276. (when (and (/= exit-status 0) (not errors))
  4277. ;; Warn about a suspicious result from the syntax checker. We do right
  4278. ;; after parsing the errors, before filtering, because a syntax checker
  4279. ;; might report errors from other files (e.g. includes) even if there
  4280. ;; are no errors in the file being checked.
  4281. (funcall callback 'suspicious
  4282. (format "Flycheck checker %S returned non-zero \
  4283. exit code %s, but its output contained no errors: %s\nTry \
  4284. installing a more recent version of %S, and please open a bug \
  4285. report if the issue persists in the latest release. Thanks!"
  4286. checker exit-status output checker)))
  4287. (funcall callback 'finished
  4288. ;; Fix error file names, by substituting them backwards from the
  4289. ;; temporaries.
  4290. (seq-map (lambda (e) (flycheck-fix-error-filename e files cwd))
  4291. errors))))
  4292. ;;; Executables of command checkers.
  4293. (defmacro flycheck-def-executable-var (checker default-executable)
  4294. "Define the executable variable for CHECKER.
  4295. DEFAULT-EXECUTABLE is the default executable. It is only used in
  4296. the docstring of the variable.
  4297. The variable is defined with `defcustom' in the
  4298. `flycheck-executables' group. It's also defined to be risky as
  4299. file-local variable, to avoid arbitrary executables being used
  4300. for syntax checking."
  4301. (let ((executable-var (flycheck-checker-executable-variable checker)))
  4302. `(progn
  4303. (defcustom ,executable-var nil
  4304. ,(format "The executable of the %s syntax checker.
  4305. Either a string containing the name or the path of the
  4306. executable, or nil to use the default executable from the syntax
  4307. checker declaration.
  4308. The default executable is %S." checker default-executable)
  4309. :type '(choice (const :tag "Default executable" nil)
  4310. (string :tag "Name or path"))
  4311. :group 'flycheck-executables
  4312. :risky t))))
  4313. (defun flycheck-set-checker-executable (checker &optional executable)
  4314. "Set the executable of CHECKER in the current buffer.
  4315. CHECKER is a syntax checker symbol. EXECUTABLE is a string with
  4316. the name of a executable or the path to an executable file, which
  4317. is to be used as executable for CHECKER. If omitted or nil,
  4318. reset the executable of CHECKER.
  4319. Interactively, prompt for a syntax checker and an executable
  4320. file, and set the executable of the selected syntax checker.
  4321. With prefix arg, prompt for a syntax checker only, and reset the
  4322. executable of the select checker to the default.
  4323. Set the executable variable of CHECKER, that is,
  4324. `flycheck-CHECKER-executable' to EXECUTABLE. Signal
  4325. `user-error', if EXECUTABLE does not denote a command or an
  4326. executable file.
  4327. This command is intended for interactive use only. In Lisp, just
  4328. `let'-bind the corresponding variable, or set it directly. Use
  4329. `flycheck-checker-executable-variable' to obtain the executable
  4330. variable symbol for a syntax checker."
  4331. (declare (interactive-only "Set the executable variable directly instead"))
  4332. (interactive
  4333. (let* ((checker (read-flycheck-checker "Syntax checker: "))
  4334. (default-executable (flycheck-checker-default-executable checker))
  4335. (executable (if current-prefix-arg
  4336. nil
  4337. (read-file-name "Executable: " nil default-executable
  4338. nil nil flycheck-executable-find))))
  4339. (list checker executable)))
  4340. (when (and executable (not (funcall flycheck-executable-find executable)))
  4341. (user-error "%s is no executable" executable))
  4342. (let ((variable (flycheck-checker-executable-variable checker)))
  4343. (set (make-local-variable variable) executable)))
  4344. ;;; Configuration files and options for command checkers
  4345. (defun flycheck-register-config-file-var (var checkers)
  4346. "Register VAR as config file var for CHECKERS.
  4347. CHECKERS is a single syntax checker or a list thereof."
  4348. (when (symbolp checkers)
  4349. (setq checkers (list checkers)))
  4350. (dolist (checker checkers)
  4351. (setf (flycheck-checker-get checker 'config-file-var) var)))
  4352. ;;;###autoload
  4353. (defmacro flycheck-def-config-file-var (symbol checker &optional file-name
  4354. &rest custom-args)
  4355. "Define SYMBOL as config file variable for CHECKER, with default FILE-NAME.
  4356. SYMBOL is declared as customizable variable using `defcustom', to
  4357. provide a configuration file for the given syntax CHECKER.
  4358. CUSTOM-ARGS are forwarded to `defcustom'.
  4359. FILE-NAME is the initial value of the new variable. If omitted,
  4360. the default value is nil.
  4361. Use this together with the `config-file' form in the `:command'
  4362. argument to `flycheck-define-checker'."
  4363. ;; FIXME: We should allow multiple config files per checker as well as
  4364. ;; multiple checkers per config file
  4365. (declare (indent 3))
  4366. `(progn
  4367. (defcustom ,symbol ,file-name
  4368. ,(format "Configuration file for `%s'.
  4369. If set to a string, locate the configuration file using the
  4370. functions from `flycheck-locate-config-file-functions'. If the
  4371. file is found pass it to the syntax checker as configuration
  4372. file.
  4373. If no configuration file is found, or if this variable is set to
  4374. nil, invoke the syntax checker without a configuration file.
  4375. Use this variable as file-local variable if you need a specific
  4376. configuration file a buffer." checker)
  4377. :type '(choice (const :tag "No configuration file" nil)
  4378. (string :tag "File name or path"))
  4379. :group 'flycheck-config-files
  4380. ,@custom-args)
  4381. (flycheck-register-config-file-var ',symbol ',checker)))
  4382. (defun flycheck-locate-config-file (filename checker)
  4383. "Locate the configuration file FILENAME for CHECKER.
  4384. Locate the configuration file using
  4385. `flycheck-locate-config-file-functions'.
  4386. Return the absolute path of the configuration file, or nil if no
  4387. configuration file was found."
  4388. (-when-let (filepath (run-hook-with-args-until-success
  4389. 'flycheck-locate-config-file-functions
  4390. filename checker))
  4391. (when (file-exists-p filepath)
  4392. filepath)))
  4393. (defun flycheck-locate-config-file-by-path (filepath _checker)
  4394. "Locate a configuration file by a FILEPATH.
  4395. If FILEPATH is a contains a path separator, expand it against the
  4396. default directory and return it if it points to an existing file.
  4397. Otherwise return nil.
  4398. _CHECKER is ignored."
  4399. ;; If the path is just a plain file name, skip it.
  4400. (unless (string= (file-name-nondirectory filepath) filepath)
  4401. (let ((file-name (expand-file-name filepath)))
  4402. (and (file-exists-p file-name) file-name))))
  4403. (defun flycheck-locate-config-file-ancestor-directories (filename _checker)
  4404. "Locate a configuration FILENAME in ancestor directories.
  4405. If the current buffer has a file name, search FILENAME in the
  4406. directory of the current buffer and all ancestors thereof (see
  4407. `locate-dominating-file'). If the file is found, return its
  4408. absolute path. Otherwise return nil.
  4409. _CHECKER is ignored."
  4410. (-when-let* ((basefile (buffer-file-name))
  4411. (directory (locate-dominating-file basefile filename)))
  4412. (expand-file-name filename directory)))
  4413. (defun flycheck-locate-config-file-home (filename _checker)
  4414. "Locate a configuration FILENAME in the home directory.
  4415. Return the absolute path, if FILENAME exists in the user's home
  4416. directory, or nil otherwise."
  4417. (let ((path (expand-file-name filename "~")))
  4418. (when (file-exists-p path)
  4419. path)))
  4420. (seq-do (apply-partially #'custom-add-frequent-value
  4421. 'flycheck-locate-config-file-functions)
  4422. '(flycheck-locate-config-file-by-path
  4423. flycheck-locate-config-file-ancestor-directories
  4424. flycheck-locate-config-file-home))
  4425. (defun flycheck-register-option-var (var checkers)
  4426. "Register an option VAR with CHECKERS.
  4427. VAR is an option symbol, and CHECKERS a syntax checker symbol or
  4428. a list thereof. Register VAR with all CHECKERS so that it
  4429. appears in the help output."
  4430. (when (symbolp checkers)
  4431. (setq checkers (list checkers)))
  4432. (dolist (checker checkers)
  4433. (cl-pushnew var (flycheck-checker-get checker 'option-vars))))
  4434. ;;;###autoload
  4435. (defmacro flycheck-def-option-var (symbol init-value checkers docstring
  4436. &rest custom-args)
  4437. "Define SYMBOL as option variable with INIT-VALUE for CHECKER.
  4438. SYMBOL is declared as customizable variable using `defcustom', to
  4439. provide an option for the given syntax CHECKERS (a checker or a
  4440. list of checkers). INIT-VALUE is the initial value of the
  4441. variable, and DOCSTRING is its docstring. CUSTOM-ARGS are
  4442. forwarded to `defcustom'.
  4443. Use this together with the `option', `option-list' and
  4444. `option-flag' forms in the `:command' argument to
  4445. `flycheck-define-checker'."
  4446. (declare (indent 3)
  4447. (doc-string 4))
  4448. `(progn
  4449. (defcustom ,symbol ,init-value
  4450. ,(concat docstring "
  4451. This variable is an option for the following syntax checkers:
  4452. "
  4453. (mapconcat (lambda (c) (format " - `%s'" c))
  4454. (if (symbolp checkers) (list checkers) checkers)
  4455. "\n"))
  4456. :group 'flycheck-options
  4457. ,@custom-args)
  4458. (flycheck-register-option-var ',symbol ',checkers)))
  4459. (defun flycheck-option-int (value)
  4460. "Convert an integral option VALUE to a string.
  4461. If VALUE is nil, return nil. Otherwise return VALUE converted to
  4462. a string."
  4463. (and value (number-to-string value)))
  4464. (defun flycheck-option-symbol (value)
  4465. "Convert a symbol option VALUE to string.
  4466. If VALUE is nil return nil. Otherwise return VALUE converted to
  4467. a string."
  4468. (and value (symbol-name value)))
  4469. (defun flycheck-option-comma-separated-list (value &optional separator filter)
  4470. "Convert VALUE into a list separated by SEPARATOR.
  4471. SEPARATOR is a string to separate items in VALUE, defaulting to
  4472. \",\". FILTER is an optional function, which takes a single
  4473. argument and returns either a string or nil.
  4474. If VALUE is a list, apply FILTER to each item in VALUE, remove
  4475. all nil items, and return a single string of all remaining items
  4476. separated by SEPARATOR.
  4477. Otherwise, apply FILTER to VALUE and return the result.
  4478. SEPARATOR is ignored in this case."
  4479. (let ((filter (or filter #'identity))
  4480. (separator (or separator ",")))
  4481. (if (listp value)
  4482. (-when-let (value (delq nil (seq-map filter value)))
  4483. (string-join value separator))
  4484. (funcall filter value))))
  4485. (defmacro flycheck-def-args-var (symbol checkers &rest custom-args)
  4486. "Define SYMBOL as argument variable for CHECKERS.
  4487. SYMBOL is declared as customizable, risky and buffer-local
  4488. variable using `defcustom' to provide an option for arbitrary
  4489. arguments for the given syntax CHECKERS (either a single checker
  4490. or a list of checkers). CUSTOM-ARGS is forwarded to `defcustom'.
  4491. Use the `eval' form to splice this variable into the
  4492. `:command'."
  4493. (declare (indent 2))
  4494. `(flycheck-def-option-var ,symbol nil ,checkers
  4495. "A list of additional command line arguments.
  4496. The value of this variable is a list of strings with additional
  4497. command line arguments."
  4498. :risky t
  4499. :type '(repeat (string :tag "Argument"))
  4500. ,@custom-args))
  4501. ;;; Command syntax checkers as compile commands
  4502. (defun flycheck-checker-pattern-to-error-regexp (pattern)
  4503. "Convert PATTERN into an error regexp for compile.el.
  4504. Return a list representing PATTERN, suitable as element in
  4505. `compilation-error-regexp-alist'."
  4506. (let* ((regexp (car pattern))
  4507. (level (cdr pattern))
  4508. (level-no (flycheck-error-level-compilation-level level)))
  4509. (list regexp 1 2 3 level-no)))
  4510. (defun flycheck-checker-compilation-error-regexp-alist (checker)
  4511. "Convert error patterns of CHECKER for use with compile.el.
  4512. Return an alist of all error patterns of CHECKER, suitable for
  4513. use with `compilation-error-regexp-alist'."
  4514. (seq-map #'flycheck-checker-pattern-to-error-regexp
  4515. (flycheck-checker-get checker 'error-patterns)))
  4516. (defun flycheck-checker-shell-command (checker)
  4517. "Get a shell command for CHECKER.
  4518. Perform substitution in the arguments of CHECKER, but with
  4519. `flycheck-substitute-shell-argument'.
  4520. Return the command of CHECKER as single string, suitable for
  4521. shell execution."
  4522. ;; Note: Do NOT use `combine-and-quote-strings' here. Despite it's name it
  4523. ;; does not properly quote shell arguments, and actually breaks for special
  4524. ;; characters. See https://github.com/flycheck/flycheck/pull/522
  4525. (let* ((args (apply #'append
  4526. (seq-map (lambda (arg)
  4527. (if (memq arg '(source source-inplace source-original))
  4528. (list (buffer-file-name))
  4529. (flycheck-substitute-argument arg checker)))
  4530. (flycheck-checker-arguments checker))))
  4531. (command (mapconcat
  4532. #'shell-quote-argument
  4533. (funcall flycheck-command-wrapper-function
  4534. (cons (flycheck-checker-executable checker) args))
  4535. " ")))
  4536. (if (flycheck-checker-get checker 'standard-input)
  4537. ;; If the syntax checker expects the source from standard input add an
  4538. ;; appropriate shell redirection
  4539. (concat command " < " (shell-quote-argument (buffer-file-name)))
  4540. command)))
  4541. (defun flycheck-compile-name (_name)
  4542. "Get a name for a Flycheck compilation buffer.
  4543. _NAME is ignored."
  4544. (format "*Flycheck %s*" (buffer-file-name)))
  4545. (defun flycheck-compile (checker)
  4546. "Run CHECKER via `compile'.
  4547. CHECKER must be a valid syntax checker. Interactively, prompt
  4548. for a syntax checker to run.
  4549. Instead of highlighting errors in the buffer, this command pops
  4550. up a separate buffer with the entire output of the syntax checker
  4551. tool, just like `compile' (\\[compile])."
  4552. (interactive
  4553. (let ((default (flycheck-get-checker-for-buffer)))
  4554. (list (read-flycheck-checker "Run syntax checker as compile command: "
  4555. (when (flycheck-checker-get default 'command)
  4556. default)
  4557. 'command))))
  4558. (unless (flycheck-valid-checker-p checker)
  4559. (user-error "%S is not a valid syntax checker" checker))
  4560. (unless (buffer-file-name)
  4561. (user-error "Cannot compile buffers without backing file"))
  4562. (unless (flycheck-may-use-checker checker)
  4563. (user-error "Cannot use syntax checker %S in this buffer" checker))
  4564. (unless (flycheck-checker-executable checker)
  4565. (user-error "Cannot run checker %S as shell command" checker))
  4566. (let* ((default-directory (flycheck-compute-working-directory checker))
  4567. (command (flycheck-checker-shell-command checker))
  4568. (buffer (compilation-start command nil #'flycheck-compile-name)))
  4569. (with-current-buffer buffer
  4570. (setq-local compilation-error-regexp-alist
  4571. (flycheck-checker-compilation-error-regexp-alist checker)))))
  4572. ;;; General error parsing for command checkers
  4573. (defun flycheck-parse-output (output checker buffer)
  4574. "Parse OUTPUT from CHECKER in BUFFER.
  4575. OUTPUT is a string with the output from the checker symbol
  4576. CHECKER. BUFFER is the buffer which was checked.
  4577. Return the errors parsed with the error patterns of CHECKER."
  4578. (funcall (flycheck-checker-get checker 'error-parser) output checker buffer))
  4579. (defun flycheck-fix-error-filename (err buffer-files cwd)
  4580. "Fix the file name of ERR from BUFFER-FILES.
  4581. Resolves error file names relative to CWD directory.
  4582. Make the file name of ERR absolute. If the absolute file name of
  4583. ERR is in BUFFER-FILES, replace it with the return value of the
  4584. function `buffer-file-name'."
  4585. (flycheck-error-with-buffer err
  4586. (-when-let (filename (flycheck-error-filename err))
  4587. (when (seq-some (apply-partially #'flycheck-same-files-p
  4588. (expand-file-name filename cwd))
  4589. buffer-files)
  4590. (setf (flycheck-error-filename err) buffer-file-name)
  4591. (when (and buffer-file-name (flycheck-error-message err))
  4592. (setf (flycheck-error-message err)
  4593. (replace-regexp-in-string
  4594. (regexp-quote filename) buffer-file-name
  4595. (flycheck-error-message err) 'fixed-case 'literal))))))
  4596. err)
  4597. ;;; Error parsers for command syntax checkers
  4598. (defun flycheck-parse-xml-region (beg end)
  4599. "Parse the xml region between BEG and END.
  4600. Wrapper around `xml-parse-region' which transforms the return
  4601. value of this function into one compatible to
  4602. `libxml-parse-xml-region' by simply returning the first element
  4603. from the node list."
  4604. (car (xml-parse-region beg end)))
  4605. (defvar flycheck-xml-parser
  4606. (if (fboundp 'libxml-parse-xml-region)
  4607. 'libxml-parse-xml-region 'flycheck-parse-xml-region)
  4608. "Parse an xml string from a region.
  4609. Use libxml if Emacs is built with libxml support. Otherwise fall
  4610. back to `xml-parse-region', via `flycheck-parse-xml-region'.")
  4611. (defun flycheck-parse-xml-string (xml)
  4612. "Parse an XML string.
  4613. Return the document tree parsed from XML in the form `(ROOT ATTRS
  4614. BODY...)'. ROOT is a symbol identifying the name of the root
  4615. element. ATTRS is an alist of the attributes of the root node.
  4616. BODY is zero or more body elements, either as strings (in case of
  4617. text nodes) or as XML nodes, in the same for as the root node."
  4618. (with-temp-buffer
  4619. (insert xml)
  4620. (funcall flycheck-xml-parser (point-min) (point-max))))
  4621. (defun flycheck-parse-checkstyle (output checker buffer)
  4622. "Parse Checkstyle errors from OUTPUT.
  4623. Parse Checkstyle-like XML output. Use this error parser for
  4624. checkers that have an option to output errors in this format.
  4625. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  4626. the BUFFER that was checked respectively.
  4627. See URL `http://checkstyle.sourceforge.net/' for information
  4628. about Checkstyle."
  4629. (pcase (flycheck-parse-xml-string output)
  4630. (`(checkstyle ,_ . ,file-nodes)
  4631. (let (errors)
  4632. (dolist (node file-nodes)
  4633. (pcase node
  4634. (`(file ,file-attrs . ,error-nodes)
  4635. (dolist (node error-nodes)
  4636. (pcase node
  4637. (`(error ,error-attrs . ,_)
  4638. (let-alist error-attrs
  4639. (push (flycheck-error-new-at
  4640. (flycheck-string-to-number-safe .line)
  4641. (flycheck-string-to-number-safe .column)
  4642. (pcase .severity
  4643. (`"error" 'error)
  4644. (`"warning" 'warning)
  4645. (`"info" 'info)
  4646. ;; Default to error for unknown .severity
  4647. (_ 'error))
  4648. .message
  4649. :checker checker :id .source
  4650. :buffer buffer
  4651. :filename (cdr (assq 'name file-attrs)))
  4652. errors))))))))
  4653. (nreverse errors)))))
  4654. (defun flycheck-parse-cppcheck (output checker buffer)
  4655. "Parse Cppcheck errors from OUTPUT.
  4656. Parse Cppcheck XML v2 output.
  4657. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  4658. the BUFFER that was checked respectively.
  4659. See URL `http://cppcheck.sourceforge.net/' for more information
  4660. about Cppcheck."
  4661. (pcase (flycheck-parse-xml-string output)
  4662. (`(results ,_ . ,body)
  4663. (let (errors)
  4664. (dolist (node body)
  4665. (pcase node
  4666. (`(errors ,_ . ,error-nodes)
  4667. (dolist (node error-nodes)
  4668. (pcase node
  4669. (`(error ,error-attrs . ,loc-nodes)
  4670. (let ((id (cdr (assq 'id error-attrs)))
  4671. (message (cdr (assq 'verbose error-attrs)))
  4672. (level (pcase (cdr (assq 'severity error-attrs))
  4673. (`"error" 'error)
  4674. (`"style" 'info)
  4675. (`"information" 'info)
  4676. (_ 'warning))))
  4677. (dolist (node loc-nodes)
  4678. (pcase node
  4679. (`(location ,loc-attrs . ,_)
  4680. (let-alist loc-attrs
  4681. (push (flycheck-error-new-at
  4682. (flycheck-string-to-number-safe .line)
  4683. nil
  4684. level
  4685. ;; cppcheck return newline characters as "\012"
  4686. (replace-regexp-in-string "\\\\012" "\n" message)
  4687. :id id
  4688. :checker checker
  4689. :buffer buffer
  4690. :filename .file)
  4691. errors))))))))))))
  4692. (nreverse errors)))))
  4693. (defun flycheck-parse-phpmd (output checker buffer)
  4694. "Parse phpmd errors from OUTPUT.
  4695. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  4696. the BUFFER that was checked respectively.
  4697. See URL `http://phpmd.org/' for more information about phpmd."
  4698. (pcase (flycheck-parse-xml-string output)
  4699. (`(pmd ,_ . ,body)
  4700. (let (errors)
  4701. (dolist (node body)
  4702. (pcase node
  4703. (`(file ,file-attrs . ,violation-nodes)
  4704. (let ((filename (cdr (assq 'name file-attrs))))
  4705. (dolist (node violation-nodes)
  4706. (pcase node
  4707. (`(violation ,vio-attrs ,(and message (pred stringp)))
  4708. (let-alist vio-attrs
  4709. (push
  4710. (flycheck-error-new-at
  4711. (flycheck-string-to-number-safe .beginline)
  4712. nil
  4713. 'warning (string-trim message)
  4714. :id .rule
  4715. :checker checker
  4716. :buffer buffer
  4717. :filename filename)
  4718. errors)))))))))
  4719. (nreverse errors)))))
  4720. (defun flycheck-parse-reek (output checker buffer)
  4721. "Parse Reek warnings from JSON OUTPUT.
  4722. CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
  4723. the BUFFER that was checked respectively.
  4724. See URL `https://github.com/troessner/reek' for more information
  4725. about Reek."
  4726. (let ((errors nil))
  4727. (dolist (message (car (flycheck-parse-json output)))
  4728. (let-alist message
  4729. (dolist (line (delete-dups .lines))
  4730. (push
  4731. (flycheck-error-new-at
  4732. line
  4733. nil
  4734. 'warning (concat .context " " .message)
  4735. :id .smell_type
  4736. :checker checker
  4737. :buffer buffer
  4738. :filename .source)
  4739. errors))))
  4740. (nreverse errors)))
  4741. (defun flycheck-parse-tslint (output checker buffer)
  4742. "Parse TSLint errors from JSON OUTPUT.
  4743. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  4744. the BUFFER that was checked respectively.
  4745. See URL `https://palantir.github.io/tslint/' for more information
  4746. about TSLint."
  4747. (let ((json-array-type 'list))
  4748. (seq-map (lambda (message)
  4749. (let-alist message
  4750. (flycheck-error-new-at
  4751. (+ 1 .startPosition.line)
  4752. (+ 1 .startPosition.character)
  4753. 'warning .failure
  4754. :id .ruleName
  4755. :checker checker
  4756. :buffer buffer
  4757. :filename .name)))
  4758. ;; Don't try to parse empty output as JSON
  4759. (and (not (string-empty-p output))
  4760. (car (flycheck-parse-json output))))))
  4761. (defun flycheck-parse-rust-collect-spans (span)
  4762. "Return a list of spans contained in a SPAN object."
  4763. (let ((spans))
  4764. (let-alist span
  4765. ;; With macro expansion errors, some spans will point to phony file names
  4766. ;; to indicate an error inside the std rust lib. We skip these spans as
  4767. ;; they won't appear in flycheck anyway.
  4768. (unless (string= .file_name "<std macros>")
  4769. (push span spans))
  4770. ;; Macro expansion errors will have a span in the 'expansion' field, so we
  4771. ;; recursively collect it.
  4772. (if .expansion.span
  4773. (append (flycheck-parse-rust-collect-spans .expansion.span)
  4774. spans)
  4775. spans))))
  4776. (defun flycheck-parse-rustc-diagnostic (diagnostic checker buffer)
  4777. "Turn a rustc DIAGNOSTIC into a `flycheck-error'.
  4778. CHECKER and BUFFER denote the CHECKER that returned DIAGNOSTIC
  4779. and the BUFFER that was checked respectively.
  4780. DIAGNOSTIC should be a parsed JSON object describing a rustc
  4781. diagnostic, following the format described there:
  4782. https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs#L67-L139"
  4783. (let ((error-message)
  4784. (error-level)
  4785. (error-code)
  4786. (primary-filename)
  4787. (primary-line)
  4788. (primary-column)
  4789. (group (make-symbol "group"))
  4790. (spans)
  4791. (children)
  4792. (errors))
  4793. ;; The diagnostic format is described in the link above. The gist of it is
  4794. ;; that a diagnostic can have several causes in the source text; these
  4795. ;; causes are represented by spans. The diagnostic has a message and a
  4796. ;; level (error, warning), while the spans have a filename, line, column,
  4797. ;; and an optional label. The primary span points to the root cause of the
  4798. ;; error in the source text, while non-primary spans point to related
  4799. ;; causes. Spans may have an 'expansion' field for macro expansion errors;
  4800. ;; these expansion fields will contain another span (and so on). In
  4801. ;; addition, a diagnostic can also have children diagnostics that are used
  4802. ;; to provide additional information through their message field, but do not
  4803. ;; seem to contain any spans (yet).
  4804. ;;
  4805. ;; We first gather spans in order to turn every span into a flycheck error
  4806. ;; object, that we collect into the `errors' list.
  4807. ;; Nested `let-alist' cause compilation warnings, hence we `setq' all
  4808. ;; these values here first to avoid nesting.
  4809. (let-alist diagnostic
  4810. (setq error-message .message
  4811. error-level (pcase .level
  4812. (`"error" 'error)
  4813. (`"warning" 'warning)
  4814. (`"note" 'info)
  4815. (_ 'error))
  4816. ;; The 'code' field of the diagnostic contains the actual error
  4817. ;; code and an optional explanation that we ignore
  4818. error-code .code.code
  4819. ;; Collect all spans recursively
  4820. spans (seq-mapcat #'flycheck-parse-rust-collect-spans .spans)
  4821. children .children))
  4822. ;; Turn each span into a flycheck error
  4823. (dolist (span spans)
  4824. (let-alist span
  4825. ;; Children lack any filename/line/column information, so we use
  4826. ;; those from the primary span
  4827. (when .is_primary
  4828. (setq primary-filename .file_name
  4829. primary-line .line_start
  4830. primary-column .column_start))
  4831. (push
  4832. (flycheck-error-new-at
  4833. .line_start
  4834. .column_start
  4835. ;; Non-primary spans are used for notes
  4836. (if .is_primary error-level 'info)
  4837. (if .is_primary
  4838. ;; Primary spans may have labels with additional information
  4839. (concat error-message (when .label
  4840. (format " (%s)" .label)))
  4841. ;; If the label is empty, fallback on the error message,
  4842. ;; otherwise we won't be able to display anything
  4843. (or .label error-message))
  4844. :id error-code
  4845. :checker checker
  4846. :buffer buffer
  4847. :filename .file_name
  4848. :group group)
  4849. errors)))
  4850. ;; Then we turn children messages into flycheck errors pointing to the
  4851. ;; location of the primary span. According to the format, children
  4852. ;; may contain spans, but they do not seem to use them in practice.
  4853. (dolist (child children)
  4854. (let-alist child
  4855. (push
  4856. (flycheck-error-new-at
  4857. primary-line
  4858. primary-column
  4859. 'info
  4860. .message
  4861. :id error-code
  4862. :checker checker
  4863. :buffer buffer
  4864. :filename primary-filename
  4865. :group group)
  4866. errors)))
  4867. ;; If there are no spans, the error is not associated with a specific
  4868. ;; file but with the project as a whole. We still need to report it to
  4869. ;; the user by emitting a corresponding flycheck-error object.
  4870. (unless spans
  4871. (push (flycheck-error-new-at
  4872. ;; We have no specific position to attach the error to, so
  4873. ;; let's use the top of the file.
  4874. 1 1
  4875. error-level
  4876. error-message
  4877. :id error-code
  4878. :checker checker
  4879. :buffer buffer
  4880. :group group)
  4881. errors))
  4882. (nreverse errors)))
  4883. (defun flycheck-parse-json (output)
  4884. "Return parsed JSON data from OUTPUT.
  4885. OUTPUT is a string that contains JSON data. Each line of OUTPUT
  4886. may be either plain text, a JSON array (starting with `['), or a
  4887. JSON object (starting with `{').
  4888. This function ignores the plain text lines, parses the JSON
  4889. lines, and returns the parsed JSON lines in a list."
  4890. (let ((objects nil)
  4891. (json-array-type 'list)
  4892. (json-false nil))
  4893. (with-temp-buffer
  4894. (insert output)
  4895. (goto-char (point-min))
  4896. (while (not (eobp))
  4897. (when (memq (char-after) '(?\{ ?\[))
  4898. (push (json-read) objects))
  4899. (forward-line)))
  4900. (nreverse objects)))
  4901. (defun flycheck-parse-rustc (output checker buffer)
  4902. "Parse rustc errors from OUTPUT and return a list of `flycheck-error'.
  4903. CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
  4904. the BUFFER that was checked respectively.
  4905. The expected format for OUTPUT is a mix of plain text lines and
  4906. JSON lines. This function ignores the plain text lines and
  4907. parses only JSON lines. Each JSON line is expected to be a JSON
  4908. object that corresponds to a diagnostic from the compiler. The
  4909. expected diagnostic format is described there:
  4910. https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs#L67-L139"
  4911. (seq-mapcat (lambda (msg)
  4912. (flycheck-parse-rustc-diagnostic msg checker buffer))
  4913. (flycheck-parse-json output)))
  4914. (defun flycheck-parse-cargo-rustc (output checker buffer)
  4915. "Parse Cargo errors from OUTPUT and return a list of `flycheck-error'.
  4916. CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
  4917. the BUFFER that was checked respectively.
  4918. The expected format for OUTPUT is a mix of plain text lines and
  4919. JSON lines. This function ignores the plain text lines and
  4920. parses only JSON lines. Each JSON line is expected to be a JSON
  4921. object that represents a message from Cargo. The format of
  4922. messages emitted by Cargo is described there:
  4923. https://github.com/rust-lang/cargo/blob/master/src/cargo/util/machine_message.rs#L20-L31"
  4924. (let ((errors))
  4925. (dolist (msg (flycheck-parse-json output))
  4926. (let-alist msg
  4927. ;; Errors and warnings from rustc are wrapped by cargo, so we filter and
  4928. ;; unwrap them, and delegate the actual construction of `flycheck-error'
  4929. ;; objects to `flycheck-parse-rustc-diagnostic'.
  4930. (when (string= .reason "compiler-message")
  4931. (push (flycheck-parse-rustc-diagnostic .message checker buffer)
  4932. errors))))
  4933. (apply #'nconc errors)))
  4934. ;;; Error parsing with regular expressions
  4935. (defun flycheck-get-regexp (patterns)
  4936. "Create a single regular expression from PATTERNS."
  4937. (rx-to-string `(or ,@(seq-map (lambda (p) (list 'regexp (car p))) patterns))
  4938. 'no-group))
  4939. (defun flycheck-tokenize-output-with-patterns (output patterns)
  4940. "Tokenize OUTPUT with PATTERNS.
  4941. Split the output into error tokens, using all regular expressions
  4942. from the error PATTERNS. An error token is simply a string
  4943. containing a single error from OUTPUT. Such a token can then be
  4944. parsed into a structured error by applying the PATTERNS again,
  4945. see `flycheck-parse-errors-with-patterns'.
  4946. Return a list of error tokens."
  4947. (let ((regexp (flycheck-get-regexp patterns))
  4948. (last-match 0)
  4949. errors)
  4950. (while (string-match regexp output last-match)
  4951. (push (match-string 0 output) errors)
  4952. (setq last-match (match-end 0)))
  4953. (reverse errors)))
  4954. (defun flycheck-try-parse-error-with-pattern (err pattern checker)
  4955. "Try to parse a single ERR with a PATTERN for CHECKER.
  4956. Return the parsed error if PATTERN matched ERR, or nil
  4957. otherwise."
  4958. (let ((regexp (car pattern))
  4959. (level (cdr pattern)))
  4960. (when (string-match regexp err)
  4961. (let ((filename (match-string 1 err))
  4962. (line (match-string 2 err))
  4963. (column (match-string 3 err))
  4964. (message (match-string 4 err))
  4965. (id (match-string 5 err)))
  4966. (flycheck-error-new-at
  4967. (flycheck-string-to-number-safe line)
  4968. (flycheck-string-to-number-safe column)
  4969. level
  4970. (unless (string-empty-p message) message)
  4971. :id (unless (string-empty-p id) id)
  4972. :checker checker
  4973. :filename (if (or (null filename) (string-empty-p filename))
  4974. (buffer-file-name)
  4975. filename))))))
  4976. (defun flycheck-parse-error-with-patterns (err patterns checker)
  4977. "Parse a gle ERR with error PATTERNS for CHECKER.
  4978. Apply each pattern in PATTERNS to ERR, in the given order, and
  4979. return the first parsed error."
  4980. ;; Try to parse patterns in the order of declaration to make sure that the
  4981. ;; first match wins.
  4982. (let (parsed-error)
  4983. (while (and patterns
  4984. (not (setq parsed-error
  4985. (flycheck-try-parse-error-with-pattern
  4986. err (car patterns) checker))))
  4987. (setq patterns (cdr patterns)))
  4988. parsed-error))
  4989. (defun flycheck-parse-with-patterns (output checker buffer)
  4990. "Parse OUTPUT from CHECKER with error patterns.
  4991. Uses the error patterns of CHECKER to tokenize the output and
  4992. tries to parse each error token with all patterns, in the order
  4993. of declaration. Hence an error is never matched twice by two
  4994. different patterns. The pattern declared first always wins.
  4995. _BUFFER is ignored.
  4996. Return a list of parsed errors and warnings (as `flycheck-error'
  4997. objects)."
  4998. (with-current-buffer buffer
  4999. (let ((patterns (flycheck-checker-get checker 'error-patterns)))
  5000. (seq-map (lambda (err)
  5001. (flycheck-parse-error-with-patterns err patterns checker))
  5002. (flycheck-tokenize-output-with-patterns output patterns)))))
  5003. ;;; Convenience definition of command-syntax checkers
  5004. (defmacro flycheck-define-checker (symbol docstring &rest properties)
  5005. "Define SYMBOL as command syntax checker with DOCSTRING and PROPERTIES.
  5006. Like `flycheck-define-command-checker', but PROPERTIES must not
  5007. be quoted. Also, implicitly define the executable variable for
  5008. SYMBOL with `flycheck-def-executable-var'."
  5009. (declare (indent 1)
  5010. (doc-string 2))
  5011. (let ((command (plist-get properties :command))
  5012. (parser (plist-get properties :error-parser))
  5013. (filter (plist-get properties :error-filter))
  5014. (explainer (plist-get properties :error-explainer))
  5015. (predicate (plist-get properties :predicate))
  5016. (enabled-fn (plist-get properties :enabled))
  5017. (verify-fn (plist-get properties :verify)))
  5018. `(progn
  5019. (flycheck-def-executable-var ,symbol ,(car command))
  5020. (flycheck-define-command-checker ',symbol
  5021. ,docstring
  5022. :command ',command
  5023. ,@(when parser
  5024. `(:error-parser #',parser))
  5025. :error-patterns ',(plist-get properties :error-patterns)
  5026. ,@(when filter
  5027. `(:error-filter #',filter))
  5028. ,@(when explainer
  5029. `(:error-explainer #',explainer))
  5030. :modes ',(plist-get properties :modes)
  5031. ,@(when predicate
  5032. `(:predicate #',predicate))
  5033. :next-checkers ',(plist-get properties :next-checkers)
  5034. ,@(when enabled-fn
  5035. `(:enabled #',enabled-fn))
  5036. ,@(when verify-fn
  5037. `(:verify #',verify-fn))
  5038. :standard-input ',(plist-get properties :standard-input)
  5039. :working-directory ',(plist-get properties :working-directory)))))
  5040. ;;; Built-in checkers
  5041. (flycheck-def-args-var flycheck-gnat-args ada-gnat
  5042. :package-version '(flycheck . "0.20"))
  5043. (flycheck-def-option-var flycheck-gnat-include-path nil ada-gnat
  5044. "A list of include directories for GNAT.
  5045. The value of this variable is a list of strings, where each
  5046. string is a directory to add to the include path of gcc.
  5047. Relative paths are relative to the file being checked."
  5048. :type '(repeat (directory :tag "Include directory"))
  5049. :safe #'flycheck-string-list-p
  5050. :package-version '(flycheck . "0.20"))
  5051. (flycheck-def-option-var flycheck-gnat-language-standard "2012" ada-gnat
  5052. "The language standard to use in GNAT.
  5053. The value of this variable is either a string denoting a language
  5054. standard, or nil, to use the default standard. When non-nil, pass
  5055. the language standard via the `-std' option."
  5056. :type '(choice (const :tag "Default standard" nil)
  5057. (string :tag "Language standard"))
  5058. :safe #'stringp
  5059. :package-version '(flycheck . "0.20"))
  5060. (flycheck-def-option-var flycheck-gnat-warnings
  5061. '("wa") ada-gnat
  5062. "A list of additional Ada warnings to enable in GNAT.
  5063. The value of this variable is a list of strings, where each
  5064. string is the name of a warning category to enable. By default,
  5065. most optional warnings are recommended, as in `-gnata'.
  5066. Refer to Info Node `(gnat_ugn_unw)Warning Message Control' for
  5067. more information about GNAT warnings."
  5068. :type '(repeat :tag "Warnings" (string :tag "Warning name"))
  5069. :safe #'flycheck-string-list-p
  5070. :package-version '(flycheck . "0.20"))
  5071. (flycheck-define-checker ada-gnat
  5072. "An Ada syntax checker using GNAT.
  5073. Uses the GNAT compiler from GCC. See URL
  5074. `http://libre.adacore.com/tools/gnat-gpl-edition/'."
  5075. :command ("gnatmake"
  5076. "-c" ; Just compile, don't bind
  5077. "-f" ; Force re-compilation
  5078. "-u" ; Compile the main file only
  5079. "-gnatf" ; Full error information
  5080. "-gnatef" ; Full source file name
  5081. "-D" temporary-directory
  5082. (option-list "-gnat" flycheck-gnat-warnings concat)
  5083. (option-list "-I" flycheck-gnat-include-path concat)
  5084. (option "-gnat" flycheck-gnat-language-standard concat)
  5085. (eval flycheck-gnat-args)
  5086. source)
  5087. :error-patterns
  5088. ((error line-start
  5089. (message "In file included from") " " (file-name) ":" line ":"
  5090. column ":"
  5091. line-end)
  5092. (info line-start (file-name) ":" line ":" column
  5093. ": note: " (message) line-end)
  5094. (warning line-start (file-name) ":" line ":" column
  5095. ": warning: " (message) line-end)
  5096. (error line-start (file-name) ":" line ":" column ;no specific error prefix in Ada
  5097. ": " (message) line-end))
  5098. :modes ada-mode)
  5099. (flycheck-define-checker asciidoc
  5100. "A AsciiDoc syntax checker using the AsciiDoc compiler.
  5101. See URL `http://www.methods.co.nz/asciidoc'."
  5102. :command ("asciidoc" "-o" null-device "-")
  5103. :standard-input t
  5104. :error-patterns
  5105. ((error line-start
  5106. "asciidoc: ERROR: <stdin>: Line " line ": " (message)
  5107. line-end)
  5108. (warning line-start
  5109. "asciidoc: WARNING: <stdin>: Line " line ": " (message)
  5110. line-end)
  5111. (info line-start
  5112. "asciidoc: DEPRECATED: <stdin>: Line " line ": " (message)
  5113. line-end))
  5114. :modes adoc-mode)
  5115. (flycheck-define-checker asciidoctor
  5116. "An AsciiDoc syntax checker using the Asciidoctor compiler.
  5117. See URL `http://asciidoctor.org'."
  5118. :command ("asciidoctor" "-o" null-device "-")
  5119. :standard-input t
  5120. :error-patterns
  5121. ((error line-start
  5122. "asciidoctor: ERROR: <stdin>: Line " line ": " (message)
  5123. line-end)
  5124. (warning line-start
  5125. "asciidoctor: WARNING: <stdin>: Line " line ": " (message)
  5126. line-end))
  5127. :modes adoc-mode)
  5128. (flycheck-def-args-var flycheck-clang-args c/c++-clang
  5129. :package-version '(flycheck . "0.22"))
  5130. (flycheck-def-option-var flycheck-clang-blocks nil c/c++-clang
  5131. "Enable blocks in Clang.
  5132. When non-nil, enable blocks in Clang with `-fblocks'. See URL
  5133. `http://clang.llvm.org/docs/BlockLanguageSpec.html' for more
  5134. information about blocks."
  5135. :type 'boolean
  5136. :safe #'booleanp
  5137. :package-version '(flycheck . "0.20"))
  5138. (flycheck-def-option-var flycheck-clang-definitions nil c/c++-clang
  5139. "Additional preprocessor definitions for Clang.
  5140. The value of this variable is a list of strings, where each
  5141. string is an additional definition to pass to Clang, via the `-D'
  5142. option."
  5143. :type '(repeat (string :tag "Definition"))
  5144. :safe #'flycheck-string-list-p
  5145. :package-version '(flycheck . "0.15"))
  5146. (flycheck-def-option-var flycheck-clang-include-path nil c/c++-clang
  5147. "A list of include directories for Clang.
  5148. The value of this variable is a list of strings, where each
  5149. string is a directory to add to the include path of Clang.
  5150. Relative paths are relative to the file being checked."
  5151. :type '(repeat (directory :tag "Include directory"))
  5152. :safe #'flycheck-string-list-p
  5153. :package-version '(flycheck . "0.14"))
  5154. (flycheck-def-option-var flycheck-clang-includes nil c/c++-clang
  5155. "A list of additional include files for Clang.
  5156. The value of this variable is a list of strings, where each
  5157. string is a file to include before syntax checking. Relative
  5158. paths are relative to the file being checked."
  5159. :type '(repeat (file :tag "Include file"))
  5160. :safe #'flycheck-string-list-p
  5161. :package-version '(flycheck . "0.15"))
  5162. (flycheck-def-option-var flycheck-clang-language-standard nil c/c++-clang
  5163. "The language standard to use in Clang.
  5164. The value of this variable is either a string denoting a language
  5165. standard, or nil, to use the default standard. When non-nil,
  5166. pass the language standard via the `-std' option."
  5167. :type '(choice (const :tag "Default standard" nil)
  5168. (string :tag "Language standard"))
  5169. :safe #'stringp
  5170. :package-version '(flycheck . "0.15"))
  5171. (make-variable-buffer-local 'flycheck-clang-language-standard)
  5172. (flycheck-def-option-var flycheck-clang-ms-extensions nil c/c++-clang
  5173. "Whether to enable Microsoft extensions to C/C++ in Clang.
  5174. When non-nil, enable Microsoft extensions to C/C++ via
  5175. `-fms-extensions'."
  5176. :type 'boolean
  5177. :safe #'booleanp
  5178. :package-version '(flycheck . "0.16"))
  5179. (flycheck-def-option-var flycheck-clang-no-exceptions nil c/c++-clang
  5180. "Whether to disable exceptions in Clang.
  5181. When non-nil, disable exceptions for syntax checks, via
  5182. `-fno-exceptions'."
  5183. :type 'boolean
  5184. :safe #'booleanp
  5185. :package-version '(flycheck . "0.20"))
  5186. (flycheck-def-option-var flycheck-clang-no-rtti nil c/c++-clang
  5187. "Whether to disable RTTI in Clang.
  5188. When non-nil, disable RTTI for syntax checks, via `-fno-rtti'."
  5189. :type 'boolean
  5190. :safe #'booleanp
  5191. :package-version '(flycheck . "0.15"))
  5192. (flycheck-def-option-var flycheck-clang-pedantic nil c/c++-clang
  5193. "Whether to warn about language extensions in Clang.
  5194. For ISO C, follows the version specified by any -std option used.
  5195. When non-nil, disable non-ISO extensions to C/C++ via
  5196. `-pedantic'."
  5197. :type 'boolean
  5198. :safe #'booleanp
  5199. :package-version '(flycheck . "0.23"))
  5200. (flycheck-def-option-var flycheck-clang-pedantic-errors nil c/c++-clang
  5201. "Whether to error on language extensions in Clang.
  5202. For ISO C, follows the version specified by any -std option used.
  5203. When non-nil, disable non-ISO extensions to C/C++ via
  5204. `-pedantic-errors'."
  5205. :type 'boolean
  5206. :safe #'booleanp
  5207. :package-version '(flycheck . "0.23"))
  5208. (flycheck-def-option-var flycheck-clang-standard-library nil c/c++-clang
  5209. "The standard library to use for Clang.
  5210. The value of this variable is the name of a standard library as
  5211. string, or nil to use the default standard library.
  5212. Refer to the Clang manual at URL
  5213. `http://clang.llvm.org/docs/UsersManual.html' for more
  5214. information about the standard library."
  5215. :type '(choice (const "libc++")
  5216. (const :tag "GNU libstdc++" "libstdc++")
  5217. (string :tag "Library name"))
  5218. :safe #'stringp
  5219. :package-version '(flycheck . "0.15"))
  5220. (flycheck-def-option-var flycheck-clang-warnings '("all" "extra") c/c++-clang
  5221. "A list of additional warnings to enable in Clang.
  5222. The value of this variable is a list of strings, where each string
  5223. is the name of a warning category to enable. By default, all
  5224. recommended warnings and some extra warnings are enabled (as by
  5225. `-Wall' and `-Wextra' respectively).
  5226. Refer to the Clang manual at URL
  5227. `http://clang.llvm.org/docs/UsersManual.html' for more
  5228. information about warnings."
  5229. :type '(choice (const :tag "No additional warnings" nil)
  5230. (repeat :tag "Additional warnings"
  5231. (string :tag "Warning name")))
  5232. :safe #'flycheck-string-list-p
  5233. :package-version '(flycheck . "0.14"))
  5234. (defun flycheck-c/c++-quoted-include-directory ()
  5235. "Get the directory for quoted includes.
  5236. C/C++ compiles typicall look up includes with quotation marks in
  5237. the directory of the file being compiled. However, since
  5238. Flycheck uses temporary copies for syntax checking, it needs to
  5239. explicitly determine the directory for quoted includes.
  5240. This function determines the directory by looking at function
  5241. `buffer-file-name', or if that is nil, at `default-directory'."
  5242. (-if-let (fn (buffer-file-name))
  5243. (file-name-directory fn)
  5244. ;; If the buffer has no file name, fall back to its default directory
  5245. default-directory))
  5246. (flycheck-define-checker c/c++-clang
  5247. "A C/C++ syntax checker using Clang.
  5248. See URL `http://clang.llvm.org/'."
  5249. :command ("clang"
  5250. "-fsyntax-only"
  5251. "-fno-color-diagnostics" ; Do not include color codes in output
  5252. "-fno-caret-diagnostics" ; Do not visually indicate the source
  5253. ; location
  5254. "-fno-diagnostics-show-option" ; Do not show the corresponding
  5255. ; warning group
  5256. "-iquote" (eval (flycheck-c/c++-quoted-include-directory))
  5257. (option "-std=" flycheck-clang-language-standard concat)
  5258. (option-flag "-pedantic" flycheck-clang-pedantic)
  5259. (option-flag "-pedantic-errors" flycheck-clang-pedantic-errors)
  5260. (option "-stdlib=" flycheck-clang-standard-library concat)
  5261. (option-flag "-fms-extensions" flycheck-clang-ms-extensions)
  5262. (option-flag "-fno-exceptions" flycheck-clang-no-exceptions)
  5263. (option-flag "-fno-rtti" flycheck-clang-no-rtti)
  5264. (option-flag "-fblocks" flycheck-clang-blocks)
  5265. (option-list "-include" flycheck-clang-includes)
  5266. (option-list "-W" flycheck-clang-warnings concat)
  5267. (option-list "-D" flycheck-clang-definitions concat)
  5268. (option-list "-I" flycheck-clang-include-path)
  5269. (eval flycheck-clang-args)
  5270. "-x" (eval
  5271. (pcase major-mode
  5272. (`c++-mode "c++")
  5273. (`c-mode "c")))
  5274. ;; Read from standard input
  5275. "-")
  5276. :standard-input t
  5277. :error-patterns
  5278. ((error line-start
  5279. (message "In file included from") " " (or "<stdin>" (file-name))
  5280. ":" line ":" line-end)
  5281. (info line-start (or "<stdin>" (file-name)) ":" line ":" column
  5282. ": note: " (optional (message)) line-end)
  5283. (warning line-start (or "<stdin>" (file-name)) ":" line ":" column
  5284. ": warning: " (optional (message)) line-end)
  5285. (error line-start (or "<stdin>" (file-name)) ":" line ":" column
  5286. ": " (or "fatal error" "error") ": " (optional (message)) line-end))
  5287. :error-filter
  5288. (lambda (errors)
  5289. (let ((errors (flycheck-sanitize-errors errors)))
  5290. (dolist (err errors)
  5291. ;; Clang will output empty messages for #error/#warning pragmas without
  5292. ;; messages. We fill these empty errors with a dummy message to get
  5293. ;; them past our error filtering
  5294. (setf (flycheck-error-message err)
  5295. (or (flycheck-error-message err) "no message")))
  5296. (flycheck-fold-include-levels errors "In file included from")))
  5297. :modes (c-mode c++-mode)
  5298. :next-checkers ((warning . c/c++-cppcheck)))
  5299. (flycheck-def-args-var flycheck-gcc-args c/c++-gcc
  5300. :package-version '(flycheck . "0.22"))
  5301. (flycheck-def-option-var flycheck-gcc-definitions nil c/c++-gcc
  5302. "Additional preprocessor definitions for GCC.
  5303. The value of this variable is a list of strings, where each
  5304. string is an additional definition to pass to GCC, via the `-D'
  5305. option."
  5306. :type '(repeat (string :tag "Definition"))
  5307. :safe #'flycheck-string-list-p
  5308. :package-version '(flycheck . "0.20"))
  5309. (flycheck-def-option-var flycheck-gcc-include-path nil c/c++-gcc
  5310. "A list of include directories for GCC.
  5311. The value of this variable is a list of strings, where each
  5312. string is a directory to add to the include path of gcc.
  5313. Relative paths are relative to the file being checked."
  5314. :type '(repeat (directory :tag "Include directory"))
  5315. :safe #'flycheck-string-list-p
  5316. :package-version '(flycheck . "0.20"))
  5317. (flycheck-def-option-var flycheck-gcc-includes nil c/c++-gcc
  5318. "A list of additional include files for GCC.
  5319. The value of this variable is a list of strings, where each
  5320. string is a file to include before syntax checking. Relative
  5321. paths are relative to the file being checked."
  5322. :type '(repeat (file :tag "Include file"))
  5323. :safe #'flycheck-string-list-p
  5324. :package-version '(flycheck . "0.20"))
  5325. (flycheck-def-option-var flycheck-gcc-language-standard nil c/c++-gcc
  5326. "The language standard to use in GCC.
  5327. The value of this variable is either a string denoting a language
  5328. standard, or nil, to use the default standard. When non-nil,
  5329. pass the language standard via the `-std' option."
  5330. :type '(choice (const :tag "Default standard" nil)
  5331. (string :tag "Language standard"))
  5332. :safe #'stringp
  5333. :package-version '(flycheck . "0.20"))
  5334. (make-variable-buffer-local 'flycheck-gcc-language-standard)
  5335. (flycheck-def-option-var flycheck-gcc-no-exceptions nil c/c++-gcc
  5336. "Whether to disable exceptions in GCC.
  5337. When non-nil, disable exceptions for syntax checks, via
  5338. `-fno-exceptions'."
  5339. :type 'boolean
  5340. :safe #'booleanp
  5341. :package-version '(flycheck . "0.20"))
  5342. (flycheck-def-option-var flycheck-gcc-no-rtti nil c/c++-gcc
  5343. "Whether to disable RTTI in GCC.
  5344. When non-nil, disable RTTI for syntax checks, via `-fno-rtti'."
  5345. :type 'boolean
  5346. :safe #'booleanp
  5347. :package-version '(flycheck . "0.20"))
  5348. (flycheck-def-option-var flycheck-gcc-openmp nil c/c++-gcc
  5349. "Whether to enable OpenMP in GCC.
  5350. When non-nil, enable OpenMP for syntax checkers, via
  5351. `-fopenmp'."
  5352. :type 'boolean
  5353. :safe #'booleanp
  5354. :package-version '(flycheck . "0.21"))
  5355. (flycheck-def-option-var flycheck-gcc-pedantic nil c/c++-gcc
  5356. "Whether to warn about language extensions in GCC.
  5357. For ISO C, follows the version specified by any -std option used.
  5358. When non-nil, disable non-ISO extensions to C/C++ via
  5359. `-pedantic'."
  5360. :type 'boolean
  5361. :safe #'booleanp
  5362. :package-version '(flycheck . "0.23"))
  5363. (flycheck-def-option-var flycheck-gcc-pedantic-errors nil c/c++-gcc
  5364. "Whether to error on language extensions in GCC.
  5365. For ISO C, follows the version specified by any -std option used.
  5366. When non-nil, disable non-ISO extensions to C/C++ via
  5367. `-pedantic-errors'."
  5368. :type 'boolean
  5369. :safe #'booleanp
  5370. :package-version '(flycheck . "0.23"))
  5371. (flycheck-def-option-var flycheck-gcc-warnings '("all" "extra") c/c++-gcc
  5372. "A list of additional warnings to enable in GCC.
  5373. The value of this variable is a list of strings, where each string
  5374. is the name of a warning category to enable. By default, all
  5375. recommended warnings and some extra warnings are enabled (as by
  5376. `-Wall' and `-Wextra' respectively).
  5377. Refer to the gcc manual at URL
  5378. `https://gcc.gnu.org/onlinedocs/gcc/' for more information about
  5379. warnings."
  5380. :type '(choice (const :tag "No additional warnings" nil)
  5381. (repeat :tag "Additional warnings"
  5382. (string :tag "Warning name")))
  5383. :safe #'flycheck-string-list-p
  5384. :package-version '(flycheck . "0.20"))
  5385. (flycheck-define-checker c/c++-gcc
  5386. "A C/C++ syntax checker using GCC.
  5387. Requires GCC 4.4 or newer. See URL `https://gcc.gnu.org/'."
  5388. :command ("gcc"
  5389. "-fshow-column"
  5390. "-iquote" (eval (flycheck-c/c++-quoted-include-directory))
  5391. (option "-std=" flycheck-gcc-language-standard concat)
  5392. (option-flag "-pedantic" flycheck-gcc-pedantic)
  5393. (option-flag "-pedantic-errors" flycheck-gcc-pedantic-errors)
  5394. (option-flag "-fno-exceptions" flycheck-gcc-no-exceptions)
  5395. (option-flag "-fno-rtti" flycheck-gcc-no-rtti)
  5396. (option-flag "-fopenmp" flycheck-gcc-openmp)
  5397. (option-list "-include" flycheck-gcc-includes)
  5398. (option-list "-W" flycheck-gcc-warnings concat)
  5399. (option-list "-D" flycheck-gcc-definitions concat)
  5400. (option-list "-I" flycheck-gcc-include-path)
  5401. (eval flycheck-gcc-args)
  5402. "-x" (eval
  5403. (pcase major-mode
  5404. (`c++-mode "c++")
  5405. (`c-mode "c")))
  5406. ;; GCC performs full checking only when actually compiling, so
  5407. ;; `-fsyntax-only' is not enough. Just let it generate assembly
  5408. ;; code.
  5409. "-S" "-o" null-device
  5410. ;; Read from standard input
  5411. "-")
  5412. :standard-input t
  5413. :error-patterns
  5414. ((error line-start
  5415. (message "In file included from") " " (or "<stdin>" (file-name))
  5416. ":" line ":" column ":" line-end)
  5417. (info line-start (or "<stdin>" (file-name)) ":" line ":" column
  5418. ": note: " (message) line-end)
  5419. (warning line-start (or "<stdin>" (file-name)) ":" line ":" column
  5420. ": warning: " (message (one-or-more (not (any "\n["))))
  5421. (optional "[" (id (one-or-more not-newline)) "]") line-end)
  5422. (error line-start (or "<stdin>" (file-name)) ":" line ":" column
  5423. ": " (or "fatal error" "error") ": " (message) line-end))
  5424. :error-filter
  5425. (lambda (errors)
  5426. (flycheck-fold-include-levels (flycheck-sanitize-errors errors)
  5427. "In file included from"))
  5428. :modes (c-mode c++-mode)
  5429. :next-checkers ((warning . c/c++-cppcheck)))
  5430. (flycheck-def-option-var flycheck-cppcheck-checks '("style") c/c++-cppcheck
  5431. "Enabled checks for Cppcheck.
  5432. The value of this variable is a list of strings, where each
  5433. string is the name of an additional check to enable. By default,
  5434. all coding style checks are enabled.
  5435. See section \"Enable message\" in the Cppcheck manual at URL
  5436. `http://cppcheck.sourceforge.net/manual.pdf', and the
  5437. documentation of the `--enable' option for more information,
  5438. including a list of supported checks."
  5439. :type '(repeat :tag "Additional checks"
  5440. (string :tag "Check name"))
  5441. :safe #'flycheck-string-list-p
  5442. :package-version '(flycheck . "0.14"))
  5443. (flycheck-def-option-var flycheck-cppcheck-standards nil c/c++-cppcheck
  5444. "The standards to use in cppcheck.
  5445. The value of this variable is either a list of strings denoting
  5446. the standards to use, or nil to pass nothing to cppcheck. When
  5447. non-nil, pass the standards via one or more `--std=' options."
  5448. :type '(choice (const :tag "Default" nil)
  5449. (repeat :tag "Custom standards"
  5450. (string :tag "Standard name")))
  5451. :safe #'flycheck-string-list-p
  5452. :package-version '(flycheck . "28"))
  5453. (make-variable-buffer-local 'flycheck-cppcheck-standards)
  5454. (flycheck-def-option-var flycheck-cppcheck-suppressions nil c/c++-cppcheck
  5455. "The suppressions to use in cppcheck.
  5456. The value of this variable is either a list of strings denoting
  5457. the suppressions to use, or nil to pass nothing to cppcheck.
  5458. When non-nil, pass the suppressions via one or more `--suppress='
  5459. options."
  5460. :type '(choice (const :tag "Default" nil)
  5461. (repeat :tag "Additional suppressions"
  5462. (string :tag "Suppression")))
  5463. :safe #'flycheck-string-list-p
  5464. :package-version '(flycheck . "28"))
  5465. (flycheck-def-option-var flycheck-cppcheck-inconclusive nil c/c++-cppcheck
  5466. "Whether to enable Cppcheck inconclusive checks.
  5467. When non-nil, enable Cppcheck inconclusive checks. This allows Cppcheck to
  5468. report warnings it's not certain of, but it may result in false positives.
  5469. This will have no effect when using Cppcheck 1.53 and older."
  5470. :type 'boolean
  5471. :safe #'booleanp
  5472. :package-version '(flycheck . "0.19"))
  5473. (flycheck-def-option-var flycheck-cppcheck-include-path nil c/c++-cppcheck
  5474. "A list of include directories for cppcheck.
  5475. The value of this variable is a list of strings, where each
  5476. string is a directory to add to the include path of cppcheck.
  5477. Relative paths are relative to the file being checked."
  5478. :type '(repeat (directory :tag "Include directory"))
  5479. :safe #'flycheck-string-list-p
  5480. :package-version '(flycheck . "0.24"))
  5481. (flycheck-define-checker c/c++-cppcheck
  5482. "A C/C++ checker using cppcheck.
  5483. See URL `http://cppcheck.sourceforge.net/'."
  5484. :command ("cppcheck" "--quiet" "--xml-version=2" "--inline-suppr"
  5485. (option "--enable=" flycheck-cppcheck-checks concat
  5486. flycheck-option-comma-separated-list)
  5487. (option-flag "--inconclusive" flycheck-cppcheck-inconclusive)
  5488. (option-list "-I" flycheck-cppcheck-include-path)
  5489. (option-list "--std=" flycheck-cppcheck-standards concat)
  5490. (option-list "--suppress=" flycheck-cppcheck-suppressions concat)
  5491. "-x" (eval
  5492. (pcase major-mode
  5493. (`c++-mode "c++")
  5494. (`c-mode "c")))
  5495. source)
  5496. :error-parser flycheck-parse-cppcheck
  5497. :modes (c-mode c++-mode))
  5498. (flycheck-define-checker cfengine
  5499. "A CFEngine syntax checker using cf-promises.
  5500. See URL `https://cfengine.com/'."
  5501. :command ("cf-promises" "-Wall" "-f"
  5502. ;; We must stay in the same directory to resolve @include
  5503. source-inplace)
  5504. :error-patterns
  5505. ((warning line-start (file-name) ":" line ":" column
  5506. ": warning: " (message) line-end)
  5507. (error line-start (file-name) ":" line ":" column
  5508. ": error: " (message) line-end))
  5509. :modes (cfengine-mode cfengine3-mode))
  5510. (flycheck-def-option-var flycheck-foodcritic-tags nil chef-foodcritic
  5511. "A list of tags to select for Foodcritic.
  5512. The value of this variable is a list of strings where each string
  5513. is a tag expression describing Foodcritic rules to enable or
  5514. disable, via the `--tags' option. To disable a tag, prefix it
  5515. with `~'."
  5516. :type '(repeat :tag "Tags" (string :tag "Tag expression"))
  5517. :safe #'flycheck-string-list-p
  5518. :package-version '(flycheck . "0.23"))
  5519. (flycheck-define-checker chef-foodcritic
  5520. "A Chef cookbooks syntax checker using Foodcritic.
  5521. See URL `http://www.foodcritic.io'."
  5522. ;; Use `source-inplace' to allow resource discovery with relative paths.
  5523. ;; foodcritic interprets these as relative to the source file, so we need to
  5524. ;; stay within the source tree. See
  5525. ;; https://github.com/flycheck/flycheck/pull/556
  5526. :command ("foodcritic"
  5527. (option-list "--tags" flycheck-foodcritic-tags)
  5528. source-inplace)
  5529. :error-patterns
  5530. ((error line-start (message) ": " (file-name) ":" line line-end))
  5531. :modes (enh-ruby-mode ruby-mode)
  5532. :predicate
  5533. (lambda ()
  5534. (let ((parent-dir (file-name-directory
  5535. (directory-file-name
  5536. (expand-file-name default-directory)))))
  5537. (or
  5538. ;; Chef CookBook
  5539. ;; http://docs.opscode.com/chef/knife.html#id38
  5540. (locate-dominating-file parent-dir "recipes")
  5541. ;; Knife Solo
  5542. ;; http://matschaffer.github.io/knife-solo/#label-Init+command
  5543. (locate-dominating-file parent-dir "cookbooks")))))
  5544. (flycheck-define-checker coffee
  5545. "A CoffeeScript syntax checker using coffee.
  5546. See URL `http://coffeescript.org/'."
  5547. ;; --print suppresses generation of compiled .js files
  5548. :command ("coffee" "--compile" "--print" "--stdio")
  5549. :standard-input t
  5550. :error-patterns
  5551. ((error line-start "[stdin]:" line ":" column
  5552. ": error: " (message) line-end))
  5553. :modes coffee-mode
  5554. :next-checkers ((warning . coffee-coffeelint)))
  5555. (flycheck-def-config-file-var flycheck-coffeelintrc coffee-coffeelint
  5556. ".coffeelint.json"
  5557. :safe #'stringp)
  5558. (flycheck-define-checker coffee-coffeelint
  5559. "A CoffeeScript style checker using coffeelint.
  5560. See URL `http://www.coffeelint.org/'."
  5561. :command
  5562. ("coffeelint"
  5563. (config-file "--file" flycheck-coffeelintrc)
  5564. "--stdin" "--reporter" "checkstyle")
  5565. :standard-input t
  5566. :error-parser flycheck-parse-checkstyle
  5567. :error-filter (lambda (errors)
  5568. (flycheck-remove-error-file-names
  5569. "stdin" (flycheck-remove-error-ids
  5570. (flycheck-sanitize-errors errors))))
  5571. :modes coffee-mode)
  5572. (flycheck-define-checker coq
  5573. "A Coq syntax checker using the Coq compiler.
  5574. See URL `https://coq.inria.fr/'."
  5575. ;; We use coqtop in batch mode, because coqc is picky about file names.
  5576. :command ("coqtop" "-batch" "-load-vernac-source" source)
  5577. :error-patterns
  5578. ((error line-start "File \"" (file-name) "\", line " line
  5579. ;; TODO: Parse the end column, once Flycheck supports that
  5580. ", characters " column "-" (one-or-more digit) ":\n"
  5581. (or "Syntax error:" "Error:")
  5582. ;; Most Coq error messages span multiple lines, and end with a dot.
  5583. ;; There are simple one-line messages, too, though.
  5584. (message (or (and (one-or-more (or not-newline "\n")) ".")
  5585. (one-or-more not-newline)))
  5586. line-end))
  5587. :error-filter
  5588. (lambda (errors)
  5589. (dolist (err (flycheck-sanitize-errors errors))
  5590. (setf (flycheck-error-message err)
  5591. (replace-regexp-in-string (rx (1+ (syntax whitespace)) line-end)
  5592. "" (flycheck-error-message err)
  5593. 'fixedcase 'literal)))
  5594. (flycheck-increment-error-columns errors))
  5595. :modes coq-mode)
  5596. (flycheck-define-checker css-csslint
  5597. "A CSS syntax and style checker using csslint.
  5598. See URL `https://github.com/CSSLint/csslint'."
  5599. :command ("csslint" "--format=checkstyle-xml" source)
  5600. :error-parser flycheck-parse-checkstyle
  5601. :error-filter flycheck-dequalify-error-ids
  5602. :modes css-mode)
  5603. (defconst flycheck-stylelint-args '("--formatter" "json")
  5604. "Common arguments to stylelint invocations.")
  5605. (flycheck-def-config-file-var flycheck-stylelintrc
  5606. (css-stylelint scss-stylelint less-stylelint) nil
  5607. :safe #'stringp)
  5608. (flycheck-def-option-var flycheck-stylelint-quiet
  5609. nil (css-stylelint scss-stylelint less-stylelint)
  5610. "Whether to run stylelint in quiet mode.
  5611. When non-nil, enable quiet mode, via `--quiet'."
  5612. :type 'boolean
  5613. :safe #'booleanp
  5614. :package-version '(flycheck . 26))
  5615. (defconst flycheck-stylelint-error-re
  5616. (flycheck-rx-to-string
  5617. '(: line-start (id (one-or-more word)) ": " (message) line-end)))
  5618. (defun flycheck-parse-stylelint (output checker buffer)
  5619. "Parse stylelint errors from OUTPUT.
  5620. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  5621. the BUFFER that was checked respectively.
  5622. The CHECKER usually returns the errors as JSON.
  5623. If the CHECKER throws an Error it returns an Error message with a stacktrace."
  5624. (condition-case nil
  5625. (flycheck-parse-stylelint-json output checker buffer)
  5626. ;; The output could not be parsed as JSON
  5627. (json-error
  5628. ;; Extract a flycheck error from the output (with a regular expression)
  5629. ;; For match-string 4/5 see flycheck-rx-message/flycheck-rx-id
  5630. (when (string-match flycheck-stylelint-error-re output)
  5631. (list (flycheck-error-new-at
  5632. 1 nil 'error
  5633. (match-string 4 output)
  5634. :id (match-string 5 output)
  5635. :checker checker
  5636. :buffer buffer
  5637. :filename (buffer-file-name buffer)))))))
  5638. (defun flycheck-parse-stylelint-json (output checker buffer)
  5639. "Parse stylelint JSON errors from OUTPUT.
  5640. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  5641. the BUFFER that was checked respectively.
  5642. See URL `http://stylelint.io/developer-guide/formatters/' for information
  5643. about the JSON format of stylelint."
  5644. (let ((json-object-type 'plist))
  5645. ;; stylelint returns a vector of result objects
  5646. ;; Since we only passed one file, the first element is enough
  5647. (let* ((stylelint-output (elt (json-read-from-string output) 0))
  5648. (filename (buffer-file-name buffer))
  5649. ;; Turn all deprecations into warnings
  5650. (deprecations
  5651. (mapcar (lambda (d)
  5652. (flycheck-error-new-at
  5653. 1 nil 'warning
  5654. (plist-get d :text)
  5655. :id "Deprecation Warning"
  5656. :checker checker
  5657. :buffer buffer
  5658. :filename filename))
  5659. (plist-get stylelint-output :deprecations)))
  5660. ;; Turn all invalid options into errors
  5661. (invalid-options
  5662. (mapcar (lambda (io)
  5663. (flycheck-error-new-at
  5664. 1 nil 'error
  5665. (plist-get io :text)
  5666. :id "Invalid Option"
  5667. :checker checker
  5668. :buffer buffer
  5669. :filename filename))
  5670. (plist-get stylelint-output :invalidOptionWarnings)))
  5671. ;; Read all linting warnings
  5672. (warnings
  5673. (mapcar (lambda (w)
  5674. (flycheck-error-new-at
  5675. (plist-get w :line) (plist-get w :column)
  5676. (pcase (plist-get w :severity)
  5677. (`"error" 'error)
  5678. (`"warning" 'warning)
  5679. ;; Default to info for unknown .severity
  5680. (_ 'info))
  5681. (plist-get w :text)
  5682. :id (plist-get w :rule)
  5683. :checker checker
  5684. :buffer buffer
  5685. :filename filename))
  5686. (plist-get stylelint-output :warnings))))
  5687. ;; Return the combined errors (deprecations, invalid options, warnings)
  5688. (append deprecations invalid-options warnings))))
  5689. (flycheck-define-checker css-stylelint
  5690. "A CSS syntax and style checker using stylelint.
  5691. See URL `http://stylelint.io/'."
  5692. :command ("stylelint"
  5693. (eval flycheck-stylelint-args)
  5694. (option-flag "--quiet" flycheck-stylelint-quiet)
  5695. (config-file "--config" flycheck-stylelintrc))
  5696. :standard-input t
  5697. :error-parser flycheck-parse-stylelint
  5698. :modes (css-mode))
  5699. (defconst flycheck-d-module-re
  5700. (rx "module" (one-or-more (syntax whitespace))
  5701. (group (one-or-more (not (syntax whitespace))))
  5702. (zero-or-more (syntax whitespace))
  5703. ";")
  5704. "Regular expression to match a D module declaration.")
  5705. (defun flycheck-d-base-directory ()
  5706. "Get the relative base directory path for this module."
  5707. (let* ((file-name (buffer-file-name))
  5708. (module-file (if (string= (file-name-nondirectory file-name)
  5709. "package.d")
  5710. (directory-file-name (file-name-directory file-name))
  5711. file-name)))
  5712. (flycheck-module-root-directory
  5713. (flycheck-find-in-buffer flycheck-d-module-re)
  5714. module-file)))
  5715. (flycheck-def-option-var flycheck-dmd-include-path nil d-dmd
  5716. "A list of include directories for dmd.
  5717. The value of this variable is a list of strings, where each
  5718. string is a directory to add to the include path of dmd.
  5719. Relative paths are relative to the file being checked."
  5720. :type '(repeat (directory :tag "Include directory"))
  5721. :safe #'flycheck-string-list-p
  5722. :package-version '(flycheck . "0.18"))
  5723. (flycheck-def-args-var flycheck-dmd-args d-dmd
  5724. :package-version '(flycheck . "0.24"))
  5725. (flycheck-define-checker d-dmd
  5726. "A D syntax checker using the DMD compiler.
  5727. Requires DMD 2.066 or newer. See URL `http://dlang.org/'."
  5728. :command ("dmd"
  5729. "-debug" ; Compile in debug mode
  5730. "-o-" ; Don't generate an object file
  5731. "-vcolumns" ; Add columns in output
  5732. "-wi" ; Compilation will continue even if there are warnings
  5733. (eval (concat "-I" (flycheck-d-base-directory)))
  5734. (option-list "-I" flycheck-dmd-include-path concat)
  5735. (eval flycheck-dmd-args)
  5736. source)
  5737. :error-patterns
  5738. ((error line-start
  5739. (file-name) "(" line "," column "): Error: " (message)
  5740. line-end)
  5741. (warning line-start (file-name) "(" line "," column "): "
  5742. (or "Warning" "Deprecation") ": " (message) line-end)
  5743. (info line-start (file-name) "(" line "," column "): "
  5744. (one-or-more " ") (message) line-end))
  5745. :modes d-mode)
  5746. (flycheck-define-checker dockerfile-hadolint
  5747. "A Dockerfile syntax checker using the hadolint.
  5748. See URL `http://hadolint.lukasmartinelli.ch/'."
  5749. :command ("hadolint" "-")
  5750. :standard-input t
  5751. :error-patterns
  5752. ((error line-start
  5753. (file-name) ":" line ":" column " " (message)
  5754. line-end)
  5755. (warning line-start
  5756. (file-name) ":" line " " (id (one-or-more alnum)) " " (message)
  5757. line-end))
  5758. :error-filter
  5759. (lambda (errors)
  5760. (flycheck-sanitize-errors
  5761. (flycheck-remove-error-file-names "/dev/stdin" errors)))
  5762. :modes dockerfile-mode)
  5763. (defun flycheck-elixir--find-default-directory (_checker)
  5764. "Come up with a suitable default directory to run CHECKER in.
  5765. This will either be the directory that contains `mix.exs' or,
  5766. if no such file is found in the directory hierarchy, the directory
  5767. of the current file."
  5768. (or
  5769. (and
  5770. buffer-file-name
  5771. (locate-dominating-file buffer-file-name "mix.exs"))
  5772. default-directory))
  5773. (defun flycheck-elixir--parse-dogma-json (output checker buffer)
  5774. "Parse Dogma errors from JSON OUTPUT.
  5775. CHECKER and BUFFER denote the CHECKER that returned OUTPUT and
  5776. the BUFFER that was checked respectively.
  5777. See URL `https://github.com/lpil/dogma' for more information
  5778. about dogma."
  5779. (let* ((json-object-type 'alist)
  5780. (json-array-type 'list)
  5781. (dogma-json-output
  5782. (car (cdr (assq 'files (json-read-from-string output)))))
  5783. (dogma-errors-list (cdr (assq 'errors dogma-json-output)))
  5784. (dogma-filename (cdr (assq 'path dogma-json-output)))
  5785. errors)
  5786. (dolist (emessage dogma-errors-list)
  5787. (let-alist emessage
  5788. (push (flycheck-error-new-at
  5789. .line
  5790. 1
  5791. 'error .message
  5792. :id .rule
  5793. :checker checker
  5794. :buffer buffer
  5795. :filename dogma-filename)
  5796. errors)))
  5797. (nreverse errors)))
  5798. (defun flycheck-elixir--check-for-dogma ()
  5799. "Check if `dogma' is installed.
  5800. Check by looking for deps/dogma in this directory or a parent to
  5801. handle umbrella apps.
  5802. Used as a predicate for enabling the checker."
  5803. (and buffer-file-name
  5804. (locate-dominating-file buffer-file-name "deps/dogma")))
  5805. (flycheck-define-checker elixir-dogma
  5806. "An Elixir syntax checker using the Dogma analysis tool.
  5807. See URL `https://github.com/lpil/dogma/'."
  5808. :command ("mix" "dogma" "--format=json" source)
  5809. :error-parser flycheck-elixir--parse-dogma-json
  5810. :working-directory flycheck-elixir--find-default-directory
  5811. :predicate flycheck-elixir--check-for-dogma
  5812. :modes elixir-mode)
  5813. (defconst flycheck-this-emacs-executable
  5814. (concat invocation-directory invocation-name)
  5815. "The path to the currently running Emacs executable.")
  5816. (defconst flycheck-emacs-args '("-Q" "--batch")
  5817. "Common arguments to Emacs invocations.")
  5818. (defmacro flycheck-prepare-emacs-lisp-form (&rest body)
  5819. "Prepare BODY for use as check form in a subprocess."
  5820. (declare (indent 0))
  5821. `(flycheck-sexp-to-string
  5822. '(progn
  5823. (defvar jka-compr-inhibit)
  5824. (unwind-protect
  5825. ;; Flycheck inhibits compression of temporary files, thus we
  5826. ;; must not attempt to decompress.
  5827. (let ((jka-compr-inhibit t))
  5828. ;; Strip option-argument separator from arguments, if present
  5829. (when (equal (car command-line-args-left) "--")
  5830. (setq command-line-args-left (cdr command-line-args-left)))
  5831. ,@body)
  5832. ;; Prevent Emacs from processing the arguments on its own, see
  5833. ;; https://github.com/flycheck/flycheck/issues/319
  5834. (setq command-line-args-left nil)))))
  5835. (defconst flycheck-emacs-lisp-check-form
  5836. (flycheck-prepare-emacs-lisp-form
  5837. ;; Keep track of the generated bytecode files, to delete them after byte
  5838. ;; compilation.
  5839. (defvar flycheck-byte-compiled-files nil)
  5840. (let ((byte-compile-dest-file-function
  5841. (lambda (source)
  5842. (let ((temp-file (make-temp-file (file-name-nondirectory source))))
  5843. (push temp-file flycheck-byte-compiled-files)
  5844. temp-file))))
  5845. (unwind-protect
  5846. (byte-compile-file (car command-line-args-left))
  5847. (mapc (lambda (f) (ignore-errors (delete-file f)))
  5848. flycheck-byte-compiled-files))
  5849. (when (bound-and-true-p flycheck-emacs-lisp-check-declare)
  5850. (check-declare-file (car command-line-args-left))))))
  5851. (flycheck-def-option-var flycheck-emacs-lisp-load-path nil emacs-lisp
  5852. "Load path to use in the Emacs Lisp syntax checker.
  5853. When set to `inherit', use the `load-path' of the current Emacs
  5854. session during syntax checking.
  5855. When set to a list of strings, add each directory in this list to
  5856. the `load-path' before invoking the byte compiler. Relative
  5857. paths in this list are expanded against the `default-directory'
  5858. of the buffer to check.
  5859. When nil, do not explicitly set the `load-path' during syntax
  5860. checking. The syntax check only uses the built-in `load-path' of
  5861. Emacs in this case.
  5862. Note that changing this variable can lead to wrong results of the
  5863. syntax check, e.g. if an unexpected version of a required library
  5864. is used."
  5865. :type '(choice (const :tag "Inherit current `load-path'" inherit)
  5866. (repeat :tag "Load path" directory))
  5867. :risky t
  5868. :package-version '(flycheck . "0.14"))
  5869. (flycheck-def-option-var flycheck-emacs-lisp-initialize-packages
  5870. 'auto emacs-lisp
  5871. "Whether to initialize packages in the Emacs Lisp syntax checker.
  5872. When nil, never initialize packages. When `auto', initialize
  5873. packages only when checking `user-init-file' or files from
  5874. `user-emacs-directory'. For any other non-nil value, always
  5875. initialize packages.
  5876. When initializing packages is enabled the `emacs-lisp' syntax
  5877. checker calls `package-initialize' before byte-compiling the file
  5878. to be checked. It also sets `package-user-dir' according to
  5879. `flycheck-emacs-lisp-package-user-dir'."
  5880. :type '(choice (const :tag "Do not initialize packages" nil)
  5881. (const :tag "Initialize packages for configuration only" auto)
  5882. (const :tag "Always initialize packages" t))
  5883. :risky t
  5884. :package-version '(flycheck . "0.14"))
  5885. (defconst flycheck-emacs-lisp-package-initialize-form
  5886. (flycheck-sexp-to-string
  5887. '(with-demoted-errors "Error during package initialization: %S"
  5888. (package-initialize)))
  5889. "Form used to initialize packages.")
  5890. (defun flycheck-option-emacs-lisp-package-initialize (value)
  5891. "Option VALUE filter for `flycheck-emacs-lisp-initialize-packages'."
  5892. (let ((shall-initialize
  5893. (if (eq value 'auto)
  5894. (or (flycheck-in-user-emacs-directory-p (buffer-file-name))
  5895. ;; `user-init-file' is nil in non-interactive sessions. Now,
  5896. ;; no user would possibly use Flycheck in a non-interactive
  5897. ;; session, but our unit tests run non-interactively, so we
  5898. ;; have to handle this case anyway
  5899. (and user-init-file
  5900. (flycheck-same-files-p (buffer-file-name)
  5901. user-init-file)))
  5902. value)))
  5903. (when shall-initialize
  5904. ;; If packages shall be initialized, return the corresponding form,
  5905. ;; otherwise make Flycheck ignore the option by returning nil.
  5906. flycheck-emacs-lisp-package-initialize-form)))
  5907. (flycheck-def-option-var flycheck-emacs-lisp-package-user-dir nil emacs-lisp
  5908. "Package directory for the Emacs Lisp syntax checker.
  5909. If set to a string set `package-user-dir' to the value of this
  5910. variable before initializing packages. If set to nil just inherit
  5911. the value of `package-user-dir' from the running Emacs session.
  5912. This variable has no effect, if
  5913. `flycheck-emacs-lisp-initialize-packages' is nil."
  5914. :type '(choice (const :tag "Default package directory" nil)
  5915. (directory :tag "Custom package directory"))
  5916. :risky t
  5917. :package-version '(flycheck . "0.14"))
  5918. (defun flycheck-option-emacs-lisp-package-user-dir (value)
  5919. "Option VALUE filter for `flycheck-emacs-lisp-package-user-dir'."
  5920. ;; Inherit the package directory from our Emacs session
  5921. (let ((value (or value (bound-and-true-p package-user-dir))))
  5922. (when value
  5923. (flycheck-sexp-to-string `(setq package-user-dir ,value)))))
  5924. (flycheck-def-option-var flycheck-emacs-lisp-check-declare nil emacs-lisp
  5925. "If non-nil, check ‘declare-function’ forms using ‘check-declare-file’."
  5926. :type '(choice (const :tag "Do not check declare forms" nil)
  5927. (const :tag "Check declare forms" t))
  5928. :risky t
  5929. :package-version '(flycheck . "31"))
  5930. (defun flycheck-option-emacs-lisp-check-declare (value)
  5931. "Option VALUE filter for `flycheck-emacs-lisp-check-declare'."
  5932. (when value
  5933. (flycheck-sexp-to-string
  5934. `(progn
  5935. (defvar flycheck-emacs-lisp-check-declare)
  5936. (setq flycheck-emacs-lisp-check-declare ,value)))))
  5937. (flycheck-define-checker emacs-lisp
  5938. "An Emacs Lisp syntax checker using the Emacs Lisp Byte compiler.
  5939. See Info Node `(elisp)Byte Compilation'."
  5940. :command ("emacs" (eval flycheck-emacs-args)
  5941. (eval
  5942. (let ((path (pcase flycheck-emacs-lisp-load-path
  5943. (`inherit load-path)
  5944. (p (seq-map #'expand-file-name p)))))
  5945. (flycheck-prepend-with-option "--directory" path)))
  5946. (option "--eval" flycheck-emacs-lisp-package-user-dir nil
  5947. flycheck-option-emacs-lisp-package-user-dir)
  5948. (option "--eval" flycheck-emacs-lisp-initialize-packages nil
  5949. flycheck-option-emacs-lisp-package-initialize)
  5950. (option "--eval" flycheck-emacs-lisp-check-declare nil
  5951. flycheck-option-emacs-lisp-check-declare)
  5952. "--eval" (eval flycheck-emacs-lisp-check-form)
  5953. "--"
  5954. source-inplace)
  5955. :error-patterns
  5956. ((error line-start (file-name) ":" line ":" column ":Error:"
  5957. (message (zero-or-more not-newline)
  5958. (zero-or-more "\n " (zero-or-more not-newline)))
  5959. line-end)
  5960. (warning line-start (file-name) ":" line ":" column ":Warning:"
  5961. (message (zero-or-more not-newline)
  5962. (zero-or-more "\n " (zero-or-more not-newline)))
  5963. line-end)
  5964. (warning line-start (file-name) ":" line ":" column
  5965. ":Warning (check-declare): said\n"
  5966. (message (zero-or-more " " (zero-or-more not-newline))
  5967. (zero-or-more "\n " (zero-or-more not-newline)))
  5968. line-end)
  5969. ;; The following is for Emacs 24 ‘check-declare-file’, which uses a
  5970. ;; less informative format.
  5971. (warning line-start "Warning (check-declare): " (file-name) " said "
  5972. (message (zero-or-more not-newline))
  5973. line-end))
  5974. :error-filter
  5975. (lambda (errors)
  5976. (flycheck-fill-empty-line-numbers
  5977. (flycheck-collapse-error-message-whitespace
  5978. (flycheck-sanitize-errors errors))))
  5979. :modes (emacs-lisp-mode lisp-interaction-mode)
  5980. :predicate
  5981. (lambda ()
  5982. (and
  5983. ;; Ensure that we only check buffers with a backing file. For buffers
  5984. ;; without a backing file we cannot guarantee that file names in error
  5985. ;; messages are properly resolved, because `byte-compile-file' emits file
  5986. ;; names *relative to the directory of the checked file* instead of the
  5987. ;; working directory. Hence our backwards-substitution will fail, because
  5988. ;; the checker process has a different base directory to resolve relative
  5989. ;; file names than the Flycheck code working on the buffer to check.
  5990. (buffer-file-name)
  5991. ;; Do not check buffers which should not be byte-compiled. The checker
  5992. ;; process will refuse to compile these, which would confuse Flycheck
  5993. (not (bound-and-true-p no-byte-compile))
  5994. ;; Do not check buffers used for autoloads generation during package
  5995. ;; installation. These buffers are too short-lived for being checked, and
  5996. ;; doing so causes spurious errors. See
  5997. ;; https://github.com/flycheck/flycheck/issues/45 and
  5998. ;; https://github.com/bbatsov/prelude/issues/248. We must also not check
  5999. ;; compilation buffers, but as these are ephemeral, Flycheck won't check
  6000. ;; them anyway.
  6001. (not (flycheck-autoloads-file-p))))
  6002. :next-checkers (emacs-lisp-checkdoc))
  6003. (defconst flycheck-emacs-lisp-checkdoc-form
  6004. (flycheck-prepare-emacs-lisp-form
  6005. (unless (require 'elisp-mode nil 'no-error)
  6006. ;; TODO: Fallback for Emacs 24, remove when dropping support for 24
  6007. (require 'lisp-mode))
  6008. (require 'checkdoc)
  6009. (let ((source (car command-line-args-left))
  6010. ;; Remember the default directory of the process
  6011. (process-default-directory default-directory))
  6012. ;; Note that we deliberately use our custom approach even despite of
  6013. ;; `checkdoc-file' which was added to Emacs 25.1. While it's conceptually
  6014. ;; the better thing, its implementation has too many flaws to be of use
  6015. ;; for us.
  6016. (with-temp-buffer
  6017. (insert-file-contents source 'visit)
  6018. (setq buffer-file-name source)
  6019. ;; And change back to the process default directory to make file-name
  6020. ;; back-substutition work
  6021. (setq default-directory process-default-directory)
  6022. (with-demoted-errors "Error in checkdoc: %S"
  6023. ;; Checkdoc needs the Emacs Lisp syntax table and comment syntax to
  6024. ;; parse sexps and identify docstrings correctly; see
  6025. ;; https://github.com/flycheck/flycheck/issues/833
  6026. (delay-mode-hooks (emacs-lisp-mode))
  6027. (setq delayed-mode-hooks nil)
  6028. (checkdoc-current-buffer t)
  6029. (with-current-buffer checkdoc-diagnostic-buffer
  6030. (princ (buffer-substring-no-properties (point-min) (point-max)))
  6031. (kill-buffer)))))))
  6032. (defconst flycheck-emacs-lisp-checkdoc-variables
  6033. '(checkdoc-symbol-words
  6034. checkdoc-arguments-in-order-flag
  6035. checkdoc-force-history-flag
  6036. checkdoc-permit-comma-termination-flag
  6037. checkdoc-force-docstrings-flag
  6038. checkdoc-package-keywords-flag
  6039. checkdoc-spellcheck-documentation-flag
  6040. checkdoc-verb-check-experimental-flag
  6041. checkdoc-max-keyref-before-warn
  6042. sentence-end-double-space)
  6043. "Variables inherited by the checkdoc subprocess.")
  6044. (defun flycheck-emacs-lisp-checkdoc-variables-form ()
  6045. "Make a sexp to pass relevant variables to a checkdoc subprocess.
  6046. Variables are taken from `flycheck-emacs-lisp-checkdoc-variables'."
  6047. `(progn
  6048. ,@(seq-map (lambda (opt) `(setq-default ,opt ,(symbol-value opt)))
  6049. (seq-filter #'boundp flycheck-emacs-lisp-checkdoc-variables))))
  6050. (flycheck-define-checker emacs-lisp-checkdoc
  6051. "An Emacs Lisp style checker using CheckDoc.
  6052. The checker runs `checkdoc-current-buffer'."
  6053. :command ("emacs" (eval flycheck-emacs-args)
  6054. "--eval" (eval (flycheck-sexp-to-string
  6055. (flycheck-emacs-lisp-checkdoc-variables-form)))
  6056. "--eval" (eval flycheck-emacs-lisp-checkdoc-form)
  6057. "--" source)
  6058. :error-patterns
  6059. ((warning line-start (file-name) ":" line ": " (message) line-end))
  6060. :modes (emacs-lisp-mode)
  6061. :predicate
  6062. (lambda ()
  6063. ;; Do not check Autoloads, Cask/Carton and dir-locals files. These files
  6064. ;; really don't need to follow Checkdoc conventions.
  6065. (not (or (flycheck-autoloads-file-p)
  6066. (and (buffer-file-name)
  6067. (member (file-name-nondirectory (buffer-file-name))
  6068. '("Cask" "Carton" ".dir-locals.el")))))))
  6069. (dolist (checker '(emacs-lisp emacs-lisp-checkdoc))
  6070. (setf (car (flycheck-checker-get checker 'command))
  6071. flycheck-this-emacs-executable))
  6072. (flycheck-def-option-var flycheck-erlang-include-path nil erlang
  6073. "A list of include directories for Erlang.
  6074. The value of this variable is a list of strings, where each
  6075. string is a directory to add to the include path of erlc.
  6076. Relative paths are relative to the file being checked."
  6077. :type '(repeat (directory :tag "Include directory"))
  6078. :safe #'flycheck-string-list-p
  6079. :package-version '(flycheck . "0.24"))
  6080. (flycheck-def-option-var flycheck-erlang-library-path nil erlang
  6081. "A list of library directories for Erlang.
  6082. The value of this variable is a list of strings, where each
  6083. string is a directory to add to the library path of erlc.
  6084. Relative paths are relative to the file being checked."
  6085. :type '(repeat (directory :tag "Library directory"))
  6086. :safe #'flycheck-string-list-p
  6087. :package-version '(flycheck . "0.24"))
  6088. (flycheck-define-checker erlang
  6089. "An Erlang syntax checker using the Erlang interpreter.
  6090. See URL `http://www.erlang.org/'."
  6091. :command ("erlc"
  6092. "-o" temporary-directory
  6093. (option-list "-I" flycheck-erlang-include-path)
  6094. (option-list "-pa" flycheck-erlang-library-path)
  6095. "-Wall"
  6096. source)
  6097. :error-patterns
  6098. ((warning line-start (file-name) ":" line ": Warning:" (message) line-end)
  6099. (error line-start (file-name) ":" line ": " (message) line-end))
  6100. :modes erlang-mode
  6101. :enabled (lambda () (string-suffix-p ".erl" (buffer-file-name))))
  6102. (defun contains-rebar-config (dir-name)
  6103. "Return DIR-NAME if DIR-NAME/rebar.config exists, nil otherwise."
  6104. (when (file-exists-p (expand-file-name "rebar.config" dir-name))
  6105. dir-name))
  6106. (defun locate-rebar3-project-root (file-name &optional prev-file-name acc)
  6107. "Find the top-most rebar project root for source FILE-NAME.
  6108. A project root directory is any directory containing a
  6109. rebar.config file. Find the top-most directory to move out of any
  6110. nested dependencies.
  6111. FILE-NAME is a source file for which to find the project.
  6112. PREV-FILE-NAME helps us prevent infinite looping
  6113. ACC is an accumulator that keeps the list of results, the first
  6114. non-nil of which will be our project root.
  6115. Return the absolute path to the directory"
  6116. (if (string= file-name prev-file-name)
  6117. (car (remove nil acc))
  6118. (let ((current-dir (file-name-directory file-name)))
  6119. (locate-rebar3-project-root
  6120. (directory-file-name current-dir)
  6121. file-name
  6122. (cons (contains-rebar-config current-dir) acc)))))
  6123. (defun flycheck-rebar3-project-root (&optional _checker)
  6124. "Return directory where rebar.config is located."
  6125. (locate-rebar3-project-root buffer-file-name))
  6126. (flycheck-define-checker erlang-rebar3
  6127. "An Erlang syntax checker using the rebar3 build tool."
  6128. :command ("rebar3" "compile")
  6129. :error-parser
  6130. (lambda (output checker buffer)
  6131. ;; rebar3 outputs ANSI terminal colors, which don't match up with
  6132. ;; :error-patterns, so we strip those color codes from the output
  6133. ;; here before passing it along to the default behavior. The
  6134. ;; relevant disucssion can be found at
  6135. ;; https://github.com/flycheck/flycheck/pull/1144
  6136. (require 'ansi-color)
  6137. (flycheck-parse-with-patterns
  6138. (and (fboundp 'ansi-color-filter-apply) (ansi-color-filter-apply output))
  6139. checker buffer))
  6140. :error-patterns
  6141. ((warning line-start
  6142. (file-name) ":" line ": Warning:" (message) line-end)
  6143. (error line-start
  6144. (file-name) ":" line ": " (message) line-end))
  6145. :modes erlang-mode
  6146. :enabled flycheck-rebar3-project-root
  6147. :predicate flycheck-buffer-saved-p
  6148. :working-directory flycheck-rebar3-project-root)
  6149. (flycheck-define-checker eruby-erubis
  6150. "A eRuby syntax checker using the `erubis' command.
  6151. See URL `http://www.kuwata-lab.com/erubis/'."
  6152. :command ("erubis" "-z" source)
  6153. :error-patterns
  6154. ((error line-start (file-name) ":" line ": " (message) line-end))
  6155. :modes (html-erb-mode rhtml-mode))
  6156. (flycheck-def-args-var flycheck-gfortran-args fortran-gfortran
  6157. :package-version '(flycheck . "0.22"))
  6158. (flycheck-def-option-var flycheck-gfortran-include-path nil fortran-gfortran
  6159. "A list of include directories for GCC Fortran.
  6160. The value of this variable is a list of strings, where each
  6161. string is a directory to add to the include path of gcc.
  6162. Relative paths are relative to the file being checked."
  6163. :type '(repeat (directory :tag "Include directory"))
  6164. :safe #'flycheck-string-list-p
  6165. :package-version '(flycheck . "0.20"))
  6166. (flycheck-def-option-var flycheck-gfortran-language-standard "f95" fortran-gfortran
  6167. "The language standard to use in GFortran.
  6168. The value of this variable is either a string denoting a language
  6169. standard, or nil, to use the default standard. When non-nil,
  6170. pass the language standard via the `-std' option."
  6171. :type '(choice (const :tag "Default standard" nil)
  6172. (string :tag "Language standard"))
  6173. :safe #'stringp
  6174. :package-version '(flycheck . "0.20"))
  6175. (flycheck-def-option-var flycheck-gfortran-layout nil fortran-gfortran
  6176. "The source code layout to use in GFortran.
  6177. The value of this variable is one of the following symbols:
  6178. nil
  6179. Let gfortran determine the layout from the extension
  6180. `free'
  6181. Use free form layout
  6182. `fixed'
  6183. Use fixed form layout
  6184. In any other case, an error is signaled."
  6185. :type '(choice (const :tag "Guess layout from extension" nil)
  6186. (const :tag "Free form layout" free)
  6187. (const :tag "Fixed form layout" fixed))
  6188. :safe (lambda (value) (or (not value) (memq value '(free fixed))))
  6189. :package-version '(flycheck . "0.20"))
  6190. (defun flycheck-option-gfortran-layout (value)
  6191. "Option VALUE filter for `flycheck-gfortran-layout'."
  6192. (pcase value
  6193. (`nil nil)
  6194. (`free "free-form")
  6195. (`fixed "fixed-form")
  6196. (_ (error "Invalid value for flycheck-gfortran-layout: %S" value))))
  6197. (flycheck-def-option-var flycheck-gfortran-warnings '("all" "extra")
  6198. fortran-gfortran
  6199. "A list of warnings for GCC Fortran.
  6200. The value of this variable is a list of strings, where each string
  6201. is the name of a warning category to enable. By default, all
  6202. recommended warnings and some extra warnings are enabled (as by
  6203. `-Wall' and `-Wextra' respectively).
  6204. Refer to the gfortran manual at URL
  6205. `https://gcc.gnu.org/onlinedocs/gfortran/' for more information
  6206. about warnings"
  6207. :type '(choice (const :tag "No additional warnings" nil)
  6208. (repeat :tag "Additional warnings"
  6209. (string :tag "Warning name")))
  6210. :safe #'flycheck-string-list-p
  6211. :package-version '(flycheck . "0.20"))
  6212. (flycheck-define-checker fortran-gfortran
  6213. "An Fortran syntax checker using GCC.
  6214. Uses GCC's Fortran compiler gfortran. See URL
  6215. `https://gcc.gnu.org/onlinedocs/gfortran/'."
  6216. :command ("gfortran"
  6217. "-fsyntax-only"
  6218. "-fshow-column"
  6219. "-fno-diagnostics-show-caret" ; Do not visually indicate the source location
  6220. "-fno-diagnostics-show-option" ; Do not show the corresponding
  6221. ; warning group
  6222. ;; Fortran has similar include processing as C/C++
  6223. "-iquote" (eval (flycheck-c/c++-quoted-include-directory))
  6224. (option "-std=" flycheck-gfortran-language-standard concat)
  6225. (option "-f" flycheck-gfortran-layout concat
  6226. flycheck-option-gfortran-layout)
  6227. (option-list "-W" flycheck-gfortran-warnings concat)
  6228. (option-list "-I" flycheck-gfortran-include-path concat)
  6229. (eval flycheck-gfortran-args)
  6230. source)
  6231. :error-patterns
  6232. ((error line-start (file-name) ":" line (or ":" ".") column (or ": " ":\n")
  6233. (or (= 3 (zero-or-more not-newline) "\n") "")
  6234. (or "Error" "Fatal Error") ": "
  6235. (message) line-end)
  6236. (warning line-start (file-name) ":" line (or ":" ".") column (or ": " ":\n")
  6237. (or (= 3 (zero-or-more not-newline) "\n") "")
  6238. "Warning: " (message) line-end))
  6239. :modes (fortran-mode f90-mode))
  6240. (flycheck-define-checker go-gofmt
  6241. "A Go syntax and style checker using the gofmt utility.
  6242. See URL `https://golang.org/cmd/gofmt/'."
  6243. :command ("gofmt")
  6244. :standard-input t
  6245. :error-patterns
  6246. ((error line-start "<standard input>:" line ":" column ": " (message) line-end))
  6247. :modes go-mode
  6248. :next-checkers ((warning . go-golint)
  6249. ;; Fall back, if go-golint doesn't exist
  6250. (warning . go-vet)
  6251. ;; Fall back, if go-vet doesn't exist
  6252. (warning . go-build) (warning . go-test)
  6253. (warning . go-errcheck)
  6254. (warning . go-unconvert)
  6255. (warning . go-megacheck)))
  6256. (flycheck-define-checker go-golint
  6257. "A Go style checker using Golint.
  6258. See URL `https://github.com/golang/lint'."
  6259. :command ("golint" source)
  6260. :error-patterns
  6261. ((warning line-start (file-name) ":" line ":" column ": " (message) line-end))
  6262. :modes go-mode
  6263. :next-checkers (go-vet
  6264. ;; Fall back, if go-vet doesn't exist
  6265. go-build go-test go-errcheck go-unconvert go-megacheck))
  6266. (flycheck-def-option-var flycheck-go-vet-print-functions nil go-vet
  6267. "A list of print-like functions for `go tool vet'.
  6268. Go vet will check these functions for format string problems and
  6269. issues, such as a mismatch between the number of formats used,
  6270. and the number of arguments given.
  6271. Each entry is in the form Name:N where N is the zero-based
  6272. argument position of the first argument involved in the print:
  6273. either the format or the first print argument for non-formatted
  6274. prints. For example, if you have Warn and Warnf functions that
  6275. take an io.Writer as their first argument, like Fprintf,
  6276. -printfuncs=Warn:1,Warnf:1 "
  6277. :type '(repeat :tag "print-like functions"
  6278. (string :tag "function"))
  6279. :safe #'flycheck-string-list-p)
  6280. (flycheck-def-option-var flycheck-go-vet-shadow nil go-vet
  6281. "Whether to check for shadowed variables with `go tool vet'.
  6282. When non-nil check for shadowed variables. When `strict' check
  6283. more strictly, which can very noisy. When nil do not check for
  6284. shadowed variables.
  6285. This option requires Go 1.6 or newer."
  6286. :type '(choice (const :tag "Do not check for shadowed variables" nil)
  6287. (const :tag "Check for shadowed variables" t)
  6288. (const :tag "Strictly check for shadowed variables" strict)))
  6289. (flycheck-def-option-var flycheck-go-megacheck-disabled-checkers nil go-megacheck
  6290. "A list of checkers to disable when running `megacheck'.
  6291. The value of this variable is a list of strings, where each
  6292. string is a checker to be disabled. Valid checkers are `simple',
  6293. `staticcheck' and `unused'. When nil, all checkers will be
  6294. enabled. "
  6295. :type '(set (const :tag "Disable simple" "simple")
  6296. (const :tag "Disable staticcheck" "staticcheck")
  6297. (const :tag "Disable unused" "unused"))
  6298. :safe #'flycheck-string-list-p)
  6299. (flycheck-define-checker go-vet
  6300. "A Go syntax checker using the `go tool vet' command.
  6301. See URL `https://golang.org/cmd/go/' and URL
  6302. `https://golang.org/cmd/vet/'."
  6303. :command ("go" "tool" "vet" "-all"
  6304. (option "-printfuncs=" flycheck-go-vet-print-functions concat
  6305. flycheck-option-comma-separated-list)
  6306. (option-flag "-shadow" flycheck-go-vet-shadow)
  6307. (option-list "-tags=" flycheck-go-build-tags concat)
  6308. (eval (when (eq flycheck-go-vet-shadow 'strict) "-shadowstrict"))
  6309. source)
  6310. :error-patterns
  6311. ((warning line-start (file-name) ":" line ": " (message) line-end))
  6312. :modes go-mode
  6313. ;; We must explicitly check whether the "vet" tool is available
  6314. :predicate (lambda ()
  6315. (let ((go (flycheck-checker-executable 'go-vet)))
  6316. (member "vet" (ignore-errors (process-lines go "tool")))))
  6317. :next-checkers (go-build
  6318. go-test
  6319. ;; Fall back if `go build' or `go test' can be used
  6320. go-errcheck
  6321. go-unconvert
  6322. go-megacheck)
  6323. :verify (lambda (_)
  6324. (let* ((go (flycheck-checker-executable 'go-vet))
  6325. (have-vet (member "vet" (ignore-errors
  6326. (process-lines go "tool")))))
  6327. (list
  6328. (flycheck-verification-result-new
  6329. :label "go tool vet"
  6330. :message (if have-vet "present" "missing")
  6331. :face (if have-vet 'success '(bold error)))))))
  6332. (flycheck-def-option-var flycheck-go-build-install-deps nil (go-build go-test)
  6333. "Whether to install dependencies in `go build' and `go test'.
  6334. If non-nil automatically install dependencies with `go build'
  6335. while syntax checking."
  6336. :type 'boolean
  6337. :safe #'booleanp
  6338. :package-version '(flycheck . "0.25"))
  6339. (flycheck-def-option-var flycheck-go-build-tags nil go-build
  6340. "A list of tags for `go build'.
  6341. Each item is a string with a tag to be given to `go build'."
  6342. :type '(repeat (string :tag "Tag"))
  6343. :safe #'flycheck-string-list-p
  6344. :package-version '(flycheck . "0.25"))
  6345. (flycheck-define-checker go-build
  6346. "A Go syntax and type checker using the `go build' command.
  6347. Requires Go 1.6 or newer. See URL `https://golang.org/cmd/go'."
  6348. :command ("go" "build"
  6349. (option-flag "-i" flycheck-go-build-install-deps)
  6350. ;; multiple tags are listed as "dev debug ..."
  6351. (option-list "-tags=" flycheck-go-build-tags concat)
  6352. "-o" null-device)
  6353. :error-patterns
  6354. ((error line-start (file-name) ":" line ":"
  6355. (optional column ":") " "
  6356. (message (one-or-more not-newline)
  6357. (zero-or-more "\n\t" (one-or-more not-newline)))
  6358. line-end)
  6359. ;; Catch error message about multiple packages in a directory, which doesn't
  6360. ;; follow the standard error message format.
  6361. (info line-start
  6362. (message "can't load package: package "
  6363. (one-or-more (not (any ?: ?\n)))
  6364. ": found packages "
  6365. (one-or-more not-newline))
  6366. line-end))
  6367. :error-filter
  6368. (lambda (errors)
  6369. (dolist (error errors)
  6370. (unless (flycheck-error-line error)
  6371. ;; Flycheck ignores errors without line numbers, but the error
  6372. ;; message about multiple packages in a directory doesn't come with a
  6373. ;; line number, so inject a fake one.
  6374. (setf (flycheck-error-line error) 1)))
  6375. errors)
  6376. :modes go-mode
  6377. :predicate (lambda ()
  6378. (and (flycheck-buffer-saved-p)
  6379. (not (string-suffix-p "_test.go" (buffer-file-name)))))
  6380. :next-checkers ((warning . go-errcheck)
  6381. (warning . go-unconvert)
  6382. (warning . go-megacheck)))
  6383. (flycheck-define-checker go-test
  6384. "A Go syntax and type checker using the `go test' command.
  6385. Requires Go 1.6 or newer. See URL `https://golang.org/cmd/go'."
  6386. :command ("go" "test"
  6387. (option-flag "-i" flycheck-go-build-install-deps)
  6388. (option-list "-tags=" flycheck-go-build-tags concat)
  6389. "-c" "-o" null-device)
  6390. :error-patterns
  6391. ((error line-start (file-name) ":" line ":"
  6392. (optional column ":") " "
  6393. (message (one-or-more not-newline)
  6394. (zero-or-more "\n\t" (one-or-more not-newline)))
  6395. line-end))
  6396. :modes go-mode
  6397. :predicate
  6398. (lambda () (and (flycheck-buffer-saved-p)
  6399. (string-suffix-p "_test.go" (buffer-file-name))))
  6400. :next-checkers ((warning . go-errcheck)
  6401. (warning . go-unconvert)
  6402. (warning . go-megacheck)))
  6403. (flycheck-define-checker go-errcheck
  6404. "A Go checker for unchecked errors.
  6405. Requires errcheck newer than commit 8515d34 (Aug 28th, 2015).
  6406. See URL `https://github.com/kisielk/errcheck'."
  6407. :command ("errcheck"
  6408. "-abspath"
  6409. (option-list "-tags=" flycheck-go-build-tags concat)
  6410. ".")
  6411. :error-patterns
  6412. ((warning line-start
  6413. (file-name) ":" line ":" column (or (one-or-more "\t") ": " ":\t")
  6414. (message)
  6415. line-end))
  6416. :error-filter
  6417. (lambda (errors)
  6418. (let ((errors (flycheck-sanitize-errors errors)))
  6419. (dolist (err errors)
  6420. (-when-let (message (flycheck-error-message err))
  6421. ;; Improve the messages reported by errcheck to make them more clear.
  6422. (setf (flycheck-error-message err)
  6423. (format "Ignored `error` returned from `%s`" message)))))
  6424. errors)
  6425. :modes go-mode
  6426. :predicate (lambda () (flycheck-buffer-saved-p))
  6427. :next-checkers ((warning . go-unconvert)
  6428. (warning . go-megacheck)))
  6429. (flycheck-define-checker go-unconvert
  6430. "A Go checker looking for unnecessary type conversions.
  6431. See URL `https://github.com/mdempsky/unconvert'."
  6432. :command ("unconvert" ".")
  6433. :error-patterns
  6434. ((warning line-start (file-name) ":" line ":" column ": " (message) line-end))
  6435. :modes go-mode
  6436. :predicate (lambda () (flycheck-buffer-saved-p))
  6437. :next-checkers ((warning . go-megacheck)))
  6438. (flycheck-define-checker go-megacheck
  6439. "A Go checker that performs static analysis and linting using the `megacheck'
  6440. command.
  6441. Requires Go 1.6 or newer. See URL
  6442. `https://github.com/dominikh/go-tools'."
  6443. :command ("megacheck"
  6444. (option-list "-tags=" flycheck-go-build-tags concat)
  6445. (eval (mapcar (lambda (checker) (concat "-" checker
  6446. ".enabled=false"))
  6447. flycheck-go-megacheck-disabled-checkers))
  6448. ;; Run in current directory to make megacheck aware of symbols
  6449. ;; declared in other files.
  6450. ".")
  6451. :error-patterns
  6452. ((warning line-start (file-name) ":" line ":" column ": " (message) line-end))
  6453. :modes go-mode)
  6454. (flycheck-define-checker groovy
  6455. "A groovy syntax checker using groovy compiler API.
  6456. See URL `http://www.groovy-lang.org'."
  6457. :command ("groovy" "-e"
  6458. "import org.codehaus.groovy.control.*
  6459. file = new File(args[0])
  6460. unit = new CompilationUnit()
  6461. unit.addSource(file)
  6462. try {
  6463. unit.compile(Phases.CONVERSION)
  6464. } catch (MultipleCompilationErrorsException e) {
  6465. e.errorCollector.write(new PrintWriter(System.out, true), null)
  6466. }
  6467. "
  6468. source)
  6469. :error-patterns
  6470. ((error line-start (file-name) ": " line ":" (message)
  6471. " @ line " line ", column " column "." line-end))
  6472. :modes groovy-mode)
  6473. (flycheck-define-checker haml
  6474. "A Haml syntax checker using the Haml compiler.
  6475. See URL `http://haml.info'."
  6476. :command ("haml" "-c" "--stdin")
  6477. :standard-input t
  6478. :error-patterns
  6479. ((error line-start "Syntax error on line " line ": " (message) line-end))
  6480. :modes haml-mode)
  6481. (flycheck-define-checker handlebars
  6482. "A Handlebars syntax checker using the Handlebars compiler.
  6483. See URL `http://handlebarsjs.com/'."
  6484. :command ("handlebars" "-i-")
  6485. :standard-input t
  6486. :error-patterns
  6487. ((error line-start
  6488. "Error: Parse error on line " line ":" (optional "\r") "\n"
  6489. (zero-or-more not-newline) "\n" (zero-or-more not-newline) "\n"
  6490. (message) line-end))
  6491. :modes (handlebars-mode handlebars-sgml-mode web-mode)
  6492. :predicate
  6493. (lambda ()
  6494. (if (eq major-mode 'web-mode)
  6495. ;; Check if this is a handlebars file since web-mode does not store the
  6496. ;; non-canonical engine name
  6497. (let* ((regexp-alist (bound-and-true-p web-mode-engine-file-regexps))
  6498. (pattern (cdr (assoc "handlebars" regexp-alist))))
  6499. (and pattern (buffer-file-name)
  6500. (string-match-p pattern (buffer-file-name))))
  6501. t)))
  6502. (defconst flycheck-haskell-module-re
  6503. (rx line-start (zero-or-more (or "\n" (any space)))
  6504. "module" (one-or-more (or "\n" (any space)))
  6505. (group (one-or-more (not (any space "(" "\n")))))
  6506. "Regular expression for a Haskell module name.")
  6507. (flycheck-def-args-var flycheck-ghc-args (haskell-stack-ghc haskell-ghc)
  6508. :package-version '(flycheck . "0.22"))
  6509. (flycheck-def-option-var flycheck-ghc-stack-use-nix nil haskell-stack-ghc
  6510. "Whether to enable nix support in stack.
  6511. When non-nil, stack will append '--nix' flag to any call."
  6512. :type 'boolean
  6513. :safe #'booleanp
  6514. :package-version '(flycheck . "26"))
  6515. (flycheck-def-option-var flycheck-ghc-no-user-package-database nil haskell-ghc
  6516. "Whether to disable the user package database in GHC.
  6517. When non-nil, disable the user package database in GHC, via
  6518. `-no-user-package-db'."
  6519. :type 'boolean
  6520. :safe #'booleanp
  6521. :package-version '(flycheck . "0.16"))
  6522. (flycheck-def-option-var flycheck-ghc-package-databases nil haskell-ghc
  6523. "Additional module databases for GHC.
  6524. The value of this variable is a list of strings, where each
  6525. string is a directory of a package database. Each package
  6526. database is given to GHC via `-package-db'."
  6527. :type '(repeat (directory :tag "Package database"))
  6528. :safe #'flycheck-string-list-p
  6529. :package-version '(flycheck . "0.16"))
  6530. (flycheck-def-option-var flycheck-ghc-search-path nil
  6531. (haskell-stack-ghc haskell-ghc)
  6532. "Module search path for (Stack) GHC.
  6533. The value of this variable is a list of strings, where each
  6534. string is a directory containing Haskell modules. Each directory
  6535. is added to the GHC search path via `-i'."
  6536. :type '(repeat (directory :tag "Module directory"))
  6537. :safe #'flycheck-string-list-p
  6538. :package-version '(flycheck . "0.16"))
  6539. (flycheck-def-option-var flycheck-ghc-language-extensions nil
  6540. (haskell-stack-ghc haskell-ghc)
  6541. "Language extensions for (Stack) GHC.
  6542. The value of this variable is a list of strings, where each
  6543. string is a Haskell language extension, as in the LANGUAGE
  6544. pragma. Each extension is enabled via `-X'."
  6545. :type '(repeat (string :tag "Language extension"))
  6546. :safe #'flycheck-string-list-p
  6547. :package-version '(flycheck . "0.19"))
  6548. (defvar flycheck-haskell-ghc-cache-directory nil
  6549. "The cache directory for `ghc' output.")
  6550. (defun flycheck-haskell-ghc-cache-directory ()
  6551. "Get the cache location for `ghc' output.
  6552. If no cache directory exists yet, create one and return it.
  6553. Otherwise return the previously used cache directory."
  6554. (setq flycheck-haskell-ghc-cache-directory
  6555. (or flycheck-haskell-ghc-cache-directory
  6556. (make-temp-file "flycheck-haskell-ghc-cache" 'directory))))
  6557. (defun flycheck--locate-dominating-file-matching (directory regexp)
  6558. "Search for a file in directory hierarchy starting at DIRECTORY.
  6559. Look up the directory hierarchy from DIRECTORY for a directory
  6560. containing a file that matches REGEXP."
  6561. (locate-dominating-file
  6562. directory
  6563. (lambda (dir)
  6564. (directory-files dir t regexp t))))
  6565. (defun flycheck-haskell--find-default-directory (checker)
  6566. "Come up with a suitable default directory for Haskell to run CHECKER in.
  6567. In case of `haskell-stack-ghc' checker it is directory with
  6568. stack.yaml file. If there's no stack.yaml file in any parent
  6569. directory, it will be the directory that \"stack path --project-root\"
  6570. command returns.
  6571. For all other checkers, it is the closest parent directory that
  6572. contains a cabal file."
  6573. (pcase checker
  6574. (`haskell-stack-ghc
  6575. (or
  6576. (when (buffer-file-name)
  6577. (flycheck--locate-dominating-file-matching
  6578. (file-name-directory (buffer-file-name))
  6579. "stack.*\\.yaml\\'"))
  6580. (-when-let* ((stack (funcall flycheck-executable-find "stack"))
  6581. (output (ignore-errors
  6582. (process-lines stack "path" "--project-root")))
  6583. (stack-dir (car output)))
  6584. (and (file-directory-p stack-dir) stack-dir))))
  6585. (_
  6586. (when (buffer-file-name)
  6587. (flycheck--locate-dominating-file-matching
  6588. (file-name-directory (buffer-file-name))
  6589. ".+\\.cabal\\'")))))
  6590. (flycheck-define-checker haskell-stack-ghc
  6591. "A Haskell syntax and type checker using `stack ghc'.
  6592. See URL `https://github.com/commercialhaskell/stack'."
  6593. :command ("stack"
  6594. (option-flag "--nix" flycheck-ghc-stack-use-nix)
  6595. "ghc" "--" "-Wall" "-no-link"
  6596. "-outputdir" (eval (flycheck-haskell-ghc-cache-directory))
  6597. (option-list "-X" flycheck-ghc-language-extensions concat)
  6598. (option-list "-i" flycheck-ghc-search-path concat)
  6599. (eval (concat
  6600. "-i"
  6601. (flycheck-module-root-directory
  6602. (flycheck-find-in-buffer flycheck-haskell-module-re))))
  6603. (eval flycheck-ghc-args)
  6604. "-x" (eval
  6605. (pcase major-mode
  6606. (`haskell-mode "hs")
  6607. (`literate-haskell-mode "lhs")))
  6608. source)
  6609. :error-patterns
  6610. ((warning line-start (file-name) ":" line ":" column ":"
  6611. (or " " "\n ") (in "Ww") "arning:"
  6612. (optional " " "[" (id (one-or-more not-newline)) "]")
  6613. (optional "\n")
  6614. (message
  6615. (one-or-more " ") (one-or-more not-newline)
  6616. (zero-or-more "\n"
  6617. (one-or-more " ")
  6618. (one-or-more not-newline)))
  6619. line-end)
  6620. (error line-start (file-name) ":" line ":" column ":" (optional " error:")
  6621. (or (message (one-or-more not-newline))
  6622. (and "\n"
  6623. (message
  6624. (one-or-more " ") (one-or-more not-newline)
  6625. (zero-or-more "\n"
  6626. (one-or-more " ")
  6627. (one-or-more not-newline)))))
  6628. line-end))
  6629. :error-filter
  6630. (lambda (errors)
  6631. (flycheck-sanitize-errors (flycheck-dedent-error-messages errors)))
  6632. :modes (haskell-mode literate-haskell-mode)
  6633. :next-checkers ((warning . haskell-hlint))
  6634. :working-directory flycheck-haskell--find-default-directory)
  6635. (flycheck-define-checker haskell-ghc
  6636. "A Haskell syntax and type checker using ghc.
  6637. See URL `https://www.haskell.org/ghc/'."
  6638. :command ("ghc" "-Wall" "-no-link"
  6639. "-outputdir" (eval (flycheck-haskell-ghc-cache-directory))
  6640. (option-flag "-no-user-package-db"
  6641. flycheck-ghc-no-user-package-database)
  6642. (option-list "-package-db" flycheck-ghc-package-databases)
  6643. (option-list "-i" flycheck-ghc-search-path concat)
  6644. ;; Include the parent directory of the current module tree, to
  6645. ;; properly resolve local imports
  6646. (eval (concat
  6647. "-i"
  6648. (flycheck-module-root-directory
  6649. (flycheck-find-in-buffer flycheck-haskell-module-re))))
  6650. (option-list "-X" flycheck-ghc-language-extensions concat)
  6651. (eval flycheck-ghc-args)
  6652. "-x" (eval
  6653. (pcase major-mode
  6654. (`haskell-mode "hs")
  6655. (`literate-haskell-mode "lhs")))
  6656. source)
  6657. :error-patterns
  6658. ((warning line-start (file-name) ":" line ":" column ":"
  6659. (or " " "\n ") (in "Ww") "arning:"
  6660. (optional " " "[" (id (one-or-more not-newline)) "]")
  6661. (optional "\n")
  6662. (message
  6663. (one-or-more " ") (one-or-more not-newline)
  6664. (zero-or-more "\n"
  6665. (one-or-more " ")
  6666. (one-or-more not-newline)))
  6667. line-end)
  6668. (error line-start (file-name) ":" line ":" column ":" (optional " error:")
  6669. (or (message (one-or-more not-newline))
  6670. (and "\n"
  6671. (message
  6672. (one-or-more " ") (one-or-more not-newline)
  6673. (zero-or-more "\n"
  6674. (one-or-more " ")
  6675. (one-or-more not-newline)))))
  6676. line-end))
  6677. :error-filter
  6678. (lambda (errors)
  6679. (flycheck-sanitize-errors (flycheck-dedent-error-messages errors)))
  6680. :modes (haskell-mode literate-haskell-mode)
  6681. :next-checkers ((warning . haskell-hlint))
  6682. :working-directory flycheck-haskell--find-default-directory)
  6683. (flycheck-def-config-file-var flycheck-hlintrc haskell-hlint "HLint.hs"
  6684. :safe #'stringp)
  6685. (flycheck-def-args-var flycheck-hlint-args haskell-hlint
  6686. :package-version '(flycheck . "0.25"))
  6687. (flycheck-def-option-var flycheck-hlint-language-extensions
  6688. nil haskell-hlint
  6689. "Extensions list to enable for hlint.
  6690. The value of this variable is a list of strings, where each
  6691. string is a name of extension to enable in
  6692. hlint (e.g. \"QuasiQuotes\")."
  6693. :type '(repeat :tag "Extensions" (string :tag "Extension"))
  6694. :safe #'flycheck-string-list-p
  6695. :package-version '(flycheck . "0.24"))
  6696. (flycheck-def-option-var flycheck-hlint-ignore-rules
  6697. nil haskell-hlint
  6698. "Ignore rules list for hlint checks.
  6699. The value of this variable is a list of strings, where each
  6700. string is an ignore rule (e.g. \"Use fmap\")."
  6701. :type '(repeat :tag "Ignore rules" (string :tag "Ignore rule"))
  6702. :safe #'flycheck-string-list-p
  6703. :package-version '(flycheck . "0.24"))
  6704. (flycheck-def-option-var flycheck-hlint-hint-packages
  6705. nil haskell-hlint
  6706. "Hint packages to include for hlint checks.
  6707. The value of this variable is a list of strings, where each
  6708. string is a default hint package (e.g. (\"Generalise\"
  6709. \"Default\" \"Dollar\"))."
  6710. :type '(repeat :tag "Hint packages" (string :tag "Hint package"))
  6711. :safe #'flycheck-string-list-p
  6712. :package-version '(flycheck . "0.24"))
  6713. (flycheck-define-checker haskell-hlint
  6714. "A Haskell style checker using hlint.
  6715. See URL `https://github.com/ndmitchell/hlint'."
  6716. :command ("hlint"
  6717. (option-list "-X" flycheck-hlint-language-extensions concat)
  6718. (option-list "-i=" flycheck-hlint-ignore-rules concat)
  6719. (option-list "-h" flycheck-hlint-hint-packages concat)
  6720. (config-file "-h" flycheck-hlintrc)
  6721. (eval flycheck-hlint-args)
  6722. source-inplace)
  6723. :error-patterns
  6724. ((info line-start
  6725. (file-name) ":" line ":" column
  6726. ": Suggestion: "
  6727. (message (one-or-more (and (one-or-more (not (any ?\n))) ?\n)))
  6728. line-end)
  6729. (warning line-start
  6730. (file-name) ":" line ":" column
  6731. ": Warning: "
  6732. (message (one-or-more (and (one-or-more (not (any ?\n))) ?\n)))
  6733. line-end)
  6734. (error line-start
  6735. (file-name) ":" line ":" column
  6736. ": Error: "
  6737. (message (one-or-more (and (one-or-more (not (any ?\n))) ?\n)))
  6738. line-end))
  6739. :modes (haskell-mode literate-haskell-mode))
  6740. (flycheck-def-config-file-var flycheck-tidyrc html-tidy ".tidyrc"
  6741. :safe #'stringp)
  6742. (flycheck-define-checker html-tidy
  6743. "A HTML syntax and style checker using Tidy.
  6744. See URL `https://github.com/htacg/tidy-html5'."
  6745. :command ("tidy" (config-file "-config" flycheck-tidyrc) "-e" "-q")
  6746. :standard-input t
  6747. :error-patterns
  6748. ((error line-start
  6749. "line " line
  6750. " column " column
  6751. " - Error: " (message) line-end)
  6752. (warning line-start
  6753. "line " line
  6754. " column " column
  6755. " - Warning: " (message) line-end))
  6756. :modes (html-mode nxhtml-mode))
  6757. (flycheck-def-config-file-var flycheck-jshintrc javascript-jshint ".jshintrc"
  6758. :safe #'stringp)
  6759. (flycheck-def-option-var flycheck-jshint-extract-javascript nil
  6760. javascript-jshint
  6761. "Whether jshint should extract Javascript from HTML.
  6762. If nil no extract rule is given to jshint. If `auto' only
  6763. extract Javascript if a HTML file is detected. If `always' or
  6764. `never' extract Javascript always or never respectively.
  6765. Refer to the jshint manual at the URL
  6766. `http://jshint.com/docs/cli/#flags' for more information."
  6767. :type
  6768. '(choice (const :tag "No extraction rule" nil)
  6769. (const :tag "Try to extract Javascript when detecting HTML files"
  6770. auto)
  6771. (const :tag "Always try to extract Javascript" always)
  6772. (const :tag "Never try to extract Javascript" never))
  6773. :safe #'symbolp
  6774. :package-version '(flycheck . "26"))
  6775. (flycheck-define-checker javascript-jshint
  6776. "A Javascript syntax and style checker using jshint.
  6777. See URL `http://www.jshint.com'."
  6778. :command ("jshint" "--reporter=checkstyle"
  6779. "--filename" source-original
  6780. (config-file "--config" flycheck-jshintrc)
  6781. (option "--extract=" flycheck-jshint-extract-javascript
  6782. concat flycheck-option-symbol)
  6783. "-")
  6784. :standard-input t
  6785. :error-parser flycheck-parse-checkstyle
  6786. :error-filter
  6787. (lambda (errors)
  6788. (flycheck-remove-error-file-names
  6789. "stdin" (flycheck-dequalify-error-ids errors)))
  6790. :modes (js-mode js2-mode js3-mode rjsx-mode)
  6791. :next-checkers ((warning . javascript-jscs)))
  6792. (flycheck-def-option-var flycheck-eslint-rules-directories nil javascript-eslint
  6793. "A list of directories with custom rules for ESLint.
  6794. The value of this variable is a list of strings, where each
  6795. string is a directory with custom rules for ESLint.
  6796. Refer to the ESLint manual at URL
  6797. `http://eslint.org/docs/user-guide/command-line-interface#--rulesdir'
  6798. for more information about the custom directories."
  6799. :type '(repeat (directory :tag "Custom rules directory"))
  6800. :safe #'flycheck-string-list-p
  6801. :package-version '(flycheck . "29"))
  6802. (defun flycheck-eslint-config-exists-p ()
  6803. "Whether there is a valid eslint config for the current buffer."
  6804. (let* ((executable (flycheck-find-checker-executable 'javascript-eslint))
  6805. (exitcode (and executable (call-process executable nil nil nil
  6806. "--print-config" "."))))
  6807. (eq exitcode 0)))
  6808. (flycheck-define-checker javascript-eslint
  6809. "A Javascript syntax and style checker using eslint.
  6810. See URL `http://eslint.org/'."
  6811. :command ("eslint" "--format=checkstyle"
  6812. (option-list "--rulesdir" flycheck-eslint-rules-directories)
  6813. "--stdin" "--stdin-filename" source-original)
  6814. :standard-input t
  6815. :error-parser flycheck-parse-checkstyle
  6816. :error-filter
  6817. (lambda (errors)
  6818. (seq-do (lambda (err)
  6819. ;; Parse error ID from the error message
  6820. (setf (flycheck-error-message err)
  6821. (replace-regexp-in-string
  6822. (rx " ("
  6823. (group (one-or-more (not (any ")"))))
  6824. ")" string-end)
  6825. (lambda (s)
  6826. (setf (flycheck-error-id err)
  6827. (match-string 1 s))
  6828. "")
  6829. (flycheck-error-message err))))
  6830. (flycheck-sanitize-errors errors))
  6831. errors)
  6832. :enabled (lambda () (flycheck-eslint-config-exists-p))
  6833. :modes (js-mode js-jsx-mode js2-mode js2-jsx-mode js3-mode rjsx-mode)
  6834. :next-checkers ((warning . javascript-jscs))
  6835. :verify
  6836. (lambda (_)
  6837. (let* ((default-directory
  6838. (flycheck-compute-working-directory 'javascript-eslint))
  6839. (have-config (flycheck-eslint-config-exists-p)))
  6840. (list
  6841. (flycheck-verification-result-new
  6842. :label "config file"
  6843. :message (if have-config "found" "missing or incorrect")
  6844. :face (if have-config 'success '(bold error)))))))
  6845. (defun flycheck-parse-jscs (output checker buffer)
  6846. "Parse JSCS OUTPUT from CHECKER and BUFFER.
  6847. Like `flycheck-parse-checkstyle', but catches errors about no
  6848. configuration found and prevents to be reported as a suspicious
  6849. error."
  6850. (if (string-match-p (rx string-start "No configuration found") output)
  6851. (let ((message "No JSCS configuration found. Set `flycheck-jscsrc' for JSCS"))
  6852. (list (flycheck-error-new-at 1 nil 'warning message
  6853. :checker checker
  6854. :buffer buffer
  6855. :filename (buffer-file-name buffer))))
  6856. (flycheck-parse-checkstyle output checker buffer)))
  6857. (flycheck-def-config-file-var flycheck-jscsrc javascript-jscs ".jscsrc"
  6858. :safe #'stringp
  6859. :package-version '(flycheck . "0.24"))
  6860. (flycheck-define-checker javascript-jscs
  6861. "A Javascript style checker using JSCS.
  6862. See URL `http://www.jscs.info'."
  6863. :command ("jscs" "--reporter=checkstyle"
  6864. (config-file "--config" flycheck-jscsrc)
  6865. "-")
  6866. :standard-input t
  6867. :error-parser flycheck-parse-jscs
  6868. :error-filter (lambda (errors)
  6869. (flycheck-remove-error-ids
  6870. (flycheck-sanitize-errors
  6871. (flycheck-remove-error-file-names "input" errors))))
  6872. :modes (js-mode js-jsx-mode js2-mode js2-jsx-mode js3-mode rjsx-mode))
  6873. (flycheck-define-checker javascript-standard
  6874. "A Javascript code and style checker for the (Semi-)Standard Style.
  6875. This checker works with `standard' and `semistandard', defaulting
  6876. to the former. To use it with the latter, set
  6877. `flycheck-javascript-standard-executable' to `semistandard'.
  6878. See URL `https://github.com/feross/standard' and URL
  6879. `https://github.com/Flet/semistandard'."
  6880. :command ("standard" "--stdin")
  6881. :standard-input t
  6882. :error-patterns
  6883. ((error line-start " <text>:" line ":" column ":" (message) line-end))
  6884. :modes (js-mode js-jsx-mode js2-mode js2-jsx-mode js3-mode rjsx-mode))
  6885. (flycheck-define-checker json-jsonlint
  6886. "A JSON syntax and style checker using jsonlint.
  6887. See URL `https://github.com/zaach/jsonlint'."
  6888. ;; We can't use standard input for jsonlint, because it doesn't output errors
  6889. ;; anymore when using -c -q with standard input :/
  6890. :command ("jsonlint" "-c" "-q" source)
  6891. :error-patterns
  6892. ((error line-start
  6893. (file-name)
  6894. ": line " line
  6895. ", col " column ", "
  6896. (message) line-end))
  6897. :error-filter
  6898. (lambda (errors)
  6899. (flycheck-sanitize-errors (flycheck-increment-error-columns errors)))
  6900. :modes json-mode)
  6901. (flycheck-define-checker json-python-json
  6902. "A JSON syntax checker using Python json.tool module.
  6903. See URL `https://docs.python.org/3.5/library/json.html#command-line-interface'."
  6904. :command ("python" "-m" "json.tool" source
  6905. ;; Send the pretty-printed output to the null device
  6906. null-device)
  6907. :error-patterns
  6908. ((error line-start
  6909. (message) ": line " line " column " column
  6910. ;; Ignore the rest of the line which shows the char position.
  6911. (one-or-more not-newline)
  6912. line-end))
  6913. :modes json-mode
  6914. ;; The JSON parser chokes if the buffer is empty and has no JSON inside
  6915. :predicate (lambda () (not (flycheck-buffer-empty-p))))
  6916. (flycheck-define-checker less
  6917. "A LESS syntax checker using lessc.
  6918. Requires lessc 1.4 or newer.
  6919. See URL `http://lesscss.org'."
  6920. :command ("lessc" "--lint" "--no-color"
  6921. "-")
  6922. :standard-input t
  6923. :error-patterns
  6924. ((error line-start (one-or-more word) ":"
  6925. (message)
  6926. " in - on line " line
  6927. ", column " column ":"
  6928. line-end))
  6929. :modes less-css-mode)
  6930. (flycheck-define-checker less-stylelint
  6931. "A LESS syntax and style checker using stylelint.
  6932. See URL `http://stylelint.io/'."
  6933. :command ("stylelint"
  6934. (eval flycheck-stylelint-args)
  6935. "--syntax" "less"
  6936. (option-flag "--quiet" flycheck-stylelint-quiet)
  6937. (config-file "--config" flycheck-stylelintrc))
  6938. :standard-input t
  6939. :error-parser flycheck-parse-stylelint
  6940. :modes (less-css-mode))
  6941. (flycheck-define-checker llvm-llc
  6942. "Flycheck LLVM IR checker using llc.
  6943. See URL `http://llvm.org/docs/CommandGuide/llc.html'."
  6944. :command ("llc" "-o" null-device source)
  6945. :error-patterns
  6946. ((error line-start
  6947. ;; llc prints the executable path
  6948. (zero-or-one (minimal-match (one-or-more not-newline)) ": ")
  6949. (file-name) ":" line ":" column ": error: " (message)
  6950. line-end))
  6951. :error-filter
  6952. (lambda (errors)
  6953. ;; sanitize errors occurring in inline assembly
  6954. (flycheck-sanitize-errors
  6955. (flycheck-remove-error-file-names "<inline asm>" errors)))
  6956. :modes llvm-mode)
  6957. (flycheck-def-config-file-var flycheck-luacheckrc lua-luacheck ".luacheckrc"
  6958. :safe #'stringp)
  6959. (flycheck-def-option-var flycheck-luacheck-standards nil lua-luacheck
  6960. "The standards to use in luacheck.
  6961. The value of this variable is either a list of strings denoting
  6962. the standards to use, or nil to pass nothing to luacheck. When
  6963. non-nil, pass the standards via one or more `--std' options."
  6964. :type '(choice (const :tag "Default" nil)
  6965. (repeat :tag "Custom standards"
  6966. (string :tag "Standard name")))
  6967. :safe #'flycheck-string-list-p)
  6968. (make-variable-buffer-local 'flycheck-luacheck-standards)
  6969. (flycheck-define-checker lua-luacheck
  6970. "A Lua syntax checker using luacheck.
  6971. See URL `https://github.com/mpeterv/luacheck'."
  6972. :command ("luacheck"
  6973. "--formatter" "plain"
  6974. "--codes" ; Show warning codes
  6975. "--no-color"
  6976. (option-list "--std" flycheck-luacheck-standards)
  6977. (config-file "--config" flycheck-luacheckrc)
  6978. "--filename" source-original
  6979. ;; Read from standard input
  6980. "-")
  6981. :standard-input t
  6982. :error-patterns
  6983. ((warning line-start
  6984. (optional (file-name))
  6985. ":" line ":" column
  6986. ": (" (id "W" (one-or-more digit)) ") "
  6987. (message) line-end)
  6988. (error line-start
  6989. (optional (file-name))
  6990. ":" line ":" column ":"
  6991. ;; `luacheck' before 0.11.0 did not output codes for errors, hence
  6992. ;; the ID is optional here
  6993. (optional " (" (id "E" (one-or-more digit)) ") ")
  6994. (message) line-end))
  6995. :modes lua-mode)
  6996. (flycheck-define-checker lua
  6997. "A Lua syntax checker using the Lua compiler.
  6998. See URL `http://www.lua.org/'."
  6999. :command ("luac" "-p" "-")
  7000. :standard-input t
  7001. :error-patterns
  7002. ((error line-start
  7003. ;; Skip the name of the luac executable.
  7004. (minimal-match (zero-or-more not-newline))
  7005. ": stdin:" line ": " (message) line-end))
  7006. :modes lua-mode)
  7007. (flycheck-def-option-var flycheck-perl-include-path nil perl
  7008. "A list of include directories for Perl.
  7009. The value of this variable is a list of strings, where each
  7010. string is a directory to add to the include path of Perl.
  7011. Relative paths are relative to the file being checked."
  7012. :type '(repeat (directory :tag "Include directory"))
  7013. :safe #'flycheck-string-list-p
  7014. :package-version '(flycheck . "0.24"))
  7015. (flycheck-define-checker perl
  7016. "A Perl syntax checker using the Perl interpreter.
  7017. See URL `https://www.perl.org'."
  7018. :command ("perl" "-w" "-c"
  7019. (option-list "-I" flycheck-perl-include-path))
  7020. :standard-input t
  7021. :error-patterns
  7022. ((error line-start (minimal-match (message))
  7023. " at - line " line
  7024. (or "." (and ", " (zero-or-more not-newline))) line-end))
  7025. :modes (perl-mode cperl-mode)
  7026. :next-checkers (perl-perlcritic))
  7027. (flycheck-def-option-var flycheck-perlcritic-severity nil perl-perlcritic
  7028. "The message severity for Perl Critic.
  7029. The value of this variable is a severity level as integer, for
  7030. the `--severity' option to Perl Critic."
  7031. :type '(integer :tag "Severity level")
  7032. :safe #'integerp
  7033. :package-version '(flycheck . "0.18"))
  7034. (flycheck-def-config-file-var flycheck-perlcriticrc perl-perlcritic
  7035. ".perlcriticrc"
  7036. :safe #'stringp
  7037. :package-version '(flycheck . "26"))
  7038. (flycheck-define-checker perl-perlcritic
  7039. "A Perl syntax checker using Perl::Critic.
  7040. See URL `https://metacpan.org/pod/Perl::Critic'."
  7041. :command ("perlcritic" "--no-color" "--verbose" "%f/%l/%c/%s/%p/%m (%e)\n"
  7042. (config-file "--profile" flycheck-perlcriticrc)
  7043. (option "--severity" flycheck-perlcritic-severity nil
  7044. flycheck-option-int))
  7045. :standard-input t
  7046. :error-patterns
  7047. ((info line-start
  7048. "STDIN/" line "/" column "/" (any "1") "/"
  7049. (id (one-or-more (not (any "/")))) "/" (message)
  7050. line-end)
  7051. (warning line-start
  7052. "STDIN/" line "/" column "/" (any "234") "/"
  7053. (id (one-or-more (not (any "/")))) "/" (message)
  7054. line-end)
  7055. (error line-start
  7056. "STDIN/" line "/" column "/" (any "5") "/"
  7057. (id (one-or-more (not (any "/")))) "/" (message)
  7058. line-end))
  7059. :modes (cperl-mode perl-mode))
  7060. (flycheck-define-checker php
  7061. "A PHP syntax checker using the PHP command line interpreter.
  7062. See URL `http://php.net/manual/en/features.commandline.php'."
  7063. :command ("php" "-l" "-d" "error_reporting=E_ALL" "-d" "display_errors=1"
  7064. "-d" "log_errors=0" source)
  7065. :error-patterns
  7066. ((error line-start (or "Parse" "Fatal" "syntax") " error" (any ":" ",") " "
  7067. (message) " in " (file-name) " on line " line line-end))
  7068. :modes (php-mode php+-mode)
  7069. :next-checkers ((warning . php-phpmd)
  7070. (warning . php-phpcs)))
  7071. (flycheck-def-option-var flycheck-phpmd-rulesets
  7072. '("cleancode" "codesize" "controversial" "design" "naming" "unusedcode")
  7073. php-phpmd
  7074. "The rule sets for PHP Mess Detector.
  7075. Set default rule sets and custom rule set files.
  7076. See section \"Using multiple rule sets\" in the PHP Mess Detector
  7077. manual at URL `https://phpmd.org/documentation/index.html'."
  7078. :type '(repeat :tag "rule sets"
  7079. (string :tag "A filename or rule set"))
  7080. :safe #'flycheck-string-list-p)
  7081. (flycheck-define-checker php-phpmd
  7082. "A PHP style checker using PHP Mess Detector.
  7083. See URL `https://phpmd.org/'."
  7084. :command ("phpmd" source "xml"
  7085. (eval (flycheck-option-comma-separated-list
  7086. flycheck-phpmd-rulesets)))
  7087. :error-parser flycheck-parse-phpmd
  7088. :modes (php-mode php+-mode)
  7089. :next-checkers (php-phpcs))
  7090. (flycheck-def-option-var flycheck-phpcs-standard nil php-phpcs
  7091. "The coding standard for PHP CodeSniffer.
  7092. When nil, use the default standard from the global PHP
  7093. CodeSniffer configuration. When set to a string, pass the string
  7094. to PHP CodeSniffer which will interpret it as name as a standard,
  7095. or as path to a standard specification."
  7096. :type '(choice (const :tag "Default standard" nil)
  7097. (string :tag "Standard name or file"))
  7098. :safe #'stringp)
  7099. (flycheck-define-checker php-phpcs
  7100. "A PHP style checker using PHP Code Sniffer.
  7101. Needs PHP Code Sniffer 2.6 or newer.
  7102. See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
  7103. :command ("phpcs" "--report=checkstyle"
  7104. ;; Use -q flag to force quiet mode
  7105. ;; Quiet mode prevents errors from extra output when phpcs has
  7106. ;; been configured with show_progress enabled
  7107. "-q"
  7108. (option "--standard=" flycheck-phpcs-standard concat)
  7109. ;; Pass original file name to phpcs. We need to concat explicitly
  7110. ;; here, because phpcs really insists to get option and argument as
  7111. ;; a single command line argument :|
  7112. (eval (when (buffer-file-name)
  7113. (concat "--stdin-path=" (buffer-file-name)))))
  7114. :standard-input t
  7115. :error-parser flycheck-parse-checkstyle
  7116. :error-filter
  7117. (lambda (errors)
  7118. (flycheck-sanitize-errors
  7119. (flycheck-remove-error-file-names "STDIN" errors)))
  7120. :modes (php-mode php+-mode)
  7121. ;; phpcs seems to choke on empty standard input, hence skip phpcs if the
  7122. ;; buffer is empty, see https://github.com/flycheck/flycheck/issues/907
  7123. :predicate (lambda () (not (flycheck-buffer-empty-p))))
  7124. (flycheck-define-checker processing
  7125. "Processing command line tool.
  7126. See https://github.com/processing/processing/wiki/Command-Line"
  7127. :command ("processing-java" "--force"
  7128. ;; Don't change the order of these arguments, processing is pretty
  7129. ;; picky
  7130. (eval (concat "--sketch=" (file-name-directory (buffer-file-name))))
  7131. (eval (concat "--output=" (flycheck-temp-dir-system)))
  7132. "--build")
  7133. :error-patterns
  7134. ((error line-start (file-name) ":" line ":" column
  7135. (zero-or-more (or digit ":")) (message) line-end))
  7136. :modes processing-mode
  7137. ;; This syntax checker needs a file name
  7138. :predicate (lambda () (buffer-file-name)))
  7139. (defun flycheck-proselint-parse-errors (output checker buffer)
  7140. "Parse proselint json output errors from OUTPUT.
  7141. CHECKER and BUFFER denoted the CHECKER that returned OUTPUT and
  7142. the BUFFER that was checked respectively.
  7143. See URL `http://proselint.com/' for more information about proselint."
  7144. (mapcar (lambda (err)
  7145. (let-alist err
  7146. (flycheck-error-new-at
  7147. .line
  7148. .column
  7149. (pcase .severity
  7150. (`"suggestion" 'info)
  7151. (`"warning" 'warning)
  7152. (`"error" 'error)
  7153. ;; Default to error
  7154. (_ 'error))
  7155. .message
  7156. :id .check
  7157. :buffer buffer
  7158. :checker checker)))
  7159. (let-alist (car (flycheck-parse-json output))
  7160. .data.errors)))
  7161. (flycheck-define-checker proselint
  7162. "Flycheck checker using Proselint.
  7163. See URL `http://proselint.com/'."
  7164. :command ("proselint" "--json" "-")
  7165. :standard-input t
  7166. :error-parser flycheck-proselint-parse-errors
  7167. :modes (text-mode markdown-mode gfm-mode))
  7168. (flycheck-define-checker protobuf-protoc
  7169. "A protobuf syntax checker using the protoc compiler.
  7170. See URL `https://developers.google.com/protocol-buffers/'."
  7171. :command ("protoc" "--error_format" "gcc"
  7172. (eval (concat "--java_out=" (flycheck-temp-dir-system)))
  7173. ;; Add the file directory of protobuf path to resolve import directives
  7174. (eval (concat "--proto_path=" (file-name-directory (buffer-file-name))))
  7175. source-inplace)
  7176. :error-patterns
  7177. ((info line-start (file-name) ":" line ":" column
  7178. ": note: " (message) line-end)
  7179. (error line-start (file-name) ":" line ":" column
  7180. ": " (message) line-end)
  7181. (error line-start
  7182. (message "In file included from") " " (file-name) ":" line ":"
  7183. column ":" line-end))
  7184. :modes protobuf-mode
  7185. :predicate (lambda () (buffer-file-name)))
  7186. (flycheck-define-checker pug
  7187. "A Pug syntax checker using the pug compiler.
  7188. See URL `https://pugjs.org/'."
  7189. :command ("pug" "-p" (eval (expand-file-name (buffer-file-name))))
  7190. :standard-input t
  7191. :error-patterns
  7192. ;; errors with includes/extends (e.g. missing files)
  7193. ((error "Error: " (message) (zero-or-more not-newline) "\n"
  7194. (zero-or-more not-newline) "at "
  7195. (zero-or-more not-newline) " line " line)
  7196. ;; syntax/runtime errors (e.g. type errors, bad indentation, etc.)
  7197. (error line-start
  7198. (optional "Type") "Error: " (file-name) ":" line (optional ":" column)
  7199. (zero-or-more not-newline) "\n"
  7200. (one-or-more (or (zero-or-more not-newline) "|"
  7201. (zero-or-more not-newline) "\n")
  7202. (zero-or-more "-") (zero-or-more not-newline) "|"
  7203. (zero-or-more not-newline) "\n")
  7204. (zero-or-more not-newline) "\n"
  7205. (one-or-more
  7206. (zero-or-more not-newline) "|"
  7207. (zero-or-more not-newline) "\n") (zero-or-more not-newline) "\n"
  7208. (message) line-end))
  7209. :modes pug-mode)
  7210. (flycheck-define-checker puppet-parser
  7211. "A Puppet DSL syntax checker using puppet's own parser.
  7212. See URL `https://puppet.com/'."
  7213. :command ("puppet" "parser" "validate" "--color=false")
  7214. :standard-input t
  7215. :error-patterns
  7216. (
  7217. ;; Patterns for Puppet 4
  7218. (error line-start "Error: Could not parse for environment "
  7219. (one-or-more (in "a-z" "0-9" "_")) ":"
  7220. (message) " at line " line ":" column line-end)
  7221. ;; Errors from Puppet < 4
  7222. (error line-start "Error: Could not parse for environment "
  7223. (one-or-more (in "a-z" "0-9" "_")) ":"
  7224. (message (minimal-match (one-or-more anything)))
  7225. " at line " line line-end)
  7226. (error line-start
  7227. ;; Skip over the path of the Puppet executable
  7228. (minimal-match (zero-or-more not-newline))
  7229. ": Could not parse for environment " (one-or-more word)
  7230. ": " (message (minimal-match (zero-or-more anything)))
  7231. " at " (file-name "/" (zero-or-more not-newline)) ":" line line-end))
  7232. :modes puppet-mode
  7233. :next-checkers ((warning . puppet-lint)))
  7234. (flycheck-def-config-file-var flycheck-puppet-lint-rc puppet-lint
  7235. ".puppet-lint.rc"
  7236. :safe #'stringp
  7237. :package-version '(flycheck . "26"))
  7238. (flycheck-def-option-var flycheck-puppet-lint-disabled-checks nil puppet-lint
  7239. "Disabled checkers for `puppet-lint'.
  7240. The value of this variable is a list of strings, where each
  7241. string is the name of a check to disable (e.g. \"80chars\" or
  7242. \"double_quoted_strings\").
  7243. See URL `http://puppet-lint.com/checks/' for a list of all checks
  7244. and their names."
  7245. :type '(repeat (string :tag "Check Name"))
  7246. :package-version '(flycheck . "26"))
  7247. (defun flycheck-puppet-lint-disabled-arg-name (check)
  7248. "Create an argument to disable a puppetlint CHECK."
  7249. (concat "--no-" check "-check"))
  7250. (flycheck-define-checker puppet-lint
  7251. "A Puppet DSL style checker using puppet-lint.
  7252. See URL `http://puppet-lint.com/'."
  7253. ;; We must check the original file, because Puppetlint is quite picky on the
  7254. ;; names of files and there place in the directory structure, to comply with
  7255. ;; Puppet's autoload directory layout. For instance, a class foo::bar is
  7256. ;; required to be in a file foo/bar.pp. Any other place, such as a Flycheck
  7257. ;; temporary file will cause an error.
  7258. :command ("puppet-lint"
  7259. (config-file "--config" flycheck-puppet-lint-rc)
  7260. "--log-format"
  7261. "%{path}:%{line}:%{kind}: %{message} (%{check})"
  7262. (option-list "" flycheck-puppet-lint-disabled-checks concat
  7263. flycheck-puppet-lint-disabled-arg-name)
  7264. source-original)
  7265. :error-patterns
  7266. ((warning line-start (file-name) ":" line ":warning: " (message) line-end)
  7267. (error line-start (file-name) ":" line ":error: " (message) line-end))
  7268. :modes puppet-mode
  7269. ;; Since we check the original file, we can only use this syntax checker if
  7270. ;; the buffer is actually linked to a file, and if it is not modified.
  7271. :predicate flycheck-buffer-saved-p)
  7272. (flycheck-def-config-file-var flycheck-flake8rc python-flake8 ".flake8rc"
  7273. :safe #'stringp)
  7274. (flycheck-def-option-var flycheck-flake8-error-level-alist
  7275. '(("^E9.*$" . error) ; Syntax errors from pep8
  7276. ("^F82.*$" . error) ; undefined variables from pyflakes
  7277. ("^F83.*$" . error) ; Duplicate arguments from flake8
  7278. ("^D.*$" . info) ; Docstring issues from flake8-pep257
  7279. ("^N.*$" . info) ; Naming issues from pep8-naming
  7280. )
  7281. python-flake8
  7282. "An alist mapping flake8 error IDs to Flycheck error levels.
  7283. Each item in this list is a cons cell `(PATTERN . LEVEL)' where
  7284. PATTERN is a regular expression matched against the error ID, and
  7285. LEVEL is a Flycheck error level symbol.
  7286. Each PATTERN is matched in the order of appearance in this list
  7287. against the error ID. If it matches the ID, the level of the
  7288. corresponding error is set to LEVEL. An error that is not
  7289. matched by any PATTERN defaults to warning level.
  7290. The default value of this option matches errors from flake8
  7291. itself and from the following flake8 plugins:
  7292. - pep8-naming
  7293. - flake8-pep257
  7294. You may add your own mappings to this option in order to support
  7295. further flake8 plugins."
  7296. :type '(repeat (cons (regexp :tag "Error ID pattern")
  7297. (symbol :tag "Error level")))
  7298. :package-version '(flycheck . "0.22"))
  7299. (flycheck-def-option-var flycheck-flake8-maximum-complexity nil python-flake8
  7300. "The maximum McCabe complexity of methods.
  7301. If nil, do not check the complexity of methods. If set to an
  7302. integer, report any complexity greater than the value of this
  7303. variable as warning.
  7304. If set to an integer, this variable overrules any similar setting
  7305. in the configuration file denoted by `flycheck-flake8rc'."
  7306. :type '(choice (const :tag "Do not check McCabe complexity" nil)
  7307. (integer :tag "Maximum complexity"))
  7308. :safe #'integerp)
  7309. (flycheck-def-option-var flycheck-flake8-maximum-line-length nil python-flake8
  7310. "The maximum length of lines.
  7311. If set to an integer, the value of this variable denotes the
  7312. maximum length of lines, overruling any similar setting in the
  7313. configuration file denoted by `flycheck-flake8rc'. An error will
  7314. be reported for any line longer than the value of this variable.
  7315. If set to nil, use the maximum line length from the configuration
  7316. file denoted by `flycheck-flake8rc', or the PEP 8 recommendation
  7317. of 79 characters if there is no configuration with this setting."
  7318. :type '(choice (const :tag "Default value")
  7319. (integer :tag "Maximum line length in characters"))
  7320. :safe #'integerp)
  7321. (defun flycheck-flake8-fix-error-level (err)
  7322. "Fix the error level of ERR.
  7323. Update the error level of ERR according to
  7324. `flycheck-flake8-error-level-alist'."
  7325. (pcase-dolist (`(,pattern . ,level) flycheck-flake8-error-level-alist)
  7326. (when (string-match-p pattern (flycheck-error-id err))
  7327. (setf (flycheck-error-level err) level)))
  7328. err)
  7329. (flycheck-define-checker python-flake8
  7330. "A Python syntax and style checker using Flake8.
  7331. Requires Flake8 3.0 or newer. See URL
  7332. `https://flake8.readthedocs.io/'."
  7333. :command ("flake8"
  7334. "--format=default"
  7335. (config-file "--config" flycheck-flake8rc)
  7336. (option "--max-complexity" flycheck-flake8-maximum-complexity nil
  7337. flycheck-option-int)
  7338. (option "--max-line-length" flycheck-flake8-maximum-line-length nil
  7339. flycheck-option-int)
  7340. "-")
  7341. :standard-input t
  7342. :error-filter (lambda (errors)
  7343. (let ((errors (flycheck-sanitize-errors errors)))
  7344. (seq-map #'flycheck-flake8-fix-error-level errors)))
  7345. :error-patterns
  7346. ((warning line-start
  7347. "stdin:" line ":" (optional column ":") " "
  7348. (id (one-or-more (any alpha)) (one-or-more digit)) " "
  7349. (message (one-or-more not-newline))
  7350. line-end))
  7351. :modes python-mode)
  7352. (flycheck-def-config-file-var flycheck-pylintrc python-pylint
  7353. ".pylintrc"
  7354. :safe #'stringp)
  7355. (flycheck-def-option-var flycheck-pylint-use-symbolic-id t python-pylint
  7356. "Whether to use pylint message symbols or message codes.
  7357. A pylint message has both an opaque identifying code (such as `F0401') and a
  7358. more meaningful symbolic code (such as `import-error'). This option governs
  7359. which should be used and reported to the user."
  7360. :type 'boolean
  7361. :safe #'booleanp
  7362. :package-version '(flycheck . "0.25"))
  7363. (flycheck-define-checker python-pylint
  7364. "A Python syntax and style checker using Pylint.
  7365. This syntax checker requires Pylint 1.0 or newer.
  7366. See URL `https://www.pylint.org/'."
  7367. ;; -r n disables the scoring report
  7368. :command ("pylint" "-r" "n"
  7369. "--output-format" "text"
  7370. "--msg-template"
  7371. (eval (if flycheck-pylint-use-symbolic-id
  7372. "{path}:{line}:{column}:{C}:{symbol}:{msg}"
  7373. "{path}:{line}:{column}:{C}:{msg_id}:{msg}"))
  7374. (config-file "--rcfile" flycheck-pylintrc)
  7375. ;; Need `source-inplace' for relative imports (e.g. `from .foo
  7376. ;; import bar'), see https://github.com/flycheck/flycheck/issues/280
  7377. source-inplace)
  7378. :error-filter
  7379. (lambda (errors)
  7380. (flycheck-sanitize-errors (flycheck-increment-error-columns errors)))
  7381. :error-patterns
  7382. ((error line-start (file-name) ":" line ":" column ":"
  7383. (or "E" "F") ":"
  7384. (id (one-or-more (not (any ":")))) ":"
  7385. (message) line-end)
  7386. (warning line-start (file-name) ":" line ":" column ":"
  7387. (or "W" "R") ":"
  7388. (id (one-or-more (not (any ":")))) ":"
  7389. (message) line-end)
  7390. (info line-start (file-name) ":" line ":" column ":"
  7391. "C:" (id (one-or-more (not (any ":")))) ":"
  7392. (message) line-end))
  7393. :modes python-mode)
  7394. (flycheck-define-checker python-pycompile
  7395. "A Python syntax checker using Python's builtin compiler.
  7396. See URL `https://docs.python.org/3.4/library/py_compile.html'."
  7397. :command ("python" "-m" "py_compile" source)
  7398. :error-patterns
  7399. ;; Python 2.7
  7400. ((error line-start " File \"" (file-name) "\", line " line "\n"
  7401. (>= 2 (zero-or-more not-newline) "\n")
  7402. "SyntaxError: " (message) line-end)
  7403. (error line-start "Sorry: IndentationError: "
  7404. (message) "(" (file-name) ", line " line ")"
  7405. line-end)
  7406. ;; 2.6
  7407. (error line-start "SyntaxError: ('" (message (one-or-more (not (any "'"))))
  7408. "', ('" (file-name (one-or-more (not (any "'")))) "', "
  7409. line ", " column ", " (one-or-more not-newline) line-end))
  7410. :modes python-mode)
  7411. (flycheck-def-option-var flycheck-lintr-caching t r-lintr
  7412. "Whether to enable caching in lintr.
  7413. By default, lintr caches all expressions in a file and re-checks
  7414. only those that have changed. Setting this option to nil
  7415. disables caching in case there are problems."
  7416. :type 'boolean
  7417. :safe #'booleanp
  7418. :package-version '(flycheck . "0.23"))
  7419. (flycheck-def-option-var flycheck-lintr-linters "default_linters" r-lintr
  7420. "Linters to use with lintr.
  7421. The value of this variable is a string containing an R
  7422. expression, which selects linters for lintr."
  7423. :type 'string
  7424. :risky t
  7425. :package-version '(flycheck . "0.23"))
  7426. (defun flycheck-r-has-lintr (R)
  7427. "Whether R has installed the `lintr' library."
  7428. (with-temp-buffer
  7429. (let ((process-environment (append '("LC_ALL=C") process-environment)))
  7430. (call-process R nil t nil
  7431. "--slave" "--restore" "--no-save" "-e"
  7432. "library('lintr')")
  7433. (goto-char (point-min))
  7434. (not (re-search-forward "there is no package called 'lintr'" nil 'no-error)))))
  7435. (flycheck-define-checker r-lintr
  7436. "An R style and syntax checker using the lintr package.
  7437. See URL `https://github.com/jimhester/lintr'."
  7438. :command ("R" "--slave" "--restore" "--no-save" "-e"
  7439. (eval (concat
  7440. "library(lintr);"
  7441. "try(lint(commandArgs(TRUE)"
  7442. ", cache=" (if flycheck-lintr-caching "TRUE" "FALSE")
  7443. ", " flycheck-lintr-linters
  7444. "))"))
  7445. "--args" source)
  7446. :error-patterns
  7447. ((info line-start (file-name) ":" line ":" column ": style: " (message)
  7448. line-end)
  7449. (warning line-start (file-name) ":" line ":" column ": warning: " (message)
  7450. line-end)
  7451. (error line-start (file-name) ":" line ":" column ": error: " (message)
  7452. line-end))
  7453. :modes ess-mode
  7454. :predicate
  7455. ;; Don't check ESS files which do not contain R, and make sure that lintr is
  7456. ;; actually available
  7457. (lambda ()
  7458. (and (equal ess-language "S")
  7459. (flycheck-r-has-lintr (flycheck-checker-executable 'r-lintr))))
  7460. :verify (lambda (checker)
  7461. (let ((has-lintr (flycheck-r-has-lintr
  7462. (flycheck-checker-executable checker))))
  7463. (list
  7464. (flycheck-verification-result-new
  7465. :label "lintr library"
  7466. :message (if has-lintr "present" "missing")
  7467. :face (if has-lintr 'success '(bold error)))))))
  7468. (defun flycheck-racket-has-expand-p (checker)
  7469. "Whether the executable of CHECKER provides the `expand' command."
  7470. (let ((raco (flycheck-find-checker-executable checker)))
  7471. (when raco
  7472. (with-temp-buffer
  7473. (call-process raco nil t nil "expand")
  7474. (goto-char (point-min))
  7475. (not (looking-at-p (rx bol (1+ not-newline)
  7476. "Unrecognized command: expand"
  7477. eol)))))))
  7478. (flycheck-define-checker racket
  7479. "A Racket syntax checker with `raco expand'.
  7480. The `compiler-lib' racket package is required for this syntax
  7481. checker.
  7482. See URL `https://racket-lang.org/'."
  7483. :command ("raco" "expand" source-inplace)
  7484. :predicate
  7485. (lambda ()
  7486. (and (or (not (eq major-mode 'scheme-mode))
  7487. ;; In `scheme-mode' we must check the current Scheme implementation
  7488. ;; being used
  7489. (and (boundp 'geiser-impl--implementation)
  7490. (eq geiser-impl--implementation 'racket)))
  7491. (flycheck-racket-has-expand-p 'racket)))
  7492. :verify
  7493. (lambda (checker)
  7494. (let ((has-expand (flycheck-racket-has-expand-p checker))
  7495. (in-scheme-mode (eq major-mode 'scheme-mode))
  7496. (geiser-impl (bound-and-true-p geiser-impl--implementation)))
  7497. (list
  7498. (flycheck-verification-result-new
  7499. :label "compiler-lib package"
  7500. :message (if has-expand "present" "missing")
  7501. :face (if has-expand 'success '(bold error)))
  7502. (flycheck-verification-result-new
  7503. :label "Geiser Implementation"
  7504. :message (cond
  7505. ((not in-scheme-mode) "Using Racket Mode")
  7506. ((eq geiser-impl 'racket) "Racket")
  7507. (geiser-impl (format "Other: %s" geiser-impl))
  7508. (t "Geiser not active"))
  7509. :face (cond
  7510. ((or (not in-scheme-mode) (eq geiser-impl 'racket)) 'success)
  7511. (t '(bold error)))))))
  7512. :error-filter
  7513. (lambda (errors)
  7514. (flycheck-sanitize-errors (flycheck-increment-error-columns errors)))
  7515. :error-patterns
  7516. ((error line-start (file-name) ":" line ":" column ":" (message) line-end))
  7517. :modes (racket-mode scheme-mode))
  7518. (flycheck-define-checker rpm-rpmlint
  7519. "A RPM SPEC file syntax checker using rpmlint.
  7520. See URL `https://sourceforge.net/projects/rpmlint/'."
  7521. :command ("rpmlint" source)
  7522. :error-patterns
  7523. ((error line-start
  7524. (file-name) ":" (optional line ":") " E: " (message)
  7525. line-end)
  7526. (warning line-start
  7527. (file-name) ":" (optional line ":") " W: " (message)
  7528. line-end))
  7529. :error-filter
  7530. ;; Add fake line numbers if they are missing in the lint output
  7531. (lambda (errors)
  7532. (dolist (err errors)
  7533. (unless (flycheck-error-line err)
  7534. (setf (flycheck-error-line err) 1)))
  7535. errors)
  7536. :error-explainer
  7537. (lambda (error)
  7538. (-when-let* ((error-message (flycheck-error-message error))
  7539. (message-id (save-match-data (string-match "\\([^ ]+\\)" error-message)
  7540. (match-string 1 error-message))))
  7541. (with-output-to-string
  7542. (call-process "rpmlint" nil standard-output nil "-I" message-id))))
  7543. :modes (sh-mode rpm-spec-mode)
  7544. :predicate (lambda () (or (not (eq major-mode 'sh-mode))
  7545. ;; In `sh-mode', we need the proper shell
  7546. (eq sh-shell 'rpm))))
  7547. (flycheck-def-option-var flycheck-markdown-mdl-rules nil markdown-mdl
  7548. "Rules to enable for mdl.
  7549. The value of this variable is a list of strings each of which is
  7550. the name of a rule to enable.
  7551. By default all rules are enabled.
  7552. See URL
  7553. `https://github.com/mivok/markdownlint/blob/master/docs/configuration.md'."
  7554. :type '(repeat :tag "Enabled rules"
  7555. (string :tag "rule name"))
  7556. :safe #'flycheck-string-list-p
  7557. :package-version '(flycheck . "27"))
  7558. (flycheck-def-option-var flycheck-markdown-mdl-tags nil markdown-mdl
  7559. "Rule tags to enable for mdl.
  7560. The value of this variable is a list of strings each of which is
  7561. the name of a rule tag. Only rules with these tags are enabled.
  7562. By default all rules are enabled.
  7563. See URL
  7564. `https://github.com/mivok/markdownlint/blob/master/docs/configuration.md'."
  7565. :type '(repeat :tag "Enabled tags"
  7566. (string :tag "tag name"))
  7567. :safe #'flycheck-string-list-p
  7568. :package-version '(flycheck . "27"))
  7569. (flycheck-def-config-file-var flycheck-markdown-mdl-style markdown-mdl nil
  7570. :safe #'stringp
  7571. :package-version '(flycheck . "27"))
  7572. (flycheck-define-checker markdown-mdl
  7573. "Markdown checker using mdl.
  7574. See URL `https://github.com/mivok/markdownlint'."
  7575. :command ("mdl"
  7576. (config-file "--style" flycheck-markdown-mdl-style)
  7577. (option "--tags=" flycheck-markdown-mdl-rules concat
  7578. flycheck-option-comma-separated-list)
  7579. (option "--rules=" flycheck-markdown-mdl-rules concat
  7580. flycheck-option-comma-separated-list))
  7581. :standard-input t
  7582. :error-patterns
  7583. ((error line-start
  7584. (file-name) ":" line ": " (id (one-or-more alnum)) " " (message)
  7585. line-end))
  7586. :error-filter
  7587. (lambda (errors)
  7588. (flycheck-sanitize-errors
  7589. (flycheck-remove-error-file-names "(stdin)" errors)))
  7590. :modes (markdown-mode gfm-mode))
  7591. (flycheck-define-checker nix
  7592. "Nix checker using nix-instantiate.
  7593. See URL `https://nixos.org/nix/manual/#sec-nix-instantiate'."
  7594. :command ("nix-instantiate" "--parse" "-")
  7595. :standard-input t
  7596. :error-patterns
  7597. ((error line-start
  7598. "error: " (message) " at " (file-name) ":" line ":" column
  7599. line-end))
  7600. :error-filter
  7601. (lambda (errors)
  7602. (flycheck-sanitize-errors
  7603. (flycheck-remove-error-file-names "(string)" errors)))
  7604. :modes nix-mode)
  7605. (defun flycheck-locate-sphinx-source-directory ()
  7606. "Locate the Sphinx source directory for the current buffer.
  7607. Return the source directory, or nil, if the current buffer is not
  7608. part of a Sphinx project."
  7609. (-when-let* ((filename (buffer-file-name))
  7610. (dir (locate-dominating-file filename "conf.py")))
  7611. (expand-file-name dir)))
  7612. (flycheck-define-checker rst
  7613. "A ReStructuredText (RST) syntax checker using Docutils.
  7614. See URL `http://docutils.sourceforge.net/'."
  7615. ;; We need to use source-inplace to properly resolve relative paths in
  7616. ;; include:: directives
  7617. :command ("rst2pseudoxml.py" "--report=2" "--halt=5"
  7618. ;; Read from standard input and throw output away
  7619. "-" null-device)
  7620. :standard-input t
  7621. :error-patterns
  7622. ((warning line-start "<stdin>:" line ": (WARNING/2) " (message) line-end)
  7623. (error line-start "<stdin>:" line
  7624. ": (" (or "ERROR/3" "SEVERE/4") ") "
  7625. (message) line-end))
  7626. :modes rst-mode)
  7627. (flycheck-def-option-var flycheck-sphinx-warn-on-missing-references t rst-sphinx
  7628. "Whether to warn about missing references in Sphinx.
  7629. When non-nil (the default), warn about all missing references in
  7630. Sphinx via `-n'."
  7631. :type 'boolean
  7632. :safe #'booleanp
  7633. :package-version '(flycheck . "0.17"))
  7634. (flycheck-define-checker rst-sphinx
  7635. "A ReStructuredText (RST) syntax checker using Sphinx.
  7636. Requires Sphinx 1.2 or newer. See URL `http://sphinx-doc.org'."
  7637. :command ("sphinx-build" "-b" "pseudoxml"
  7638. "-q" "-N" ; Reduced output and no colors
  7639. (option-flag "-n" flycheck-sphinx-warn-on-missing-references)
  7640. (eval (flycheck-locate-sphinx-source-directory))
  7641. temporary-directory ; Redirect the output to a temporary
  7642. ; directory
  7643. source-original) ; Sphinx needs the original document
  7644. :error-patterns
  7645. ((warning line-start (file-name) ":" line ": WARNING: " (message) line-end)
  7646. (error line-start
  7647. (file-name) ":" line
  7648. ": " (or "ERROR" "SEVERE") ": "
  7649. (message) line-end))
  7650. :modes rst-mode
  7651. :predicate (lambda () (and (flycheck-buffer-saved-p)
  7652. (flycheck-locate-sphinx-source-directory))))
  7653. (flycheck-def-config-file-var flycheck-rubocoprc ruby-rubocop ".rubocop.yml"
  7654. :safe #'stringp)
  7655. (flycheck-def-option-var flycheck-rubocop-lint-only nil ruby-rubocop
  7656. "Whether to only report code issues in Rubocop.
  7657. When non-nil, only report code issues in Rubocop, via `--lint'.
  7658. Otherwise report style issues as well."
  7659. :safe #'booleanp
  7660. :type 'boolean
  7661. :package-version '(flycheck . "0.16"))
  7662. (flycheck-define-checker ruby-rubocop
  7663. "A Ruby syntax and style checker using the RuboCop tool.
  7664. You need at least RuboCop 0.34 for this syntax checker.
  7665. See URL `http://batsov.com/rubocop/'."
  7666. :command ("rubocop" "--display-cop-names" "--format" "emacs"
  7667. ;; Explicitly disable caching to prevent Rubocop 0.35.1 and earlier
  7668. ;; from caching standard input. Later versions of Rubocop
  7669. ;; automatically disable caching with --stdin, see
  7670. ;; https://github.com/flycheck/flycheck/issues/844 and
  7671. ;; https://github.com/bbatsov/rubocop/issues/2576
  7672. "--cache" "false"
  7673. (config-file "--config" flycheck-rubocoprc)
  7674. (option-flag "--lint" flycheck-rubocop-lint-only)
  7675. ;; Rubocop takes the original file name as argument when reading
  7676. ;; from standard input
  7677. "--stdin" source-original)
  7678. :standard-input t
  7679. :error-patterns
  7680. ((info line-start (file-name) ":" line ":" column ": C: "
  7681. (optional (id (one-or-more (not (any ":")))) ": ") (message) line-end)
  7682. (warning line-start (file-name) ":" line ":" column ": W: "
  7683. (optional (id (one-or-more (not (any ":")))) ": ") (message)
  7684. line-end)
  7685. (error line-start (file-name) ":" line ":" column ": " (or "E" "F") ": "
  7686. (optional (id (one-or-more (not (any ":")))) ": ") (message)
  7687. line-end))
  7688. :modes (enh-ruby-mode ruby-mode)
  7689. :next-checkers ((warning . ruby-reek)
  7690. (warning . ruby-rubylint)))
  7691. ;; Default to `nil' to let Reek find its configuration file by itself
  7692. (flycheck-def-config-file-var flycheck-reekrc ruby-reek nil
  7693. :safe #'string-or-null-p
  7694. :package-version '(flycheck . "30"))
  7695. (flycheck-define-checker ruby-reek
  7696. "A Ruby smell checker using reek.
  7697. See URL `https://github.com/troessner/reek'."
  7698. :command ("reek" "--format" "json"
  7699. (config-file "--config" flycheck-reekrc)
  7700. source)
  7701. :error-parser flycheck-parse-reek
  7702. :modes (enh-ruby-mode ruby-mode)
  7703. :next-checkers ((warning . ruby-rubylint)))
  7704. ;; Default to `nil' to let Rubylint find its configuration file by itself, and
  7705. ;; to maintain backwards compatibility with older Rubylint and Flycheck releases
  7706. (flycheck-def-config-file-var flycheck-rubylintrc ruby-rubylint nil
  7707. :safe #'stringp)
  7708. (flycheck-define-checker ruby-rubylint
  7709. "A Ruby syntax and code analysis checker using ruby-lint.
  7710. Requires ruby-lint 2.0.2 or newer. See URL
  7711. `https://github.com/YorickPeterse/ruby-lint'."
  7712. :command ("ruby-lint" "--presenter=syntastic"
  7713. (config-file "--config" flycheck-rubylintrc)
  7714. source)
  7715. ;; Ruby Lint can't read from standard input
  7716. :error-patterns
  7717. ((info line-start
  7718. (file-name) ":I:" line ":" column ": " (message) line-end)
  7719. (warning line-start
  7720. (file-name) ":W:" line ":" column ": " (message) line-end)
  7721. (error line-start
  7722. (file-name) ":E:" line ":" column ": " (message) line-end))
  7723. :modes (enh-ruby-mode ruby-mode))
  7724. (flycheck-define-checker ruby
  7725. "A Ruby syntax checker using the standard Ruby interpreter.
  7726. Please note that the output of different Ruby versions and
  7727. implementations varies wildly. This syntax checker supports
  7728. current versions of MRI and JRuby, but may break when used with
  7729. other implementations or future versions of these
  7730. implementations.
  7731. Please consider using `ruby-rubocop' or `ruby-reek' instead.
  7732. See URL `https://www.ruby-lang.org/'."
  7733. :command ("ruby" "-w" "-c")
  7734. :standard-input t
  7735. :error-patterns
  7736. ;; These patterns support output from JRuby, too, to deal with RVM or Rbenv
  7737. ((error line-start "SyntaxError in -:" line ": " (message) line-end)
  7738. (warning line-start "-:" line ":" (optional column ":")
  7739. " warning: " (message) line-end)
  7740. (error line-start "-:" line ": " (message) line-end))
  7741. :modes (enh-ruby-mode ruby-mode)
  7742. :next-checkers ((warning . ruby-rubylint)))
  7743. (flycheck-define-checker ruby-jruby
  7744. "A Ruby syntax checker using the JRuby interpreter.
  7745. This syntax checker is very primitive, and may break on future
  7746. versions of JRuby.
  7747. Please consider using `ruby-rubocop' or `ruby-rubylint' instead.
  7748. See URL `http://jruby.org/'."
  7749. :command ("jruby" "-w" "-c")
  7750. :standard-input t
  7751. :error-patterns
  7752. ((error line-start "SyntaxError in -:" line ": " (message) line-end)
  7753. (warning line-start "-:" line ":" " warning: " (message) line-end)
  7754. (error line-start "-:" line ": " (message) line-end))
  7755. :modes (enh-ruby-mode ruby-mode)
  7756. :next-checkers ((warning . ruby-rubylint)))
  7757. (flycheck-def-args-var flycheck-cargo-rustc-args (rust-cargo)
  7758. :package-version '(flycheck . "30"))
  7759. (flycheck-def-args-var flycheck-rust-args (rust-cargo rust)
  7760. :package-version '(flycheck . "0.24"))
  7761. (flycheck-def-option-var flycheck-rust-check-tests t (rust-cargo rust)
  7762. "Whether to check test code in Rust.
  7763. When non-nil, `rustc' is passed the `--test' flag, which will
  7764. check any code marked with the `#[cfg(test)]' attribute and any
  7765. functions marked with `#[test]'. Otherwise, `rustc' is not passed
  7766. `--test' and test code will not be checked. Skipping `--test' is
  7767. necessary when using `#![no_std]', because compiling the test
  7768. runner requires `std'."
  7769. :type 'boolean
  7770. :safe #'booleanp
  7771. :package-version '("flycheck" . "0.19"))
  7772. (flycheck-def-option-var flycheck-rust-crate-root nil rust
  7773. "A path to the crate root for the current buffer.
  7774. The value of this variable is either a string with the path to
  7775. the crate root for the current buffer, or nil if the current buffer
  7776. is a crate. A relative path is relative to the current buffer.
  7777. If this variable is non nil the current buffer will only be checked
  7778. if it is not modified, i.e. after it has been saved."
  7779. :type 'string
  7780. :package-version '(flycheck . "0.20")
  7781. :safe #'stringp)
  7782. (make-variable-buffer-local 'flycheck-rust-crate-root)
  7783. (flycheck-def-option-var flycheck-rust-crate-type "lib" (rust-cargo rust)
  7784. "The type of the Rust Crate to check.
  7785. For `rust-cargo', the value should be a string denoting the
  7786. target type passed to Cargo. See
  7787. `flycheck-rust-valid-crate-type-p' for the list of allowed
  7788. values.
  7789. For `rust', the value should be a string denoting the crate type
  7790. for the `--crate-type' flag of rustc."
  7791. :type '(choice (const :tag "nil (rust/rust-cargo)" nil)
  7792. (const :tag "lib (rust/rust-cargo)" "lib")
  7793. (const :tag "bin (rust/rust-cargo)" "bin")
  7794. (const :tag "example (rust-cargo)" "example")
  7795. (const :tag "test (rust-cargo)" "test")
  7796. (const :tag "bench (rust-cargo)" "bench")
  7797. (const :tag "rlib (rust)" "rlib")
  7798. (const :tag "dylib (rust)" "dylib")
  7799. (const :tag "cdylib (rust)" "cdylib")
  7800. (const :tag "staticlib (rust)" "staticlib")
  7801. (const :tag "metadata (rust)" "metadata"))
  7802. :safe #'stringp
  7803. :package-version '(flycheck . "0.20"))
  7804. (make-variable-buffer-local 'flycheck-rust-crate-type)
  7805. (flycheck-def-option-var flycheck-rust-binary-name nil rust-cargo
  7806. "The name of the binary to pass to `cargo rustc --CRATE-TYPE'.
  7807. The value of this variable is a string denoting the name of the
  7808. target to check: usually the name of the crate, or the name of
  7809. one of the files under `src/bin', `tests', `examples' or
  7810. `benches'.
  7811. This always requires a non-nil value, unless
  7812. `flycheck-rust-crate-type' is `lib' or nil, in which case it is
  7813. ignored."
  7814. :type 'string
  7815. :safe #'stringp
  7816. :package-version '(flycheck . "28"))
  7817. (make-variable-buffer-local 'flycheck-rust-binary-name)
  7818. (flycheck-def-option-var flycheck-rust-library-path nil rust
  7819. "A list of library directories for Rust.
  7820. The value of this variable is a list of strings, where each
  7821. string is a directory to add to the library path of Rust.
  7822. Relative paths are relative to the file being checked."
  7823. :type '(repeat (directory :tag "Library directory"))
  7824. :safe #'flycheck-string-list-p
  7825. :package-version '(flycheck . "0.18"))
  7826. (defun flycheck-rust-error-explainer (error)
  7827. "Return an explanation text for the given `flycheck-error' ERROR."
  7828. (-when-let (error-code (flycheck-error-id error))
  7829. (with-output-to-string
  7830. (call-process "rustc" nil standard-output nil "--explain" error-code))))
  7831. (defun flycheck-rust-error-filter (errors)
  7832. "Filter ERRORS from rustc output that have no explanatory value."
  7833. (seq-remove (lambda (err)
  7834. (string-match-p
  7835. (rx "aborting due to " (optional (one-or-more num) " ")
  7836. "previous error")
  7837. (flycheck-error-message err)))
  7838. errors))
  7839. (defun flycheck-rust-valid-crate-type-p (crate-type)
  7840. "Whether CRATE-TYPE is a valid target type for Cargo.
  7841. A valid Cargo target type is one of `lib', `bin', `example',
  7842. `test' or `bench'."
  7843. (member crate-type '(nil "lib" "bin" "example" "test" "bench")))
  7844. (flycheck-define-checker rust-cargo
  7845. "A Rust syntax checker using Cargo.
  7846. This syntax checker requires Rust 1.15 or newer. See URL
  7847. `https://www.rust-lang.org'."
  7848. :command ("cargo" "rustc"
  7849. (eval (when flycheck-rust-crate-type
  7850. (concat "--" flycheck-rust-crate-type)))
  7851. ;; All crate targets except "lib" need a binary name
  7852. (eval (when (and flycheck-rust-crate-type
  7853. (not (string= flycheck-rust-crate-type "lib")))
  7854. flycheck-rust-binary-name))
  7855. "--message-format=json"
  7856. (eval flycheck-cargo-rustc-args)
  7857. "--"
  7858. ;; Passing the "--test" flag when the target is a test binary or
  7859. ;; bench is unnecessary and triggers an error.
  7860. (eval (when flycheck-rust-check-tests
  7861. (unless (member flycheck-rust-crate-type '("test" "bench"))
  7862. "--test")))
  7863. (eval flycheck-rust-args))
  7864. :error-parser flycheck-parse-cargo-rustc
  7865. :error-filter flycheck-rust-error-filter
  7866. :error-explainer flycheck-rust-error-explainer
  7867. :modes rust-mode
  7868. :predicate flycheck-buffer-saved-p
  7869. :enabled (lambda ()
  7870. (-when-let (file (buffer-file-name))
  7871. (locate-dominating-file file "Cargo.toml")))
  7872. :verify (lambda (_)
  7873. (-when-let (file (buffer-file-name))
  7874. (let* ((has-toml (locate-dominating-file file "Cargo.toml"))
  7875. (valid-crate-type (flycheck-rust-valid-crate-type-p
  7876. flycheck-rust-crate-type))
  7877. (need-binary-name
  7878. (and flycheck-rust-crate-type
  7879. (not (string= flycheck-rust-crate-type "lib")))))
  7880. (list
  7881. (flycheck-verification-result-new
  7882. :label "Cargo.toml"
  7883. :message (if has-toml "Found" "Missing")
  7884. :face (if has-toml 'success '(bold warning)))
  7885. (flycheck-verification-result-new
  7886. :label "Crate type"
  7887. :message (if valid-crate-type
  7888. (format "%s" flycheck-rust-crate-type)
  7889. (format "%s (invalid, should be one of 'lib', 'bin', 'test', 'example' or 'bench')"
  7890. flycheck-rust-crate-type))
  7891. :face (if valid-crate-type 'success '(bold error)))
  7892. (flycheck-verification-result-new
  7893. :label "Binary name"
  7894. :message (cond
  7895. ((not need-binary-name) "Not required")
  7896. ((not flycheck-rust-binary-name) "Required")
  7897. (t (format "%s" flycheck-rust-binary-name)))
  7898. :face (cond
  7899. ((not need-binary-name) 'success)
  7900. ((not flycheck-rust-binary-name) '(bold error))
  7901. (t 'success))))))))
  7902. (flycheck-define-checker rust
  7903. "A Rust syntax checker using Rust compiler.
  7904. This syntax checker needs Rust 1.7 or newer. See URL
  7905. `https://www.rust-lang.org'."
  7906. :command ("rustc"
  7907. (option "--crate-type" flycheck-rust-crate-type)
  7908. "--error-format=json"
  7909. (option-flag "--test" flycheck-rust-check-tests)
  7910. (option-list "-L" flycheck-rust-library-path concat)
  7911. (eval flycheck-rust-args)
  7912. (eval (or flycheck-rust-crate-root
  7913. (flycheck-substitute-argument 'source-original 'rust))))
  7914. :error-parser flycheck-parse-rustc
  7915. :error-filter flycheck-rust-error-filter
  7916. :error-explainer flycheck-rust-error-explainer
  7917. :modes rust-mode
  7918. :predicate flycheck-buffer-saved-p)
  7919. (defvar flycheck-sass-scss-cache-directory nil
  7920. "The cache directory for `sass' and `scss'.")
  7921. (defun flycheck-sass-scss-cache-location ()
  7922. "Get the cache location for `sass' and `scss'.
  7923. If no cache directory exists yet, create one and return it.
  7924. Otherwise return the previously used cache directory."
  7925. (setq flycheck-sass-scss-cache-directory
  7926. (or flycheck-sass-scss-cache-directory
  7927. (make-temp-file "flycheck-sass-scss-cache" 'directory))))
  7928. (flycheck-def-option-var flycheck-sass-compass nil sass
  7929. "Whether to enable the Compass CSS framework.
  7930. When non-nil, enable the Compass CSS framework, via `--compass'."
  7931. :type 'boolean
  7932. :safe #'booleanp
  7933. :package-version '(flycheck . "0.16"))
  7934. (flycheck-define-checker sass
  7935. "A Sass syntax checker using the Sass compiler.
  7936. See URL `http://sass-lang.com'."
  7937. :command ("sass"
  7938. "--cache-location" (eval (flycheck-sass-scss-cache-location))
  7939. (option-flag "--compass" flycheck-sass-compass)
  7940. "--check" "--stdin")
  7941. :standard-input t
  7942. :error-patterns
  7943. ((error line-start
  7944. (or "Syntax error: " "Error: ")
  7945. (message (one-or-more not-newline)
  7946. (zero-or-more "\n"
  7947. (one-or-more " ")
  7948. (one-or-more not-newline)))
  7949. (optional "\r") "\n" (one-or-more " ") "on line " line
  7950. " of standard input"
  7951. line-end)
  7952. (warning line-start
  7953. "WARNING: "
  7954. (message (one-or-more not-newline)
  7955. (zero-or-more "\n"
  7956. (one-or-more " ")
  7957. (one-or-more not-newline)))
  7958. (optional "\r") "\n" (one-or-more " ") "on line " line
  7959. " of " (one-or-more not-newline)
  7960. line-end))
  7961. :modes sass-mode)
  7962. (flycheck-def-config-file-var flycheck-sass-lintrc sass/scss-sass-lint ".sass-lint.yml"
  7963. :safe #'stringp
  7964. :package-version '(flycheck . "30"))
  7965. (flycheck-define-checker sass/scss-sass-lint
  7966. "A SASS/SCSS syntax checker using sass-Lint.
  7967. See URL `https://github.com/sasstools/sass-lint'."
  7968. :command ("sass-lint"
  7969. "--verbose"
  7970. "--no-exit"
  7971. "--format" "Checkstyle"
  7972. (config-file "--config" flycheck-sass-lintrc)
  7973. source)
  7974. :error-parser flycheck-parse-checkstyle
  7975. :modes (sass-mode scss-mode))
  7976. (flycheck-define-checker scala
  7977. "A Scala syntax checker using the Scala compiler.
  7978. See URL `http://www.scala-lang.org/'."
  7979. :command ("scalac" "-Ystop-after:parser" source)
  7980. :error-patterns
  7981. ((error line-start (file-name) ":" line ": error: " (message) line-end))
  7982. :modes scala-mode
  7983. :next-checkers ((warning . scala-scalastyle)))
  7984. (flycheck-def-config-file-var flycheck-scalastylerc scala-scalastyle nil
  7985. :safe #'stringp
  7986. :package-version '(flycheck . "0.20"))
  7987. (flycheck-define-checker scala-scalastyle
  7988. "A Scala style checker using scalastyle.
  7989. Note that this syntax checker is not used if
  7990. `flycheck-scalastylerc' is nil or refers to a non-existing file.
  7991. See URL `http://www.scalastyle.org'."
  7992. :command ("scalastyle"
  7993. (config-file "-c" flycheck-scalastylerc)
  7994. source)
  7995. :error-patterns
  7996. ((error line-start "error file=" (file-name) " message="
  7997. (message) " line=" line (optional " column=" column) line-end)
  7998. (warning line-start "warning file=" (file-name) " message="
  7999. (message) " line=" line (optional " column=" column) line-end))
  8000. :error-filter (lambda (errors)
  8001. (flycheck-sanitize-errors
  8002. (flycheck-increment-error-columns errors)))
  8003. :modes scala-mode
  8004. :predicate
  8005. ;; Inhibit this syntax checker if the JAR or the configuration are unset or
  8006. ;; missing
  8007. (lambda () (and flycheck-scalastylerc
  8008. (flycheck-locate-config-file flycheck-scalastylerc
  8009. 'scala-scalastyle)))
  8010. :verify (lambda (checker)
  8011. (let ((config-file (and flycheck-scalastylerc
  8012. (flycheck-locate-config-file
  8013. flycheck-scalastylerc checker))))
  8014. (list
  8015. (flycheck-verification-result-new
  8016. :label "Configuration file"
  8017. :message (cond
  8018. ((not flycheck-scalastylerc)
  8019. "`flycheck-scalastyletrc' not set")
  8020. ((not config-file)
  8021. (format "file %s not found" flycheck-scalastylerc))
  8022. (t (format "found at %s" config-file)))
  8023. :face (cond
  8024. ((not flycheck-scalastylerc) '(bold warning))
  8025. ((not config-file) '(bold error))
  8026. (t 'success)))))))
  8027. (flycheck-define-checker scheme-chicken
  8028. "A CHICKEN Scheme syntax checker using the CHICKEN compiler `csc'.
  8029. See URL `http://call-cc.org/'."
  8030. :command ("csc" "-analyze-only" "-local" source)
  8031. :error-patterns
  8032. ((info line-start
  8033. "Note: " (zero-or-more not-newline) ":\n"
  8034. (one-or-more (any space)) "(" (file-name) ":" line ") " (message)
  8035. line-end)
  8036. (warning line-start
  8037. "Warning: " (zero-or-more not-newline) ":\n"
  8038. (one-or-more (any space)) "(" (file-name) ":" line ") " (message)
  8039. line-end)
  8040. (error line-start "Error: (line " line ") " (message) line-end)
  8041. (error line-start "Syntax error: (" (file-name) ":" line ")"
  8042. (zero-or-more not-newline) " - "
  8043. (message (one-or-more not-newline)
  8044. (zero-or-more "\n"
  8045. (zero-or-more space)
  8046. (zero-or-more not-newline))
  8047. (one-or-more space) "<--")
  8048. line-end)
  8049. (error line-start
  8050. "Error: " (zero-or-more not-newline) ":\n"
  8051. (one-or-more (any space)) "(" (file-name) ":" line ") " (message)
  8052. line-end))
  8053. :predicate
  8054. (lambda ()
  8055. ;; In `scheme-mode' we must check the current Scheme implementation
  8056. ;; being used
  8057. (and (boundp 'geiser-impl--implementation)
  8058. (eq geiser-impl--implementation 'chicken)))
  8059. :verify
  8060. (lambda (_checker)
  8061. (let ((geiser-impl (bound-and-true-p geiser-impl--implementation)))
  8062. (list
  8063. (flycheck-verification-result-new
  8064. :label "Geiser Implementation"
  8065. :message (cond
  8066. ((eq geiser-impl 'chicken) "Chicken Scheme")
  8067. (geiser-impl (format "Other: %s" geiser-impl))
  8068. (t "Geiser not active"))
  8069. :face (cond
  8070. ((eq geiser-impl 'chicken) 'success)
  8071. (t '(bold error)))))))
  8072. :modes scheme-mode)
  8073. (defconst flycheck-scss-lint-checkstyle-re
  8074. (rx "cannot load such file" (1+ not-newline) "scss_lint_reporter_checkstyle")
  8075. "Regular expression to parse missing checkstyle error.")
  8076. (defun flycheck-parse-scss-lint (output checker buffer)
  8077. "Parse SCSS-Lint OUTPUT from CHECKER and BUFFER.
  8078. Like `flycheck-parse-checkstyle', but catches errors about
  8079. missing checkstyle reporter from SCSS-Lint."
  8080. (if (string-match-p flycheck-scss-lint-checkstyle-re output)
  8081. (list (flycheck-error-new-at
  8082. 1 nil 'error "Checkstyle reporter for SCSS-Lint missing.
  8083. Please run gem install scss_lint_reporter_checkstyle"
  8084. :checker checker
  8085. :buffer buffer
  8086. :filename (buffer-file-name buffer)))
  8087. (flycheck-parse-checkstyle output checker buffer)))
  8088. (flycheck-def-config-file-var flycheck-scss-lintrc scss-lint ".scss-lint.yml"
  8089. :safe #'stringp
  8090. :package-version '(flycheck . "0.23"))
  8091. (flycheck-define-checker scss-lint
  8092. "A SCSS syntax checker using SCSS-Lint.
  8093. Needs SCSS-Lint 0.43.2 or newer.
  8094. See URL `https://github.com/brigade/scss-lint'."
  8095. :command ("scss-lint"
  8096. "--require=scss_lint_reporter_checkstyle"
  8097. "--format=Checkstyle"
  8098. (config-file "--config" flycheck-scss-lintrc)
  8099. "--stdin-file-path" source-original "-")
  8100. :standard-input t
  8101. ;; We cannot directly parse Checkstyle XML, since for some mysterious reason
  8102. ;; SCSS-Lint doesn't have a built-in Checkstyle reporter, and instead ships it
  8103. ;; as an addon which might not be installed. We use a custom error parser to
  8104. ;; check whether the addon is missing and turn that into a special kind of
  8105. ;; Flycheck error.
  8106. :error-parser flycheck-parse-scss-lint
  8107. :modes scss-mode
  8108. :verify (lambda (checker)
  8109. (let* ((executable (flycheck-find-checker-executable checker))
  8110. (reporter-missing
  8111. (and executable
  8112. (with-temp-buffer
  8113. (call-process executable nil t nil
  8114. "--require=scss_lint_reporter_checkstyle")
  8115. (goto-char (point-min))
  8116. (re-search-forward
  8117. flycheck-scss-lint-checkstyle-re
  8118. nil 'no-error)))))
  8119. (when executable
  8120. (list
  8121. (flycheck-verification-result-new
  8122. :label "checkstyle reporter"
  8123. :message (if reporter-missing
  8124. "scss_lint_reporter_checkstyle missing"
  8125. "present")
  8126. :face (if reporter-missing
  8127. '(bold error)
  8128. 'success)))))))
  8129. (flycheck-define-checker scss-stylelint
  8130. "A SCSS syntax and style checker using stylelint.
  8131. See URL `http://stylelint.io/'."
  8132. :command ("stylelint"
  8133. (eval flycheck-stylelint-args)
  8134. "--syntax" "scss"
  8135. (option-flag "--quiet" flycheck-stylelint-quiet)
  8136. (config-file "--config" flycheck-stylelintrc))
  8137. :standard-input t
  8138. :error-parser flycheck-parse-stylelint
  8139. :modes (scss-mode))
  8140. (flycheck-def-option-var flycheck-scss-compass nil scss
  8141. "Whether to enable the Compass CSS framework.
  8142. When non-nil, enable the Compass CSS framework, via `--compass'."
  8143. :type 'boolean
  8144. :safe #'booleanp
  8145. :package-version '(flycheck . "0.16"))
  8146. (flycheck-define-checker scss
  8147. "A SCSS syntax checker using the SCSS compiler.
  8148. See URL `http://sass-lang.com'."
  8149. :command ("scss"
  8150. "--cache-location" (eval (flycheck-sass-scss-cache-location))
  8151. (option-flag "--compass" flycheck-scss-compass)
  8152. "--check" "--stdin")
  8153. :standard-input t
  8154. :error-patterns
  8155. ((error line-start
  8156. (or "Syntax error: " "Error: ")
  8157. (message (one-or-more not-newline)
  8158. (zero-or-more "\n"
  8159. (one-or-more " ")
  8160. (one-or-more not-newline)))
  8161. (optional "\r") "\n" (one-or-more " ") "on line " line
  8162. " of standard input"
  8163. line-end)
  8164. (warning line-start
  8165. "WARNING: "
  8166. (message (one-or-more not-newline)
  8167. (zero-or-more "\n"
  8168. (one-or-more " ")
  8169. (one-or-more not-newline)))
  8170. (optional "\r") "\n" (one-or-more " ") "on line " line
  8171. " of an unknown file"
  8172. line-end))
  8173. :modes scss-mode)
  8174. (flycheck-define-checker sh-bash
  8175. "A Bash syntax checker using the Bash shell.
  8176. See URL `http://www.gnu.org/software/bash/'."
  8177. :command ("bash" "--norc" "-n" "--")
  8178. :standard-input t
  8179. :error-patterns
  8180. ((error line-start
  8181. ;; The name/path of the bash executable
  8182. (one-or-more (not (any ":"))) ":"
  8183. ;; A label "line", possibly localized
  8184. (one-or-more (not (any digit)))
  8185. line (zero-or-more " ") ":" (zero-or-more " ")
  8186. (message) line-end))
  8187. :modes sh-mode
  8188. :predicate (lambda () (eq sh-shell 'bash))
  8189. :next-checkers ((warning . sh-shellcheck)))
  8190. (flycheck-define-checker sh-posix-dash
  8191. "A POSIX Shell syntax checker using the Dash shell.
  8192. See URL `http://gondor.apana.org.au/~herbert/dash/'."
  8193. :command ("dash" "-n")
  8194. :standard-input t
  8195. :error-patterns
  8196. ((error line-start (one-or-more (not (any ":"))) ": " line ": " (message)))
  8197. :modes sh-mode
  8198. :predicate (lambda () (eq sh-shell 'sh))
  8199. :next-checkers ((warning . sh-shellcheck)))
  8200. (flycheck-define-checker sh-posix-bash
  8201. "A POSIX Shell syntax checker using the Bash shell.
  8202. See URL `http://www.gnu.org/software/bash/'."
  8203. :command ("bash" "--posix" "--norc" "-n" "--")
  8204. :standard-input t
  8205. :error-patterns
  8206. ((error line-start
  8207. ;; The name/path of the bash executable
  8208. (one-or-more (not (any ":"))) ":"
  8209. ;; A label "line", possibly localized
  8210. (one-or-more (not (any digit)))
  8211. line (zero-or-more " ") ":" (zero-or-more " ")
  8212. (message) line-end))
  8213. :modes sh-mode
  8214. :predicate (lambda () (eq sh-shell 'sh))
  8215. :next-checkers ((warning . sh-shellcheck)))
  8216. (flycheck-define-checker sh-zsh
  8217. "A Zsh syntax checker using the Zsh shell.
  8218. See URL `http://www.zsh.org/'."
  8219. :command ("zsh" "--no-exec" "--no-globalrcs" "--no-rcs" source)
  8220. :error-patterns
  8221. ((error line-start (file-name) ":" line ": " (message) line-end))
  8222. :modes sh-mode
  8223. :predicate (lambda () (eq sh-shell 'zsh))
  8224. :next-checkers ((warning . sh-shellcheck)))
  8225. (defconst flycheck-shellcheck-supported-shells '(bash ksh88 sh)
  8226. "Shells supported by ShellCheck.")
  8227. (flycheck-def-option-var flycheck-shellcheck-excluded-warnings nil sh-shellcheck
  8228. "A list of excluded warnings for ShellCheck.
  8229. The value of this variable is a list of strings, where each
  8230. string is a warning code to be excluded from ShellCheck reports.
  8231. By default, no warnings are excluded."
  8232. :type '(repeat :tag "Excluded warnings"
  8233. (string :tag "Warning code"))
  8234. :safe #'flycheck-string-list-p
  8235. :package-version '(flycheck . "0.21"))
  8236. (flycheck-def-option-var flycheck-shellcheck-follow-sources t sh-shellcheck
  8237. "Whether to follow external sourced files in scripts.
  8238. Shellcheck will follow and parse sourced files so long as a
  8239. pre-runtime resolvable path to the file is present. This can
  8240. either be part of the source command itself:
  8241. source /full/path/to/file.txt
  8242. or added as a shellcheck directive before the source command:
  8243. # shellcheck source=/full/path/to/file.txt."
  8244. :type 'boolean
  8245. :safe #'booleanp
  8246. :package-version '(flycheck . "31"))
  8247. (flycheck-define-checker sh-shellcheck
  8248. "A shell script syntax and style checker using Shellcheck.
  8249. See URL `https://github.com/koalaman/shellcheck/'."
  8250. :command ("shellcheck"
  8251. "--format" "checkstyle"
  8252. "--shell" (eval (symbol-name sh-shell))
  8253. (option-flag "--external-sources" flycheck-shellcheck-follow-sources)
  8254. (option "--exclude" flycheck-shellcheck-excluded-warnings list
  8255. flycheck-option-comma-separated-list)
  8256. "-")
  8257. :standard-input t
  8258. :error-parser flycheck-parse-checkstyle
  8259. :error-filter
  8260. (lambda (errors)
  8261. (flycheck-remove-error-file-names
  8262. "-" (flycheck-dequalify-error-ids errors)))
  8263. :modes sh-mode
  8264. :predicate (lambda () (memq sh-shell flycheck-shellcheck-supported-shells))
  8265. :verify (lambda (_)
  8266. (let ((supports-shell (memq sh-shell
  8267. flycheck-shellcheck-supported-shells)))
  8268. (list
  8269. (flycheck-verification-result-new
  8270. :label (format "Shell %s supported" sh-shell)
  8271. :message (if supports-shell "yes" "no")
  8272. :face (if supports-shell 'success '(bold warning)))))))
  8273. (flycheck-define-checker slim
  8274. "A Slim syntax checker using the Slim compiler.
  8275. See URL `http://slim-lang.com'."
  8276. :command ("slimrb" "--compile")
  8277. :standard-input t
  8278. :error-patterns
  8279. ((error line-start
  8280. "Slim::Parser::SyntaxError:" (message) (optional "\r") "\n "
  8281. "STDIN, Line " line (optional ", Column " column)
  8282. line-end))
  8283. :modes slim-mode
  8284. :next-checkers ((warning . slim-lint)))
  8285. (flycheck-define-checker slim-lint
  8286. "A Slim linter.
  8287. See URL `https://github.com/sds/slim-lint'."
  8288. :command ("slim-lint" "--reporter=checkstyle" source)
  8289. :error-parser flycheck-parse-checkstyle
  8290. :modes slim-mode)
  8291. (flycheck-define-checker sql-sqlint
  8292. "A SQL syntax checker using the sqlint tool.
  8293. See URL `https://github.com/purcell/sqlint'."
  8294. :command ("sqlint")
  8295. :standard-input t
  8296. :error-patterns
  8297. ((warning line-start "stdin:" line ":" column ":WARNING "
  8298. (message (one-or-more not-newline)
  8299. (zero-or-more "\n"
  8300. (one-or-more " ")
  8301. (one-or-more not-newline)))
  8302. line-end)
  8303. (error line-start "stdin:" line ":" column ":ERROR "
  8304. (message (one-or-more not-newline)
  8305. (zero-or-more "\n"
  8306. (one-or-more " ")
  8307. (one-or-more not-newline)))
  8308. line-end))
  8309. :modes (sql-mode))
  8310. (flycheck-define-checker systemd-analyze
  8311. "A systemd unit checker using systemd-analyze(1).
  8312. See URL `https://www.freedesktop.org/software/systemd/man/systemd-analyze.html'."
  8313. :command ("systemd-analyze" "verify" source)
  8314. :error-patterns
  8315. ((error line-start "[" (file-name) ":" line "] " (message) line-end))
  8316. :modes (systemd-mode))
  8317. (flycheck-def-config-file-var flycheck-chktexrc tex-chktex ".chktexrc"
  8318. :safe #'stringp)
  8319. (flycheck-define-checker tex-chktex
  8320. "A TeX and LaTeX syntax and style checker using chktex.
  8321. See URL `http://www.nongnu.org/chktex/'."
  8322. :command ("chktex"
  8323. (config-file "--localrc" flycheck-chktexrc)
  8324. ;; Compact error messages, and no version information, and execute
  8325. ;; \input statements
  8326. "--verbosity=0" "--quiet" "--inputfiles")
  8327. :standard-input t
  8328. :error-patterns
  8329. ((warning line-start "stdin:" line ":" column ":"
  8330. (id (one-or-more digit)) ":" (message) line-end))
  8331. :error-filter
  8332. (lambda (errors)
  8333. (flycheck-sanitize-errors (flycheck-increment-error-columns errors)))
  8334. :modes (latex-mode plain-tex-mode))
  8335. (flycheck-define-checker tex-lacheck
  8336. "A LaTeX syntax and style checker using lacheck.
  8337. See URL `http://www.ctan.org/pkg/lacheck'."
  8338. :command ("lacheck" source-inplace)
  8339. :error-patterns
  8340. ((warning line-start
  8341. "\"" (file-name) "\", line " line ": " (message)
  8342. line-end))
  8343. :modes latex-mode)
  8344. (flycheck-define-checker texinfo
  8345. "A Texinfo syntax checker using makeinfo.
  8346. See URL `http://www.gnu.org/software/texinfo/'."
  8347. :command ("makeinfo" "-o" null-device "-")
  8348. :standard-input t
  8349. :error-patterns
  8350. ((warning line-start
  8351. "-:" line (optional ":" column) ": " "warning: " (message)
  8352. line-end)
  8353. (error line-start
  8354. "-:" line (optional ":" column) ": " (message)
  8355. line-end))
  8356. :modes texinfo-mode)
  8357. (flycheck-def-config-file-var flycheck-typescript-tslint-config
  8358. typescript-tslint "tslint.json"
  8359. :safe #'stringp
  8360. :package-version '(flycheck . "27"))
  8361. (flycheck-def-option-var flycheck-typescript-tslint-rulesdir
  8362. nil typescript-tslint
  8363. "The directory of custom rules for TSLint.
  8364. The value of this variable is either a string containing the path
  8365. to a directory with custom rules, or nil, to not give any custom
  8366. rules to TSLint.
  8367. Refer to the TSLint manual at URL
  8368. `http://palantir.github.io/tslint/usage/cli/'
  8369. for more information about the custom directory."
  8370. :type '(choice (const :tag "No custom rules directory" nil)
  8371. (directory :tag "Custom rules directory"))
  8372. :safe #'stringp
  8373. :package-version '(flycheck . "27"))
  8374. (flycheck-def-args-var flycheck-tslint-args (typescript-tslint)
  8375. :package-version '(flycheck . "31"))
  8376. (flycheck-define-checker typescript-tslint
  8377. "TypeScript style checker using TSLint.
  8378. Note that this syntax checker is not used if
  8379. `flycheck-typescript-tslint-config' is nil or refers to a
  8380. non-existing file.
  8381. See URL `https://github.com/palantir/tslint'."
  8382. :command ("tslint" "--format" "json"
  8383. (config-file "--config" flycheck-typescript-tslint-config)
  8384. (option "--rules-dir" flycheck-typescript-tslint-rulesdir)
  8385. (eval flycheck-tslint-args)
  8386. source)
  8387. :error-parser flycheck-parse-tslint
  8388. :modes (typescript-mode))
  8389. (flycheck-def-option-var flycheck-verilator-include-path nil verilog-verilator
  8390. "A list of include directories for Verilator.
  8391. The value of this variable is a list of strings, where each
  8392. string is a directory to add to the include path of Verilator.
  8393. Relative paths are relative to the file being checked."
  8394. :type '(repeat (directory :tag "Include directory"))
  8395. :safe #'flycheck-string-list-p
  8396. :package-version '(flycheck . "0.24"))
  8397. (flycheck-define-checker verilog-verilator
  8398. "A Verilog syntax checker using the Verilator Verilog HDL simulator.
  8399. See URL `https://www.veripool.org/wiki/verilator'."
  8400. :command ("verilator" "--lint-only" "-Wall"
  8401. (option-list "-I" flycheck-verilator-include-path concat)
  8402. source)
  8403. :error-patterns
  8404. ((warning line-start "%Warning-" (zero-or-more not-newline) ": "
  8405. (file-name) ":" line ": " (message) line-end)
  8406. (error line-start "%Error: " (file-name) ":"
  8407. line ": " (message) line-end))
  8408. :modes verilog-mode)
  8409. (flycheck-def-option-var flycheck-xml-xmlstarlet-xsd-path nil xml-xmlstarlet
  8410. "An XSD schema to validate against."
  8411. :type '(file :tag "XSD schema")
  8412. :safe #'stringp
  8413. :package-version '(flycheck . "31"))
  8414. (flycheck-define-checker xml-xmlstarlet
  8415. "A XML syntax checker and validator using the xmlstarlet utility.
  8416. See URL `http://xmlstar.sourceforge.net/'."
  8417. ;; Validate standard input with verbose error messages, and do not dump
  8418. ;; contents to standard output
  8419. :command ("xmlstarlet" "val" "--err" "--quiet"
  8420. (option "--xsd" flycheck-xml-xmlstarlet-xsd-path)
  8421. "-")
  8422. :standard-input t
  8423. :error-patterns
  8424. ((error line-start "-:" line "." column ": " (message) line-end))
  8425. :modes (xml-mode nxml-mode))
  8426. (flycheck-def-option-var flycheck-xml-xmllint-xsd-path nil xml-xmllint
  8427. "An XSD schema to validate against."
  8428. :type '(file :tag "XSD schema")
  8429. :safe #'stringp
  8430. :package-version '(flycheck . "31"))
  8431. (flycheck-define-checker xml-xmllint
  8432. "A XML syntax checker and validator using the xmllint utility.
  8433. The xmllint is part of libxml2, see URL
  8434. `http://www.xmlsoft.org/'."
  8435. :command ("xmllint" "--noout"
  8436. (option "--schema" flycheck-xml-xmllint-xsd-path)
  8437. "-")
  8438. :standard-input t
  8439. :error-patterns
  8440. ((error line-start "-:" line ": " (message) line-end))
  8441. :modes (xml-mode nxml-mode))
  8442. (flycheck-define-checker yaml-jsyaml
  8443. "A YAML syntax checker using JS-YAML.
  8444. See URL `https://github.com/nodeca/js-yaml'."
  8445. :command ("js-yaml")
  8446. :standard-input t
  8447. :error-patterns
  8448. ((error line-start
  8449. (or "JS-YAML" "YAMLException") ": "
  8450. (message) " at line " line ", column " column ":"
  8451. line-end))
  8452. :modes yaml-mode)
  8453. (flycheck-define-checker yaml-ruby
  8454. "A YAML syntax checker using Ruby's YAML parser.
  8455. This syntax checker uses the YAML parser from Ruby's standard
  8456. library.
  8457. See URL `http://www.ruby-doc.org/stdlib-2.0.0/libdoc/yaml/rdoc/YAML.html'."
  8458. :command ("ruby" "-ryaml" "-e" "begin;
  8459. YAML.load(STDIN); \
  8460. rescue Exception => e; \
  8461. STDERR.puts \"stdin:#{e}\"; \
  8462. end")
  8463. :standard-input t
  8464. :error-patterns
  8465. ((error line-start "stdin:" (zero-or-more not-newline) ":" (message)
  8466. "at line " line " column " column line-end))
  8467. :modes yaml-mode)
  8468. (provide 'flycheck)
  8469. ;; Local Variables:
  8470. ;; coding: utf-8
  8471. ;; indent-tabs-mode: nil
  8472. ;; End:
  8473. ;;; flycheck.el ends here