diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..188a0cb --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,86 @@ +const jsExtends = [ + 'eslint:recommended', + 'plugin:import/recommended', + 'prettier', +] + +const tsExtends = [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'prettier', +] + +const jsPlugins = ['prettier', 'import', 'jest-formatting'] + +const tsPlugins = ['@typescript-eslint', ...jsPlugins] + +const jsParserOptions = { + ecmaVersion: 'latest', + sourceType: 'module', +} + +const tsParserOptions = { + ...jsParserOptions, + project: './tsconfig.json', +} + +const jsRules = { + eqeqeq: 'error', + 'import/no-default-export': 'error', + 'import/no-unresolved': 'error', + 'import/order': [ + 'error', + { + pathGroups: [ + { + group: 'external', + pattern: '~shared/**', + position: 'after', + }, + ], + pathGroupsExcludedImportTypes: ['builtin'], + }, + ], + 'prettier/prettier': [ + 'warn', + { + endOfLine: 'auto', + }, + ], + 'jest-formatting/padding-around-describe-blocks': 2, + 'jest-formatting/padding-around-test-blocks': 2, +} + +const tsRules = { + ...jsRules, + '@typescript-eslint/explicit-module-boundary-types': 'error', + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, + ], +} + +module.exports = { + env: { + node: true, + }, + extends: jsExtends, + ignorePatterns: ['**/node_modules'], + parserOptions: jsParserOptions, + plugins: jsPlugins, + root: true, + rules: jsRules, + overrides: [ + { + files: ['**/*.ts'], + extends: tsExtends, + parser: '@typescript-eslint/parser', + parserOptions: tsParserOptions, + plugins: tsPlugins, + rules: tsRules, + }, + ], +} diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 61caa16..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "env": { - "node": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:import/recommended", - "plugin:import/typescript", - "prettier" - ], - "ignorePatterns": ["**/node_modules"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": "latest", - "sourceType": "module" - }, - "plugins": ["@typescript-eslint", "prettier", "import", "jest-formatting"], - "root": true, - "rules": { - "eqeqeq": "error", - "import/no-default-export": "error", - "import/no-unresolved": "error", - "import/order": [ - "error", - { - "pathGroups": [ - { - "group": "external", - "pattern": "~shared/**", - "position": "after" - } - ], - "pathGroupsExcludedImportTypes": ["builtin"] - } - ], - "prettier/prettier": [ - "warn", - { - "endOfLine": "auto" - } - ], - "jest-formatting/padding-around-describe-blocks": 2, - "jest-formatting/padding-around-test-blocks": 2, - "@typescript-eslint/explicit-module-boundary-types": "error", - "@typescript-eslint/explicit-function-return-type": "error", - "@typescript-eslint/no-unused-vars": [ - "error", - { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" } - ] - } -} diff --git a/.prettierignore b/.prettierignore index 425cceb..0709d75 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,5 @@ package-lock.json package.json -.eslintrc.json .prettierrc.js tsconfig.json bin \ No newline at end of file diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000..419c0d1 --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,4 @@ +module.exports = { + '**/*.{js,ts}': ['npm run format', 'npm run lint:fix'], + '**/*.ts': () => 'npm run typecheck', +} diff --git a/package.json b/package.json index 70436d4..002233b 100644 --- a/package.json +++ b/package.json @@ -52,12 +52,5 @@ }, "dependencies": { "prompts": "^2.4.2" - }, - "lint-staged": { - "*.{js,ts}": [ - "npm run typecheck", - "npm run format", - "npm run lint:fix" - ] } }