Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
150 lines (148 loc) · 5.96 KB
/
Copy patheslint.config.js
File metadata and controls
150 lines (148 loc) · 5.96 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
// For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format
import storybook from "eslint-plugin-storybook";
import js from "@eslint/js";
import globals from "globals";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import tseslint from "typescript-eslint";
import i18next from "eslint-plugin-i18next";
import { defineConfig, globalIgnores } from "eslint/config";
export default defineConfig([
globalIgnores([
"dist",
"**/dist",
"**/node_modules",
"storybook-static",
"coverage",
"**/coverage",
// Third-party bundle staged from node_modules by `npm run stage-du-wc`;
// its du-assets/ ship .ts sources that are not ours to lint.
"public/du-vs-wc",
]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
// i18n enforcement for conversational-agent-chat.
// Narrow scope + strict enforcement: fire only on surfaces that definitely
// render to users (JSX text + explicit user-facing attributes + setError args)
// so the rule's false-positive rate stays near zero and eslint-disable
// comments don't become normalized.
{
files: ["packages/conversational-agent-chat/src/**/*.{ts,tsx}"],
ignores: ["**/*.stories.{ts,tsx}", "**/*.test.{ts,tsx}", "**/__tests__/**"],
plugins: { i18next },
rules: {
"i18next/no-literal-string": [
"error",
{
mode: "jsx-only",
"jsx-attributes": {
include: [
"label",
"title",
"placeholder",
"aria-label",
"alt",
"tooltip",
"description",
"message",
"footerDisclaimer",
"inputPlaceholder",
],
},
callees: {
exclude: [
"i18n(ext)?",
"t",
"require",
"addEventListener",
"removeEventListener",
"postMessage",
"getElementById",
"dispatch",
"commit",
"includes",
"indexOf",
"endsWith",
"startsWith",
"console\\..*",
"trackTelemetry",
],
},
},
],
// Catch raw literals passed to setError / chatService.setError,
// which are rendered to the user but live outside JSX ancestry and
// so escape no-literal-string's jsx-only mode. The `value=/.+/`
// filter skips `setError(null)` / `setError("")` (legitimate clears).
"no-restricted-syntax": [
"error",
{
selector:
"CallExpression[callee.property.name='setError'][arguments.0.type='Literal'][arguments.0.value=/.+/]",
message:
"Pass a translated string via t('key') to setError, not a raw literal.",
},
{
selector:
"CallExpression[callee.name='setError'][arguments.0.type='Literal'][arguments.0.value=/.+/]",
message:
"Pass a translated string via t('key') to setError, not a raw literal.",
},
{
selector:
"CallExpression[callee.property.name='setError'][arguments.0.type='TemplateLiteral']",
message:
"Pass a translated string via t('key') to setError, not a template literal.",
},
{
selector:
"CallExpression[callee.name='setError'][arguments.0.type='TemplateLiteral']",
message:
"Pass a translated string via t('key') to setError, not a template literal.",
},
// Lock t() keys to static string literals. Dynamic keys (t(someVar),
// t(`prefix_${x}`)) bypass check-i18n's key-coverage verification AND
// silently render un-localized English when the dynamic value happens
// to be an English string (i18next falls back to the key when the
// lookup misses). If you need a conditional, switch/if on the known
// keys: t(cond ? "key_a" : "key_b").
{
selector:
"CallExpression[callee.name='t'][arguments.length>0][arguments.0.type!='Literal'][arguments.0.type!='TemplateLiteral']",
message:
"t() key must be a static string literal. If genuinely dynamic, enumerate possible keys in a comment and disable this rule on the next line (see CONTRIBUTING.md § Internationalization).",
},
{
selector:
"CallExpression[callee.name='t'][arguments.0.type='TemplateLiteral'][arguments.0.expressions.length>0]",
message:
"t() key must be a static string literal. Interpolated template literals cannot be verified at PR time. If genuinely dynamic, enumerate possible keys in a comment and disable this rule on the next line (see CONTRIBUTING.md § Internationalization).",
},
{
selector:
"CallExpression[callee.property.name='t'][arguments.length>0][arguments.0.type!='Literal'][arguments.0.type!='TemplateLiteral']",
message:
"t() key must be a static string literal. If genuinely dynamic, enumerate possible keys in a comment and disable this rule on the next line (see CONTRIBUTING.md § Internationalization).",
},
{
selector:
"CallExpression[callee.property.name='t'][arguments.0.type='TemplateLiteral'][arguments.0.expressions.length>0]",
message:
"t() key must be a static string literal. Interpolated template literals cannot be verified at PR time. If genuinely dynamic, enumerate possible keys in a comment and disable this rule on the next line (see CONTRIBUTING.md § Internationalization).",
},
],
},
},
...storybook.configs["flat/recommended"],
]);