-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflycheck-mix.el
99 lines (86 loc) · 3.27 KB
/
flycheck-mix.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
;;; flycheck-mix.el --- Elixir mix flycheck integration DEPRECATED -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Tomasz Kowal
;; Author: Tomasz Kowal <tomekowal@gmail.com>
;; Version: 1.0.0
;; Package-Requires: ((flycheck "27") (elixir-mode "1.8.0"))
;; Keywords: Elixir flycheck mix
;; URL: https://github.com/tomekowal/flycheck-mix
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; The package is deprecated and will be removed from melpa
;; Please use elixir-lsp instead https://elixirforum.com/t/emacs-elixir-setup-configuration-wiki/
;; This package adds support for Elixir mix to flycheck.
;; To use it, add to your init.el:
;;
;; (require 'flycheck-mix)
;; (flycheck-mix-setup)
;;
;; Elixir compilation uses macros and it can run arbitrary code.
;; You should use =elixir-mix= checker only with trusted projects.
;;; Code:
(require 'flycheck)
(flycheck-define-checker
elixir-mix
"Defines a checker for elixir with mix compile.
The project must be valid mix project with =mix.exs= file"
:command ("elixir"
"-e"
(eval (flycheck-mix-cd-and-set-mix-env))
"-S"
"mix"
"compile")
:error-patterns
((warning line-start
"warning:"
;; Multiline warnings
(message (minimal-match (one-or-more anything)))
(file-name "lib/" (minimal-match (one-or-more not-newline)) )
":"
line
line-end)
(error line-start
"** ("
(one-or-more word)
"Error) "
(file-name)
":"
line
": "
(message)
line-end))
:error-filter
(lambda (errors)
(dolist (err (flycheck-sanitize-errors errors))
(setf (flycheck-error-filename err)
(concat (flycheck-mix-project-root)
(flycheck-error-filename err))))
errors)
:modes (elixir-mode)
:predicate (lambda ()
(and
(flycheck-buffer-saved-p)
(flycheck-mix-project-root))))
(defun flycheck-mix-project-root ()
"Return directory where =mix.exs= is located."
(locate-dominating-file buffer-file-name "mix.exs"))
(defun flycheck-mix-cd-and-set-mix-env ()
"Generate change directory command for elixir executable."
(format "IEx.Helpers.cd(\"%s\"); Mix.start(); Mix.env(:test)"
(shell-quote-argument (flycheck-mix-project-root))
))
;;;###autoload
(defun flycheck-mix-setup ()
"Setup Flycheck for Elixir."
(message "This package is deprecated and will be removed from Melpa. Please, use lsp-mode instead https://elixirforum.com/t/emacs-elixir-setup-configuration-wiki/")
(add-to-list 'flycheck-checkers 'elixir-mix))
(provide 'flycheck-mix)
;;; flycheck-mix.el ends here