Skip to content

Commit

Permalink
Switch types to @typescript-eslint/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
karlhorky committed Nov 14, 2023
1 parent ee990aa commit a3830a4
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 40 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import upleveled from './index.js';

/** @type {import('eslint').Linter.FlatConfig[]} */
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
const config = [
...upleveled,
{
Expand Down
37 changes: 16 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import unicorn from 'eslint-plugin-unicorn';
import upleveled from 'eslint-plugin-upleveled';
import globals from 'globals';

/** @type {import('eslint').Linter.RuleEntry} */
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.RuleEntry} */
const noRestrictedSyntaxOptions = [
'warn',
// Currently it is not possible to use Markdown eg. links in ESLint warnings / error messages
Expand Down Expand Up @@ -215,7 +215,7 @@ Instead, move anything you want to import to a non-page file`,
* https://github.com/facebook/create-react-app/blob/main/packages/eslint-config-react-app/index.js
* https://github.com/facebook/create-react-app/blob/main/packages/eslint-config-react-app/base.js
*
* @type {import('eslint').Linter.FlatConfig['rules']}
* @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Rules}
*/
const eslintConfigReactAppRules = {
'array-callback-return': 'warn',
Expand Down Expand Up @@ -452,7 +452,7 @@ const eslintConfigReactAppRules = {
'react-hooks/rules-of-hooks': 'error',
};

/** @type {import('eslint').Linter.FlatConfig[]} */
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.ConfigArray} */
const config = [
{
// Lint common extensions by default with rules above
Expand All @@ -479,9 +479,7 @@ const config = [
'build/**/*',
],
languageOptions: {
parser: /** @type {import('eslint').Linter.ParserModule} */ (
typescriptParser
),
parser: typescriptParser,
parserOptions: {
project: './tsconfig.json',
// typescript-eslint specific options
Expand All @@ -498,9 +496,7 @@ const config = [
},
plugins: {
'@next/next': next,
'@typescript-eslint': /** @type {import('eslint').ESLint.Plugin} */ (
/** @type {unknown} */ (eslintTypescript)
),
'@typescript-eslint': eslintTypescript,
'jsx-a11y': jsxA11y,
'jsx-expressions': jsxExpressions,
'react-hooks': reactHooks,
Expand All @@ -525,12 +521,7 @@ const config = [
},
rules: {
...eslintConfigReactAppRules,
// eslint-disable-next-line rest-spread-spacing
.../** @type {Exclude<Exclude<import('eslint').ESLint.Plugin['configs'], undefined>['recommended'], undefined | import('eslint').Linter.FlatConfig[]>} */ (
/** @type {Exclude<import('eslint').ESLint.Plugin['configs'], undefined>} */ (
jsxA11y.configs
).recommended
).rules,
...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 @@ -940,16 +931,20 @@ The following environment variables are not set: ${missingEnvVars.join(', ')}
);
}

/** @type {Exclude<import('eslint').Linter.FlatConfig['plugins'], undefined>} */ (
/** @type {import('eslint').Linter.FlatConfig} */ (config[0]).plugins
/** @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 {Exclude<import('eslint').Linter.FlatConfig['rules'], undefined>} */
(/** @type {import('eslint').Linter.FlatConfig} */ (config[0]).rules)[
'@ts-safeql/check-sql'
] = [
/** @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'] = [
'error',
{
connections: [
Expand Down
4 changes: 2 additions & 2 deletions types/@next__eslint-plugin-next.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module '@next/eslint-plugin-next' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-import.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-import' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
8 changes: 6 additions & 2 deletions types/eslint-plugin-jsx-a11y.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
declare module 'eslint-plugin-jsx-a11y' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin & {
configs: {
recommended: FlatConfig.Config;
};
};
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-jsx-expressions.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-jsx-expressions' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-react-hooks.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-react-hooks' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-react.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-react' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-security.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-security' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-unicorn.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-unicorn' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}
4 changes: 2 additions & 2 deletions types/eslint-plugin-upleveled.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'eslint-plugin-upleveled' {
import type { ESLint } from 'eslint';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

let plugin: ESLint.Plugin;
let plugin: FlatConfig.Plugin;
export default plugin;
}

0 comments on commit a3830a4

Please sign in to comment.