Skip to content

Commit 687ceca

Browse files
authored
feat(lint): Add command for org-lint (#328)
* feat: Add command for org-lint * split org lint to its own test * chore: changelog
1 parent 075d1dc commit 687ceca

File tree

10 files changed

+190
-30
lines changed

10 files changed

+190
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1717
* fix(lisp/extern): Clean up `compat` (2b41f5db4b5bbe145c9671f95850f79a00dcbd48)
1818
* fix(lisp): Paint keywords with nested ansi codes (#323)
1919
* feat(create): Add new command for `el-project` (#325)
20+
* feat(lint): Add command for `org-lint` (#328)
2021

2122
## 0.11.x
2223
> Released Apr 03, 2025

cmds/lint/org.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (C) 2025 the Eask authors.
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 this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
"use strict";
19+
20+
exports.command = ['org [files..]'];
21+
exports.desc = `Run org-lint on Org files`;
22+
exports.builder = yargs => yargs
23+
.positional(
24+
'[files..]', {
25+
description: 'files you want org-lint to run on',
26+
type: 'array',
27+
});
28+
29+
exports.handler = async (argv) => {
30+
await UTIL.e_call(argv, 'lint/org', argv.files);
31+
};

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -808,38 +808,46 @@ Run indent-lint.
808808
eask [GLOBAL-OPTIONS] lint indent [FILES..]
809809
```
810810

811-
## 🔍 eask lint keywords
811+
## 🔍 eask lint declare
812812

813-
Run keywords checker (built-in).
813+
Run check-declare (built-in).
814814

815815
```sh
816-
eask [GLOBAL-OPTIONS] lint keywords
816+
eask [GLOBAL-OPTIONS] lint declare [FILES..]
817817
```
818818

819-
## 🔍 eask lint license
819+
## 🔍 eask lint regexps
820820

821-
Run license check.
821+
Run [relint](https://github.com/mattiase/relint).
822+
823+
Alias: `lint relint`
822824

823825
```sh
824-
eask [GLOBAL-OPTIONS] lint license
826+
eask [GLOBAL-OPTIONS] lint regexps [FILES..]
825827
```
826828

827-
## 🔍 eask lint declare
829+
## 🔍 eask lint keywords
828830

829-
Run check-declare (built-in).
831+
Run keywords checker (built-in).
830832

831833
```sh
832-
eask [GLOBAL-OPTIONS] lint declare [FILES..]
834+
eask [GLOBAL-OPTIONS] lint keywords
833835
```
834836

835-
## 🔍 eask lint regexps
837+
## 🔍 eask lint license
836838

837-
Run [relint](https://github.com/mattiase/relint).
839+
Run license check.
838840

839-
Alias: `lint relint`
841+
```sh
842+
eask [GLOBAL-OPTIONS] lint license
843+
```
844+
845+
## 🔍 eask lint org
846+
847+
Run `org-lint` on Org files.
840848

841849
```sh
842-
eask [GLOBAL-OPTIONS] lint regexps [FILES..]
850+
eask [GLOBAL-OPTIONS] lint org
843851
```
844852

845853
# 🚩 Testing

docs/content/Getting-Started/Commands-and-options/_index.zh-tw.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -754,15 +754,15 @@ eask [GLOBAL-OPTIONS] lint package [FILES..]
754754

755755
## 🔍 eask lint checkdoc
756756

757-
運行 checkdoc (自帶).
757+
運行 checkdoc (自帶)
758758

759759
```sh
760760
eask [GLOBAL-OPTIONS] lint checkdoc [FILES..]
761761
```
762762

763763
## 🔍 eask lint elint
764764

765-
運行 elint (自帶).
765+
運行 elint (自帶)
766766

767767
```sh
768768
eask [GLOBAL-OPTIONS] lint elint [FILES..]
@@ -794,38 +794,46 @@ eask [GLOBAL-OPTIONS] lint lint elsa [FILES..]
794794
eask [GLOBAL-OPTIONS] lint indent [FILES..]
795795
```
796796

797-
## 🔍 eask lint keywords
797+
## 🔍 eask lint declare
798798

799-
運行 keywords checker (自帶).
799+
運行 check-declare (自帶)
800800

801801
```sh
802-
eask [GLOBAL-OPTIONS] lint keywords
802+
eask [GLOBAL-OPTIONS] lint declare [FILES..]
803803
```
804804

805-
## 🔍 eask lint license
805+
## 🔍 eask lint regexps
806806

807-
運行 license check.
807+
Run [relint](https://github.com/mattiase/relint).
808+
809+
別名: `lint relint`
808810

809811
```sh
810-
eask [GLOBAL-OPTIONS] lint license
812+
eask [GLOBAL-OPTIONS] lint regexps [FILES..]
811813
```
812814

813-
## 🔍 eask lint declare
815+
## 🔍 eask lint keywords
814816

815-
運行 check-declare (自帶).
817+
運行 keywords checker (自帶).
816818

817819
```sh
818-
eask [GLOBAL-OPTIONS] lint declare [FILES..]
820+
eask [GLOBAL-OPTIONS] lint keywords
819821
```
820822

821-
## 🔍 eask lint regexps
823+
## 🔍 eask lint license
822824

823-
Run [relint](https://github.com/mattiase/relint).
825+
運行 license 檢查器。
824826

825-
別名: `lint relint`
827+
```sh
828+
eask [GLOBAL-OPTIONS] lint license
829+
```
830+
831+
## 🔍 eask lint org
832+
833+
在 Org 檔案上運行 `org-lint`
826834

827835
```sh
828-
eask [GLOBAL-OPTIONS] lint regexps [FILES..]
836+
eask [GLOBAL-OPTIONS] lint org
829837
```
830838

831839
# 🚩 測試框架

lisp/help/lint/org

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
💡 You need to specify pattern(s) you want to check
3+
4+
$ eask lint org [FILES..]
5+
6+
For example,
7+
8+
$ eask lint org README.org docs/*.org

lisp/lint/org.el

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
;;; lint/org.el --- Run org-lint on Org files -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Commmand use to run `org-lint' for all files
6+
;;
7+
;; $ eask lint org [files..]
8+
;;
9+
;;
10+
;; Positionals:
11+
;;
12+
;; [files..] files you want org-lint to run on
13+
;;
14+
15+
;;; Code:
16+
17+
(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
18+
(load (expand-file-name "_prepare.el"
19+
(locate-dominating-file dir "_prepare.el"))
20+
nil t))
21+
22+
;;
23+
;;; Flags
24+
25+
(advice-add #'eask-allow-error-p :override #'eask-always)
26+
27+
;;
28+
;;; Core
29+
30+
(defun eask-lint-org--print-error (file result)
31+
"Print the error RESULT from FILE."
32+
(let* ((data (cl-second result))
33+
(filename (file-name-nondirectory file))
34+
(line (elt data 0))
35+
(text (elt data 2))
36+
(msg (concat filename ":" line ": " text)))
37+
(if (eask-strict-p) (error msg) (warn msg))))
38+
39+
(defun eask-lint-org--file (file)
40+
"Run `org-lint' on FILE."
41+
(eask-msg "`%s` with org-lint" (ansi-green file))
42+
(with-temp-buffer
43+
(insert-file-contents file)
44+
(org-mode)
45+
(if-let* ((results (org-lint)))
46+
(mapc (lambda (result)
47+
(eask-lint-org--print-error file result))
48+
results)
49+
(eask-msg "No issues found"))))
50+
51+
(eask-start
52+
;; Preparation
53+
(eask-archive-install-packages '("gnu")
54+
'org)
55+
56+
;; Start Linting
57+
(require 'org-lint)
58+
(let* ((patterns (eask-args))
59+
(files (eask-expand-file-specs patterns)))
60+
(cond
61+
;; Files found, do the action!
62+
(files
63+
(mapcar #'eask-lint-org--file files)
64+
(eask-msg "")
65+
(eask-info "(Total of %s file%s linted)" (length files)
66+
(eask--sinr files "" "s")))
67+
;; Pattern defined, but no file found!
68+
(patterns
69+
(eask-msg "")
70+
(eask-info "(No files match wildcard: %s)"
71+
(mapconcat #'identity patterns " ")))
72+
;; Default, print help!
73+
(t
74+
(eask-msg "")
75+
(eask-info "(No files have been linted)")
76+
(eask-help "lint/org")))))
77+
78+
;;; lint/org.el ends here

test/jest/local.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ describe("local", () => {
198198
describe("Linting", () => {
199199
// some lint commands may fail if packages are missing
200200
beforeAll(async () => await ctx.runEask("install-deps"));
201+
201202
it.each([
202203
"lint checkdoc",
203204
"lint declare",
@@ -210,15 +211,21 @@ describe("local", () => {
210211
])("eask %s", async (cmd) => {
211212
await ctx.runEask(cmd);
212213
});
214+
213215
it("lint regexps", async () => {
214216
if ((await emacsVersion()) >= "27.1") {
215217
await ctx.runEask("lint regexps");
216218
}
217219
});
220+
218221
// XXX: Elsa is not stable, ignore it for now
219222
test.skip("lint elsa", async () => {
220223
await ctx.runEask("lint elsa");
221224
});
225+
226+
it("lint org *.org", async () => {
227+
await ctx.runEask("lint org *.org");
228+
});
222229
});
223230

224231
describe("Testing", () => {

test/jest/local/Eask

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;; -*- mode: eask; lexical-binding: t -*-
22

33
(package "mini.pkg.1"
4-
"5.5.6"
4+
"9.9.10"
55
"Minimal test package")
66

77
(website-url "https://github.com/emacs-eask/cli/tree/master/test/fixtures/mini.pkg.1")

test/jest/local/README.org

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
* Test Org File
2+
This is a test org file used for Emacs behavior checking.
3+
4+
** TODO Broken heading without space
5+
***BROKEN Heading
6+
7+
** Code Block
8+
#+BEGIN_SRC emacs-lisp
9+
(message "Hello, Emacs!")
10+
(1+ ) ; Intentional syntax error
11+
#+END_SRC
12+
13+
** Bad Property
14+
:PROPERTIES:
15+
:WRONGPROP without value
16+
:END:
17+
18+
** Notes
19+
Unclosed *bold and /italic text.

test/jest/local/mini.pkg.1.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
;; Author: Shen, Jen-Chieh <[email protected]>
77
;; URL: https://github.com/emacs-eask/cli/tree/master/test/fixtures/mini.pkg.1
8-
;; Version: 5.5.6
8+
;; Version: 9.9.10
99
;; Package-Requires: ((emacs "24.3") (s "1.12.0") (fringe-helper "1.0.1"))
1010
;; Keywords: test local
1111

0 commit comments

Comments
 (0)