From 1351a392ab21ed8de40ef414d0e6aa71384b473e Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Fri, 12 Jul 2024 18:45:25 -0500 Subject: [PATCH] chore: lint eslint-config-sheriff with eslint-config-sheriff --- .../eslint-config-sheriff/eslint.config.js | 25 ++ packages/eslint-config-sheriff/package.json | 1 + .../src/getAstroConfig.ts | 5 +- .../src/getBaseConfig.ts | 39 +-- .../src/getExportableConfig.ts | 26 +- .../src/getJestConfig.ts | 3 +- .../src/getReactConfig.ts | 13 +- .../src/getVitestConfig.ts | 5 +- .../src/handledModules.d.ts | 227 ++++++++++++++++-- .../src/handpickedRules/fpHandPickedRules.ts | 4 +- .../getBaseEslintHandPickedRules.ts | 9 +- .../handpickedRules/importHandPickedRules.ts | 4 +- .../handpickedRules/jestHandPickedRules.ts | 4 +- .../handpickedRules/jsdocHandPickedRules.ts | 4 +- .../handpickedRules/lodashHandPickedRules.ts | 4 +- .../playwrightHandPickedRules.ts | 4 +- .../handpickedRules/reactHandPickedRules.ts | 4 +- .../handpickedRules/sonarjsHandPickedRules.ts | 4 +- .../stylisticHandPickedRules.ts | 4 +- .../typescriptHandPickedRules.ts | 4 +- .../handpickedRules/unicornHandPickedRules.ts | 4 +- .../handpickedRules/vitestHandPickedRules.ts | 4 +- .../eslint-config-sheriff/src/lodashConfig.ts | 3 +- .../eslint-config-sheriff/src/nextjsConfig.ts | 3 +- .../src/playwrightConfig.ts | 3 +- .../src/prettierOverrides.ts | 3 +- .../getFilteredBaseNoRestrictedSyntax.ts | 10 +- .../src/utils/getLanguageOptionsTypescript.ts | 3 +- .../getLanguageOptionsTypescriptReact.ts | 3 +- .../src/utils/getTsNamingConventionRule.ts | 4 +- 30 files changed, 348 insertions(+), 85 deletions(-) create mode 100644 packages/eslint-config-sheriff/eslint.config.js diff --git a/packages/eslint-config-sheriff/eslint.config.js b/packages/eslint-config-sheriff/eslint.config.js new file mode 100644 index 00000000..a8338963 --- /dev/null +++ b/packages/eslint-config-sheriff/eslint.config.js @@ -0,0 +1,25 @@ +// @ts-check +import sheriff from 'eslint-config-sheriff'; +import { defineFlatConfig } from 'eslint-define-config'; + +const sheriffOptions = { + react: false, + next: false, + astro: false, + lodash: false, + playwright: false, + jest: false, + vitest: false, +}; + +const sheriffRules = sheriff(sheriffOptions); + +export default defineFlatConfig([ + ...sheriffRules, + { + files: ['**.ts'], + rules: { + 'fsecond/prefer-destructured-optionals': 'off', + }, + }, +]); diff --git a/packages/eslint-config-sheriff/package.json b/packages/eslint-config-sheriff/package.json index bafbe034..e8247bfa 100644 --- a/packages/eslint-config-sheriff/package.json +++ b/packages/eslint-config-sheriff/package.json @@ -51,6 +51,7 @@ "clean": "rm -rf .turbo dist", "build": "tsup", "typecheck": "tsc --noEmit", + "lint": "eslint . --max-warnings=0 --cache --cache-location=node_modules/.cache/.eslintcache", "publint": "publint", "typesync": "typesync --dry=fail", "are-the-types-wrong": "attw --pack ." diff --git a/packages/eslint-config-sheriff/src/getAstroConfig.ts b/packages/eslint-config-sheriff/src/getAstroConfig.ts index 3066e5b2..838451d7 100644 --- a/packages/eslint-config-sheriff/src/getAstroConfig.ts +++ b/packages/eslint-config-sheriff/src/getAstroConfig.ts @@ -1,10 +1,11 @@ -import astro from 'eslint-plugin-astro'; import astroParser from 'astro-eslint-parser'; +import astro from 'eslint-plugin-astro'; +import type { TSESLint } from '@typescript-eslint/utils'; export const getAstroConfig = ( hasReact: boolean, customTSConfigPath: string | string[] | undefined, -) => { +): TSESLint.FlatConfig.Config => { return { files: ['**/*.astro'], plugins: { diff --git a/packages/eslint-config-sheriff/src/getBaseConfig.ts b/packages/eslint-config-sheriff/src/getBaseConfig.ts index d61b8c7c..2bf18b85 100644 --- a/packages/eslint-config-sheriff/src/getBaseConfig.ts +++ b/packages/eslint-config-sheriff/src/getBaseConfig.ts @@ -1,35 +1,39 @@ -import eslintRecommended from '@eslint/js'; -import tseslint from 'typescript-eslint'; -import unicorn from 'eslint-plugin-unicorn'; -import sonarjs from 'eslint-plugin-sonarjs'; -import jsdoc from 'eslint-plugin-jsdoc'; +import arrowReturnStyle from 'eslint-plugin-arrow-return-style'; +import fp from 'eslint-plugin-fp'; +import fsecond from 'eslint-plugin-fsecond'; import pluginImport from 'eslint-plugin-import'; +import jsdoc from 'eslint-plugin-jsdoc'; import simpleImportSort from 'eslint-plugin-simple-import-sort'; -import fp from 'eslint-plugin-fp'; -import preferEarlyReturn from '@regru/eslint-plugin-prefer-early-return'; -import tsdoc from 'eslint-plugin-tsdoc'; +import sonarjs from 'eslint-plugin-sonarjs'; import storybook from 'eslint-plugin-storybook'; -import fsecond from 'eslint-plugin-fsecond'; -import arrowReturnStyle from 'eslint-plugin-arrow-return-style'; +import tsdoc from 'eslint-plugin-tsdoc'; +import unicorn from 'eslint-plugin-unicorn'; +import tseslint from 'typescript-eslint'; +import eslintRecommended from '@eslint/js'; +import preferEarlyReturn from '@regru/eslint-plugin-prefer-early-return'; +import { allJsExtensions, supportedFileTypes } from '@sherifforg/constants'; +import type { SheriffSettings } from '@sherifforg/types'; import stylistic from '@stylistic/eslint-plugin'; -import { supportedFileTypes, allJsExtensions } from '@sherifforg/constants'; -import { SheriffSettings } from '@sherifforg/types'; +import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import { getAstroConfig } from './getAstroConfig'; import { fpHandPickedRules } from './handpickedRules/fpHandPickedRules'; -import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule'; +import { getBaseEslintHandPickedRules } from './handpickedRules/getBaseEslintHandPickedRules'; import { importHandPickedRules } from './handpickedRules/importHandPickedRules'; import { jsdocHandPickedRules } from './handpickedRules/jsdocHandPickedRules'; import { sonarjsHandPickedRules } from './handpickedRules/sonarjsHandPickedRules'; import { stylisticHandPickedRules } from './handpickedRules/stylisticHandPickedRules'; import { typescriptHandPickedRules } from './handpickedRules/typescriptHandPickedRules'; import { unicornHandPickedRules } from './handpickedRules/unicornHandPickedRules'; -import { getBaseEslintHandPickedRules } from './handpickedRules/getBaseEslintHandPickedRules'; import { getLanguageOptionsTypescript } from './utils/getLanguageOptionsTypescript'; +import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule'; -export const getBaseConfig = (userConfigChoices: SheriffSettings) => { +export const getBaseConfig = ( + userConfigChoices: SheriffSettings, +): FlatConfig.ConfigArray => { const customTSConfigPath = userConfigChoices.pathsOverrides?.tsconfigLocation; - const { noRestrictedSyntaxOverride } = userConfigChoices; - const hasReact = Boolean(userConfigChoices.react); + // eslint-disable-next-line @typescript-eslint/naming-convention + const { noRestrictedSyntaxOverride, react } = userConfigChoices; + const hasReact = Boolean(react); return tseslint.config( { @@ -99,6 +103,7 @@ export const getBaseConfig = (userConfigChoices: SheriffSettings) => { files: [supportedFileTypes], plugins: { sonarjs }, rules: { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access -- Still has eslintrc types. ...sonarjs.configs.recommended.rules, ...sonarjsHandPickedRules, }, diff --git a/packages/eslint-config-sheriff/src/getExportableConfig.ts b/packages/eslint-config-sheriff/src/getExportableConfig.ts index 85fd6f28..2a90119d 100644 --- a/packages/eslint-config-sheriff/src/getExportableConfig.ts +++ b/packages/eslint-config-sheriff/src/getExportableConfig.ts @@ -1,23 +1,24 @@ -import eslintConfigPrettier from 'eslint-config-prettier'; import getGitignorePatterns from 'eslint-config-flat-gitignore'; -import lodash from 'lodash'; +import eslintConfigPrettier from 'eslint-config-prettier'; import type { FlatESLintConfig } from 'eslint-define-config'; -import { SheriffSettings } from '@sherifforg/types'; +import lodash from 'lodash'; import { ignores } from '@sherifforg/constants'; -import { getReactConfig } from './getReactConfig'; +import type { SheriffSettings } from '@sherifforg/types'; +import type { TSESLint } from '@typescript-eslint/utils'; import { getBaseConfig } from './getBaseConfig'; -import { nextjsConfig } from './nextjsConfig'; -import { playwrightConfig } from './playwrightConfig'; -import { lodashConfig } from './lodashConfig'; import { getJestConfig } from './getJestConfig'; +import { getReactConfig } from './getReactConfig'; import { getVitestConfig } from './getVitestConfig'; +import { lodashConfig } from './lodashConfig'; +import { nextjsConfig } from './nextjsConfig'; +import { playwrightConfig } from './playwrightConfig'; import { prettierOverrides } from './prettierOverrides'; -import { type TSESLint } from '@typescript-eslint/utils'; export const getExportableConfig = ( userConfigChoices: SheriffSettings, areAllRulesForced?: boolean, ): FlatESLintConfig[] => { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- ESLint isn't TypeScript first, so this is just in case. if (!userConfigChoices) { throw new Error('No settings provided.'); } @@ -52,7 +53,6 @@ export const getExportableConfig = ( if (userConfigChoices.vitest) { exportableConfig.push( - //@ts-expect-error getVitestConfig(userConfigChoices.pathsOverrides?.tests), ); } @@ -69,9 +69,7 @@ export const getExportableConfig = ( exportableConfig.push(playwrightConfig); } - exportableConfig.push(eslintConfigPrettier); - //@ts-expect-error - exportableConfig.push(prettierOverrides); + exportableConfig.push(eslintConfigPrettier, prettierOverrides); if (userConfigChoices.files) { const allowedPatterns = userConfigChoices.files.map( @@ -93,13 +91,13 @@ export const getExportableConfig = ( const hasIgnoresRecommended = lodash.isBoolean( userConfigChoices.ignores?.recommended, ) - ? userConfigChoices.ignores?.recommended + ? userConfigChoices.ignores.recommended : true; const hasIgnoresInheritedFromGitignore = lodash.isBoolean( userConfigChoices.ignores?.inheritedFromGitignore, ) - ? userConfigChoices.ignores?.inheritedFromGitignore + ? userConfigChoices.ignores.inheritedFromGitignore : true; exportableConfig.push({ diff --git a/packages/eslint-config-sheriff/src/getJestConfig.ts b/packages/eslint-config-sheriff/src/getJestConfig.ts index 983e0b2c..edbe4847 100644 --- a/packages/eslint-config-sheriff/src/getJestConfig.ts +++ b/packages/eslint-config-sheriff/src/getJestConfig.ts @@ -1,8 +1,9 @@ import jest from 'eslint-plugin-jest'; import { allJsExtensions } from '@sherifforg/constants'; +import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import { jestHandPickedRules } from './handpickedRules/jestHandPickedRules'; -export const getJestConfig = (pathsOverrides?: string[]) => { +export const getJestConfig = (pathsOverrides?: string[]): FlatConfig.Config => { return { files: pathsOverrides ?? [ `**/*.{test,spec}.{${allJsExtensions}}`, diff --git a/packages/eslint-config-sheriff/src/getReactConfig.ts b/packages/eslint-config-sheriff/src/getReactConfig.ts index 401cd8d6..3a149011 100644 --- a/packages/eslint-config-sheriff/src/getReactConfig.ts +++ b/packages/eslint-config-sheriff/src/getReactConfig.ts @@ -1,20 +1,23 @@ -import reactRecommended from 'eslint-plugin-react/configs/recommended.js'; -import jsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js'; +import fsecond from 'eslint-plugin-fsecond'; import reactAccessibility from 'eslint-plugin-jsx-a11y'; +import jsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js'; +import reactRecommended from 'eslint-plugin-react/configs/recommended.js'; import reactHooks from 'eslint-plugin-react-hooks'; import reactRefresh from 'eslint-plugin-react-refresh'; -import fsecond from 'eslint-plugin-fsecond'; import rel1cxReact from '@eslint-react/eslint-plugin'; import { allJsExtensions, allJsxExtensions, supportedFileTypes, } from '@sherifforg/constants'; -import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule'; +import type { TSESLint } from '@typescript-eslint/utils'; import { reactHandPickedRules } from './handpickedRules/reactHandPickedRules'; import { getLanguageOptionsTypescriptReact } from './utils/getLanguageOptionsTypescriptReact'; +import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule'; -export const getReactConfig = (customTSConfigPath?: string | string[]) => { +export const getReactConfig = ( + customTSConfigPath?: string | string[], +): TSESLint.FlatConfig.ConfigArray => { return [ { files: [supportedFileTypes], diff --git a/packages/eslint-config-sheriff/src/getVitestConfig.ts b/packages/eslint-config-sheriff/src/getVitestConfig.ts index 3651923c..2d32043d 100644 --- a/packages/eslint-config-sheriff/src/getVitestConfig.ts +++ b/packages/eslint-config-sheriff/src/getVitestConfig.ts @@ -1,8 +1,11 @@ import vitest from 'eslint-plugin-vitest'; import { allJsExtensions } from '@sherifforg/constants'; +import type { TSESLint } from '@typescript-eslint/utils'; import { vitestHandPickedRules } from './handpickedRules/vitestHandPickedRules'; -export const getVitestConfig = (pathsOverrides?: string[]) => { +export const getVitestConfig = ( + pathsOverrides?: string[], +): TSESLint.FlatConfig.Config => { return { files: pathsOverrides ?? [ `**/*.{test,spec}.{${allJsExtensions}}`, diff --git a/packages/eslint-config-sheriff/src/handledModules.d.ts b/packages/eslint-config-sheriff/src/handledModules.d.ts index e32bf6ea..6843711f 100644 --- a/packages/eslint-config-sheriff/src/handledModules.d.ts +++ b/packages/eslint-config-sheriff/src/handledModules.d.ts @@ -1,16 +1,211 @@ -declare module '@eslint/js'; -declare module '@next/eslint-plugin-next'; -declare module '@regru/eslint-plugin-prefer-early-return'; -declare module 'eslint-plugin-unicorn'; -declare module 'eslint-plugin-playwright'; -declare module 'eslint-plugin-jsdoc'; -declare module 'eslint-plugin-lodash-f'; -declare module 'eslint-plugin-import'; -declare module 'eslint-plugin-fp'; -declare module 'eslint-plugin-jest'; -declare module 'eslint-plugin-storybook'; -declare module 'eslint-plugin-react*'; -declare module 'eslint-plugin-jsx-a11y'; -declare module 'eslint-plugin-react-hooks'; -declare module 'eslint-plugin-react-refresh'; -declare module 'eslint-plugin-fsecond'; +declare module '@eslint/js' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module '@next/eslint-plugin-next' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + 'core-web-vitals': { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module '@regru/eslint-plugin-prefer-early-return' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} + +declare module 'eslint-plugin-unicorn' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} + +declare module 'eslint-plugin-playwright' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + 'playwright-test': { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-jsdoc' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-lodash-f' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-import' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} + +declare module 'eslint-plugin-fp' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} + +declare module 'eslint-plugin-jest' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + environments: { + globals: { + globals: Record; + }; + }; + configs: { + style: { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-storybook' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + csf: { + rules: TSESLint.FlatConfig.Rules; + }; + 'csf-strict': { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-react' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} + +declare module 'eslint-plugin-react/configs/recommended.js' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Rules; + + export default defaultExport; +} + +declare module 'eslint-plugin-react/configs/jsx-runtime.js' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Rules; + + export default defaultExport; +} + +declare module 'eslint-plugin-jsx-a11y' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-react-hooks' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin & { + configs: { + recommended: { + rules: TSESLint.FlatConfig.Rules; + }; + }; + }; + + export default defaultExport; +} + +declare module 'eslint-plugin-react-refresh' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} + +declare module 'eslint-plugin-fsecond' { + import type { TSESLint } from '@typescript-eslint/utils'; + + declare const defaultExport: TSESLint.FlatConfig.Plugin; + + export default defaultExport; +} diff --git a/packages/eslint-config-sheriff/src/handpickedRules/fpHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/fpHandPickedRules.ts index 5ab05d19..b69a9a2b 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/fpHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/fpHandPickedRules.ts @@ -1,6 +1,8 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const fpHandPickedRules = { 'fp/no-arguments': 2, 'fp/no-class': 2, 'fp/no-delete': 2, 'fp/no-proxy': 2, -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/getBaseEslintHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/getBaseEslintHandPickedRules.ts index 08e5d659..1ba2f110 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/getBaseEslintHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/getBaseEslintHandPickedRules.ts @@ -1,10 +1,11 @@ -import type { NoRestrictedSyntaxOverride } from '@sherifforg/types'; import { baseNoRestrictedSyntaxRules } from '@sherifforg/constants'; +import type { NoRestrictedSyntaxOverride } from '@sherifforg/types'; +import type { TSESLint } from '@typescript-eslint/utils'; import { getFilteredBaseNoRestrictedSyntax } from '../utils/getFilteredBaseNoRestrictedSyntax'; export const getBaseEslintHandPickedRules = ( noRestrictedSyntaxOverride?: NoRestrictedSyntaxOverride, -) => { +): TSESLint.FlatConfig.Rules => { return { 'func-style': 2, 'no-promise-executor-return': 2, @@ -104,9 +105,7 @@ export const getBaseEslintHandPickedRules = ( baseNoRestrictedSyntaxRules, noRestrictedSyntaxOverride?.allows, ), - ...(noRestrictedSyntaxOverride?.adjuncts - ? noRestrictedSyntaxOverride.adjuncts - : []), + ...(noRestrictedSyntaxOverride?.adjuncts ?? []), ], 'no-return-await': 0, 'no-use-before-define': 0, // we are using the @typescript/eslint version diff --git a/packages/eslint-config-sheriff/src/handpickedRules/importHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/importHandPickedRules.ts index 739c4e2f..5ec3f688 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/importHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/importHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const importHandPickedRules = { 'import/named': 0, 'import/namespace': 0, @@ -14,4 +16,4 @@ export const importHandPickedRules = { 'import/newline-after-import': 2, 'import/no-useless-path-segments': [2, { noUselessIndex: true }], // 'import/consistent-type-specifier-style': [2, 'prefer-inline'], // this is not actually needed when "@typescript-eslint/no-import-type-side-effects is set. Explanation here: https://github.com/import-js/eslint-plugin-import/issues/2676#issuecomment-1407107260 -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/jestHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/jestHandPickedRules.ts index f3e54fcc..c5f8bdd6 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/jestHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/jestHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const jestHandPickedRules = { 'jest/no-conditional-expect': 2, 'jest/no-conditional-in-test': 2, @@ -24,4 +26,4 @@ export const jestHandPickedRules = { 'jest/valid-expect': 2, 'jest/consistent-test-it': [2, { fn: 'test', withinDescribe: 'test' }], 'jest/unbound-method': 2, // we need to overwrite @typescript-eslint/unbound-method. -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/jsdocHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/jsdocHandPickedRules.ts index edbc9c96..9d5b3433 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/jsdocHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/jsdocHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const jsdocHandPickedRules = { 'jsdoc/require-description': 2, 'jsdoc/require-description-complete-sentence': 2, @@ -18,4 +20,4 @@ export const jsdocHandPickedRules = { ], 'jsdoc/sort-tags': 2, 'jsdoc/tag-lines': [2, 'any', { startLines: 1 }], -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/lodashHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/lodashHandPickedRules.ts index 7e22a883..a170110a 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/lodashHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/lodashHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const lodashHandPickedRules = { 'lodash-f/import-scope': [2, 'member'], 'lodash-f/prefer-some': [2, { includeNative: false }], @@ -8,4 +10,4 @@ export const lodashHandPickedRules = { 'lodash-f/prefer-over-quantifier': 0, 'lodash-f/prefer-get': 0, 'unicorn/no-instanceof-array': 0, // we are enabling "prefer-lodash-typecheck", therefore we need to disable this. -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/playwrightHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/playwrightHandPickedRules.ts index 8c19255b..a5e495eb 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/playwrightHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/playwrightHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const playwrightHandPickedRules = { 'playwright/no-force-option': 0, 'playwright/prefer-lowercase-title': 2, @@ -5,4 +7,4 @@ export const playwrightHandPickedRules = { 'playwright/require-top-level-describe': 2, 'playwright/prefer-to-be': 2, 'playwright/prefer-strict-equal': 2, -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/reactHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/reactHandPickedRules.ts index 82b5ec0e..d6a8befd 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/reactHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/reactHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const reactHandPickedRules = { 'react/prop-types': 0, 'react/no-unstable-nested-components': [2, { allowAsProps: false }], @@ -37,4 +39,4 @@ export const reactHandPickedRules = { reservedFirst: false, }, ], -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/sonarjsHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/sonarjsHandPickedRules.ts index 5cd81b07..a5b5f229 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/sonarjsHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/sonarjsHandPickedRules.ts @@ -1,4 +1,6 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const sonarjsHandPickedRules = { 'sonarjs/cognitive-complexity': 0, 'sonarjs/prefer-immediate-return': 0, -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/stylisticHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/stylisticHandPickedRules.ts index 335ab85e..faa6b1dd 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/stylisticHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/stylisticHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const stylisticHandPickedRules = { // Prettier doesn't have strong opinions about emptyLines. See: https://prettier.io/docs/en/rationale.html#empty-lines. '@stylistic/padding-line-between-statements': [ @@ -13,4 +15,4 @@ export const stylisticHandPickedRules = { //require blank lines before all return statements, like the newline-before-return rule. { blankLine: 'always', prev: '*', next: 'return' }, ], -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/typescriptHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/typescriptHandPickedRules.ts index 81df3e67..1f324f90 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/typescriptHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/typescriptHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const typescriptHandPickedRules = { '@typescript-eslint/ban-ts-comment': 0, '@typescript-eslint/no-unsafe-assignment': 0, @@ -54,4 +56,4 @@ export const typescriptHandPickedRules = { ignoreFunctionTypeParameterNameValueShadow: true, }, ], -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/unicornHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/unicornHandPickedRules.ts index bcc6c154..ff99e468 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/unicornHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/unicornHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const unicornHandPickedRules = { 'unicorn/better-regex': 2, 'unicorn/explicit-length-check': 2, @@ -41,4 +43,4 @@ export const unicornHandPickedRules = { 'unicorn/prefer-string-slice': 2, 'unicorn/no-await-in-promise-methods': 2, 'unicorn/no-single-promise-in-promise-methods': 2, -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/handpickedRules/vitestHandPickedRules.ts b/packages/eslint-config-sheriff/src/handpickedRules/vitestHandPickedRules.ts index 068eda25..286ae120 100644 --- a/packages/eslint-config-sheriff/src/handpickedRules/vitestHandPickedRules.ts +++ b/packages/eslint-config-sheriff/src/handpickedRules/vitestHandPickedRules.ts @@ -1,3 +1,5 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + export const vitestHandPickedRules = { 'vitest/consistent-test-it': [2, { fn: 'test', withinDescribe: 'test' }], 'vitest/expect-expect': 2, @@ -34,4 +36,4 @@ export const vitestHandPickedRules = { 'vitest/require-top-level-describe': 2, 'vitest/valid-describe-callback': 2, 'vitest/valid-expect': 2, -}; +} as const satisfies TSESLint.FlatConfig.Rules; diff --git a/packages/eslint-config-sheriff/src/lodashConfig.ts b/packages/eslint-config-sheriff/src/lodashConfig.ts index 41697bce..f5e60607 100644 --- a/packages/eslint-config-sheriff/src/lodashConfig.ts +++ b/packages/eslint-config-sheriff/src/lodashConfig.ts @@ -1,5 +1,6 @@ import lodashPlugin from 'eslint-plugin-lodash-f'; import { supportedFileTypes } from '@sherifforg/constants'; +import type { TSESLint } from '@typescript-eslint/utils'; import { lodashHandPickedRules } from './handpickedRules/lodashHandPickedRules'; export const lodashConfig = { @@ -11,4 +12,4 @@ export const lodashConfig = { ...lodashPlugin.configs.recommended.rules, ...lodashHandPickedRules, }, -}; +} as const satisfies TSESLint.FlatConfig.Config; diff --git a/packages/eslint-config-sheriff/src/nextjsConfig.ts b/packages/eslint-config-sheriff/src/nextjsConfig.ts index 4e19669f..e7fe1dc4 100644 --- a/packages/eslint-config-sheriff/src/nextjsConfig.ts +++ b/packages/eslint-config-sheriff/src/nextjsConfig.ts @@ -1,5 +1,6 @@ import nextjs from '@next/eslint-plugin-next'; import { supportedFileTypes } from '@sherifforg/constants'; +import type { TSESLint } from '@typescript-eslint/utils'; export const nextjsConfig = { files: [supportedFileTypes], @@ -10,4 +11,4 @@ export const nextjsConfig = { ...nextjs.configs.recommended.rules, ...nextjs.configs['core-web-vitals'].rules, }, -}; +} as const satisfies TSESLint.FlatConfig.Config; diff --git a/packages/eslint-config-sheriff/src/playwrightConfig.ts b/packages/eslint-config-sheriff/src/playwrightConfig.ts index 285c63c3..d13ce688 100644 --- a/packages/eslint-config-sheriff/src/playwrightConfig.ts +++ b/packages/eslint-config-sheriff/src/playwrightConfig.ts @@ -1,5 +1,6 @@ import playwright from 'eslint-plugin-playwright'; import { allJsExtensions } from '@sherifforg/constants'; +import type { TSESLint } from '@typescript-eslint/utils'; import { playwrightHandPickedRules } from './handpickedRules/playwrightHandPickedRules'; export const playwrightConfig = { @@ -11,4 +12,4 @@ export const playwrightConfig = { ...playwright.configs['playwright-test'].rules, ...playwrightHandPickedRules, }, -}; +} as const satisfies TSESLint.FlatConfig.Config; diff --git a/packages/eslint-config-sheriff/src/prettierOverrides.ts b/packages/eslint-config-sheriff/src/prettierOverrides.ts index ade411f9..c59a724c 100644 --- a/packages/eslint-config-sheriff/src/prettierOverrides.ts +++ b/packages/eslint-config-sheriff/src/prettierOverrides.ts @@ -1,8 +1,9 @@ import { supportedFileTypes } from '@sherifforg/constants'; +import type { TSESLint } from '@typescript-eslint/utils'; export const prettierOverrides = { files: [supportedFileTypes], rules: { curly: [2, 'all'], }, -}; +} as const satisfies TSESLint.FlatConfig.Config; diff --git a/packages/eslint-config-sheriff/src/utils/getFilteredBaseNoRestrictedSyntax.ts b/packages/eslint-config-sheriff/src/utils/getFilteredBaseNoRestrictedSyntax.ts index 68502f71..0ba27631 100644 --- a/packages/eslint-config-sheriff/src/utils/getFilteredBaseNoRestrictedSyntax.ts +++ b/packages/eslint-config-sheriff/src/utils/getFilteredBaseNoRestrictedSyntax.ts @@ -1,9 +1,9 @@ -import { NoRestrictedSyntaxSlice } from '@sherifforg/types'; +import type { NoRestrictedSyntaxSlice } from '@sherifforg/types'; export const getFilteredBaseNoRestrictedSyntax = ( baseNoRestrictedSyntaxRules: NoRestrictedSyntaxSlice[], userProvidedNoRestrictedSyntaxSelectors?: string[], -) => { +): NoRestrictedSyntaxSlice[] => { if ( !userProvidedNoRestrictedSyntaxSelectors || userProvidedNoRestrictedSyntaxSelectors.length === 0 @@ -11,9 +11,9 @@ export const getFilteredBaseNoRestrictedSyntax = ( return baseNoRestrictedSyntaxRules; } - const filteredList = baseNoRestrictedSyntaxRules.filter((rule) => { - return !userProvidedNoRestrictedSyntaxSelectors.includes(rule.selector); - }); + const filteredList = baseNoRestrictedSyntaxRules.filter( + (rule) => !userProvidedNoRestrictedSyntaxSelectors.includes(rule.selector), + ); return filteredList; }; diff --git a/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescript.ts b/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescript.ts index 45fabebd..f96183fd 100644 --- a/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescript.ts +++ b/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescript.ts @@ -1,8 +1,9 @@ import tseslint from 'typescript-eslint'; +import type { TSESLint } from '@typescript-eslint/utils'; export const getLanguageOptionsTypescript = ( userChosenTSConfig?: string | string[], -) => { +): TSESLint.FlatConfig.LanguageOptions => { return { parser: tseslint.parser, parserOptions: { diff --git a/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescriptReact.ts b/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescriptReact.ts index e4ffbe1c..7ea76d79 100644 --- a/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescriptReact.ts +++ b/packages/eslint-config-sheriff/src/utils/getLanguageOptionsTypescriptReact.ts @@ -1,8 +1,9 @@ import tseslint from 'typescript-eslint'; +import type { TSESLint } from '@typescript-eslint/utils'; export const getLanguageOptionsTypescriptReact = ( userChosenTSConfig?: string | string[], -) => { +): TSESLint.FlatConfig.LanguageOptions => { return { parser: tseslint.parser, parserOptions: { diff --git a/packages/eslint-config-sheriff/src/utils/getTsNamingConventionRule.ts b/packages/eslint-config-sheriff/src/utils/getTsNamingConventionRule.ts index 084e8b13..42e1b87f 100644 --- a/packages/eslint-config-sheriff/src/utils/getTsNamingConventionRule.ts +++ b/packages/eslint-config-sheriff/src/utils/getTsNamingConventionRule.ts @@ -1,10 +1,12 @@ +import type { TSESLint } from '@typescript-eslint/utils'; + interface GetTsNamingConventionRuleOptions { isTsx: boolean; } export const getTsNamingConventionRule = ({ isTsx, -}: GetTsNamingConventionRuleOptions) => { +}: GetTsNamingConventionRuleOptions): TSESLint.FlatConfig.Rules => { return { '@typescript-eslint/naming-convention': [ 2,