dify/web/eslint.config.mjs

164 lines
4.5 KiB
JavaScript
Raw Normal View History

2024-10-22 09:49:56 +08:00
import {
2024-10-22 15:32:48 +08:00
GLOB_TESTS, combine, javascript, node,
stylistic, typescript, unicorn,
} from '@antfu/eslint-config'
2024-10-21 13:16:56 +08:00
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
2024-10-21 17:03:04 +08:00
import globals from 'globals'
2024-10-25 12:51:11 +08:00
import storybook from 'eslint-plugin-storybook'
import { fixupConfigRules } from '@eslint/compat'
2024-10-21 13:16:56 +08:00
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})
2024-10-21 16:21:12 +08:00
export default combine(
stylistic({
lessOpinionated: true,
// original @antfu/eslint-config does not support jsx
jsx: false,
2024-10-22 15:32:48 +08:00
semi: false,
quotes: 'single',
2024-10-21 16:21:12 +08:00
overrides: {
2024-10-22 09:49:56 +08:00
// original config
2024-10-22 15:32:48 +08:00
'style/indent': ['error', 2],
'style/quotes': ['error', 'single'],
2024-10-25 12:51:11 +08:00
'curly': ['error', 'multi-or-nest', 'consistent'],
2024-10-22 15:32:48 +08:00
'style/comma-spacing': ['error', { before: false, after: true }],
'style/quote-props': ['warn', 'consistent-as-needed'],
2024-10-21 13:16:56 +08:00
2024-10-21 16:21:12 +08:00
// these options does not exist in old version
2024-10-22 09:49:56 +08:00
// maybe useless
2024-10-22 15:32:48 +08:00
'style/indent-binary-ops': 'off',
'style/multiline-ternary': 'off',
'antfu/top-level-function': 'off',
'antfu/curly': 'off',
'antfu/consistent-chaining': 'off',
// copy from eslint-config-antfu 0.36.0
'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'style/dot-location': ['error', 'property'],
'style/object-curly-newline': ['error', { consistent: true, multiline: true }],
'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
'style/template-curly-spacing': ['error', 'never'],
'style/keyword-spacing': 'off',
2024-10-21 13:16:56 +08:00
2024-10-22 09:49:56 +08:00
// not exist in old version, and big change
2024-10-22 15:32:48 +08:00
'style/member-delimiter-style': 'off',
},
2024-10-21 16:21:12 +08:00
}),
2024-10-21 17:03:04 +08:00
javascript({
overrides: {
2024-10-22 09:49:56 +08:00
// handled by unused-imports/no-unused-vars
2024-10-21 17:03:04 +08:00
'no-unused-vars': 'off',
2024-10-25 12:51:11 +08:00
},
}),
typescript({
overrides: {
2024-10-28 11:00:44 +08:00
// original config
'ts/consistent-type-definitions': ['warn', 'type'],
2024-10-25 12:51:11 +08:00
// useful, but big change
'ts/no-empty-object-type': 'off',
2024-10-22 15:32:48 +08:00
},
2024-10-21 17:03:04 +08:00
}),
2024-10-22 09:49:56 +08:00
unicorn(),
node(),
2024-10-25 12:51:11 +08:00
// use nextjs config will break @eslint/config-inspector
// use `ESLINT_CONFIG_INSPECTOR=true pnpx @eslint/config-inspector` to check the config
2024-10-22 11:36:42 +08:00
...process.env.ESLINT_CONFIG_INSPECTOR
? []
// TODO: remove this when upgrade to nextjs 15
2024-10-25 12:51:11 +08:00
: fixupConfigRules(compat.extends('next')),
2024-10-21 16:21:12 +08:00
{
ignores: [
'**/node_modules/*',
'**/node_modules/',
'**/dist/',
'**/build/',
'**/out/',
'**/.next/',
'**/public/*',
'**/*.json',
2024-10-22 15:32:48 +08:00
],
2024-10-21 13:16:56 +08:00
},
2024-10-21 16:21:12 +08:00
{
// orignal config
rules: {
2024-10-22 09:49:56 +08:00
// orignal ts/no-var-requires
2024-10-21 16:21:12 +08:00
'ts/no-require-imports': 'off',
2024-10-22 15:32:48 +08:00
'no-console': 'off',
'react-hooks/exhaustive-deps': 'warn',
'react/display-name': 'off',
'array-callback-return': ['error', {
allowImplicit: false,
checkForEach: false,
}],
2024-10-22 09:49:56 +08:00
2024-10-22 15:32:48 +08:00
// copy from eslint-config-antfu 0.36.0
'camelcase': 'off',
'default-case-last': 'error',
2024-10-22 09:49:56 +08:00
// antfu use eslint-plugin-perfectionist to replace this
2024-10-22 15:32:48 +08:00
// will cause big change, so keep the original sort-imports
'sort-imports': [
2024-10-22 09:49:56 +08:00
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: false,
},
],
// antfu migrate to eslint-plugin-unused-imports
2024-10-22 15:32:48 +08:00
'unused-imports/no-unused-vars': 'warn',
'unused-imports/no-unused-imports': 'warn',
2024-10-22 11:36:42 +08:00
},
2024-10-22 09:49:56 +08:00
2024-10-22 11:36:42 +08:00
languageOptions: {
globals: {
...globals.browser,
...globals.es2025,
...globals.node,
2024-10-22 15:32:48 +08:00
React: 'readable',
JSX: 'readable',
},
},
2024-10-21 16:21:12 +08:00
},
2024-10-25 12:51:11 +08:00
storybook.configs['flat/recommended'],
2024-10-21 16:21:12 +08:00
// need futher research
{
rules: {
// not exist in old version
2024-10-22 15:32:48 +08:00
'antfu/consistent-list-newline': 'off',
2024-10-22 09:49:56 +08:00
'node/prefer-global/process': 'off',
'node/prefer-global/buffer': 'off',
'node/no-callback-literal': 'off',
2024-10-21 17:03:04 +08:00
// useful, but big change
2024-10-22 15:32:48 +08:00
'unicorn/prefer-number-properties': 'warn',
'unicorn/no-new-array': 'warn',
},
2024-10-21 17:03:04 +08:00
},
// suppress error for `no-undef` rule
{
files: GLOB_TESTS,
languageOptions: {
globals: {
...globals.browser,
...globals.es2021,
...globals.node,
2024-10-22 11:36:42 +08:00
...globals.jest,
2024-10-21 17:03:04 +08:00
},
},
},
2024-10-21 16:21:12 +08:00
)