2025-12-23 08:58:55 +00:00
|
|
|
// @ts-check
|
2026-03-20 09:23:17 +00:00
|
|
|
|
|
|
|
|
import antfu, { GLOB_MARKDOWN, GLOB_TESTS, GLOB_TS, GLOB_TSX, isInEditorEnv, isInGitHooksOrLintStaged } from '@antfu/eslint-config'
|
2026-01-04 03:20:06 +00:00
|
|
|
import pluginQuery from '@tanstack/eslint-plugin-query'
|
2026-03-20 09:23:17 +00:00
|
|
|
import md from 'eslint-markdown'
|
2026-02-05 09:36:08 +00:00
|
|
|
import tailwindcss from 'eslint-plugin-better-tailwindcss'
|
2026-02-09 10:37:41 +00:00
|
|
|
import hyoban from 'eslint-plugin-hyoban'
|
2026-03-20 09:23:17 +00:00
|
|
|
import markdownPreferences from 'eslint-plugin-markdown-preferences'
|
2025-12-23 08:58:55 +00:00
|
|
|
import sonar from 'eslint-plugin-sonarjs'
|
2025-02-17 09:05:13 +00:00
|
|
|
import storybook from 'eslint-plugin-storybook'
|
2026-03-19 05:04:04 +00:00
|
|
|
import {
|
|
|
|
|
HYOBAN_PREFER_TAILWIND_ICONS_OPTIONS,
|
|
|
|
|
NEXT_PLATFORM_RESTRICTED_IMPORT_PATHS,
|
|
|
|
|
NEXT_PLATFORM_RESTRICTED_IMPORT_PATTERNS,
|
|
|
|
|
OVERLAY_MIGRATION_LEGACY_BASE_FILES,
|
|
|
|
|
OVERLAY_RESTRICTED_IMPORT_PATTERNS,
|
|
|
|
|
} from './eslint.constants.mjs'
|
2026-03-06 06:54:24 +00:00
|
|
|
import dify from './plugins/eslint/index.js'
|
2025-02-17 09:05:13 +00:00
|
|
|
|
2026-02-10 05:55:42 +00:00
|
|
|
// Enable Tailwind CSS IntelliSense mode for ESLint runs
|
|
|
|
|
// See: tailwind-css-plugin.ts
|
|
|
|
|
process.env.TAILWIND_MODE ??= 'ESLINT'
|
|
|
|
|
|
2026-03-11 04:42:18 +00:00
|
|
|
const disableRuleAutoFix = !(isInEditorEnv() || isInGitHooksOrLintStaged())
|
|
|
|
|
|
2025-12-23 08:58:55 +00:00
|
|
|
export default antfu(
|
|
|
|
|
{
|
|
|
|
|
react: {
|
2026-01-19 04:45:02 +00:00
|
|
|
// This react compiler rules are pretty slow
|
|
|
|
|
// We can wait for https://github.com/Rel1cx/eslint-react/issues/1237
|
|
|
|
|
reactCompiler: false,
|
2025-12-23 08:58:55 +00:00
|
|
|
overrides: {
|
|
|
|
|
'react/no-context-provider': 'off',
|
|
|
|
|
'react/no-forward-ref': 'off',
|
|
|
|
|
'react/no-use-context': 'off',
|
2025-12-31 07:31:11 +00:00
|
|
|
|
2026-01-16 03:58:28 +00:00
|
|
|
// prefer react-hooks-extra/no-direct-set-state-in-use-effect
|
|
|
|
|
'react-hooks/set-state-in-effect': 'off',
|
2026-01-17 11:51:56 +00:00
|
|
|
'react-hooks-extra/no-direct-set-state-in-use-effect': 'error',
|
2025-12-23 08:58:55 +00:00
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
},
|
2025-12-23 08:58:55 +00:00
|
|
|
nextjs: true,
|
2026-02-05 09:36:08 +00:00
|
|
|
ignores: ['public', 'types/doc-paths.ts', 'eslint-suppressions.json'],
|
2025-12-23 08:58:55 +00:00
|
|
|
typescript: {
|
|
|
|
|
overrides: {
|
|
|
|
|
'ts/consistent-type-definitions': ['error', 'type'],
|
2026-01-17 11:51:56 +00:00
|
|
|
'ts/no-explicit-any': 'error',
|
2025-12-23 08:58:55 +00:00
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
},
|
2025-12-23 08:58:55 +00:00
|
|
|
test: {
|
|
|
|
|
overrides: {
|
|
|
|
|
'test/prefer-lowercase-title': 'off',
|
|
|
|
|
},
|
2025-08-27 08:05:57 +00:00
|
|
|
},
|
2025-12-23 08:58:55 +00:00
|
|
|
stylistic: {
|
|
|
|
|
overrides: {
|
|
|
|
|
'antfu/top-level-function': 'off',
|
|
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
},
|
2026-03-11 04:42:18 +00:00
|
|
|
e18e: false,
|
2025-02-17 09:05:13 +00:00
|
|
|
},
|
2026-03-20 09:23:17 +00:00
|
|
|
markdownPreferences.configs.standard,
|
|
|
|
|
{
|
|
|
|
|
files: [GLOB_MARKDOWN],
|
|
|
|
|
plugins: { md },
|
|
|
|
|
rules: {
|
|
|
|
|
'md/no-url-trailing-slash': 'error',
|
|
|
|
|
'markdown-preferences/prefer-link-reference-definitions': [
|
|
|
|
|
'error',
|
|
|
|
|
{
|
|
|
|
|
minLinks: 1,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'markdown-preferences/ordered-list-marker-sequence': [
|
|
|
|
|
'error',
|
|
|
|
|
{ increment: 'never' },
|
|
|
|
|
],
|
|
|
|
|
'markdown-preferences/definitions-last': 'error',
|
|
|
|
|
'markdown-preferences/sort-definitions': 'error',
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-01-17 11:51:56 +00:00
|
|
|
{
|
|
|
|
|
rules: {
|
|
|
|
|
'node/prefer-global/process': 'off',
|
2026-03-16 08:48:22 +00:00
|
|
|
'next/no-img-element': 'off',
|
2026-01-17 11:51:56 +00:00
|
|
|
},
|
|
|
|
|
},
|
2026-01-16 03:58:28 +00:00
|
|
|
{
|
|
|
|
|
files: ['**/*.ts', '**/*.tsx'],
|
|
|
|
|
settings: {
|
|
|
|
|
'react-x': {
|
|
|
|
|
additionalStateHooks: '/^use\\w*State(?:s)?|useAtom$/u',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
storybook.configs['flat/recommended'],
|
2026-01-04 03:20:06 +00:00
|
|
|
...pluginQuery.configs['flat/recommended'],
|
2025-04-14 07:28:20 +00:00
|
|
|
// sonar
|
|
|
|
|
{
|
|
|
|
|
rules: {
|
2026-01-19 04:45:02 +00:00
|
|
|
// Manually pick rules that are actually useful and not slow.
|
|
|
|
|
// Or we can just drop the plugin entirely.
|
2025-04-14 07:28:20 +00:00
|
|
|
},
|
|
|
|
|
plugins: {
|
|
|
|
|
sonarjs: sonar,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
{
|
2026-02-09 10:20:09 +00:00
|
|
|
files: [GLOB_TS, GLOB_TSX],
|
|
|
|
|
ignores: GLOB_TESTS,
|
2026-02-05 09:36:08 +00:00
|
|
|
plugins: {
|
|
|
|
|
tailwindcss,
|
2025-03-21 09:41:03 +00:00
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
rules: {
|
2026-02-05 09:36:08 +00:00
|
|
|
'tailwindcss/enforce-consistent-class-order': 'error',
|
|
|
|
|
'tailwindcss/no-duplicate-classes': 'error',
|
|
|
|
|
'tailwindcss/no-unnecessary-whitespace': 'error',
|
|
|
|
|
'tailwindcss/no-unknown-classes': 'warn',
|
2025-02-17 09:05:13 +00:00
|
|
|
},
|
|
|
|
|
},
|
2026-01-30 06:10:09 +00:00
|
|
|
{
|
2026-02-09 10:37:41 +00:00
|
|
|
name: 'dify/custom/setup',
|
|
|
|
|
plugins: {
|
|
|
|
|
dify,
|
|
|
|
|
hyoban,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
files: ['**/*.tsx'],
|
|
|
|
|
rules: {
|
2026-03-19 05:04:04 +00:00
|
|
|
'hyoban/prefer-tailwind-icons': ['warn', HYOBAN_PREFER_TAILWIND_ICONS_OPTIONS],
|
2026-02-09 10:37:41 +00:00
|
|
|
},
|
2026-01-30 06:10:09 +00:00
|
|
|
},
|
2026-01-05 07:49:31 +00:00
|
|
|
{
|
2026-01-30 04:26:07 +00:00
|
|
|
files: ['i18n/**/*.json'],
|
2026-01-05 07:49:31 +00:00
|
|
|
rules: {
|
|
|
|
|
'sonarjs/max-lines': 'off',
|
|
|
|
|
'max-lines': 'off',
|
|
|
|
|
'jsonc/sort-keys': 'error',
|
|
|
|
|
|
2026-02-09 10:37:41 +00:00
|
|
|
'hyoban/i18n-flat-key': 'error',
|
2026-01-30 06:10:09 +00:00
|
|
|
'dify/no-extra-keys': 'error',
|
|
|
|
|
'dify/consistent-placeholders': 'error',
|
2026-01-05 07:49:31 +00:00
|
|
|
},
|
|
|
|
|
},
|
2026-01-20 13:14:50 +00:00
|
|
|
{
|
|
|
|
|
files: ['**/package.json'],
|
|
|
|
|
rules: {
|
2026-02-09 10:37:41 +00:00
|
|
|
'hyoban/no-dependency-version-prefix': 'error',
|
2026-01-20 13:14:50 +00:00
|
|
|
},
|
|
|
|
|
},
|
2026-03-03 08:56:13 +00:00
|
|
|
{
|
|
|
|
|
name: 'dify/base-ui-primitives',
|
2026-03-11 06:26:04 +00:00
|
|
|
files: ['app/components/base/ui/**/*.tsx', 'app/components/base/avatar/**/*.tsx'],
|
2026-03-03 08:56:13 +00:00
|
|
|
rules: {
|
|
|
|
|
'react-refresh/only-export-components': 'off',
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-03-16 08:48:22 +00:00
|
|
|
{
|
2026-03-18 02:37:29 +00:00
|
|
|
name: 'dify/no-direct-next-imports',
|
2026-03-16 08:48:22 +00:00
|
|
|
files: [GLOB_TS, GLOB_TSX],
|
2026-03-18 02:37:29 +00:00
|
|
|
ignores: ['next/**'],
|
2026-03-16 08:48:22 +00:00
|
|
|
rules: {
|
|
|
|
|
'no-restricted-imports': ['error', {
|
2026-03-18 02:37:29 +00:00
|
|
|
paths: NEXT_PLATFORM_RESTRICTED_IMPORT_PATHS,
|
2026-03-16 08:48:22 +00:00
|
|
|
patterns: NEXT_PLATFORM_RESTRICTED_IMPORT_PATTERNS,
|
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-03-03 08:56:13 +00:00
|
|
|
{
|
|
|
|
|
name: 'dify/overlay-migration',
|
|
|
|
|
files: [GLOB_TS, GLOB_TSX],
|
|
|
|
|
ignores: [
|
2026-03-18 02:37:29 +00:00
|
|
|
'next/**',
|
2026-03-03 08:56:13 +00:00
|
|
|
...GLOB_TESTS,
|
|
|
|
|
...OVERLAY_MIGRATION_LEGACY_BASE_FILES,
|
|
|
|
|
],
|
|
|
|
|
rules: {
|
|
|
|
|
'no-restricted-imports': ['error', {
|
2026-03-18 02:37:29 +00:00
|
|
|
paths: NEXT_PLATFORM_RESTRICTED_IMPORT_PATHS,
|
2026-03-16 08:48:22 +00:00
|
|
|
patterns: [
|
|
|
|
|
...NEXT_PLATFORM_RESTRICTED_IMPORT_PATTERNS,
|
|
|
|
|
...OVERLAY_RESTRICTED_IMPORT_PATTERNS,
|
|
|
|
|
],
|
2026-03-03 08:56:13 +00:00
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-02-17 09:05:13 +00:00
|
|
|
)
|
2026-03-11 04:42:18 +00:00
|
|
|
.disableRulesFix(disableRuleAutoFix
|
|
|
|
|
? [
|
|
|
|
|
'tailwindcss/enforce-consistent-class-order',
|
|
|
|
|
'tailwindcss/no-duplicate-classes',
|
|
|
|
|
'tailwindcss/no-unnecessary-whitespace',
|
|
|
|
|
]
|
|
|
|
|
: [])
|