feat: add `@zotero-plugin/eslint-config`
info
@zotero-plugin/eslint-config:
homepage: https://northword.github.io/zotero-plugin-scaffold/eslint.html repo: https://github.com/northword/zotero-plugin-scaffold/tree/main/packages/eslint-config
todo
no-restricted-globals
Do the following rules actually work?
"no-restricted-globals": [
"error",
{ message: "Use `Zotero.getMainWindow()` instead.", name: "window" },
{
message: "Use `Zotero.getMainWindow().document` instead.",
name: "document",
},
{
message: "Use `Zotero.getActiveZoteroPane()` instead.",
name: "ZoteroPane",
},
"Zotero_Tabs",
],
如果是,我们需要屏蔽所有浏览器变量吗?
-> https://github.com/sindresorhus/globals/blob/main/data/browser.mjs
@typescript-eslint/no-unused-vars
The following rule is recommended to be enabled, but the template example has a lot of unused function arguments.
https://typescript-eslint.io/rules/no-unused-vars/
"@typescript-eslint/no-unused-vars": ["error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
}],
如果是,我们需要屏蔽所有浏览器变量吗?
会影响类型定义中使用浏览器变量(例如HTMLElement)吗?如果不会,我觉得可以全部屏蔽,除zotero中单独引入的变量外。
https://github.com/zotero/zotero/blob/6f8da4825e2d42f1d531fb685f23e7d00e2ceb05/chrome/content/zotero/xpcom/plugins.js#L125-L173
同时需要有针对部分子文件夹(例如,配置为编译到单独的脚本文件并在浏览器/worker中运行的)正常使用这些变量的解决方案。
同时需要有针对部分子文件夹(例如,配置为编译到单独的脚本文件并在浏览器/worker中运行的)正常使用这些变量的解决方案。
约定 **/extras/** 和 **/workers 目录存放这类代码,不应用这些规则?
感觉限制有点大,这个是不是没法动态配置
感觉限制有点大,这个是不是没法动态配置
你的意思是让用户指定路径吗?这样可以实现,在工厂函数里传个参数,比如“browserScripts”,指定不应用这些规则的路径就好。
// eslint.config.js
import zotero from "@zotero-plugin/eslint-config"
export default zotero({
browserScripts: ["**/workers"]
})
或者可以默认关闭 no-restricted-globals 规则,然后把 no-restricted-globals 导出,让用户自己去设置。
import zotero from "@zotero-plugin/eslint-config"
import { jsForSandbox } from "@zotero-plugin/eslint-config"
export default zotero({
override: [
{
files: ["**/src/", "!**/src/extras"]
...jsForSandbox
}
]
})
(只是设想,还没验证)
这样的话,实现上没啥问题了。比较麻烦的是可能要加一些例子用来说明这个不同环境的区别,但又可能增加学习成本了