Skip to content

Commit fd33f13

Browse files
authored
fix: update types for no-restricted-imports rule (#19060)
1 parent 5ff6c1d commit fd33f13

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

lib/types/rules/ecmascript-6.d.ts

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@
2727

2828
import { Linter } from "../index";
2929

30+
export interface NoRestrictedImportPathCommonOptions {
31+
name: string;
32+
message?: string;
33+
}
34+
35+
export type EitherImportNamesOrAllowImportName =
36+
| { importNames?: string[]; allowImportNames?: never }
37+
| { allowImportNames?: string[]; importNames?: never }
38+
39+
export type ValidNoRestrictedImportPathOptions = NoRestrictedImportPathCommonOptions & EitherImportNamesOrAllowImportName;
40+
41+
export interface NoRestrictedImportPatternCommonOptions {
42+
message?: string;
43+
caseSensitive?: boolean;
44+
}
45+
46+
// Base type for group or regex constraint, ensuring mutual exclusivity
47+
export type EitherGroupOrRegEx =
48+
| { group: string[]; regex?: never }
49+
| { regex: string; group?: never };
50+
51+
// Base type for import name specifiers, ensuring mutual exclusivity
52+
export type EitherNameSpecifiers =
53+
| { importNames: string[]; allowImportNames?: never; importNamePattern?: never; allowImportNamePattern?: never }
54+
| { importNamePattern: string; allowImportNames?: never; importNames?: never; allowImportNamePattern?: never }
55+
| { allowImportNames: string[]; importNames?: never; importNamePattern?: never; allowImportNamePattern?: never }
56+
| { allowImportNamePattern: string; importNames?: never; allowImportNames?: never; importNamePattern?: never }
57+
58+
// Adds oneOf and not constraints, ensuring group or regex are present and mutually exclusive sets for importNames, allowImportNames, etc., as per the schema.
59+
export type ValidNoRestrictedImportPatternOptions = NoRestrictedImportPatternCommonOptions & EitherGroupOrRegEx & EitherNameSpecifiers;
60+
3061
export interface ECMAScript6 extends Linter.RulesRecord {
3162
/**
3263
* Rule to require braces around arrow function bodies.
@@ -291,23 +322,12 @@ export interface ECMAScript6 extends Linter.RulesRecord {
291322
[
292323
...Array<
293324
| string
294-
| {
295-
name: string;
296-
importNames?: string[] | undefined;
297-
message?: string | undefined;
298-
}
325+
| ValidNoRestrictedImportPathOptions
299326
| Partial<{
300-
paths: Array<
301-
| string
302-
| {
303-
name: string;
304-
importNames?: string[] | undefined;
305-
message?: string | undefined;
306-
}
307-
>;
308-
patterns: string[];
309-
}>
310-
>,
327+
paths: Array<string | ValidNoRestrictedImportPathOptions>;
328+
patterns: Array<string | ValidNoRestrictedImportPatternOptions>;
329+
}>
330+
>
311331
]
312332
>;
313333

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy