Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Add support for `elisp-lint` (#79)
* Adapt `-a`/`--all` option for archives command (#83)
* Merge command `list-all` to list with `-a`/`--all` option (#84)
* Support JSON format with Eask-file linter (#85)

## 0.7.x
> Released Sep 08, 2022
Expand Down
15 changes: 14 additions & 1 deletion cmds/checker/check-eask.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,20 @@

exports.command = ['check-eask [files..]'];
exports.desc = 'run eask checker';
exports.builder = {
files: {
description: 'specify Eask-files for checker to lint',
requiresArg: false,
type: 'array',
},
json: {
description: 'Output lint result in JSON format',
type: 'boolean',
},
};

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'checker/check-eask');
await UTIL.e_call(argv, 'checker/check-eask'
, argv.files
, UTIL.def_flag(argv.json, '--json', argv.json));
};
20 changes: 18 additions & 2 deletions docs/content/en/Getting Started/Commands and options.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ Eask will generate file like:
"VERSION"
"YOUR PACKAGE SUMMARY")

(website-url "https://example.com/project-url/")
(keywords "KEYWORD1" "KEYWORD2")

(package-file "PACKAGE-FILE")

(script "test" "echo \"Error: no test specified\" && exit 1")

(source "gnu")

(depends-on "emacs" "26.1")
Expand Down Expand Up @@ -484,7 +489,7 @@ $ eask [GLOBAL-OPTIONS] upgrade-eask
```

{{< hint warning >}}
💡 This will only work if you install it from source!
💡 This will only work if you install it from the source!
{{< /hint >}}

## 🔍 eask locate
Expand All @@ -504,7 +509,18 @@ Commands to check your Eask-file.
Lint an `Eask`-file.

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

```bash
# lint all Eask-files in the current directory and subdirectories
eask check-eask
# lint specific files
eask check-eask Eask Eask.27
# lint all Eask-files in specified directory and subdirectories
eask check-eask src/
# print result as JSON
eask check-eask --json
```

# 🚩 Global Options
Expand Down
52 changes: 29 additions & 23 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
(require 'ansi-color)
(require 'package)
(require 'project)
(require 'json)
(require 'nsm)
(require 'url-vars)

Expand Down Expand Up @@ -433,6 +434,7 @@ the `eask-start' execution.")
(defun eask-allow-error-p () (eask--flag "--allow-error")) ; --allow-error
(defun eask-insecure-p () (eask--flag "--insecure")) ; --insecure
(defun eask-no-color-p () (eask--flag "--no-color")) ; --no-color
(defun eask-json-p () (eask--flag "--json")) ; --json

;;; String (with arguments)
(defun eask-proxy () (eask--flag-value "--proxy")) ; --proxy
Expand Down Expand Up @@ -502,7 +504,8 @@ other scripts internally. See function `eask-call'.")
(eask--form-options
'("--proxy" "--http-proxy" "--https-proxy" "--no-proxy"
"--verbose" "--silent"
"--depth" "--dest"))
"--depth" "--dest"
"--json"))
"List of arguments (number/string) type options.")

(defconst eask--command-list
Expand Down Expand Up @@ -594,7 +597,7 @@ Eask file in the workspace."
(defun eask-file-load (location &optional noerror)
"Load Eask file in the LOCATION."
(when-let* ((target-eask-file (expand-file-name location user-emacs-directory))
(result (eask--alias-env (load target-eask-file noerror t))))
(result (eask--alias-env (load target-eask-file 'noerror t))))
(setq eask-file target-eask-file ; assign eask file only if success
eask-file-root (file-name-directory target-eask-file))
(run-hooks 'eask-file-loaded-hook)
Expand Down Expand Up @@ -642,35 +645,38 @@ Eask file in the workspace."
(eask--print-env-info)
(cond
((eask-global-p)
;; We accept Eask file in global scope, but it shouldn't be used
;; as a sandbox.
(if (eask-file-try-load "./")
(eask-msg "✓ Loading config Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading config Eask file... missing!"))
(message "")
(package-activate-all)
(eask-with-progress
(ansi-green "Loading your configuration... ")
(eask-with-verbosity 'debug
(unless (eask-quick-p)
(load (locate-user-emacs-file "early-init.el") t)
(load (locate-user-emacs-file "../.emacs") t)
(load (locate-user-emacs-file "init.el") t)))
(ansi-green (if (eask-quick-p) "skipped ✗" "done ✓")))
(eask--with-hooks ,@body))
(let* ((special (eask-special-p))
(inhibit-config (or special (eask-quick-p))))
(unless special
;; We accept Eask-file in global scope, but it shouldn't be used
;; for the sandbox.
(if (eask-file-try-load "./")
(eask-msg "✓ Loading config Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading config Eask file... missing!")))
(message "")
(package-activate-all)
(eask-with-progress
(ansi-green "Loading your configuration... ")
(eask-with-verbosity 'debug
(unless inhibit-config
(load (locate-user-emacs-file "early-init.el") t)
(load (locate-user-emacs-file "../.emacs") t)
(load (locate-user-emacs-file "init.el") t)))
(ansi-green (if inhibit-config "skipped ✗" "done ✓")))
(eask--with-hooks ,@body)))
(t
(let* ((user-emacs-directory (expand-file-name (concat ".eask/" emacs-version "/")))
(package-user-dir (expand-file-name "elpa" user-emacs-directory))
(eask--first-init-p (not (file-directory-p user-emacs-directory)))
(user-init-file (locate-user-emacs-file "init.el"))
(custom-file (locate-user-emacs-file "custom.el"))
(special (eask-special-p)))
(if (or (eask-file-try-load "../../")
special)
(unless special
(if (eask-file-try-load "../../")
(eask-msg "✓ Loading Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading Eask file... missing!")))
(if (or special eask-file)
(progn
(if eask-file
(eask-msg "✓ Loading Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading Eask file... missing!"))
(message "")
(package-activate-all)
(unless special
Expand Down
127 changes: 111 additions & 16 deletions lisp/checker/check-eask.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
;;
;; Commmand use to run Eask checker
;;
;; $ eask check-eask
;; $ eask check-eask [FILES..]
;;
;;
;; Initialization options:
;;
;; [files..] specify Eask-files for checker to lint
;; --json Output lint result in JSON format
;;

;;; Code:
Expand All @@ -14,34 +20,123 @@
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
nil t)

;; Plain Text
(defvar eask--checker-log nil)
;; JSON format
(defvar eask--checker-warnings nil)
(defvar eask--checker-errors nil)

(defun eask--pretty-json (json)
"Return pretty JSON."
(with-temp-buffer (insert json) (json-pretty-print-buffer) (buffer-string)))

(defun eask--column-at-point (point)
"Get column at POINT."
(save-excursion (goto-char point) (current-column)))

(defun eask--load-buffer ()
"Return the current loading file session."
"Return the current file loading session."
(car (cl-remove-if-not
(lambda (elm) (string-prefix-p " *load*-" (buffer-name elm))) (buffer-list))))

(defun eask--write-json-format (level msg)
"Prepare log for JSON format."
(let* ((thing (thing-at-point 'sexp))
(bounds (bounds-of-thing-at-point 'sexp))
(filename (or load-file-name eask-file))
(start (car bounds))
(end (cdr bounds))
(start-line (if load-file-name (line-number-at-pos start) 0))
(start-col (if load-file-name (eask--column-at-point start) 0))
(start-pos (if load-file-name start 0))
(end-line (if load-file-name (line-number-at-pos end) 0))
(end-col (if load-file-name (eask--column-at-point end) 0))
(end-pos (if load-file-name end 0))
(msg (ansi-color-filter-apply msg)))
(push `((range . ((start . ((line . ,start-line)
(col . ,start-col)
(pos . ,start-pos)))
(end . ((line . ,end-line)
(col . ,end-col)
(pos . ,end-pos)))))
(filename . ,filename)
(message . ,msg))
(cl-case level
(`error eask--checker-errors)
(`warn eask--checker-warnings)))))

