|
104 | 104 | eask-depends-on-dev) |
105 | 105 | ,@body)) |
106 | 106 |
|
| 107 | +(defun eask--check-file (files) |
| 108 | + "Lint list of Eask FILES." |
| 109 | + (let (checked-files content) |
| 110 | + ;; Linting |
| 111 | + (dolist (file files) |
| 112 | + (eask--save-eask-file-state |
| 113 | + (eask--setup-env |
| 114 | + (eask--alias-env |
| 115 | + (when (ignore-errors (load file 'noerror t)) |
| 116 | + (push file checked-files)))))) |
| 117 | + |
| 118 | + ;; Print result |
| 119 | + (eask-msg "") |
| 120 | + (cond ((and (eask-json-p) ; JSON format |
| 121 | + (or eask--checker-warnings eask--checker-errors)) |
| 122 | + (setq content |
| 123 | + (eask--pretty-json (json-encode |
| 124 | + `((warnings . ,eask--checker-warnings) |
| 125 | + (errors . ,eask--checker-errors))))) |
| 126 | + (eask-msg content)) |
| 127 | + (eask--checker-log ; Plain text |
| 128 | + (setq content |
| 129 | + (with-temp-buffer |
| 130 | + (dolist (msg (reverse eask--checker-log)) |
| 131 | + (insert msg "\n")) |
| 132 | + (buffer-string))) |
| 133 | + (mapc #'eask-msg (reverse eask--checker-log))) |
| 134 | + (t |
| 135 | + (eask-info "(Checked %s file%s)" |
| 136 | + (length checked-files) |
| 137 | + (eask--sinr checked-files "" "s")))) |
| 138 | + |
| 139 | + ;; Output file |
| 140 | + (when (and content (eask-output)) |
| 141 | + (write-region content nil (eask-output))))) |
| 142 | + |
107 | 143 | ;; |
108 | 144 | ;;; Program Entry |
109 | 145 |
|
|
113 | 149 |
|
114 | 150 | (let* ((default-directory (if (eask-global-p) user-emacs-directory |
115 | 151 | default-directory)) |
116 | | - (files (or (eask-expand-file-specs (eask-args)) |
117 | | - (eask-expand-file-specs '("Eask*" "**/Eask*")))) |
118 | | - checked-files |
119 | | - content) |
120 | | - ;; Linting |
121 | | - (dolist (file files) |
122 | | - (eask--save-eask-file-state |
123 | | - (eask--setup-env |
124 | | - (eask--alias-env |
125 | | - (when (ignore-errors (load file 'noerror t)) |
126 | | - (push file checked-files)))))) |
127 | | - |
128 | | - ;; Print result |
129 | | - (eask-msg "") |
130 | | - (cond ((and (eask-json-p) ; JSON format |
131 | | - (or eask--checker-warnings eask--checker-errors)) |
132 | | - (setq content |
133 | | - (eask--pretty-json (json-encode |
134 | | - `((warnings . ,eask--checker-warnings) |
135 | | - (errors . ,eask--checker-errors))))) |
136 | | - (eask-msg content)) |
137 | | - (eask--checker-log ; Plain text |
138 | | - (setq content |
139 | | - (with-temp-buffer |
140 | | - (dolist (msg (reverse eask--checker-log)) |
141 | | - (insert msg "\n")) |
142 | | - (buffer-string))) |
143 | | - (mapc #'eask-msg (reverse eask--checker-log))) |
144 | | - (t |
145 | | - (eask-info "(Checked %s file%s)" |
146 | | - (length checked-files) |
147 | | - (eask--sinr checked-files "" "s")))) |
148 | | - |
149 | | - ;; Output file |
150 | | - (when (and content (eask-output)) |
151 | | - (write-region content nil (eask-output)))) |
| 152 | + (patterns (eask-args)) |
| 153 | + (files (if patterns |
| 154 | + (eask-expand-file-specs patterns) |
| 155 | + (eask-expand-file-specs '("Eask*" "**/Eask*"))))) |
| 156 | + (cond |
| 157 | + ;; Files found, do the action! |
| 158 | + (files |
| 159 | + (eask--check-file files)) |
| 160 | + ;; Pattern defined, but no file found! |
| 161 | + (patterns |
| 162 | + (eask-info "No files found with wildcard pattern: %s" |
| 163 | + (mapconcat #'identity patterns " "))) |
| 164 | + ;; Default, print help! |
| 165 | + (t |
| 166 | + (eask-info "(No Eask-files have been checked)") |
| 167 | + (eask-help "checker/check-eask")))) |
152 | 168 |
|
153 | 169 | ;;; checker/check-eask.el ends here |
0 commit comments