@noctcore/eslint-plugin-contracts 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/index.cjs +1410 -84
- package/dist/index.d.cts +94 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +1410 -84
- package/docs/rules/fetch-must-check-ok.md +83 -0
- package/docs/rules/schema-enum-field-consistency.md +75 -0
- package/docs/rules/translation-key-exists.md +155 -0
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Translation catalog loading for the i18n rules.
|
|
5
|
+
*
|
|
6
|
+
* A catalog is a JSON file (or a subtree of one) that holds the keys of ONE
|
|
7
|
+
* namespace. Projects lay catalogs out in a handful of shapes, and a
|
|
8
|
+
* `CatalogSource` describes each of them without the rule knowing any project:
|
|
9
|
+
*
|
|
10
|
+
* one file per namespace `{ file: 'locales/en/{ns}.json' }`
|
|
11
|
+
* one file, ns at the top `{ file: 'locales/en.json', keyPath: '{ns}' }`
|
|
12
|
+
* a fixed file for one ns `{ file: 'src/i18n/en.json', namespace: 'common' }`
|
|
13
|
+
* single-namespace app `{ file: 'src/i18n/en.json' }` (the default namespace)
|
|
14
|
+
*
|
|
15
|
+
* `{ns}` is substituted with the namespace being resolved. A templated source
|
|
16
|
+
* whose file or subtree does not exist simply does not supply that namespace;
|
|
17
|
+
* a FIXED source that cannot be read is a configuration error and is surfaced.
|
|
18
|
+
*/
|
|
19
|
+
interface CatalogSource {
|
|
20
|
+
/** JSON catalog path, relative to the ESLint cwd. May contain `{ns}`. */
|
|
21
|
+
readonly file: string;
|
|
22
|
+
/** Namespace a fixed (non-templated) source supplies. Defaults to the default namespace. */
|
|
23
|
+
readonly namespace?: string;
|
|
24
|
+
/** Dot-separated subtree inside the file holding the namespace's keys. May contain `{ns}`. */
|
|
25
|
+
readonly keyPath?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface TranslationKeyExistsOptions {
|
|
29
|
+
/** Where each namespace's catalog lives. Empty = rule is inert. */
|
|
30
|
+
readonly catalogs?: readonly CatalogSource[];
|
|
31
|
+
/** The namespace an unqualified `useTranslation()` / `i18n.t` resolves to (i18next `defaultNS`). */
|
|
32
|
+
readonly defaultNamespace?: string;
|
|
33
|
+
/** Namespaces searched after the bound ones (i18next `fallbackNS`). */
|
|
34
|
+
readonly fallbackNamespaces?: readonly string[];
|
|
35
|
+
/** Hooks returning a namespace-bound `t` (`useTranslation`). */
|
|
36
|
+
readonly hooks?: readonly string[];
|
|
37
|
+
/** i18next instance identifiers: `<instance>.t(...)`, `<instance>.getFixedT(...)`. */
|
|
38
|
+
readonly instances?: readonly string[];
|
|
39
|
+
/** Free translation functions bound to the default namespace when imported or global (`t`). */
|
|
40
|
+
readonly functions?: readonly string[];
|
|
41
|
+
/** Type names whose first type argument names a parameter's namespace (`TFunction<'ns'>`). */
|
|
42
|
+
readonly typeNames?: readonly string[];
|
|
43
|
+
/** JSX components taking an `i18nKey` prop (`Trans`). */
|
|
44
|
+
readonly transComponents?: readonly string[];
|
|
45
|
+
/** Identifiers holding a namespace name that live in another module (`{ HELP_NS: 'help' }`). */
|
|
46
|
+
readonly namespaceIdentifiers?: Readonly<Record<string, string>>;
|
|
47
|
+
/** i18next `nsSeparator`; `false` disables `ns:key` parsing. */
|
|
48
|
+
readonly nsSeparator?: string | false;
|
|
49
|
+
/** i18next `keySeparator`; `false` means flat catalogs. */
|
|
50
|
+
readonly keySeparator?: string | false;
|
|
51
|
+
/** i18next `pluralSeparator`. */
|
|
52
|
+
readonly pluralSeparator?: string;
|
|
53
|
+
/** i18next `contextSeparator`. */
|
|
54
|
+
readonly contextSeparator?: string;
|
|
55
|
+
/** `ignore` stays silent on template keys; `check-prefix` requires their static head to exist. */
|
|
56
|
+
readonly dynamicKeys?: 'ignore' | 'check-prefix';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface FetchMustCheckOkOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Callees whose result is a `Response`: a bare name (`fetch`) or a dotted path
|
|
62
|
+
* (`globalThis.fetch`, `http.fetchWithRetry`). Default `['fetch']`.
|
|
63
|
+
*/
|
|
64
|
+
readonly fetchFunctions?: readonly string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface SchemaEnumFieldConsistencyOptions {
|
|
68
|
+
/** Names the zod namespace is imported under. */
|
|
69
|
+
readonly zodIdentifiers?: readonly string[];
|
|
70
|
+
/** Field names allowed to be an enum in one schema and a string in another. */
|
|
71
|
+
readonly ignoreFields?: readonly string[];
|
|
72
|
+
/**
|
|
73
|
+
* Regex source. An IMPORTED identifier counts as an enum only when its name
|
|
74
|
+
* matches. Unset, no imported identifier does.
|
|
75
|
+
*/
|
|
76
|
+
readonly enumIdentifierPattern?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
3
79
|
interface EnvVarSchemaParityOptions {
|
|
4
80
|
/** Path to the env declaration source — a `.env.example` or a zod-env module. Empty = rule is inert. */
|
|
5
81
|
readonly schema?: string;
|
|
@@ -83,6 +159,15 @@ declare const rules: {
|
|
|
83
159
|
'require-schema-parse-at-boundary': _typescript_eslint_utils_ts_eslint.RuleModule<"castedBoundaryData", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
84
160
|
name: string;
|
|
85
161
|
};
|
|
162
|
+
'schema-enum-field-consistency': _typescript_eslint_utils_ts_eslint.RuleModule<"widenedEnumField", [SchemaEnumFieldConsistencyOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
165
|
+
'fetch-must-check-ok': _typescript_eslint_utils_ts_eslint.RuleModule<"missingOkCheck", [FetchMustCheckOkOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
166
|
+
name: string;
|
|
167
|
+
};
|
|
168
|
+
'translation-key-exists': _typescript_eslint_utils_ts_eslint.RuleModule<"missingKey" | "missingKeyPrefix" | "unknownNamespace" | "catalogUnreadable", [TranslationKeyExistsOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
169
|
+
name: string;
|
|
170
|
+
};
|
|
86
171
|
};
|
|
87
172
|
|
|
88
173
|
declare const plugin: {
|
|
@@ -121,6 +206,15 @@ declare const plugin: {
|
|
|
121
206
|
'require-schema-parse-at-boundary': _typescript_eslint_utils_ts_eslint.RuleModule<"castedBoundaryData", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
122
207
|
name: string;
|
|
123
208
|
};
|
|
209
|
+
'schema-enum-field-consistency': _typescript_eslint_utils_ts_eslint.RuleModule<"widenedEnumField", [SchemaEnumFieldConsistencyOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
210
|
+
name: string;
|
|
211
|
+
};
|
|
212
|
+
'fetch-must-check-ok': _typescript_eslint_utils_ts_eslint.RuleModule<"missingOkCheck", [FetchMustCheckOkOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
213
|
+
name: string;
|
|
214
|
+
};
|
|
215
|
+
'translation-key-exists': _typescript_eslint_utils_ts_eslint.RuleModule<"missingKey" | "missingKeyPrefix" | "unknownNamespace" | "catalogUnreadable", [TranslationKeyExistsOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
216
|
+
name: string;
|
|
217
|
+
};
|
|
124
218
|
};
|
|
125
219
|
configs: Record<string, unknown>;
|
|
126
220
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Translation catalog loading for the i18n rules.
|
|
5
|
+
*
|
|
6
|
+
* A catalog is a JSON file (or a subtree of one) that holds the keys of ONE
|
|
7
|
+
* namespace. Projects lay catalogs out in a handful of shapes, and a
|
|
8
|
+
* `CatalogSource` describes each of them without the rule knowing any project:
|
|
9
|
+
*
|
|
10
|
+
* one file per namespace `{ file: 'locales/en/{ns}.json' }`
|
|
11
|
+
* one file, ns at the top `{ file: 'locales/en.json', keyPath: '{ns}' }`
|
|
12
|
+
* a fixed file for one ns `{ file: 'src/i18n/en.json', namespace: 'common' }`
|
|
13
|
+
* single-namespace app `{ file: 'src/i18n/en.json' }` (the default namespace)
|
|
14
|
+
*
|
|
15
|
+
* `{ns}` is substituted with the namespace being resolved. A templated source
|
|
16
|
+
* whose file or subtree does not exist simply does not supply that namespace;
|
|
17
|
+
* a FIXED source that cannot be read is a configuration error and is surfaced.
|
|
18
|
+
*/
|
|
19
|
+
interface CatalogSource {
|
|
20
|
+
/** JSON catalog path, relative to the ESLint cwd. May contain `{ns}`. */
|
|
21
|
+
readonly file: string;
|
|
22
|
+
/** Namespace a fixed (non-templated) source supplies. Defaults to the default namespace. */
|
|
23
|
+
readonly namespace?: string;
|
|
24
|
+
/** Dot-separated subtree inside the file holding the namespace's keys. May contain `{ns}`. */
|
|
25
|
+
readonly keyPath?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface TranslationKeyExistsOptions {
|
|
29
|
+
/** Where each namespace's catalog lives. Empty = rule is inert. */
|
|
30
|
+
readonly catalogs?: readonly CatalogSource[];
|
|
31
|
+
/** The namespace an unqualified `useTranslation()` / `i18n.t` resolves to (i18next `defaultNS`). */
|
|
32
|
+
readonly defaultNamespace?: string;
|
|
33
|
+
/** Namespaces searched after the bound ones (i18next `fallbackNS`). */
|
|
34
|
+
readonly fallbackNamespaces?: readonly string[];
|
|
35
|
+
/** Hooks returning a namespace-bound `t` (`useTranslation`). */
|
|
36
|
+
readonly hooks?: readonly string[];
|
|
37
|
+
/** i18next instance identifiers: `<instance>.t(...)`, `<instance>.getFixedT(...)`. */
|
|
38
|
+
readonly instances?: readonly string[];
|
|
39
|
+
/** Free translation functions bound to the default namespace when imported or global (`t`). */
|
|
40
|
+
readonly functions?: readonly string[];
|
|
41
|
+
/** Type names whose first type argument names a parameter's namespace (`TFunction<'ns'>`). */
|
|
42
|
+
readonly typeNames?: readonly string[];
|
|
43
|
+
/** JSX components taking an `i18nKey` prop (`Trans`). */
|
|
44
|
+
readonly transComponents?: readonly string[];
|
|
45
|
+
/** Identifiers holding a namespace name that live in another module (`{ HELP_NS: 'help' }`). */
|
|
46
|
+
readonly namespaceIdentifiers?: Readonly<Record<string, string>>;
|
|
47
|
+
/** i18next `nsSeparator`; `false` disables `ns:key` parsing. */
|
|
48
|
+
readonly nsSeparator?: string | false;
|
|
49
|
+
/** i18next `keySeparator`; `false` means flat catalogs. */
|
|
50
|
+
readonly keySeparator?: string | false;
|
|
51
|
+
/** i18next `pluralSeparator`. */
|
|
52
|
+
readonly pluralSeparator?: string;
|
|
53
|
+
/** i18next `contextSeparator`. */
|
|
54
|
+
readonly contextSeparator?: string;
|
|
55
|
+
/** `ignore` stays silent on template keys; `check-prefix` requires their static head to exist. */
|
|
56
|
+
readonly dynamicKeys?: 'ignore' | 'check-prefix';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface FetchMustCheckOkOptions {
|
|
60
|
+
/**
|
|
61
|
+
* Callees whose result is a `Response`: a bare name (`fetch`) or a dotted path
|
|
62
|
+
* (`globalThis.fetch`, `http.fetchWithRetry`). Default `['fetch']`.
|
|
63
|
+
*/
|
|
64
|
+
readonly fetchFunctions?: readonly string[];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface SchemaEnumFieldConsistencyOptions {
|
|
68
|
+
/** Names the zod namespace is imported under. */
|
|
69
|
+
readonly zodIdentifiers?: readonly string[];
|
|
70
|
+
/** Field names allowed to be an enum in one schema and a string in another. */
|
|
71
|
+
readonly ignoreFields?: readonly string[];
|
|
72
|
+
/**
|
|
73
|
+
* Regex source. An IMPORTED identifier counts as an enum only when its name
|
|
74
|
+
* matches. Unset, no imported identifier does.
|
|
75
|
+
*/
|
|
76
|
+
readonly enumIdentifierPattern?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
3
79
|
interface EnvVarSchemaParityOptions {
|
|
4
80
|
/** Path to the env declaration source — a `.env.example` or a zod-env module. Empty = rule is inert. */
|
|
5
81
|
readonly schema?: string;
|
|
@@ -83,6 +159,15 @@ declare const rules: {
|
|
|
83
159
|
'require-schema-parse-at-boundary': _typescript_eslint_utils_ts_eslint.RuleModule<"castedBoundaryData", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
84
160
|
name: string;
|
|
85
161
|
};
|
|
162
|
+
'schema-enum-field-consistency': _typescript_eslint_utils_ts_eslint.RuleModule<"widenedEnumField", [SchemaEnumFieldConsistencyOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
163
|
+
name: string;
|
|
164
|
+
};
|
|
165
|
+
'fetch-must-check-ok': _typescript_eslint_utils_ts_eslint.RuleModule<"missingOkCheck", [FetchMustCheckOkOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
166
|
+
name: string;
|
|
167
|
+
};
|
|
168
|
+
'translation-key-exists': _typescript_eslint_utils_ts_eslint.RuleModule<"missingKey" | "missingKeyPrefix" | "unknownNamespace" | "catalogUnreadable", [TranslationKeyExistsOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
169
|
+
name: string;
|
|
170
|
+
};
|
|
86
171
|
};
|
|
87
172
|
|
|
88
173
|
declare const plugin: {
|
|
@@ -121,6 +206,15 @@ declare const plugin: {
|
|
|
121
206
|
'require-schema-parse-at-boundary': _typescript_eslint_utils_ts_eslint.RuleModule<"castedBoundaryData", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
122
207
|
name: string;
|
|
123
208
|
};
|
|
209
|
+
'schema-enum-field-consistency': _typescript_eslint_utils_ts_eslint.RuleModule<"widenedEnumField", [SchemaEnumFieldConsistencyOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
210
|
+
name: string;
|
|
211
|
+
};
|
|
212
|
+
'fetch-must-check-ok': _typescript_eslint_utils_ts_eslint.RuleModule<"missingOkCheck", [FetchMustCheckOkOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
213
|
+
name: string;
|
|
214
|
+
};
|
|
215
|
+
'translation-key-exists': _typescript_eslint_utils_ts_eslint.RuleModule<"missingKey" | "missingKeyPrefix" | "unknownNamespace" | "catalogUnreadable", [TranslationKeyExistsOptions], unknown, _typescript_eslint_utils_ts_eslint.RuleListener> & {
|
|
216
|
+
name: string;
|
|
217
|
+
};
|
|
124
218
|
};
|
|
125
219
|
configs: Record<string, unknown>;
|
|
126
220
|
};
|