-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(eslint-config): typescript-eslint 8 #1326
Changes from 8 commits
bc2df9a
9552fb8
d996c7b
d4cb7b8
e1c92ea
25ae817
13886a5
3f5ed29
8408867
420cbeb
db08a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ | |
'@typescript-eslint/no-unsafe-member-access': 'warn', | ||
'@typescript-eslint/no-floating-promises': 'warn', | ||
'@typescript-eslint/no-unsafe-call': 'warn', | ||
'@typescript-eslint/no-throw-literal': 'warn', | ||
'@typescript-eslint/only-throw-error': 'warn', | ||
'@typescript-eslint/no-confusing-void-expression': 'off', | ||
'@typescript-eslint/restrict-template-expressions': 'off', | ||
'@typescript-eslint/no-empty-function': 'warn', | ||
|
@@ -94,10 +94,10 @@ | |
rules: vitest.configs.recommended.rules, | ||
settings: { vitest: { typecheck: true } }, | ||
}, | ||
jestDom.configs['flat/recommended'] as unknown as ReturnType<typeof tseslint.config>[number], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beautiful..❤️ |
||
jestDom.configs['flat/recommended'], | ||
{ | ||
plugins: { | ||
import: importPlugin, | ||
}, | ||
rules: { | ||
'sort-imports': ['error', { ignoreDeclarationSort: true }], | ||
|
@@ -113,20 +113,20 @@ | |
], | ||
}, | ||
}, | ||
eslintPluginPrettierRecommended as unknown as ReturnType<typeof tseslint.config>[number] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy..❤️ |
||
eslintPluginPrettierRecommended | ||
) | ||
|
||
export const suspensiveReactTypeScriptConfig: ReturnType<typeof tseslint.config> = tseslint.config( | ||
...suspensiveTypeScriptConfig, | ||
{ | ||
files: ['**/*.{ts,tsx}'], | ||
...(pluginReact.configs.recommended as unknown as ReturnType<typeof tseslint.config>[number]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So cool...❤️ |
||
...pluginReact.configs.recommended, | ||
ignores: ['**/*.mdx/**/*.{ts,tsx}'], | ||
}, | ||
{ | ||
plugins: { | ||
'react-hooks': reactHooks.configs.recommended, | ||
Check warning on line 128 in configs/eslint-config/src/index.ts GitHub Actions / Check quality (ci:eslint)
|
||
'react-compiler': reactCompiler, | ||
}, | ||
languageOptions: { | ||
globals: { | ||
|
@@ -146,7 +146,7 @@ | |
|
||
export const suspensiveNextTypeScriptConfig: ReturnType<typeof tseslint.config> = [ | ||
...suspensiveReactTypeScriptConfig, | ||
{ plugins: { 'plugin:@next/next/recommended': next.configs.recommended } }, | ||
Check warning on line 149 in configs/eslint-config/src/index.ts GitHub Actions / Check quality (ci:eslint)
|
||
] | ||
|
||
export const suspensiveMDXConfig: Linter.Config[] = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ | |
"preserveWatchOutput": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"resolveJsonModule": true | ||
"resolveJsonModule": true, | ||
"allowJs": true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0:0 error Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser. The file was not found in any of the provided project(s): eslint.config.mjs By default, tsconfig does not include .js files. This behavior caused the error: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if the purpose of ESLint is to lint only TypeScript files. If that's the case, couldn't we remove the -"ci:eslint": "eslint \"**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}\"",
+"ci:eslint": "eslint \"**/*.{ts,tsx,cts,mts}\"", There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I respect your opinion, and I believe that excluding checks for .js files in ESLint settings might be a somewhat regrettable choice. ESLint provides various rules that help maintain code conventions, and these rules still hold significant meaning for files that do not use TypeScript. For example, rules like import/order and prettier can greatly enhance code readability and maintain consistency within the project. From this perspective, I think it is more desirable to apply ESLint checks to all files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If we remove the .js extension from tseslint.configs.strictTypeChecked, the error will disappear, but this means that ESLint will not be applied to JavaScript files at all, which I think is not an ideal solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to follow this problem as @kangju2000 way. I agree both opinion by you guys, but I see this error and I couldn't resolve it during quite long time! so I made this commit 8408867 |
||
}, | ||
"exclude": ["dist", "esm", "build", "node_modules"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,72 +15,78 @@ const loadableAtom = loadable(asyncAtom) | |
|
||
describe('<Atom/>', () => { | ||
it('type check', () => { | ||
;() => ( | ||
;(() => ( | ||
<Atom atom={countAtom}> | ||
{(result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const returnOfJotai = useAtom(countAtom) | ||
expectTypeOf(result).toEqualTypeOf<typeof returnOfJotai>() | ||
return <></> | ||
}} | ||
</Atom> | ||
) | ||
;() => ( | ||
))() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool |
||
;(() => ( | ||
<Atom atom={readOnlyCountAtom}> | ||
{(result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const returnOfJotai = useAtom(readOnlyCountAtom) | ||
expectTypeOf(result).toEqualTypeOf<typeof returnOfJotai>() | ||
return <></> | ||
}} | ||
</Atom> | ||
) | ||
;() => ( | ||
))() | ||
;(() => ( | ||
<Atom atom={writeOnlyCountAtom}> | ||
{(result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const returnOfJotai = useAtom(writeOnlyCountAtom) | ||
expectTypeOf(result).toEqualTypeOf<typeof returnOfJotai>() | ||
return <></> | ||
}} | ||
</Atom> | ||
) | ||
;() => ( | ||
))() | ||
;(() => ( | ||
<Atom atom={asyncAtom}> | ||
{(result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const returnOfJotai = useAtom(asyncAtom) | ||
expectTypeOf(result).toEqualTypeOf<typeof returnOfJotai>() | ||
return <></> | ||
}} | ||
</Atom> | ||
) | ||
;() => ( | ||
))() | ||
;(() => ( | ||
<Atom atom={asyncIncrementAtom}> | ||
{(result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const returnOfJotai = useAtom(asyncIncrementAtom) | ||
expectTypeOf(result).toEqualTypeOf<typeof returnOfJotai>() | ||
return <></> | ||
}} | ||
</Atom> | ||
) | ||
;() => ( | ||
))() | ||
;(() => ( | ||
<Atom atom={loadableAtom}> | ||
{(result) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const returnOfJotai = useAtom(loadableAtom) | ||
expectTypeOf(result).toEqualTypeOf<typeof returnOfJotai>() | ||
return <></> | ||
}} | ||
</Atom> | ||
) | ||
))() | ||
|
||
expectTypeOf(<Atom atom={countAtom}>{() => <></>}</Atom>).toEqualTypeOf<JSX.Element>() | ||
expectTypeOf(<Atom atom={countAtom}>{() => <></>}</Atom>).toEqualTypeOf<React.JSX.Element>() | ||
expectTypeOf(<Atom atom={countAtom}>{() => <></>}</Atom>).not.toEqualTypeOf<ReactNode>() | ||
expectTypeOf(<Atom atom={readOnlyCountAtom}>{() => <></>}</Atom>).toEqualTypeOf<JSX.Element>() | ||
expectTypeOf(<Atom atom={readOnlyCountAtom}>{() => <></>}</Atom>).toEqualTypeOf<React.JSX.Element>() | ||
expectTypeOf(<Atom atom={readOnlyCountAtom}>{() => <></>}</Atom>).not.toEqualTypeOf<ReactNode>() | ||
expectTypeOf(<Atom atom={writeOnlyCountAtom}>{() => <></>}</Atom>).toEqualTypeOf<JSX.Element>() | ||
expectTypeOf(<Atom atom={writeOnlyCountAtom}>{() => <></>}</Atom>).toEqualTypeOf<React.JSX.Element>() | ||
expectTypeOf(<Atom atom={writeOnlyCountAtom}>{() => <></>}</Atom>).not.toEqualTypeOf<ReactNode>() | ||
expectTypeOf(<Atom atom={asyncAtom}>{() => <></>}</Atom>).toEqualTypeOf<JSX.Element>() | ||
expectTypeOf(<Atom atom={asyncAtom}>{() => <></>}</Atom>).toEqualTypeOf<React.JSX.Element>() | ||
expectTypeOf(<Atom atom={asyncAtom}>{() => <></>}</Atom>).not.toEqualTypeOf<ReactNode>() | ||
expectTypeOf(<Atom atom={asyncIncrementAtom}>{() => <></>}</Atom>).toEqualTypeOf<JSX.Element>() | ||
expectTypeOf(<Atom atom={asyncIncrementAtom}>{() => <></>}</Atom>).toEqualTypeOf<React.JSX.Element>() | ||
expectTypeOf(<Atom atom={asyncIncrementAtom}>{() => <></>}</Atom>).not.toEqualTypeOf<ReactNode>() | ||
expectTypeOf(<Atom atom={loadableAtom}>{() => <></>}</Atom>).toEqualTypeOf<JSX.Element>() | ||
expectTypeOf(<Atom atom={loadableAtom}>{() => <></>}</Atom>).toEqualTypeOf<React.JSX.Element>() | ||
expectTypeOf(<Atom atom={loadableAtom}>{() => <></>}</Atom>).not.toEqualTypeOf<ReactNode>() | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @typescript-eslint plugin does not have a no-throw-literal rule. Instead, I replaced it with @typescript-eslint/only-throw-error, which enforces the same rule.