From fe7aaafcc5a26dc66b94162673cddf982ccf4e32 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 7 Nov 2022 20:48:13 +0000 Subject: [PATCH] chore: setup eslint and prettier --- .editorconfig | 15 +++++++++++++ .eslintignore | 2 ++ .eslintrc | 51 +++++++++++++++++++++++++++++++++++++++++++- .prettierrc | 5 +++++ tsconfig.eslint.json | 12 +++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .prettierrc create mode 100644 tsconfig.eslint.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..4f4d652c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[*.js] +indent_style = space +indent_size = 2 + +[{package.json,*.yml,*.cjson}] +indent_style = space +indent_size = 2 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..de4d1f00 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +dist +node_modules diff --git a/.eslintrc b/.eslintrc index 09c2e423..a7092ba4 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,52 @@ { - "extends": "@antfu" + "extends": [ + "@nuxtjs/eslint-config-typescript", + // Enable typescript-specific recommended rules + "plugin:@typescript-eslint/recommended", + // Turns off all rules that are unnecessary or might conflict with Prettier (needs to be last) + "prettier" + ], + "plugins": ["unused-imports"], + "rules": { + // Workaround for bug https://github.com/nuxt/eslint-config/issues/147 + "no-useless-constructor": "off", + "@typescript-eslint/no-useless-constructor": "error", + // Don"t report unused imports (this is handled by prettier) + "unused-imports/no-unused-imports": "off", + // Report unused variables (except the ones prefixed with an underscore) + "unused-imports/no-unused-vars": [ + "warn", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_" + } + ], + // Ensure void operator is not used, except for variable assignment or function return (might be handy for promises) + "no-void": ["error", { "allowAsStatement": true }], + // Demote this to warning as long as we are still using cjs modules + "import/named": "warn", + // Import order is handled by prettier (which is incompatible with this rule: https://github.com/simonhaenisch/prettier-plugin-organize-imports/issues/65) + "import/order": "off" + }, + "overrides": [ + { + "files": ["*.ts", "*.vue"], + // Parser supporting vue files + "parser": "vue-eslint-parser", + "parserOptions": { + // Use ts parser for ts files and for the script tag in vue files + "parser": "@typescript-eslint/parser", + // Path to tsconfig to enable rules that require type information + "project": "./tsconfig.eslint.json", + // Correctly handle vue files + "extraFileExtensions": [".vue"] + }, + "extends": [ + // Enable recommended rules for typescript that use typing information (may be CPU intensive) + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ] + } + ] } diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..2fb5885d --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": false, + "singleQuote": true, + "singleAttributePerLine": true +} diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 00000000..7be48630 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + // ensure that nobody can accidentally use this config for a build + "noEmit": true + }, + "include": [ + // whatever paths you intend to lint + "src", + "test" + ] +}