(defun eask--write-plain-text (level msg)
"Prepare log for plain text format."
(let* ((level-string (cl-case level
(`error "Error")
(`warn "Warning")))
(log (format "%s:%s:%s %s: %s"
(or load-file-name eask-file)
(if load-file-name (line-number-at-pos) 0)
(if load-file-name (current-column) 0)
level-string
msg)))
(push (ansi-color-filter-apply log) eask--checker-log)))

(defun eask--write-log (level msg)
"Write the log."
(unless (string= " *temp*" (buffer-name)) ; avoid error from `package-file' directive
(with-current-buffer (or (eask--load-buffer) (buffer-name))
(let* ((level-string (cl-case level
(`error "Error")
(`warn "Warning")))
(log (format "%s:%s:%s %s: %s"
(file-name-nondirectory (or load-file-name eask-file))
(if load-file-name (line-number-at-pos) 0)
(if load-file-name (current-column) 0)
level-string
msg)))
(push (ansi-color-filter-apply log) eask--checker-log)))))
(funcall
(cond ((eask-json-p) #'eask--write-json-format)
(t #'eask--write-plain-text))
level msg))))

(defmacro eask--save-eask-file-state (&rest body)
"Execute BODY without touching the Eask-file global variables."
(declare (indent 0) (debug t))
`(let (package-archives
package-archive-priorities
eask-package
eask-package-desc
eask-website-url
eask-keywords
eask-package-file
eask-files
eask-scripts
eask-depends-on-emacs
eask-depends-on
eask-depends-on-dev)
,@body))

;;
;;; Program Entry

;; Preparation
(add-hook 'eask-on-error-hook #'eask--write-log)
(add-hook 'eask-on-warning-hook #'eask--write-log)

(eask-start
(if eask--checker-log
(mapc #'eask-msg (reverse eask--checker-log))
(eask-msg "(No issues found)")))
(let* ((default-directory (if (eask-global-p) user-emacs-directory
default-directory))
(files (or (eask-expand-file-specs (eask-args))
(eask-expand-file-specs '("Eask*" "**/Eask*"))))
checked-files)
;; Linting
(dolist (file files)
(eask--save-eask-file-state
(eask--setup-env
(eask--alias-env
(when (ignore-errors (load file 'noerror t))
(push file checked-files))))))

;; Print result
(eask-msg "")
(cond ((and (eask-json-p) ; JSON format
(or eask--checker-warnings eask--checker-errors))
(eask-msg
(eask--pretty-json (json-encode
`((warnings . ,eask--checker-warnings)
(errors . ,eask--checker-errors))))))
(eask--checker-log ; Plain text
(mapc #'eask-msg (reverse eask--checker-log)))
(t
(eask-info "(Checked %s file%s)"
(length checked-files)
(eask--sinr checked-files "" "s")))))

;;; checker/check-eask.el ends here
3 changes: 2 additions & 1 deletion lisp/clean/dist.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
(eask-dist-path (expand-file-name eask-dist-path)))
(if (file-directory-p eask-dist-path)
(eask--clean-dist eask-dist-path)
(eask-info "Target dist path is missing: %s" eask-dist-path))))
(eask-msg "")
(eask-info "(No dist folder needs to be cleaned)" eask-dist-path))))

;;; clean/dist.el ends here
1 change: 1 addition & 0 deletions lisp/clean/elc.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
(mapc #'eask-delete-file files)
(eask-info "✓ (Total of %s .elc file%s deleted)" (length files)
(eask--sinr files "" "s")))
(eask-msg "")
(eask-info "(No .elc file found in workspace)")))

;;; clean/elc.el ends here
4 changes: 2 additions & 2 deletions lisp/clean/workspace.el
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(file-name-directory (directory-file-name user-emacs-directory)))))
(ignore-errors (delete-directory target-dir t))
(if eask--first-init-p
(eask-info "(Workspace already cleaned)")
(eask-info "✓ Done (workspace `%s` is cleaned)" target-dir))))
(eask-info "(Workspace is already cleaned)")
(eask-info "✓ (Workspace is now cleaned)" target-dir))))

;;; clean/workspace.el ends here
1 change: 1 addition & 0 deletions lisp/core/compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
(let* ((compiled (cl-remove-if-not #'eask--byte-compile-file files))
(compiled (length compiled))
(skipped (- (length files) compiled)))
(eask-msg "")
(eask-info "(Total of %s file%s compiled, %s skipped)" compiled
(eask--sinr compiled "" "s")
skipped)))
Expand Down
1 change: 1 addition & 0 deletions lisp/core/concat.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(with-temp-buffer
(eask-progress-seq " - Visiting" files "appended! ✓" #'insert-file-contents)
(write-region (buffer-string) nil target-filename)
(eask-msg "")
(eask-info "Done. (Wrote file in %s)" target-filename)))))

;;; core/concat.el ends here
1 change: 1 addition & 0 deletions lisp/core/exec-path.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(eask-start
(eask-pkg-init)
(mapc #'eask--print-exec-path exec-path)
(eask-msg "")
(eask-info "(Total of %s exec-path)" (length exec-path)))

;;; core/exec-path.el ends here
1 change: 1 addition & 0 deletions lisp/core/files.el
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
(eask-start
(let ((files (eask-package-files)))
(mapc #'eask--print-filename files)
(eask-msg "")
(eask-info "(Total of %s item%s listed)" (length files) (eask--sinr files "" "s"))))

;;; core/files.el ends here
2 changes: 2 additions & 0 deletions lisp/core/install.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(installed (length pkg-not-installed)) (skipped (- len installed)))
(eask-log "Installing %s specified package%s..." len s)
(mapc #'eask-package-install names)
(eask-msg "")
(eask-info "(Total of %s package%s installed, %s skipped)"
installed s skipped)))

Expand All @@ -52,6 +53,7 @@
(progn
(add-to-list 'load-path (expand-file-name (eask-packaged-name) package-user-dir))
(package-install-file target)
(eask-msg "")
(eask-info "(Installed in %s)"
(file-name-directory (locate-library name))))
(eask-info "✗ (No files have been intalled)")
Expand Down
Loading