Skip to content

Instantly share code, notes, and snippets.

@FrankFang
Last active July 2, 2024 08:57
Show Gist options
  • Save FrankFang/b6ec4ab273d702ce0594e88b62e0ecd6 to your computer and use it in GitHub Desktop.
Save FrankFang/b6ec4ab273d702ce0594e88b62e0ecd6 to your computer and use it in GitHub Desktop.
eslint flat config
// @ts-check
import js from '@eslint/js'
import ts from 'typescript-eslint'
import globals from 'globals'
import parserTs from '@typescript-eslint/parser'
import stylistic from '@stylistic/eslint-plugin'
import stylisticTs from '@stylistic/eslint-plugin-ts'
import stylisticJsx from '@stylistic/eslint-plugin-jsx'
import stylisticJs from '@stylistic/eslint-plugin-js'
export default ts.config(
{
languageOptions: {
globals: {
...globals.browser
}
}
},
js.configs.recommended,
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
languageOptions: {
parserOptions: {
project: './tsconfig.app.json',
}
},
extends: ts.configs.recommendedTypeChecked,
rules: {
'@typescript-eslint/no-unused-vars': 'warn'
}
},
{
files: ['**/*.js', 'src/**/*.jsx', 'src/**/*.ts', 'src/**/*.tsx'],
plugins: {
'@stylistic': stylistic,
'@stylistic/js': stylisticJs,
},
languageOptions: {
parser: parserTs,
},
rules: {
'@stylistic/indent': ['error', 2],
'@stylistic/semi': ['error', 'never'],
}
},
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
plugins: {
'@stylistic/ts': stylisticTs,
},
languageOptions: {
parser: parserTs,
},
rules: {
// '@stylistic/ts/indent': ['error', 2],
'@stylistic/ts/type-annotation-spacing': 'error',
}
},
{
files: ['src/**/*.jsx', 'src/**/*.tsx'],
plugins: {
'@stylistic/js': stylisticJs,
'@stylistic/ts': stylisticTs,
'@stylistic/jsx': stylisticJsx
},
languageOptions: {
parser: parserTs,
},
rules: {
'@stylistic/jsx/jsx-indent': ['error',2, {indentLogicalExpressions: true}],
'@stylistic/jsx/jsx-closing-tag-location':'error',
'@stylistic/jsx/jsx-self-closing-comp': 'error',
"@stylistic/jsx/jsx-sort-props": ['error', {
"callbacksLast": true,
"shorthandFirst": true,
"shorthandLast": false,
"multiline": "last",
"ignoreCase": true,
"noSortAlphabetically": true,
"reservedFirst": true
}]
}
}
)
{
"type": "module",
"devDependencies": {
"globals": "15.6.0",
"@eslint/js": "9.5.0",
"@stylistic/eslint-plugin": "2.2.2",
"@stylistic/eslint-plugin-jsx": "2.3.0",
"@stylistic/eslint-plugin-migrate": "2.3.0",
"@stylistic/eslint-plugin-ts": "2.3.0",
"@types/eslint__js": "8.42.3",
"@types/node": "20.14.8",
"eslint": "9.5.0",
"typescript": "5.5.2",
"typescript-eslint": "7.14.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment