Skip to content

Commit 99ec942

Browse files
committed
Add new command indent
1 parent 1085493 commit 99ec942

9 files changed

Lines changed: 121 additions & 24 deletions

File tree

cmds/lint/indent.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 = ['indent [files..]', 'lint-indent [files..]'];
23+
exports.desc = 'lint the package using package-lint';
24+
exports.builder = {
25+
files: {
26+
description: 'specify files to do package lint',
27+
requiresArg: false,
28+
type: 'array',
29+
},
30+
};
31+
32+
exports.handler = async (argv) => {
33+
await UTIL.e_call(argv, 'lint/indent', argv.files);
34+
};

cmds/lint/lint.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020
"use strict";
2121

22-
exports.command = ['lint [names..]', 'lint-package [names..]'];
22+
exports.command = ['lint [files..]', 'lint-package [files..]'];
2323
exports.desc = 'lint the package using package-lint';
2424
exports.builder = {
25-
names: {
26-
description: 'specify files to lint',
25+
files: {
26+
description: 'specify files to do package lint',
2727
requiresArg: false,
2828
type: 'array',
2929
},
3030
};
3131

3232
exports.handler = async (argv) => {
33-
await UTIL.e_call(argv, 'lint/lint', argv.names);
33+
await UTIL.e_call(argv, 'lint/lint', argv.files);
3434
};

lisp/_prepare.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,12 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
950950
(eask-msg (ansi-white (buffer-string)))))
951951
(eask-error "Help manual missig %s" help-file))))
952952

953+
(defun eask--print-no-matching-files ()
954+
"Print message for no matching files found."
955+
(eask-log "")
956+
(eask-log "Cannot find matching files with given pattern %s" (eask-args))
957+
(eask-log ""))
958+
953959
;;
954960
;;; Checker
955961

lisp/help/checkdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ For example,
1212

1313
[+] (files "*.el")
1414

15-
💡 Tip: You can use command [files] to show all selected files
15+
💡 Tip: You can use the command [files] to show all selected files
1616

1717
$ eask files

lisp/help/lint

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11

2-
💡 Use directive (package-file ..) or (files ..) to specify package files
2+
💡 You need to specify file(s) you want the package-lint to run
33

4-
[+] (package-file "PKG-MAIN.el")
5-
6-
Or,
4+
[+] (package-file "ENTRY") ; One argument with a string
5+
[+] (files "FILE-1" "FILE-2" ...) ; All arguments are wildcard patterns
76

7+
For example,
8+
89
[+] (files "*.el")
10+
11+
💡 Tip: You can use the command [files] to show all selected files
12+
13+
$ eask files

lisp/lint/buttercup.el

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
;;
55
;; Command to run buttercup tests,
66
;;
7-
;; $ eask buttercup [files..]
8-
;;
9-
;;
10-
;; Initialization options:
11-
;;
12-
;; [files..] specify files to run ert tests
7+
;; $ eask buttercup
138
;;
149

1510
;;; Code:

lisp/lint/checkdoc.el

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@
4545

4646
(eask-start
4747
(require 'checkdoc)
48-
(if-let* ((files (or (eask-expand-file-specs (eask-args))
49-
(eask-package-el-files)))
48+
(if-let* ((files (if (eask-args)
49+
(eask-expand-file-specs (eask-args))
50+
(eask-package-el-files)))
5051
(len (length files))
5152
(s (eask--sinr len "" "s"))
5253
(have (eask--sinr len "has" "have")))
5354
(progn
5455
(mapcar #'eask--checkdoc-file files)
5556
(eask-info "(Total of %s file%s %s checked)" len s have))
5657
(eask-info "(No files have been checked (checkdoc))")
57-
(eask-help 'checkdoc)))
58+
(if (eask-args)
59+
(eask--print-no-matching-files)
60+
(eask-help 'checkdoc))))
5861

5962
;;; checkdoc.el ends here

lisp/lint/indent.el

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
;;; indent.el --- Lint the package using `indent-lint' -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Command use to ,
6+
;;
7+
;; $ eask indent [names..]
8+
;;
9+
;;
10+
;; Initialization options:
11+
;;
12+
;; [names..] specify files to do indent lint
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--undo-lines (undo-list)
23+
"Return list of lines changed in UNDO-LIST."
24+
(let ((lines))
25+
(dolist (elm undo-list)
26+
(when (and (consp elm) (numberp (cdr elm)))
27+
(push (line-number-at-pos (abs (cdr elm))) lines)))
28+
(reverse lines)))
29+
30+
(defun eask--indent-lint-file (file)
31+
"Lint indent for FILE."
32+
(eask-msg "")
33+
(eask-msg "`%s` with indent-lint" (ansi-green (eask-root-del file)))
34+
(find-file file)
35+
(let ((report-func (if (eask-strict-p) #'eask-error #'eask-warn))
36+
(tick (buffer-modified-tick)))
37+
(eask--silent (indent-region (point-min) (point-max)))
38+
(if (/= tick (buffer-modified-tick))
39+
;; Indentation changed: warn for each line.
40+
(dolist (line (eask--undo-lines buffer-undo-list))
41+
(funcall report-func "%s:%s: Indentation mismatch" (buffer-name) line))
42+
(eask-msg "No issues found"))))
43+
44+
(eask-start
45+
(if-let ((files (if (eask-args)
46+
(eask-expand-file-specs (eask-args))
47+
(eask-package-el-files))))
48+
(progn
49+
(mapcar #'eask--indent-lint-file files)
50+
(eask-info "(Total of %s files linted)" (length files)))
51+
(eask-info "(No files have been linted)")
52+
(if (eask-args)
53+
(eask--print-no-matching-files)
54+
(eask-help 'indent))))
55+
56+
;;; indent.el ends here

lisp/lint/lint.el

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
;;
1010
;; Initialization options:
1111
;;
12-
;; [names..] specify files to byte-compile
12+
;; [names..] specify files to do package lint
1313
;;
1414

1515
;;; Code:
@@ -38,18 +38,16 @@
3838
(eask-start
3939
(eask-with-archives "melpa"
4040
(eask-package-install 'package-lint))
41-
(if-let ((files (if (eask-args) (eask-expand-file-specs (eask-args))
41+
(if-let ((files (if (eask-args)
42+
(eask-expand-file-specs (eask-args))
4243
(eask-package-el-files))))
4344
(progn
4445
(setq package-lint-main-file eask-package-file)
4546
(mapcar #'eask--package-lint-file files)
4647
(eask-info "(Total of %s files linted)" (length files)))
4748
(eask-info "(No files have been linted)")
4849
(if (eask-args)
49-
(progn
50-
(eask-log "")
51-
(eask-log "Cannot find matching files with given pattern %s" (eask-args))
52-
(eask-log ""))
50+
(eask--print-no-matching-files)
5351
(eask-help 'lint))))
5452

5553
;;; lint.el ends here

0 commit comments

Comments
 (0)