npm.io
0.1.4 • Published 26m ago

@atlisp/lint

Licence
MIT
Version
0.1.4
Deps
0
Vulns
0
Weekly
0

@atlisp/lint

AutoLISP 静态分析工具 — 括号匹配、安全检查、编码检测、命名规范、函数复杂度、SBCL 语法校验。

安装

npm install -g @atlisp/lint

需要 Node.js >= 18。SBCL 语法校验为可选功能,如需启用请安装 SBCL

快速开始

# 在项目目录下初始化配置文件
npx @atlisp/lint --init

# 运行检查
npx @atlisp/lint

# 输出 JSON 格式
npx @atlisp/lint --format json

# 自动修复可修复问题(尾部空格、BOM)
npx @atlisp/lint --fix

CLI 选项

--src <dir>          指定源码目录(可多次使用)
--test <dir>         指定测试目录(可多次使用)
--config <path>      指定配置文件路径
--staged             仅检查 git 暂存区中的 .lsp 文件
--format <format>    输出格式:default(默认)| json
--init               在当前目录生成 atlisp-lint.json
--install-hook       安装 git pre-commit hook
--fix                自动修复尾部空格、UTF-8 BOM 等问题
--cache              启用文件哈希缓存,跳过未变更的文件
--clear-cache        清除缓存目录
--parallel           开启多线程并行检查(使用 Worker Threads)
--hook-args <args>   自定义 pre-commit hook 参数(配合 --install-hook)

检查规则

阶段 1:静态检查
规则 默认 说明
parens error 括号不匹配
encoding error 非 UTF-8 编码
cl_syntax warn Common Lisp 特有语法(如 &key
quit_exit error 调用 quit / exit(会终止 CAD)
command_shell error 调用 command 执行 shell
startapp warn 调用 startapp 启动外部程序
vl_registry_write warn 写注册表
vlax_without_loading warn 使用 vlax-* 前未调用 vl-load-com
token_in_url warn URL 中包含 token=(凭据泄露)
open_without_close warn open/close 数量不匹配(资源泄露)
bare_function_names warn defun 缺少命名空间前缀
line_length warn 行长度超过限制
function_complexity warn 函数行数或嵌套深度超限
parameter_naming warn 参数首字母大写
unused_variable warn 变量被赋值但未使用
missing_doc warn 函数缺少注释说明
trailing_whitespace warn 行尾多余空格
module_registration off 模块文件未注册到 *modules*
namespace_header off 缺少 (in-package ...)
阶段 2:SBCL 语法校验

调用 SBCL 对每个 .lsp 文件做 Common Lisp reader 级别的深度解析:

  • 语法错误 — reader 无法解析的内容
  • 符号未找到 — 未注册到 stub packages 中的符号
  • CL-ism — #(#\#. 等 AutoLISP 无效语法
  • defmacro — 默认不允许,除非文件在允许列表中

行内忽略

在代码行尾添加注释可以忽略特定规则的检查:

(setq secret "token=abc123") ; atlisp-lint: disable=token_in_url

配置文件

atlisp-lint.json

{
  "locale": "zh",
  "source": {
    "globs": ["**/*.lsp"],
    "exclude": ["**/node_modules/**", "**/vendor/**", "**/.git/**"]
  },
  "checks": {
    "parens": "error",
    "encoding": "error",
    "cl_syntax": "warn",
    "quit_exit": "error",
    "command_shell": "error",
    "startapp": "warn",
    "vl_registry_write": "warn",
    "vlax_without_loading": "warn",
    "token_in_url": "warn",
    "open_without_close": "warn",
    "bare_function_names": "warn",
    "line_length": "warn",
    "function_complexity": "warn",
    "parameter_naming": "warn",
    "unused_variable": "warn",
    "missing_doc": "warn",
    "trailing_whitespace": "warn",
    "module_registration": "off",
    "namespace_header": "off"
  },
  "line_length": {
    "max": 100,
    "tab_width": 2
  },
  "function_complexity": {
    "max_lines": 60,
    "max_nesting": 6
  },
  "cl_syntax": {
    "keywords": ["&key"]
  },
  "dangerous_calls": {
    "quit": "error",
    "exit": "error",
    "command_shell": "error",
    "startapp": "warn",
    "vl_registry_write": "warn"
  },
  "bare_function_names": {
    "allowlist": ["T", "nil"],
    "namespace_pattern": "^[a-z]+:"
  },
  "sbcl": {
    "walk_exclude": [".vscode", "vendor", ".git"],
    "defmacro_allow_files": ["compat-cl"]
  }
}

多语言

支持中文和英文,通过配置文件的 locale 字段切换:

{ "locale": "zh" }  // 中文(默认)
{ "locale": "en" }  // English

Git 集成

# 安装 pre-commit hook,每次提交前自动检查暂存文件
npx @atlisp/lint --install-hook

# 带自定义参数的 hook
npx @atlisp/lint --install-hook --hook-args "--config ci-config.json"

# 手动检查暂存文件
npx @atlisp/lint --staged

开发

# 安装依赖
npm install

# 编译
npm run build

# 测试
npm test

许可

MIT

Keywords