Skip to content

Commit ca021ac

Browse files
authored
Update to eslint 9 (#637)
1 parent bbcf907 commit ca021ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4198
-2321
lines changed

.eslintrc.yaml

Lines changed: 0 additions & 48 deletions
This file was deleted.

eslint-base.yaml

Lines changed: 0 additions & 72 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import js from "@eslint/js";
2+
import eslintConfigPrettier from "eslint-config-prettier";
3+
import mochaPlugin from "eslint-plugin-mocha";
4+
import globals from "globals";
5+
6+
import tseslint from "typescript-eslint";
7+
8+
export default [
9+
{
10+
ignores: [
11+
"**/node_modules/",
12+
"*/coverage/",
13+
"*/dist/",
14+
"*/esm/",
15+
"*/vendor/",
16+
"fluent-*/index.js",
17+
"html/",
18+
"tools/",
19+
],
20+
},
21+
{
22+
languageOptions: {
23+
ecmaVersion: 2018,
24+
sourceType: "module",
25+
},
26+
},
27+
28+
// Config files
29+
{
30+
files: ["**/*.mjs"],
31+
languageOptions: { ecmaVersion: 2020 },
32+
},
33+
{
34+
files: ["**/*.cjs"],
35+
languageOptions: { globals: { ...globals.node } },
36+
},
37+
38+
js.configs.recommended,
39+
{
40+
files: ["**/*.js", "**/*.mjs", "*/src/*.ts"],
41+
rules: {
42+
"consistent-return": "warn",
43+
"dot-notation": "error",
44+
eqeqeq: "error",
45+
"max-depth": ["error", 6],
46+
"no-caller": "error",
47+
"no-console": "warn",
48+
"no-constant-condition": ["warn", { checkLoops: false }],
49+
"no-duplicate-imports": "error",
50+
"no-else-return": "error",
51+
"no-empty": "warn",
52+
"no-eval": "error",
53+
"no-extend-native": "error",
54+
"no-extra-bind": "error",
55+
"no-implicit-globals": "error",
56+
"no-implied-eval": "error",
57+
"no-iterator": "error",
58+
"no-loop-func": "error",
59+
"no-multi-str": "error",
60+
"no-nested-ternary": "error",
61+
"no-proto": "error",
62+
"no-sequences": "error",
63+
"no-shadow": "error",
64+
"no-undef-init": "error",
65+
"no-unneeded-ternary": "error",
66+
"no-unreachable": "warn",
67+
"no-unused-vars": "warn",
68+
"no-use-before-define": ["error", { functions: false, classes: false }],
69+
"no-useless-call": "error",
70+
"no-useless-concat": "error",
71+
"no-useless-return": "error",
72+
"prefer-arrow-callback": "warn",
73+
"prefer-rest-params": "error",
74+
"prefer-spread": "error",
75+
"prefer-template": "error",
76+
"spaced-comment": ["error", "always"],
77+
strict: ["error", "global"],
78+
},
79+
},
80+
81+
// TypeScript
82+
...tseslint.configs.recommendedTypeChecked.map(cfg => ({
83+
...cfg,
84+
files: ["**/*.ts"],
85+
})),
86+
{
87+
files: ["**/*.ts"],
88+
languageOptions: {
89+
parserOptions: {
90+
projectService: true,
91+
tsconfigRootDir: import.meta.dirname,
92+
},
93+
},
94+
rules: {
95+
complexity: "off",
96+
"prefer-const": "off",
97+
"no-undef": "off",
98+
"no-unused-vars": ["error", { args: "none" }],
99+
"no-use-before-define": "off",
100+
"@typescript-eslint/no-inferrable-types": "off",
101+
"@typescript-eslint/no-unused-vars": ["error", { args: "none" }],
102+
"@typescript-eslint/no-use-before-define": "off",
103+
"@typescript-eslint/explicit-function-return-type": "error",
104+
},
105+
},
106+
eslintConfigPrettier,
107+
108+
// Test suites
109+
{
110+
files: ["*/test/**"],
111+
languageOptions: {
112+
globals: { ...globals.mocha, ...globals.node },
113+
ecmaVersion: 2020,
114+
},
115+
plugins: { mocha: mochaPlugin },
116+
rules: {
117+
"mocha/no-exclusive-tests": "error",
118+
"mocha/no-identical-title": "error",
119+
"no-console": "off",
120+
"prefer-arrow-callback": "off",
121+
},
122+
},
123+
{
124+
files: ["fluent-dom/test/*"],
125+
languageOptions: { globals: { ...globals.browser } },
126+
},
127+
{
128+
files: ["fluent-react/test/**"],
129+
languageOptions: {
130+
globals: { ...globals.browser, ...globals.jest },
131+
ecmaVersion: 2020,
132+
parserOptions: { ecmaFeatures: { jsx: true } },
133+
},
134+
plugins: { mocha: mochaPlugin },
135+
rules: {
136+
"mocha/no-exclusive-tests": "error",
137+
"mocha/no-identical-title": "error",
138+
"no-unused-vars": "off",
139+
},
140+
},
141+
];

fluent-bundle/src/resource.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ export class FluentResource {
534534
// Normalize a blank block and extract the indent details.
535535
function makeIndent(blank: string): Indent {
536536
let value = blank.replace(RE_BLANK_LINES, "\n");
537-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
538537
let length = RE_INDENT.exec(blank)![1].length;
539538
return new Indent(value, length);
540539
}

fluent-bundle/src/scope.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export class Scope {
6969
}
7070
let id = JSON.stringify(opts);
7171
if (!cache[id]) {
72+
// @ts-expect-error This is fine.
73+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
7274
cache[id] = new ctor(this.bundle.locales, opts);
7375
}
7476
return cache[id];

fluent-bundle/src/types.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -127,36 +127,35 @@ export class FluentNumber extends FluentType<number> {
127127
* option bag of options which will be passed to `Intl.DateTimeFormat` when the
128128
* `FluentDateTime` is formatted to a string.
129129
*/
130-
export class FluentDateTime extends FluentType<
131-
| number
132-
| Date
133-
| TemporalObject
134-
> {
130+
export class FluentDateTime extends FluentType<number | Date | TemporalObject> {
135131
/** Options passed to `Intl.DateTimeFormat`. */
136132
public opts: Intl.DateTimeFormatOptions;
137133

138-
static supportsValue(value: unknown): value is ConstructorParameters<typeof FluentDateTime>[0] {
134+
static supportsValue(
135+
value: unknown
136+
): value is ConstructorParameters<typeof FluentDateTime>[0] {
139137
if (typeof value === "number") return true;
140138
if (value instanceof Date) return true;
141-
if (value instanceof FluentType) return FluentDateTime.supportsValue(value.valueOf());
139+
if (value instanceof FluentType)
140+
return FluentDateTime.supportsValue(value.valueOf());
142141
// Temporary workaround to support environments without Temporal
143-
if ('Temporal' in globalThis) {
142+
if ("Temporal" in globalThis) {
144143
// for TypeScript, which doesn't know about Temporal yet
145144
const _Temporal = (
146145
globalThis as unknown as { Temporal: Record<string, () => unknown> }
147146
).Temporal;
148147
if (
149-
value instanceof _Temporal.Instant ||
150-
value instanceof _Temporal.PlainDateTime ||
151-
value instanceof _Temporal.PlainDate ||
152-
value instanceof _Temporal.PlainMonthDay ||
153-
value instanceof _Temporal.PlainTime ||
148+
value instanceof _Temporal.Instant ||
149+
value instanceof _Temporal.PlainDateTime ||
150+
value instanceof _Temporal.PlainDate ||
151+
value instanceof _Temporal.PlainMonthDay ||
152+
value instanceof _Temporal.PlainTime ||
154153
value instanceof _Temporal.PlainYearMonth
155154
) {
156155
return true;
157156
}
158157
}
159-
return false
158+
return false;
160159
}
161160

162161
/**
@@ -167,12 +166,7 @@ export class FluentDateTime extends FluentType<
167166
* @param opts Options which will be passed to `Intl.DateTimeFormat`.
168167
*/
169168
constructor(
170-
value:
171-
| number
172-
| Date
173-
| TemporalObject
174-
| FluentDateTime
175-
| FluentType<number>,
169+
value: number | Date | TemporalObject | FluentDateTime | FluentType<number>,
176170
opts: Intl.DateTimeFormatOptions = {}
177171
) {
178172
// unwrap any FluentType value, but only retain the opts from FluentDateTime
@@ -184,7 +178,11 @@ export class FluentDateTime extends FluentType<
184178
}
185179

186180
// Intl.DateTimeFormat defaults to gregorian calendar, but Temporal defaults to iso8601
187-
if (typeof value === "object" && 'calendarId' in value && opts.calendar === undefined) {
181+
if (
182+
typeof value === "object" &&
183+
"calendarId" in value &&
184+
opts.calendar === undefined
185+
) {
188186
opts = { ...opts, calendar: value.calendarId };
189187
}
190188

@@ -202,11 +200,11 @@ export class FluentDateTime extends FluentType<
202200
if (typeof value === "number") return value;
203201
if (value instanceof Date) return value.getTime();
204202

205-
if ('epochMilliseconds' in value) {
203+
if ("epochMilliseconds" in value) {
206204
return value.epochMilliseconds as number;
207205
}
208206

209-
if ('toZonedDateTime' in value) {
207+
if ("toZonedDateTime" in value) {
210208
return value.toZonedDateTime!("UTC").epochMilliseconds;
211209
}
212210

@@ -219,7 +217,9 @@ export class FluentDateTime extends FluentType<
219217
toString(scope: Scope): string {
220218
try {
221219
const dtf = scope.memoizeIntlObject(Intl.DateTimeFormat, this.opts);
222-
return dtf.format(this.value as Parameters<Intl.DateTimeFormat["format"]>[0]);
220+
return dtf.format(
221+
this.value as Parameters<Intl.DateTimeFormat["format"]>[0]
222+
);
223223
} catch (err) {
224224
scope.reportError(err);
225225
if (typeof this.value === "number" || this.value instanceof Date) {

0 commit comments

Comments
 (0)