Skip to content

Commit d34812d

Browse files
committed
refactor: move language preference to utilities/kit package
The commit moves language preference functionality from shared package to utilities/kit package. This includes moving schemas, types and constants related to language preferences.
1 parent 78d7cf6 commit d34812d

File tree

118 files changed

+4243
-213
lines changed

Some content is hidden

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

118 files changed

+4243
-213
lines changed

packages/shared/docs/-internal-/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@
2828
- [ExactOptionalSchema](interfaces/ExactOptionalSchema.md)
2929
- [ExactOptionalSchemaAsync](interfaces/ExactOptionalSchemaAsync.md)
3030
- [FailureDataset](interfaces/FailureDataset.md)
31-
- [LiteralIssue](interfaces/LiteralIssue.md)
32-
- [LiteralSchema](interfaces/LiteralSchema.md)
3331
- [MapPathItem](interfaces/MapPathItem.md)
3432
- [NormalizedOptions](interfaces/NormalizedOptions.md)
3533
- [NullishSchema](interfaces/NullishSchema.md)
3634
- [NullishSchemaAsync](interfaces/NullishSchemaAsync.md)
37-
- [NumberIssue](interfaces/NumberIssue.md)
38-
- [NumberSchema](interfaces/NumberSchema.md)
3935
- [ObjectEntries](interfaces/ObjectEntries.md)
4036
- [ObjectEntriesAsync](interfaces/ObjectEntriesAsync.md)
4137
- [ObjectIssue](interfaces/ObjectIssue.md)
@@ -57,8 +53,6 @@
5753
- [StringIssue](interfaces/StringIssue.md)
5854
- [StringSchema](interfaces/StringSchema.md)
5955
- [SuccessDataset](interfaces/SuccessDataset.md)
60-
- [UnionIssue](interfaces/UnionIssue.md)
61-
- [UnionSchema](interfaces/UnionSchema.md)
6256
- [UnknownDataset](interfaces/UnknownDataset.md)
6357
- [UnknownPathItem](interfaces/UnknownPathItem.md)
6458
- [\_PartialDeep](type-aliases/PartialDeep.md)
@@ -92,7 +86,6 @@
9286
- [KeyIndexGetter](type-aliases/KeyIndexGetter.md)
9387
- [KeyTransformer](type-aliases/KeyTransformer.md)
9488
- [LastTupleItem](type-aliases/LastTupleItem.md)
95-
- [Literal](type-aliases/Literal.md)
9689
- [MarkOptional](type-aliases/MarkOptional.md)
9790
- [MatchingKeyComparator](type-aliases/MatchingKeyComparator.md)
9891
- [MaybePromise](type-aliases/MaybePromise.md)
@@ -133,7 +126,6 @@
133126
- [SchemaWithPipe](type-aliases/SchemaWithPipe.md)
134127
- [SchemaWithPipeAsync](type-aliases/SchemaWithPipeAsync.md)
135128
- [StandardResult](type-aliases/StandardResult.md)
136-
- [UnionOptions](type-aliases/UnionOptions.md)
137129

138130
## Type
139131

packages/shared/docs/-internal-/interfaces/BaseIssue.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ Base issue interface.
1515
## Extended by
1616

1717
- [`ObjectIssue`](ObjectIssue.md)
18-
- [`BooleanIssue`](BooleanIssue.md)
19-
- [`UnionIssue`](UnionIssue.md)
20-
- [`LiteralIssue`](LiteralIssue.md)
21-
- [`NumberIssue`](NumberIssue.md)
2218
- [`StringIssue`](StringIssue.md)
19+
- [`BooleanIssue`](BooleanIssue.md)
2320
- [`ArrayIssue`](ArrayIssue.md)
2421

2522
## Type Parameters

packages/shared/docs/-internal-/interfaces/BaseSchema.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ Base schema interface.
1111
## Extended by
1212

