Skip to content

Commit 9121e1c

Browse files
committed
code: impls relint
1 parent 0f78020 commit 9121e1c

5 files changed

Lines changed: 109 additions & 6 deletions

File tree

cmds/lint/regexps.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (C) 2022 Jen-Chieh Shen
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3, or (at your option)
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with GNU Emacs; see the file COPYING. If not, write to the
16+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301, USA.
18+
*/
19+
20+
"use strict";
21+
22+
exports.command = ['regexps [files..]', 'lint-regexps [files..]', 'relint [files..]'];
23+
exports.desc = 'run relint';
24+
exports.builder = {
25+
files: {
26+
description: 'files you want relint to run on',
27+
requiresArg: false,
28+
type: 'array',
29+
},
30+
};
31+
32+
exports.handler = async (argv) => {
33+
await UTIL.e_call(argv, 'lint/regexps', argv.files);
34+
};

docs/content/en/Getting Started/Commands and options.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ Alias: `lint-declare`
369369
$ eask [GLOBAL-OPTIONS] declare [FILES..]
370370
```
371371

372+
## 🔍 eask regexps
373+
374+
Alias: `lint-regexps` and `relint`
375+
376+
```sh
377+
$ eask [GLOBAL-OPTIONS] regexps [FILES..]
378+
```
379+
372380
# 🚩 Utilities
373381

374382
Other helper commands.

docs/content/en/_index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ for! 👀
4545
- [ ] [FEAT] Add `elisp-lint` command
4646
- [ ] [FEAT] Add `elint` command
4747
- [ ] [FEAT] Add `elsa` command
48-
- [ ] [FEAT] Add `lint-regexps` command
4948

5049
## 📂 Underlying Projects
5150

lisp/_prepare.el

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ the `eask-start' execution.")
9595
(declare (indent 0) (debug t))
9696
`(let (inhibit-message) ,@body))
9797

98+
(defun eask-2str (obj)
99+
"Convert OBJ to string."
100+
(format "%s" obj))
101+
98102
(defun eask--sinr (len-or-list form-1 form-2)
99103
"If LEN-OR-LIST has length of 1; return FORM-1, else FORM-2."
100104
(let ((len (if (numberp len-or-list) len-or-list (length len-or-list))))
@@ -103,7 +107,7 @@ the `eask-start' execution.")
103107
(defun eask-seq-str-max (sequence)
104108
"Return max length in list of strings."
105109
(let ((result 0))
106-
(mapc (lambda (elm) (setq result (max result (length (format "%s" elm))))) sequence)
110+
(mapc (lambda (elm) (setq result (max result (length (eask-2str elm))))) sequence)
107111
result))
108112

109113
;;
@@ -914,7 +918,7 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
914918
(defun eask-progress-seq (prefix sequence suffix func)
915919
"Progress SEQUENCE with messages."
916920
(let* ((total (length sequence)) (count 0)
917-
(offset (format "%s" (length (format "%s" total)))))
921+
(offset (eask-2str (length (eask-2str total)))))
918922
(mapc
919923
(lambda (item)
920924
(cl-incf count)
@@ -942,7 +946,7 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
942946

943947
(defun eask-help (command)
944948
"Show help."
945-
(let* ((command (format "%s" command)) ; convert to string
949+
(let* ((command (eask-2str command)) ; convert to string
946950
(help-file (concat eask-lisp-root "help/" command)))
947951
(if (file-exists-p help-file)
948952
(with-temp-buffer
@@ -982,10 +986,10 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
982986
(eask-package-description) (package-desc-summary eask-package-desc))
983987
(let* ((dependencies (append eask-depends-on-emacs eask-depends-on))
984988
(dependencies (mapcar #'car dependencies))
985-
(dependencies (mapcar (lambda (elm) (format "%s" elm)) dependencies))
989+
(dependencies (mapcar (lambda (elm) (eask-2str elm)) dependencies))
986990
(requirements (package-desc-reqs eask-package-desc))
987991
(requirements (mapcar #'car requirements))
988-
(requirements (mapcar (lambda (elm) (format "%s" elm)) requirements)))
992+
(requirements (mapcar (lambda (elm) (eask-2str elm)) requirements)))
989993
(dolist (req requirements)
990994
(unless (member req dependencies)
991995
(eask-warn "Unmatch dependency '%s'; add (depends-on \"%s\") to Eask-file or consider removing it" req req)))

lisp/lint/regexps.el

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
;;; regexps.el --- Lint the package using `relint' -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Commmand use to run `relint' for all files
6+
;;
7+
;; $ eask regexps [names..]
8+
;;
9+
;;
10+
;; Initialization options:
11+
;;
12+
;; [names..] files you want relint to run on
13+
;;
14+
15+
;;; Code:
16+
17+
(load (expand-file-name
18+
"../_prepare.el"
19+
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
20+
nil t)
21+
22+
(defun eask--relint-file (filename)
23+
"Package lint FILENAME."
24+
(let* ((filename (expand-file-name filename))
25+
(file (eask-root-del filename))
26+
(errors))
27+
(eask-msg "")
28+
(eask-msg "`%s` with relint" (ansi-green file))
29+
(with-current-buffer (find-file filename)
30+
(setq errors (relint-buffer (current-buffer)))
31+
(dolist (err errors)
32+
(let* ((msg (nth 0 err))
33+
(error-pos (nth 2 err))
34+
(severity (nth 5 err))
35+
(report-func (pcase severity
36+
(`error #'eask-error)
37+
(`warning #'eask-warn))))
38+
(funcall report-func "%s:%s %s: %s"
39+
file (line-number-at-pos error-pos)
40+
(capitalize (eask-2str severity)) msg)))
41+
(kill-this-buffer))))
42+
43+
(eask-start
44+
(eask-with-archives "gnu"
45+
(eask-package-install 'relint))
46+
(if-let ((files (if (eask-args)
47+
(eask-expand-file-specs (eask-args))
48+
(eask-package-el-files))))
49+
(progn
50+
(setq package-lint-main-file eask-package-file)
51+
(mapcar #'eask--relint-file files)
52+
(eask-info "(Total of %s files linted)" (length files)))
53+
(eask-info "(No files have been linted)")
54+
(if (eask-args)
55+
(eask--print-no-matching-files)
56+
(eask-help 'regexps))))
57+
58+
;;; regexps.el ends here

0 commit comments

Comments
 (0)