Merge pull request #38 from northword:eslint

Add ESlint and Prettier
This commit is contained in:
windingwind 2023-05-04 20:12:24 +08:00 committed by GitHub
commit 7f733416ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 133 additions and 81 deletions

39
.eslintrc.json Normal file
View File

@ -0,0 +1,39 @@
{
"env": {
"browser": true,
"es2021": true
},
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/ban-ts-comment": ["warn", "allow-with-description"],
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": ["off", { "ignoreRestArgs": true }],
"@typescript-eslint/no-non-null-assertion": "off"
},
"ignorePatterns": [
"**/dist/**",
"**/node_modules/**",
"**/abbrevIso*",
"**/example*",
"**/*.bak",
"coverage/**",
"docs-shared/lib/**",
"packages/*/assets/**",
"packages/*/lib/**",
"!.vuepress/**",
"**/.vuepress/.cache/**",
"**/.vuepress/.temp/**"
]
}

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

3
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}

10
.vscode/launch.json vendored
View File

@ -9,20 +9,14 @@
"request": "launch", "request": "launch",
"name": "Restart", "name": "Restart",
"runtimeExecutable": "npm", "runtimeExecutable": "npm",
"runtimeArgs": [ "runtimeArgs": ["run", "restart"]
"run",
"restart"
],
}, },
{ {
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"name": "Restart in Prod Mode", "name": "Restart in Prod Mode",
"runtimeExecutable": "npm", "runtimeExecutable": "npm",
"runtimeArgs": [ "runtimeArgs": ["run", "restart-prod"]
"run",
"restart-prod"
],
} }
] ]
} }

7
.vscode/setting.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"editor.formatOnType": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}

View File

@ -24,7 +24,9 @@
"restart-prod": "npm run build-prod && npm run stop && npm run start", "restart-prod": "npm run build-prod && npm run stop && npm run start",
"restart": "npm run restart-dev", "restart": "npm run restart-dev",
"release": "release-it", "release": "release-it",
"test": "echo \"Error: no test specified\" && exit 1" "lint": "prettier --write . && eslint . --ext .ts --fix",
"test": "echo \"Error: no test specified\" && exit 1",
"update-deps": "npm update --save"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -41,14 +43,22 @@
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^18.11.17", "@types/node": "^18.11.17",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"compressing": "^1.6.3", "compressing": "^1.6.3",
"concurrently": "^7.6.0", "concurrently": "^7.6.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"esbuild": "^0.17.4", "esbuild": "^0.17.4",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"minimist": "^1.2.7", "minimist": "^1.2.7",
"prettier": "2.8.8",
"release-it": "^15.6.0", "release-it": "^15.6.0",
"replace-in-file": "^6.3.5", "replace-in-file": "^6.3.5",
"typescript": "^4.9.4", "typescript": "^4.9.4",
"zotero-types": "^1.0.12" "zotero-types": "^1.0.12"
},
"prettier": {
"tabWidth": 2
} }
} }

View File

@ -21,7 +21,7 @@ class Addon {
// Lifecycle hooks // Lifecycle hooks
public hooks: typeof hooks; public hooks: typeof hooks;
// APIs // APIs
public api: {}; public api: object;
constructor() { constructor() {
this.data = { this.data = {

View File

@ -8,10 +8,7 @@ export function initLocale() {
}; };
} }
export function getString( export function getString(localString: string, noReload = false): string {
localString: string,
noReload: boolean = false
): string {
try { try {
return addon.data.locale?.stringBundle.GetStringFromName(localString); return addon.data.locale?.stringBundle.GetStringFromName(localString);
} catch (e) { } catch (e) {

View File

@ -46,7 +46,8 @@ async function updatePrefsUI() {
// with addon.data.prefs.window.document // with addon.data.prefs.window.document
// Or bind some events to the elements // Or bind some events to the elements
const renderLock = ztoolkit.getGlobal("Zotero").Promise.defer(); const renderLock = ztoolkit.getGlobal("Zotero").Promise.defer();
const tableHelper = new ztoolkit.VirtualizedTable(addon.data.prefs?.window!) if (addon.data.prefs?.window == undefined) return;
const tableHelper = new ztoolkit.VirtualizedTable(addon.data.prefs?.window)
.setContainerId(`${config.addonRef}-table-container`) .setContainerId(`${config.addonRef}-table-container`)
.setProp({ .setProp({
id: `${config.addonRef}-prefs-table`, id: `${config.addonRef}-prefs-table`,
@ -122,7 +123,7 @@ function bindPrefEvents() {
}); });
addon.data addon.data
.prefs!!.window.document.querySelector( .prefs!.window.document.querySelector(
`#zotero-prefpane-${config.addonRef}-input` `#zotero-prefpane-${config.addonRef}-input`
) )
?.addEventListener("change", (e) => { ?.addEventListener("change", (e) => {