Skip to content

Commit

Permalink
code: impls relint
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Apr 29, 2022
1 parent 0f78020 commit 9121e1c
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 6 deletions.
34 changes: 34 additions & 0 deletions cmds/lint/regexps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (C) 2022 Jen-Chieh Shen
*
* 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, 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 GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

"use strict";

exports.command = ['regexps [files..]', 'lint-regexps [files..]', 'relint [files..]'];
exports.desc = 'run relint';
exports.builder = {
files: {
description: 'files you want relint to run on',
requiresArg: false,
type: 'array',
},
};

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'lint/regexps', argv.files);
};
8 changes: 8 additions & 0 deletions docs/content/en/Getting Started/Commands and options.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ Alias: `lint-declare`
$ eask [GLOBAL-OPTIONS] declare [FILES..]
```

## 🔍 eask regexps

Alias: `lint-regexps` and `relint`

```sh
$ eask [GLOBAL-OPTIONS] regexps [FILES..]
```

# 🚩 Utilities

Other helper commands.
Expand Down
1 change: 0 additions & 1 deletion docs/content/en/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ for! 👀
- [ ] [FEAT] Add `elisp-lint` command
- [ ] [FEAT] Add `elint` command
- [ ] [FEAT] Add `elsa` command
- [ ] [FEAT] Add `lint-regexps` command

## 📂 Underlying Projects

Expand Down
14 changes: 9 additions & 5 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ the `eask-start' execution.")
(declare (indent 0) (debug t))
`(let (inhibit-message) ,@body))

(defun eask-2str (obj)
"Convert OBJ to string."
(format "%s" obj))

(defun eask--sinr (len-or-list form-1 form-2)
"If LEN-OR-LIST has length of 1; return FORM-1, else FORM-2."
(let ((len (if (numberp len-or-list) len-or-list (length len-or-list))))
Expand All @@ -103,7 +107,7 @@ the `eask-start' execution.")
(defun eask-seq-str-max (sequence)
"Return max length in list of strings."
(let ((result 0))
(mapc (lambda (elm) (setq result (max result (length (format "%s" elm))))) sequence)
(mapc (lambda (elm) (setq result (max result (length (eask-2str elm))))) sequence)
result))

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

(defun eask-help (command)
"Show help."
(let* ((command (format "%s" command)) ; convert to string
(let* ((command (eask-2str command)) ; convert to string
(help-file (concat eask-lisp-root "help/" command)))
(if (file-exists-p help-file)
(with-temp-buffer
Expand Down Expand Up @@ -982,10 +986,10 @@ Standard is, 0 (error), 1 (warning), 2 (info), 3 (log), 4 or above (debug)."
(eask-package-description) (package-desc-summary eask-package-desc))
(let* ((dependencies (append eask-depends-on-emacs eask-depends-on))
(dependencies (mapcar #'car dependencies))
(dependencies (mapcar (lambda (elm) (format "%s" elm)) dependencies))
(dependencies (mapcar (lambda (elm) (eask-2str elm)) dependencies))
(requirements (package-desc-reqs eask-package-desc))
(requirements (mapcar #'car requirements))
(requirements (mapcar (lambda (elm) (format "%s" elm)) requirements)))
(requirements (mapcar (lambda (elm) (eask-2str elm)) requirements)))
(dolist (req requirements)
(unless (member req dependencies)
(eask-warn "Unmatch dependency '%s'; add (depends-on \"%s\") to Eask-file or consider removing it" req req)))
Expand Down
58 changes: 58 additions & 0 deletions lisp/lint/regexps.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
;;; regexps.el --- Lint the package using `relint' -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Commmand use to run `relint' for all files
;;
;; $ eask regexps [names..]
;;
;;
;; Initialization options:
;;
;; [names..] files you want relint to run on
;;

;;; Code:

(load (expand-file-name
"../_prepare.el"
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
nil t)

(defun eask--relint-file (filename)
"Package lint FILENAME."
(let* ((filename (expand-file-name filename))
(file (eask-root-del filename))
(errors))
(eask-msg "")
(eask-msg "`%s` with relint" (ansi-green file))
(with-current-buffer (find-file filename)
(setq errors (relint-buffer (current-buffer)))
(dolist (err errors)
(let* ((msg (nth 0 err))
(error-pos (nth 2 err))
(severity (nth 5 err))
(report-func (pcase severity
(`error #'eask-error)
(`warning #'eask-warn))))
(funcall report-func "%s:%s %s: %s"
file (line-number-at-pos error-pos)
(capitalize (eask-2str severity)) msg)))
(kill-this-buffer))))

(eask-start
(eask-with-archives "gnu"
(eask-package-install 'relint))
(if-let ((files (if (eask-args)
(eask-expand-file-specs (eask-args))
(eask-package-el-files))))
(progn
(setq package-lint-main-file eask-package-file)
(mapcar #'eask--relint-file files)
(eask-info "(Total of %s files linted)" (length files)))
(eask-info "(No files have been linted)")
(if (eask-args)
(eask--print-no-matching-files)
(eask-help 'regexps))))

;;; regexps.el ends here

0 comments on commit 9121e1c

Please sign in to comment.