forked from WordPress/ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
135 lines (123 loc) · 3.15 KB
/
eslint.config.mjs
File metadata and controls
135 lines (123 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
* ESLint flat config for the AI plugin.
*
* @see https://eslint.org/docs/latest/use/configure/configuration-files
*/
// @ts-ignore TS7016
import wordpress from '@wordpress/eslint-plugin';
export default [
// Global ignores — these directories and config files are skipped entirely.
{
ignores: [
'**/build/**',
'**/build-scripts/**',
'**/node_modules/**',
'**/vendor/**',
'**/tests/_output/**',
// Config files (ESLint does not auto-ignore flat config files).
'eslint.config.mjs',
'webpack.config.js',
],
},
// Base config.
...wordpress.configs.recommended,
// Project-specific customizations applied on top of the WP recommended set.
{
name: 'ai/custom-rules',
rules: {
// --- React best practices ---
'react/jsx-boolean-value': 'error',
'react/jsx-curly-brace-presence': [
'error',
{ props: 'never', children: 'never' },
],
// --- WordPress-specific rules (not in recommended) ---
'@wordpress/dependency-group': 'error',
'@wordpress/data-no-store-string-literals': 'error',
'@wordpress/wp-global-usage': 'error',
'@wordpress/react-no-unsafe-timeout': 'error',
// Override WP defaults.
'@wordpress/i18n-text-domain': [
'error',
{
allowedTextDomain: 'ai',
},
],
// --- Import rules (override WP defaults: warn → error) ---
'import/default': 'error',
'import/named': 'error',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: [
'**/*.@(spec|test).@(j|t)s?(x)',
'**/@(webpack|jest).config.@(j|t)s',
'**/scripts/**',
'**/tests/**',
'.prettierrc.js',
],
},
],
// --- Restricted imports ---
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'lodash',
message: 'Please use native functionality instead.',
},
{
name: 'classnames',
message:
"Please use `clsx` instead. It's a lighter and faster drop-in replacement for `classnames`.",
},
{
name: 'redux',
importNames: [ 'combineReducers' ],
message:
'Please use `combineReducers` from `@wordpress/data` instead.',
},
],
},
],
// --- Restricted syntax ---
'no-restricted-syntax': [
'error',
{
selector:
'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]',
message:
'Path access on WordPress dependencies is not allowed.',
},
{
selector:
'JSXAttribute[name.name="id"][value.type="Literal"]',
message:
'Do not use string literals for IDs; use withInstanceId instead.',
},
{
selector:
'CallExpression[callee.object.name="Math"][callee.property.name="random"]',
message:
"Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If you're not generating unique IDs: ignore this message.)",
},
],
},
},
// TypeScript-specific overrides.
{
name: 'ai/typescript-overrides',
files: [ '**/*.ts?(x)' ],
rules: {
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
disallowTypeAnnotations: false,
},
],
'jsdoc/require-param': 'off',
},
},
];