Skip to content

Commit

Permalink
Rely on @typescript-eslint Plugin['configs'] types
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky committed Nov 16, 2023
1 parent 81175a4 commit bb2a860
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 249 deletions.
43 changes: 26 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,14 +496,18 @@ const config = [
},
plugins: {
'@next/next': next,
'@typescript-eslint': eslintTypescript,
'@typescript-eslint': {
rules: eslintTypescript.rules,
},
'jsx-a11y': jsxA11y,
'jsx-expressions': jsxExpressions,
'react-hooks': reactHooks,
import: eslintImport,
react,
security,
sonarjs,
sonarjs: {
rules: sonarjs.rules,
},
unicorn,
upleveled,
},
Expand All @@ -521,7 +525,12 @@ const config = [
},
rules: {
...eslintConfigReactAppRules,
...jsxA11y.configs.recommended.rules,
// eslint-disable-next-line rest-spread-spacing -- Allow JSDoc casting
.../** @type {Exclude<Exclude<import('@typescript-eslint/utils/ts-eslint').FlatConfig.Plugin['configs'], undefined>[string], undefined>} */ (
/** @type {Exclude<import('@typescript-eslint/utils/ts-eslint').FlatConfig.Plugin['configs'], undefined>} */ (
jsxA11y.configs
).recommended
).rules,

// Error about importing next/document in a page other than pages/_document.js
// https://github.com/vercel/next.js/blob/canary/errors/no-document-import-in-page.md
Expand Down Expand Up @@ -930,21 +939,21 @@ The following environment variables are not set: ${missingEnvVars.join(', ')}
`,
);
}
const firstConfig = config[0];

if (!firstConfig || !firstConfig.plugins || !firstConfig.rules) {
throw new Error(
`SafeQL configuration failed
The UpLeveled ESLint config object does not contain properties plugins and rules`,
);
}

// @ts-expect-error 2307 Cannot find module '@ts-safeql/eslint-plugin' because it is not a dependency of the ESLint config
// eslint-disable-next-line import/no-unresolved
firstConfig.plugins['@ts-safeql'] = await import('@ts-safeql/eslint-plugin');

/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Plugins} */ (
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Config} */ (
config[0]
).plugins
// @ts-expect-error 2307 Cannot find module '@ts-safeql/eslint-plugin' because it is not a dependency of the ESLint config
// eslint-disable-next-line import/no-unresolved
)['@ts-safeql'] = await import('@ts-safeql/eslint-plugin');

/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Rules} */
(
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Config} */ (
config[0]
).rules
)['@ts-safeql/check-sql'] = [
firstConfig.rules['@ts-safeql/check-sql'] = [
'error',
{
connections: [
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"dependencies": {
"@babel/eslint-parser": "7.23.3",
"@next/eslint-plugin-next": "14.0.2",
"@typescript-eslint/eslint-plugin": "6.11.0",
"@typescript-eslint/parser": "6.11.0",
"@typescript-eslint/eslint-plugin": "6.11.1-alpha.20",
"@typescript-eslint/parser": "6.11.1-alpha.20",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsx-a11y": "6.8.0",
Expand All @@ -54,7 +54,7 @@
"devDependencies": {
"@types/eslint": "8.44.7",
"@types/prettier": "2.7.3",
"@typescript-eslint/utils": "6.11.0",
"@typescript-eslint/utils": "6.11.1-alpha.20",
"eslint-config-upleveled": "7.0.1",
"prettier-plugin-embed": "0.2.5",
"prettier-plugin-sql": "0.16.0",
Expand Down

0 comments on commit bb2a860

Please sign in to comment.