1313
- [`ObjectSchema`](ObjectSchema.md)
14+
- [`StringSchema`](StringSchema.md)
1415
- [`OptionalSchema`](OptionalSchema.md)
1516
- [`BooleanSchema`](BooleanSchema.md)
16-
- [`UnionSchema`](UnionSchema.md)
17-
- [`LiteralSchema`](LiteralSchema.md)
18-
- [`NumberSchema`](NumberSchema.md)
19-
- [`StringSchema`](StringSchema.md)
2017
- [`ArraySchema`](ArraySchema.md)
2118
- [`ExactOptionalSchema`](ExactOptionalSchema.md)
2219
- [`NullishSchema`](NullishSchema.md)

packages/shared/docs/-internal-/type-aliases/Literal.md

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

packages/shared/docs/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
- [CustomComponentSchema](variables/CustomComponentSchema.md)
2828
- [CustomHooksSchema](variables/CustomHooksSchema.md)
2929
- [DEFAULT\_ESLINT\_REACT\_SETTINGS](variables/DEFAULT_ESLINT_REACT_SETTINGS.md)
30-
- [DEFAULT\_LANGUAGE\_PREFERENCE](variables/DEFAULT_LANGUAGE_PREFERENCE.md)
3130
- [defineSettings](variables/defineSettings.md)
3231
- [GITHUB\_URL](variables/GITHUB_URL.md)
3332
- [NPM\_SCOPE](variables/NPM_SCOPE.md)
@@ -36,6 +35,5 @@
3635
## Functions
3736

3837
- [getId](functions/getId.md)
39-
- [getLanguagePreferenceFromContext](functions/getLanguagePreferenceFromContext.md)
4038
- [getReactVersion](functions/getReactVersion.md)
4139
- [getSettingsFromContext](functions/getSettingsFromContext.md)

packages/shared/docs/functions/getLanguagePreferenceFromContext.md

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

