n8n 节点代码检查器#
¥n8n node linter
n8n 的节点代码检查工具 eslint-plugin-n8n-nodes-base 会对官方仓库和社区软件包中的 n8n 节点和凭据的源代码进行静态分析 ("lints")。代码检查工具会检测问题并自动修复,以帮助你遵循最佳实践。
¥n8n's node linter, eslint-plugin-n8n-nodes-base, statically analyzes ("lints") the source code of n8n nodes and credentials in the official repository and in community packages. The linter detects issues and automatically fixes them to help you follow best practices.
eslint-plugin-n8n-nodes-base 包含用于存放节点文件 (*.node.ts)、资源描述文件 (*Description.ts)、凭证文件 (*.credentials.ts) 以及社区包的 package.json 的 规则集。
¥eslint-plugin-n8n-nodes-base contains a collection of rules for node files (*.node.ts), resource description files (*Description.ts), credential files (*.credentials.ts), and the package.json of a community package.
设置#
¥Setup
如果使用 n8n 节点启动器:在启动项目中运行 npm install 以安装所有依赖。安装完成后,即可使用代码检查器。
¥If using the n8n node starter: Run npm install in the starter project to install all dependencies. Once the installation finishes, the linter is available to you.
如果使用 VS Code,请安装 ESLint VS Code 扩展。对于其他 IDE,请参考其 ESLint 集成。
¥If using VS Code, install the ESLint VS Code extension. For other IDEs, refer to their ESLint integrations.
Don't edit the configuration file
.eslintrc.js 包含 eslint-plugin-n8n-nodes-base 的配置。请勿编辑此文件。
¥.eslintrc.js contains the configuration for eslint-plugin-n8n-nodes-base. Don't edit this file.
用法#
¥Usage
你可以在社区包或 n8n 主仓库中使用代码检查器。
¥You can use the linter in a community package or in the main n8n repository.
代码检查#
¥Linting
在社区包中,代码检查器会在安装依赖之后、将包发布到 npm 之前自动运行。在 主 n8n 仓库 中,每当你推送拉取请求时,代码检查器都会使用 GitHub Actions 自动运行。
¥In a community package, the linter runs automatically after installing dependencies and before publishing the package to npm. In the main n8n repository, the linter runs automatically using GitHub Actions whenever you push to your pull request.
在这两种情况下,VS Code 都会在你处理项目时在后台进行代码检查。将鼠标悬停在检测到的问题上,即可查看完整的代码检查描述以及指向更多信息的链接。
¥In both cases, VS Code lints in the background as you work on your project. Hover over a detected issue to see a full description of the linting and a link to further information.
你也可以手动运行代码检查器:
¥You can also run the linter manually:
- 运行
npm run lint进行代码检查并在控制台中查看检测到的问题。
¥Run npm run lint to lint and view detected issues in your console.
- 运行
npm run lintfix进行代码检查并自动修复问题。代码检查工具会修复违反规则 标记为可自动修复 的问题。
¥Run npm run lintfix to lint and automatically fix issues. The linter fixes violations of rules marked as automatically fixable.
这两个命令都可以在社区软件包的根目录下运行,也可以在主仓库的 /packages/nodes-base/ 实例下运行。
¥Both commands can run in the root directory of your community package, or in /packages/nodes-base/ in the main repository.
例外#
¥Exceptions
除了修复规则违规之外,你还可以为其创建例外,这样代码检查器就不会标记它。
¥Instead of fixing a rule violation, you can also make an exception for it, so the linter doesn't flag it.
在 VS Code 中创建 lint 异常:将鼠标悬停在问题上,然后单击 Quick fix(macOS 中为 cmd+.),并为该行选择“禁用 {rule}”。仅在有充分理由的情况下才禁用某行规则。如果你认为代码检查器错误地报告了问题,请 在代码检查器存储库中报告。
¥To make a lint exception from VS Code: hover over the issue and click on Quick fix (or cmd+. in macOS) and select Disable {rule} for this line. Only disable rules for a line where you have good reason to. If you think the linter is incorrectly reporting an issue, please report it in the linter repository.
要向单个文件添加 lint 异常,请添加代码注释。尤其需要注意的是,TSLint 规则可能不会显示在 VS Code 中,可能需要使用代码注释将其关闭。请参阅 TSLint 文档,了解更多指导。
¥To add a lint exception to a single file, add a code comment. In particular, TSLint rules may not show up in VS Code and may need to be turned off using code comments. Refer to the TSLint documentation for more guidance.