@atlisp/lint 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atlisp-lint.default.json +90 -0
- package/dist/checks/arg-count.js +1 -1
- package/dist/checks/assoc-without-cdr.js +1 -1
- package/dist/checks/cond-duplicate.js +1 -1
- package/dist/checks/constant-condition.js +3 -3
- package/dist/checks/dangerous-calls.js +1 -1
- package/dist/checks/dangling-defun.js +1 -1
- package/dist/checks/double-not.js +1 -1
- package/dist/checks/empty-branch.js +1 -1
- package/dist/checks/empty-catch.js +1 -1
- package/dist/checks/function-complexity.js +1 -1
- package/dist/checks/global-naming.js +1 -1
- package/dist/checks/identical-branches.js +1 -1
- package/dist/checks/misplaced-else.js +1 -1
- package/dist/checks/multiple-setq.js +1 -1
- package/dist/checks/no-return.js +1 -1
- package/dist/checks/open-close.js +1 -1
- package/dist/checks/parameter-naming.js +1 -1
- package/dist/checks/quote-vs-function.js +1 -1
- package/dist/checks/recursive-call.js +1 -1
- package/dist/checks/redundant-let.js +1 -1
- package/dist/checks/redundant-nil-else.js +1 -1
- package/dist/checks/redundant-progn.js +1 -1
- package/dist/checks/redundant-quotes.js +1 -1
- package/dist/checks/redundant-setq.js +1 -1
- package/dist/checks/self-compare.js +1 -1
- package/dist/checks/setq-single-arg.js +1 -1
- package/dist/checks/single-arg-and-or.js +1 -1
- package/dist/checks/undeclared-setq.js +1 -1
- package/dist/checks/unused-catch-result.js +1 -1
- package/dist/checks/unused-let.js +1 -1
- package/dist/checks/unused-local-fun.js +1 -1
- package/dist/checks/unused-package-dep.js +1 -1
- package/dist/checks/unused-param.js +1 -1
- package/dist/checks/unused-variable.js +1 -1
- package/dist/checks/variable-shadow.js +1 -1
- package/dist/checks/while-constant.js +1 -1
- package/dist/formatters.d.ts +0 -1
- package/dist/formatters.js +0 -16
- package/dist/lib/lint-sbcl.lisp +161 -0
- package/dist/project.js +5 -5
- package/dist/runner.d.ts +1 -1
- package/dist/runner.js +207 -93
- package/dist/stub-packages.json +41 -0
- package/dist/visitor-runner.js +5 -9
- package/package.json +2 -2
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
;; @lisp SBCL Lint — syntax validation via SBCL
|
|
2
|
+
;; Usage: sbcl --script lint-sbcl.lisp <src-dir> <stub-packages.json> <walk-exclude-json> <defmacro-allow-files-json> <locale>
|
|
3
|
+
|
|
4
|
+
(require :uiop)
|
|
5
|
+
|
|
6
|
+
(defparameter *errors* 0)
|
|
7
|
+
(defparameter *warnings* 0)
|
|
8
|
+
(defparameter *checked* 0)
|
|
9
|
+
(defparameter *locale* "zh")
|
|
10
|
+
|
|
11
|
+
;; ── i18n ──────────────────────────────────────────────────────────────
|
|
12
|
+
(defun i18n (key)
|
|
13
|
+
(cdr (assoc key
|
|
14
|
+
(if (string= *locale* "zh")
|
|
15
|
+
'((:not-found . "not found symbol")
|
|
16
|
+
(:syntax-error . "syntax error")
|
|
17
|
+
(:vec-syntax . "#( vector syntax")
|
|
18
|
+
(:char-syntax . "# backslash char literal")
|
|
19
|
+
(:eval-syntax . "#. read-time eval")
|
|
20
|
+
(:defmacro . "defmacro")
|
|
21
|
+
(:trailing-ws . "trailing whitespace")
|
|
22
|
+
(:ok . "OK")
|
|
23
|
+
(:fail . "FAIL")
|
|
24
|
+
(:header . " @lisp SBCL Lint")
|
|
25
|
+
(:source . " Source")
|
|
26
|
+
(:found . " Found ~d .lsp files")
|
|
27
|
+
(:scanned . " Scanned")
|
|
28
|
+
(:errors . " Errors")
|
|
29
|
+
(:warnings . " Warnings"))
|
|
30
|
+
'((:not-found . "not found symbol")
|
|
31
|
+
(:syntax-error . "syntax error")
|
|
32
|
+
(:vec-syntax . "#( vector syntax")
|
|
33
|
+
(:char-syntax . "# backslash char literal")
|
|
34
|
+
(:eval-syntax . "#. read-time eval")
|
|
35
|
+
(:defmacro . "defmacro")
|
|
36
|
+
(:trailing-ws . "trailing whitespace")
|
|
37
|
+
(:ok . "OK")
|
|
38
|
+
(:fail . "FAIL")
|
|
39
|
+
(:header . " @lisp SBCL Lint")
|
|
40
|
+
(:source . " Source")
|
|
41
|
+
(:found . " Found ~d .lsp files")
|
|
42
|
+
(:scanned . " Scanned")
|
|
43
|
+
(:errors . " Errors")
|
|
44
|
+
(:warnings . " Warnings"))))))
|
|
45
|
+
|
|
46
|
+
;; ── Stub packages from external file ──────────────────────────────────
|
|
47
|
+
(defun load-stub-packages (file-path)
|
|
48
|
+
(flet ((ensure-pkg (name &optional use-list)
|
|
49
|
+
(unless (find-package name)
|
|
50
|
+
(make-package name :use (or use-list '())))))
|
|
51
|
+
(with-open-file (s file-path :direction :input)
|
|
52
|
+
(let ((packages (read s)))
|
|
53
|
+
(dolist (pkg packages)
|
|
54
|
+
(ensure-pkg (first pkg) (second pkg)))))))
|
|
55
|
+
|
|
56
|
+
;; ── File walking ──────────────────────────────────────────────────────
|
|
57
|
+
(defun source-files (dir)
|
|
58
|
+
(sort
|
|
59
|
+
(remove-if-not
|
|
60
|
+
(lambda (p)
|
|
61
|
+
(let ((n (pathname-type p)))
|
|
62
|
+
(and n (string-equal n "lsp"))))
|
|
63
|
+
(uiop:directory-files dir))
|
|
64
|
+
'string< :key #'namestring))
|
|
65
|
+
|
|
66
|
+
(defun walk-tree (dir exclude-dirs)
|
|
67
|
+
(let ((result (source-files dir)))
|
|
68
|
+
(dolist (sub (uiop:subdirectories dir))
|
|
69
|
+
(let ((name (car (last (pathname-directory sub)))))
|
|
70
|
+
(unless (find name exclude-dirs :test 'string=)
|
|
71
|
+
(setf result (append result (walk-tree sub exclude-dirs))))))
|
|
72
|
+
result))
|
|
73
|
+
|
|
74
|
+
;; ── Per-file check ────────────────────────────────────────────────────
|
|
75
|
+
(defun check-file (path src-dir defmacro-allow-files)
|
|
76
|
+
(incf *checked*)
|
|
77
|
+
(let* ((rel (enough-namestring path src-dir))
|
|
78
|
+
(fullname (format nil "~a.~a" (pathname-name path) (pathname-type path))))
|
|
79
|
+
(format t " ~a ... " rel)
|
|
80
|
+
(force-output)
|
|
81
|
+
;; Syntax check via READ
|
|
82
|
+
(handler-case
|
|
83
|
+
(with-open-file (s path :direction :input)
|
|
84
|
+
(loop for form = (read s nil :eof)
|
|
85
|
+
until (eq form :eof)))
|
|
86
|
+
(error (e)
|
|
87
|
+
(let ((msg (princ-to-string e)))
|
|
88
|
+
(cond
|
|
89
|
+
((search "not found" msg)
|
|
90
|
+
(format t "~% [NOTE] ~a: ~a~%" rel (i18n :not-found))
|
|
91
|
+
(incf *warnings*))
|
|
92
|
+
(t
|
|
93
|
+
(format t "~a~% [ERROR] ~a: ~a~%" (i18n :fail) rel (i18n :syntax-error))
|
|
94
|
+
(incf *errors*)
|
|
95
|
+
(return-from check-file))))))
|
|
96
|
+
;; Trailing whitespace
|
|
97
|
+
(with-open-file (s path :direction :input)
|
|
98
|
+
(loop for line = (read-line s nil nil)
|
|
99
|
+
for lineno from 1
|
|
100
|
+
while line
|
|
101
|
+
when (and (> (length line) 0)
|
|
102
|
+
(find (char line (1- (length line))) '(#\Space #\Tab)))
|
|
103
|
+
do (progn
|
|
104
|
+
(format t "~% [WARN] ~a line ~d: ~a~%" rel lineno (i18n :trailing-ws))
|
|
105
|
+
(incf *warnings*))))
|
|
106
|
+
;; CL-ism checks: raw content scan
|
|
107
|
+
(with-open-file (s path :direction :input)
|
|
108
|
+
(let ((content (make-string (file-length s))))
|
|
109
|
+
(file-position s 0)
|
|
110
|
+
(read-sequence content s)
|
|
111
|
+
(when (search "#(" content)
|
|
112
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :vec-syntax))
|
|
113
|
+
(incf *warnings*))
|
|
114
|
+
(when (search "#\\" content)
|
|
115
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :char-syntax))
|
|
116
|
+
(incf *warnings*))
|
|
117
|
+
(when (search "#." content)
|
|
118
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :eval-syntax))
|
|
119
|
+
(incf *warnings*))
|
|
120
|
+
(when (and (search "defmacro" content)
|
|
121
|
+
(not (some (lambda (s) (search s fullname)) defmacro-allow-files)))
|
|
122
|
+
(format t "~% [WARN] ~a: ~a~%" rel (i18n :defmacro))
|
|
123
|
+
(incf *warnings*))))
|
|
124
|
+
(format t "~a~%" (i18n :ok))))
|
|
125
|
+
|
|
126
|
+
;; ── Main ──────────────────────────────────────────────────────────────
|
|
127
|
+
(defun main ()
|
|
128
|
+
(let* ((args (uiop:command-line-arguments))
|
|
129
|
+
(src-dir (first args))
|
|
130
|
+
(stub-file (second args))
|
|
131
|
+
(walk-exclude (if (third args)
|
|
132
|
+
(read-from-string (third args))
|
|
133
|
+
'(".vscode" "test" "experiment" "tools" ".git")))
|
|
134
|
+
(defmacro-allow (if (fourth args)
|
|
135
|
+
(read-from-string (fourth args))
|
|
136
|
+
'("compat-cl")))
|
|
137
|
+
(locale (fifth args)))
|
|
138
|
+
(when locale (setf *locale* locale))
|
|
139
|
+
(load-stub-packages stub-file)
|
|
140
|
+
|
|
141
|
+
(format t "~%==================================================~%")
|
|
142
|
+
(format t "~a~%" (i18n :header))
|
|
143
|
+
(format t "~a: ~a~%" (i18n :source) (namestring (pathname src-dir)))
|
|
144
|
+
(format t "==================================================~%~%")
|
|
145
|
+
(setf *errors* 0 *warnings* 0 *checked* 0)
|
|
146
|
+
|
|
147
|
+
(let ((files (walk-tree src-dir walk-exclude)))
|
|
148
|
+
(format t "~a~%~%" (format nil (i18n :found) (length files)))
|
|
149
|
+
(dolist (f files)
|
|
150
|
+
(check-file f src-dir defmacro-allow)))
|
|
151
|
+
|
|
152
|
+
(format t "~%==================================================~%")
|
|
153
|
+
(format t "~a: ~d~%" (i18n :scanned) *checked*)
|
|
154
|
+
(format t "~a: ~d~%" (i18n :errors) *errors*)
|
|
155
|
+
(format t "~a: ~d~%" (i18n :warnings) *warnings*)
|
|
156
|
+
(format t "==================================================~%~%")
|
|
157
|
+
(if (> *errors* 0)
|
|
158
|
+
(uiop:quit 1)
|
|
159
|
+
(uiop:quit 0))))
|
|
160
|
+
|
|
161
|
+
(main)
|
package/dist/project.js
CHANGED
|
@@ -44,7 +44,7 @@ const duplicate_defun_1 = require("./checks/duplicate-defun");
|
|
|
44
44
|
const locale_1 = require("./locale");
|
|
45
45
|
function collectDefuns(file) {
|
|
46
46
|
const content = fs.readFileSync(file, 'utf-8');
|
|
47
|
-
const ast = (0, parser_1.parseAst)(content);
|
|
47
|
+
const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
|
|
48
48
|
const results = [];
|
|
49
49
|
const defunNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'defun') || (0, parser_1.astIsList)(n, 'defun-q'));
|
|
50
50
|
for (const node of defunNodes) {
|
|
@@ -56,7 +56,7 @@ function collectDefuns(file) {
|
|
|
56
56
|
}
|
|
57
57
|
function collectReferences(file) {
|
|
58
58
|
const content = fs.readFileSync(file, 'utf-8');
|
|
59
|
-
const ast = (0, parser_1.parseAst)(content);
|
|
59
|
+
const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
|
|
60
60
|
const results = [];
|
|
61
61
|
const allCalls = (0, parser_1.astFindAll)(ast, n => {
|
|
62
62
|
if (n.type !== 'list' || !n.children || n.children.length === 0)
|
|
@@ -73,7 +73,7 @@ function collectReferences(file) {
|
|
|
73
73
|
}
|
|
74
74
|
function countFunctionArgs(file) {
|
|
75
75
|
const content = fs.readFileSync(file, 'utf-8');
|
|
76
|
-
const ast = (0, parser_1.parseAst)(content);
|
|
76
|
+
const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
|
|
77
77
|
const result = new Map();
|
|
78
78
|
const defunNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'defun') || (0, parser_1.astIsList)(n, 'defun-q'));
|
|
79
79
|
for (const node of defunNodes) {
|
|
@@ -102,7 +102,7 @@ function countFunctionArgs(file) {
|
|
|
102
102
|
}
|
|
103
103
|
function countCallArgs(file) {
|
|
104
104
|
const content = fs.readFileSync(file, 'utf-8');
|
|
105
|
-
const ast = (0, parser_1.parseAst)(content);
|
|
105
|
+
const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
|
|
106
106
|
const result = new Map();
|
|
107
107
|
const allCalls = (0, parser_1.astFindAll)(ast, n => {
|
|
108
108
|
if (n.type !== 'list' || !n.children || n.children.length === 0)
|
|
@@ -122,7 +122,7 @@ function countCallArgs(file) {
|
|
|
122
122
|
}
|
|
123
123
|
function findModuleDeps(filepath) {
|
|
124
124
|
const content = fs.readFileSync(filepath, 'utf-8');
|
|
125
|
-
const ast = (0, parser_1.parseAst)(content);
|
|
125
|
+
const ast = (0, parser_1.parseAst)(content, { errorRecovery: true });
|
|
126
126
|
const imports = [];
|
|
127
127
|
const exports = [];
|
|
128
128
|
const inPackageNodes = (0, parser_1.astFindAll)(ast, n => (0, parser_1.astIsList)(n, 'in-package'));
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Issue, LintConfig } from './types';
|
|
2
2
|
export declare function runChecks(content: string, file: string, config: LintConfig): Issue[];
|
|
3
|
-
export declare function runChecksWithVisitorWrapper(content: string, file: string, config: LintConfig): Issue[];
|
|
4
3
|
export declare function lintFiles(files: string[], config: LintConfig, rootDir: string): Issue[];
|
|
5
4
|
export declare function lintFilesParallel(files: string[], config: LintConfig, rootDir: string): Promise<Issue[]>;
|
|
5
|
+
export declare const FIXABLE_RULES: Set<string>;
|
|
6
6
|
export declare function applyFixes(issues: Issue[], content: string, filepath: string): string;
|
|
7
7
|
export declare function parseIgnoreFile(rootDir: string): string[];
|
|
8
8
|
export declare function fixFile(filepath: string): string[];
|