packages/shared/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"@eslint-react/kit": "workspace:*",
4747
"@typescript-eslint/utils": "^8.29.0",
4848
"picomatch": "^4.0.2",
49-
"ts-pattern": "^5.7.0"
49+
"ts-pattern": "^5.7.0",
50+
"valibot": "^1.0.0"
5051
},
5152
"devDependencies": {
5253
"@local/configs": "workspace:*",
@@ -55,8 +56,7 @@
5556
"fast-equals": "^5.2.2",
5657
"micro-memoize": "^4.1.3",
5758
"tsup": "^8.4.0",
58-
"type-fest": "^4.38.0",
59-
"valibot": "^1.0.0"
59+
"type-fest": "^4.38.0"
6060
},
6161
"engines": {
6262
"bun": ">=1.0.15",

packages/shared/src/schemas.ts

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,6 @@
11
/* eslint-disable perfectionist/sort-objects */
22
import type { InferOutput } from "valibot";
3-
import { array, boolean, literal, number, object, optional, parse, string, union } from "valibot";
4-
5-
/**
6-
* @internal
7-
*/
8-
export const LanguagePreferenceSchema = object({
9-
bracketSameLine: optional(boolean(), false),
10-
bracketSpacing: optional(boolean(), true),
11-
endOfLine: optional(
12-
union([
13-
literal("lf"),
14-
literal("crlf"),
15-
literal("cr"),
16-
literal("auto"),
17-
]),
18-
"lf",
19-
),
20-
indentStyle: optional(
21-
union([
22-
literal("tab"),
23-
literal("space"),
24-
]),
25-
"space",
26-
),
27-
indentWidth: optional(number(), 2),
28-
insertFinalNewline: optional(boolean(), true),
29-
quoteStyle: optional(
30-
union([
31-
literal("alwaysDouble"),
32-
literal("alwaysSingle"),
33-
literal("preferDouble"),
34-
literal("preferSingle"),
35-
]),
36-
"preferSingle",
37-
),
38-
jsxQuoteStyle: optional(
39-
union([
40-
literal("preferDouble"),
41-
literal("preferSingle"),
42-
]),
43-
"preferDouble",
44-
),
45-
semicolon: optional(
46-
union([
47-
literal("always"),
48-
literal("prefer"),
49-
literal("asi"),
50-
]),
51-
"always",
52-
),
53-
trailingComma: optional(
54-
union([
55-
literal("all"),
56-
literal("es5"),
57-
literal("none"),
58-
]),
59-
"all",
60-
),
61-
});
3+
import { array, boolean, object, optional, parse, string } from "valibot";
624

635
export const CustomComponentPropSchema = object({
646
/**
@@ -205,17 +147,11 @@ export const ESLintReactSettingsSchema = object({
205147
additionalComponents: optional(array(CustomComponentSchema)),
206148
});
207149

208-
/**
209-
* @internal
210-
*/
211-
export type LanguagePreference = InferOutput<typeof LanguagePreferenceSchema>;
212-
213150
/**
214151
* @internal
215152
*/
216153
export const ESLintSettingsSchema = optional(
217154
object({
218-
languagePreference: optional(LanguagePreferenceSchema),
219155
"react-x": optional(ESLintReactSettingsSchema),
220156
/** @deprecated Use `react-x` instead */
221157
reactOptions: optional(ESLintReactSettingsSchema),
@@ -233,11 +169,6 @@ export type ESLintReactSettings = InferOutput<typeof ESLintReactSettingsSchema>;
233169

234170
export type ESLintSettings = InferOutput<typeof ESLintSettingsSchema>;
235171

236-
/**
237-
* The default language preference.
238-
*/
239-
export const DEFAULT_LANGUAGE_PREFERENCE = parse(LanguagePreferenceSchema, {});
240-
241172
/**
242173
* The default ESLint settings for "react-x".
243174
*/

packages/shared/src/settings.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { _ } from "@eslint-react/eff";
33
import type { SharedConfigurationSettings } from "@typescript-eslint/utils/ts-eslint"; // eslint-disable-line @typescript-eslint/no-unused-vars
44
import type { PartialDeep } from "type-fest";
5-
import type { CustomHooks, ESLintReactSettings, LanguagePreference } from "./schemas";
5+
import type { CustomHooks, ESLintReactSettings } from "./schemas";
66
import { identity } from "@eslint-react/eff";
77
import { shallowEqual } from "fast-equals";
88
import memoize from "micro-memoize";
@@ -11,7 +11,7 @@ import { match, P } from "ts-pattern";
1111

1212
import { parse } from "valibot";
1313
import { getReactVersion } from "./get-react-version";
14-
import { DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_LANGUAGE_PREFERENCE, ESLintSettingsSchema } from "./schemas";
14+
import { DEFAULT_ESLINT_REACT_SETTINGS, ESLintSettingsSchema } from "./schemas";
1515

1616
export interface CustomComponentNormalized {
1717
name: string;
@@ -117,10 +117,6 @@ export function getSettingsFromContext(context: { settings: unknown }): ESLintRe
117117
return toNormalizedSettings(decodeSettings(context.settings));
118118
}
119119

120-
export function getLanguagePreferenceFromContext(context: { settings: unknown }): LanguagePreference {
121-
return parse(ESLintSettingsSchema, context.settings).languagePreference ?? DEFAULT_LANGUAGE_PREFERENCE;
122-
}
123-
124120
/**
125121
* A helper function to define settings for "react-x" with type checking in JavaScript files.
126122
* @param settings The settings.
@@ -130,7 +126,6 @@ export const defineSettings: (settings: ESLintReactSettings) => ESLintReactSetti
130126

131127
declare module "@typescript-eslint/utils/ts-eslint" {
132128
export interface SharedConfigurationSettings {
133-
languagePreference?: Partial<LanguagePreference>;
134129
["react-x"]?: Partial<ESLintReactSettings>;
135130
}
136131
}

0 commit comments

Comments
 (0)