From b9a0e401e0c8d198870f9e4865f66e23391dfa72 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 29 Feb 2024 13:18:14 +0100 Subject: [PATCH] configure eslint --- .eslintignore | 3 +-- .eslintrc | 23 ------------------- eslint.config.mjs | 56 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 15 ++++++++----- tsconfig.json | 49 ++++++++++++++++++++++------------------- 5 files changed, 94 insertions(+), 52 deletions(-) delete mode 100644 .eslintrc create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore index e019f3c..0501293 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,2 @@ node_modules/ - -main.js +**/*.mjs diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 0807290..0000000 --- a/.eslintrc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "root": true, - "parser": "@typescript-eslint/parser", - "env": { "node": true }, - "plugins": [ - "@typescript-eslint" - ], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "parserOptions": { - "sourceType": "module" - }, - "rules": { - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], - "@typescript-eslint/ban-ts-comment": "off", - "no-prototype-builtins": "off", - "@typescript-eslint/no-empty-function": "off" - } - } \ No newline at end of file diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..2783f8f --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,56 @@ +import eslint from '@eslint/js'; +import tseslint from 'typescript-eslint'; +import globals from 'globals'; + +export default tseslint.config( + eslint.configs.recommended, + ...tseslint.configs.recommendedTypeChecked, + { + languageOptions: { + parserOptions: { + sourceType: "module", + parser: "@typescript-eslint/parser", + project: "./tsconfig.json", + }, + globals: { + ...globals.browser, ...globals.worker + } + }, + rules: { + "no-unused-vars": "off", + "no-prototype-bultins": "off", + "no-self-compare": "warn", + "no-eval": "error", + "no-implied-eval": "error", + "prefer-const": "off", + "no-console": [ + "warn", + { + "allow": ["warn", "error", "debug"] + } + ], + "no-restricted-globals": [ + "error", + { + "name": "app", + "message": "Avoid using the global app object. Instead use the reference provided by your plugin instance." + } + ], + "no-alert": "error", + "no-undef": "error", + "@typescript/eslint-ban-ts-comment": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + "args": "none" + } + ], + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/await-thenable": "warn", + "@typescript-eslint/no-invalid-this": "error", + "@typescript-eslint/no-require-imports": "warn", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn" + } + }, +); diff --git a/package.json b/package.json index 6a00766..9d2f628 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "dev": "node esbuild.config.mjs", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json" + "version": "node version-bump.mjs && git add manifest.json versions.json", + "lint": "eslint src" }, "keywords": [], "author": "", @@ -15,10 +16,14 @@ "@types/node": "^16.11.6", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", - "builtin-modules": "3.3.0", - "esbuild": "0.17.3", - "obsidian": "latest", + "esbuild": "0.20.1", + "eslint": "8.57.0", + "typescript-eslint": "7.1.0", "tslib": "2.4.0", - "typescript": "4.7.4" + "typescript": "4.7.4", + "globals": "14.0.0" + }, + "dependencies": { + "obsidian": "latest" } } diff --git a/tsconfig.json b/tsconfig.json index 2d6fbdf..8a11ee1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,29 @@ { - "compilerOptions": { - "baseUrl": ".", - "inlineSourceMap": true, - "inlineSources": true, - "module": "ESNext", - "target": "ES6", - "allowJs": true, - "noImplicitAny": true, - "moduleResolution": "node", - "importHelpers": true, - "isolatedModules": true, - "strictNullChecks": true, - "lib": [ - "DOM", - "ES5", - "ES6", - "ES7" - ] - }, - "include": [ - "**/*.ts" - ] + "compilerOptions": { + "baseUrl": "src", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "target": "ES6", + "allowJs": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noImplicitReturns": true, + "moduleResolution": "node", + "importHelpers": true, + "noUncheckedIndexedAccess": true, + "isolatedModules": true, + "strictNullChecks": true, + "strictBindCallApply": true, + "useUnknownInCatchVariables": true, + "lib": [ + "DOM", + "ES5", + "ES6", + "ES7" + ] + }, + "include": [ + "src/**/*.ts" + ] }