Skip to content

Commit 92072a2

Browse files
authored
refactor(kit): simplify LanguagePreferenceSchema (#1033)
1 parent 6e28b98 commit 92072a2

File tree

4 files changed

+39
-61
lines changed

4 files changed

+39
-61
lines changed

packages/utilities/ast/src/get-nested-return-statements.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { isFunction } from "./is";
1111
* @returns The nested return statements in the node
1212
*/
1313
export function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTree.ReturnStatement[] {
14-
const returnStatements: TSESTree.ReturnStatement[] = [];
15-
const functionNode = isFunction(node)
14+
const statements: TSESTree.ReturnStatement[] = [];
15+
const boundaryNode = isFunction(node)
1616
? node
1717
: findParentNode(node, isFunction);
1818
simpleTraverse(node, {
@@ -21,11 +21,11 @@ export function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTre
2121
return;
2222
}
2323
const parentFunction = findParentNode(node, isFunction);
24-
if (parentFunction !== functionNode) {
24+
if (parentFunction !== boundaryNode) {
2525
return;
2626
}
27-
returnStatements.push(node);
27+
statements.push(node);
2828
},
2929
});
30-
return returnStatements;
30+
return statements;
3131
}

packages/utilities/kit/docs/@eslint-react/namespaces/LanguagePreference/variables/DEFAULT_LANGUAGE_PREFERENCE.md

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,26 @@ The default language preference.
1212

1313
## Type declaration
1414

15-
### bracketSameLine
16-
17-
> **bracketSameLine**: `boolean`
18-
19-
### bracketSpacing
20-
21-
> **bracketSpacing**: `boolean`
22-
23-
### endOfLine
24-
25-
> **endOfLine**: `"lf"` \| `"crlf"` \| `"cr"` \| `"auto"`
26-
2715
### indentStyle
2816

29-
> **indentStyle**: `"tab"` \| `"space"`
17+
> `readonly` **indentStyle**: `"space"` = `"space"`
3018
3119
### indentWidth
3220

33-
> **indentWidth**: `number`
34-
35-
### insertFinalNewline
36-
37-
> **insertFinalNewline**: `boolean`
21+
> `readonly` **indentWidth**: `2` = `2`
3822
3923
### jsxQuoteStyle
4024

41-
> **jsxQuoteStyle**: `"preferDouble"` \| `"preferSingle"`
25+
> `readonly` **jsxQuoteStyle**: `"double"` = `"double"`
4226
4327
### quoteStyle
4428

45-
> **quoteStyle**: `"preferDouble"` \| `"preferSingle"` \| `"alwaysDouble"` \| `"alwaysSingle"`
29+
> `readonly` **quoteStyle**: `"single"` = `"single"`
4630
47-
### semicolon
31+
### semicolons
4832

49-
> **semicolon**: `"always"` \| `"prefer"` \| `"asi"`
33+
> `readonly` **semicolons**: `"always"` = `"always"`
5034
51-
### trailingComma
35+
### trailingCommas
5236

53-
> **trailingComma**: `"all"` \| `"es5"` \| `"none"`
37+
> `readonly` **trailingCommas**: `"all"` = `"all"`

packages/utilities/kit/src/LanguagePreference/LanguagePreference.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SharedConfigurationSettings } from "@typescript-eslint/utils/ts-eslint"; // eslint-disable-line @typescript-eslint/no-unused-vars
2-
import { type InferOutput, parse } from "valibot";
3-
import { LanguagePreferenceSchema } from "./LanguagePreferenceSchema";
2+
import type { LanguagePreferenceSchema } from "./LanguagePreferenceSchema";
3+
import { type InferOutput } from "valibot";
44

55
/**
66
* @internal
@@ -10,7 +10,14 @@ export type LanguagePreference = InferOutput<typeof LanguagePreferenceSchema>;
1010
/**
1111
* The default language preference.
1212
*/
13-
export const DEFAULT_LANGUAGE_PREFERENCE = parse(LanguagePreferenceSchema, {});
13+
export const DEFAULT_LANGUAGE_PREFERENCE = {
14+
indentStyle: "space",
15+
indentWidth: 2,
16+
jsxQuoteStyle: "double",
17+
quoteStyle: "single",
18+
semicolons: "always",
19+
trailingCommas: "all",
20+
} as const satisfies LanguagePreference;
1421

1522
declare module "@typescript-eslint/utils/ts-eslint" {
1623
export interface SharedConfigurationSettings {
Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
import { boolean, literal, number, object, optional, union } from "valibot";
1+
import { literal, number, object, optional, union } from "valibot";
22

33
/**
44
* @internal
55
*/
66
export const LanguagePreferenceSchema = object({
7-
bracketSameLine: optional(boolean(), false),
8-
bracketSpacing: optional(boolean(), true),
9-
endOfLine: optional(
10-
union([
11-
literal("lf"),
12-
literal("crlf"),
13-
literal("cr"),
14-
literal("auto"),
15-
]),
16-
"lf",
17-
),
187
indentStyle: optional(
198
union([
209
literal("tab"),
@@ -23,37 +12,35 @@ export const LanguagePreferenceSchema = object({
2312
"space",
2413
),
2514
indentWidth: optional(number(), 2),
26-
insertFinalNewline: optional(boolean(), true),
27-
jsxQuoteStyle: optional(
28-
union([
29-
literal("preferDouble"),
30-
literal("preferSingle"),
31-
]),
32-
"preferDouble",
33-
),
3415
quoteStyle: optional(
3516
union([
36-
literal("alwaysDouble"),
37-
literal("alwaysSingle"),
38-
literal("preferDouble"),
39-
literal("preferSingle"),
17+
literal("single"),
18+
literal("double"),
4019
]),
41-
"preferSingle",
20+
"single",
4221
),
43-
semicolon: optional(
22+
semicolons: optional(
4423
union([
4524
literal("always"),
46-
literal("prefer"),
47-
literal("asi"),
25+
literal("asNeeded"),
4826
]),
4927
"always",
5028
),
51-
trailingComma: optional(
29+
trailingCommas: optional(
5230
union([
5331
literal("all"),
5432
literal("es5"),
5533
literal("none"),
5634
]),
5735
"all",
5836
),
37+
38+
// JSX specific options
39+
jsxQuoteStyle: optional(
40+
union([
41+
literal("single"),
42+
literal("double"),
43+
]),
44+
"double",
45+
),
5946
});

0 commit comments

Comments
 (0)