-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Expand file tree
/
Copy patheslint.shared.mjs
More file actions
174 lines (158 loc) · 6.64 KB
/
Copy patheslint.shared.mjs
File metadata and controls
174 lines (158 loc) · 6.64 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Shared building blocks for workspace ESLint flat configs. Each export is a
// rule object, a helper, or a plugin definition. Workspaces import only the
// pieces they need; this file imports nothing from the eslint plugin ecosystem
// so consumers don't take transitive peer deps via it.
import path from 'node:path';
// === Rule sets ===
// Correctness baseline shared by every workspace flat config. Each rule is
// individually overridable in the consumer's `rules` block.
export const correctnessRules = {
curly: 'error',
camelcase: ['error', {properties: 'never'}],
'dot-notation': 'error',
eqeqeq: ['error', 'always'],
'no-plusplus': ['error', {allowForLoopAfterthoughts: true}],
'no-eval': 'error',
'no-useless-call': 'error',
'no-console': 'error',
'no-shadow': 'error',
'array-callback-return': 'error',
'no-constructor-return': 'error',
'no-promise-executor-return': 'error',
'ghost/filenames/match-regex': ['error', '^[a-z0-9.-]+$', false]
};
// TS-aware unused-vars: disables the base rule, enables the TS variant with
// args ignore pattern. Most TS workspaces want this.
export const tsUnusedVarsRule = {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', {
args: 'after-used',
argsIgnorePattern: '^_',
caughtErrors: 'none'
}]
};
// Vanilla unused-vars with caughtErrors:'none' — ESLint 9 flipped the default
// to 'all'. For non-TS workspaces where the previous behavior is wanted.
export const jsUnusedVarsRule = {
'no-unused-vars': ['error', {caughtErrors: 'none'}]
};
// Import-sort autofix from eslint-plugin-ghost.
export const sortImportsRule = {
'ghost/sort-imports-es6-autofix/sort-imports-es6': ['error', {
memberSyntaxSortOrder: ['none', 'all', 'single', 'multiple']
}]
};
// Block barrel imports of @tryghost/shade; consumers must import from layered
// subpaths. Used by admin-x-* / posts / activitypub / admin host.
export const shadeLayeredImportsRule = {
'no-restricted-imports': ['error', {
paths: [{
name: '@tryghost/shade',
message: 'Import from layered subpaths instead (components/primitives/patterns/utils/app/tokens).'
}]
}]
};
// React rule defaults turned off across React workspaces.
export const reactDefaultsOff = {
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off'
};
// React stylistic + correctness preferences applied across the React workspaces.
export const reactStrictRules = {
'react/jsx-sort-props': ['error', {
reservedFirst: true,
callbacksLast: true,
shorthandLast: true,
locale: 'en'
}],
'react/button-has-type': 'error',
'react/no-array-index-key': 'error',
'react/jsx-key': 'off'
};
// Tailwind v4 ruleset using settings-based config (consumer sets
// `settings.tailwindcss.config`). For v3 workspaces use tailwindRulesWithConfig().
// All rules are 'error' or 'off' — Ghost's stance is no warnings (warnings
// get ignored and pollute context). migration-from-tailwind-2 is off since
// Ghost is already on v4; the rule is no longer providing value.
export const tailwindRulesV4 = {
'tailwindcss/classnames-order': 'error',
'tailwindcss/enforces-negative-arbitrary-values': 'error',
'tailwindcss/enforces-shorthand': 'error',
'tailwindcss/migration-from-tailwind-2': 'off',
'tailwindcss/no-arbitrary-value': 'off',
'tailwindcss/no-custom-classname': 'off',
'tailwindcss/no-contradicting-classname': 'error'
};
// Tailwind v3 ruleset with config passed per-rule (v3 didn't read `settings`
// the same way). Use the consumer's tailwind config absolute path. Same
// error-or-off stance as tailwindRulesV4.
export function tailwindRulesWithConfig(config) {
return {
'tailwindcss/classnames-order': ['error', {config}],
'tailwindcss/enforces-negative-arbitrary-values': ['error', {config}],
'tailwindcss/enforces-shorthand': ['error', {config}],
'tailwindcss/migration-from-tailwind-2': 'off',
'tailwindcss/no-arbitrary-value': 'off',
'tailwindcss/no-custom-classname': 'off',
'tailwindcss/no-contradicting-classname': ['error', {config}]
};
}
// === Helpers ===
// Build an object that disables every `ghost/mocha/*` rule shipped by
// eslint-plugin-ghost. Used in test blocks so Vitest patterns don't trip
// false-positive mocha warnings. Pass the consumer's ghostPlugin.
export function mochaRulesOff(ghostPlugin) {
return Object.fromEntries(
Object.keys(ghostPlugin.rules || {})
.filter(rule => rule.startsWith('mocha/'))
.map(rule => [`ghost/${rule}`, 'off'])
);
}
// === Plugins ===
// eslint-plugin-filenames-ts@1.3.2's match-regex rule calls context.getScope(),
// which ESLint 9 removed. Minimal replacement: filename check + optional
// ignoreExporting via AST scan (no scope traversal). Use under the
// 'local-filenames' plugin name. Compatible with the three call sites that
// previously defined their own shim (ghost/core, ghost/admin, ghost/i18n).
const filenamesMatchRegex = {
meta: {
type: 'problem',
schema: [
{type: 'string'},
{type: ['boolean', 'null']},
{type: ['boolean', 'null']}
]
},
create(context) {
const pattern = new RegExp(context.options[0]);
const ignoreExporting = Boolean(context.options[1]);
return {
Program(node) {
if (ignoreExporting) {
const hasExport = node.body.some(stmt =>
stmt.type === 'ExportDefaultDeclaration' ||
stmt.type === 'ExportNamedDeclaration' ||
(stmt.type === 'ExpressionStatement' &&
stmt.expression.type === 'AssignmentExpression' &&
stmt.expression.left.type === 'MemberExpression' &&
stmt.expression.left.object.type === 'Identifier' &&
stmt.expression.left.object.name === 'module' &&
stmt.expression.left.property.type === 'Identifier' &&
stmt.expression.left.property.name === 'exports')
);
if (hasExport) return;
}
const filename = path.parse(context.filename).name;
if (!pattern.test(filename)) {
context.report({
node,
message: `Filename '${filename}' does not match the naming convention.`
});
}
}
};
}
};
export const localFilenamesPlugin = {
rules: {'match-regex': filenamesMatchRegex}
};