From da308df384a76444a6559486cc38cc775f53d51f Mon Sep 17 00:00:00 2001 From: "a.khmyrov" Date: Thu, 15 Sep 2022 18:40:33 +0300 Subject: [PATCH] feat: make rules stronger --- __tests__/rules.test.ts | 9 +++++++ global.d.ts | 50 ------------------------------------- package.json | 9 ++++--- rules/@typescript-eslint.js | 20 --------------- rules/import.js | 2 ++ yarn.lock | 18 +++++++++++++ 6 files changed, 34 insertions(+), 74 deletions(-) delete mode 100644 global.d.ts diff --git a/__tests__/rules.test.ts b/__tests__/rules.test.ts index e56c664..42b9e85 100644 --- a/__tests__/rules.test.ts +++ b/__tests__/rules.test.ts @@ -6,6 +6,15 @@ const validateConfig = (config: string) => { const eslint = new ESLint({ overrideConfigFile: config, useEslintrc: false, + overrideConfig: { + // should be set in project, not in lib + parserOptions: { + project: './tsconfig.json', + ecmaFeatures: { + jsx: true, + }, + }, + }, }) return eslint.lintText('') } diff --git a/global.d.ts b/global.d.ts deleted file mode 100644 index 3db46fa..0000000 --- a/global.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -declare module 'eslint' { - export interface ESLintOptions { - overrideConfigFile?: string - useEslintrc?: boolean - } - - export interface LintResult { - filePath: string - messages: LintMessage[] - fixableErrorCount: number - fixableWarningCount: number - errorCount: number - warningCount: number - output: string | undefined - source: string | undefined - usedDeprecatedRules: DeprecatedRule[] - } - - export interface LintMessage { - ruleId: string - severity: 1 | 2 - message: string - line: number - column: number - endLine: number | undefined - endColumn: number | undefined - fix: EditInfo | undefined - suggestions: Suggestion[] | undefined - } - - export interface EditInfo { - range: [number, number] - test: string - } - - export interface Suggestion { - desc: string - fix: EditInfo - } - - export interface DeprecatedRule { - ruleId: string - replacedBy: string[] - } - - export class ESLint { - constructor(options?: ESLintOptions) - lintText: (code: string) => Promise - } -} diff --git a/package.json b/package.json index f9f5240..20df919 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bestdoctor/eslint-config", - "version": "0.5.8", + "version": "0.6.0", "description": "BestDoctor ESLint config", "main": "index.js", "author": "NMVikings", @@ -19,6 +19,7 @@ "eslint-plugin-tsdoc": "^0.2.11" }, "devDependencies": { + "@types/eslint": "^8.4.6", "@types/jest": "^25.2.2", "eslint": "^7.0.0", "jest": "^26.0.1", @@ -27,9 +28,9 @@ "typescript": "^3.9.2" }, "peerDependencies": { - "eslint": ">=6.0.0", - "prettier": ">=1.18.0", - "typescript": ">=3.5.0" + "eslint": ">=7.0.0", + "prettier": ">=2.0.0", + "typescript": ">=4.0.0" }, "scripts": { "test": "jest", diff --git a/rules/@typescript-eslint.js b/rules/@typescript-eslint.js index 5365c37..5f2a7aa 100644 --- a/rules/@typescript-eslint.js +++ b/rules/@typescript-eslint.js @@ -1,13 +1,6 @@ module.exports = { parser: '@typescript-eslint/parser', - parserOptions: { - project: './tsconfig.json', - ecmaFeatures: { - jsx: true, - }, - }, - plugins: ['@typescript-eslint', 'eslint-plugin-tsdoc'], extends: [ @@ -30,16 +23,6 @@ module.exports = { ], '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], '@typescript-eslint/no-non-null-assertion': 'error', - '@typescript-eslint/no-empty-interface': 'off', - '@typescript-eslint/comma-dangle': 'off', - '@typescript-eslint/ban-types': 'off', - '@typescript-eslint/no-floating-promises': 'off', - '@typescript-eslint/restrict-template-expressions': 'off', - '@typescript-eslint/no-unsafe-return': 'off', - '@typescript-eslint/no-unsafe-assignment': 'off', - '@typescript-eslint/no-unsafe-call': 'off', - '@typescript-eslint/unbound-method': 'off', - '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', 'tsdoc/syntax': 'warn', }, @@ -49,8 +32,5 @@ module.exports = { 'import/parsers': { '@typescript-eslint/parser': ['.ts', '.tsx'], }, - 'import/resolver': { - typescript: {}, - }, }, } diff --git a/rules/import.js b/rules/import.js index 69189ff..2d86832 100644 --- a/rules/import.js +++ b/rules/import.js @@ -17,6 +17,8 @@ module.exports = { '**/*.stories.tsx', '**/fixtures.ts', '**/setupTests.ts', + '**/jest-setup.ts', + '**/jest-setup.tsx', './*.ts', './*.js', ], diff --git a/yarn.lock b/yarn.lock index 9a776ec..fecac51 100644 --- a/yarn.lock +++ b/yarn.lock @@ -609,6 +609,19 @@ resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== +"@types/eslint@^8.4.6": + version "8.4.6" + resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.4.6.tgz#7976f054c1bccfcf514bff0564c0c41df5c08207" + integrity sha512-/fqTbjxyFUaYNO7VcW5g+4npmqVACz1bB7RTHYuLj+PRjw9hrCwrUXVQFpChUS0JsyEFvMZ7U/PfmvWgxJhI9g== + dependencies: + "@types/estree" "*" + "@types/json-schema" "*" + +"@types/estree@*": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.0.tgz#5fb2e536c1ae9bf35366eed879e827fa59ca41c2" + integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ== + "@types/graceful-fs@^4.1.2": version "4.1.3" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f" @@ -644,6 +657,11 @@ jest-diff "^25.2.1" pretty-format "^25.2.1" +"@types/json-schema@*": + version "7.0.11" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" + integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== + "@types/json-schema@^7.0.3": version "7.0.4" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339"