-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathelsa.el
More file actions
94 lines (79 loc) · 2.54 KB
/
elsa.el
File metadata and controls
94 lines (79 loc) · 2.54 KB
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
;;; lint/elsa.el --- Run elsa -*- lexical-binding: t; -*-
;;; Commentary:
;;
;; Commmand use to run `elsa' for all files
;;
;; $ eask lint elsa [files..]
;;
;;
;; Positionals:
;;
;; [files..] files you want elsa to run on
;;
;;; Code:
(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
(load (expand-file-name "_prepare.el"
(locate-dominating-file dir "_prepare.el"))
nil t))
;;
;;; Externals
(require 'dash nil t)
(defvar elsa-global-state)
(declare-function elsa-message-format "ext:elsa.el")
(declare-function elsa-analyse-file "ext:elsa.el")
(declare-function --each "ext:dash.el")
;;
;;; Flags
(advice-add #'eask-allow-error-p :override #'eask-always)
;;
;;; Core
(defconst eask-lint-elsa--version nil
"Elsa version.")
(defun eask-lint-elsa--analyse-file (filename)
"Process FILENAME."
(let* ((filename (expand-file-name filename))
(file (eask-root-del filename))
errors)
(eask-msg "")
(eask-msg "`%s` with elsa (%s)" (ansi-green file) eask-lint-elsa--version)
(eask-with-verbosity 'debug
(setq errors (oref (elsa-analyse-file filename elsa-global-state) errors)))
(if errors
(--each (reverse errors)
(let ((line (string-trim (concat file ":" (elsa-message-format it)))))
(cond ((string-match-p "[: ][Ee]rror:" line)
(eask-error line))
((string-match-p "[: ][Ww]arning:" line)
(eask-warn line))
(t (eask-log line)))))
(eask-msg "No issues found"))))
(eask-start
;; Preparation
(eask-archive-install-packages '("gnu" "melpa")
'elsa)
(setq eask-lint-elsa--version (eask-package--version-string 'elsa))
;; Start Linting
(require 'elsa)
(let* ((patterns (eask-args))
(files (if patterns
(eask-expand-file-specs patterns)
(eask-package-el-files))))
(cond
;; Files found, do the action!
(files
(elsa-load-config)
(mapcar #'eask-lint-elsa--analyse-file files)
(eask-msg "")
(eask-info "(Total of %s file%s linted)" (length files)
(eask--sinr files "" "s")))
;; Pattern defined, but no file found!
(patterns
(eask-msg "")
(eask-info "(No files match wildcard: %s)"
(mapconcat #'identity patterns " ")))
;; Default, print help!
(t
(eask-msg "")
(eask-info "(No files have been linted)")
(eask-help "lint/elsa")))))
;;; lint/elsa.el ends here