@hyperlane-xyz/utils 0.0.0-beta-20251201221151
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 +20 -0
- package/dist/addresses.d.ts +65 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +475 -0
- package/dist/addresses.js.map +1 -0
- package/dist/addresses.test.d.ts +2 -0
- package/dist/addresses.test.d.ts.map +1 -0
- package/dist/addresses.test.js +68 -0
- package/dist/addresses.test.js.map +1 -0
- package/dist/amount.d.ts +70 -0
- package/dist/amount.d.ts.map +1 -0
- package/dist/amount.js +143 -0
- package/dist/amount.js.map +1 -0
- package/dist/amount.test.d.ts +2 -0
- package/dist/amount.test.d.ts.map +1 -0
- package/dist/amount.test.js +113 -0
- package/dist/amount.test.js.map +1 -0
- package/dist/arrays.d.ts +11 -0
- package/dist/arrays.d.ts.map +1 -0
- package/dist/arrays.js +26 -0
- package/dist/arrays.js.map +1 -0
- package/dist/arrays.test.d.ts +2 -0
- package/dist/arrays.test.d.ts.map +1 -0
- package/dist/arrays.test.js +77 -0
- package/dist/arrays.test.js.map +1 -0
- package/dist/async.d.ts +66 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +146 -0
- package/dist/async.js.map +1 -0
- package/dist/async.test.d.ts +2 -0
- package/dist/async.test.d.ts.map +1 -0
- package/dist/async.test.js +204 -0
- package/dist/async.test.js.map +1 -0
- package/dist/base58.d.ts +5 -0
- package/dist/base58.d.ts.map +1 -0
- package/dist/base58.js +15 -0
- package/dist/base58.js.map +1 -0
- package/dist/base58.test.d.ts +2 -0
- package/dist/base58.test.d.ts.map +1 -0
- package/dist/base58.test.js +31 -0
- package/dist/base58.test.js.map +1 -0
- package/dist/base64.d.ts +3 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +25 -0
- package/dist/base64.js.map +1 -0
- package/dist/base64.test.d.ts +2 -0
- package/dist/base64.test.d.ts.map +1 -0
- package/dist/base64.test.js +54 -0
- package/dist/base64.test.js.map +1 -0
- package/dist/big-numbers.d.ts +50 -0
- package/dist/big-numbers.d.ts.map +1 -0
- package/dist/big-numbers.js +80 -0
- package/dist/big-numbers.js.map +1 -0
- package/dist/big-numbers.test.d.ts +2 -0
- package/dist/big-numbers.test.d.ts.map +1 -0
- package/dist/big-numbers.test.js +96 -0
- package/dist/big-numbers.test.js.map +1 -0
- package/dist/calldata.d.ts +3 -0
- package/dist/calldata.d.ts.map +1 -0
- package/dist/calldata.js +4 -0
- package/dist/calldata.js.map +1 -0
- package/dist/checkpoints.d.ts +6 -0
- package/dist/checkpoints.d.ts.map +1 -0
- package/dist/checkpoints.js +24 -0
- package/dist/checkpoints.js.map +1 -0
- package/dist/checkpoints.test.d.ts +2 -0
- package/dist/checkpoints.test.d.ts.map +1 -0
- package/dist/checkpoints.test.js +105 -0
- package/dist/checkpoints.test.js.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +84 -0
- package/dist/config.js.map +1 -0
- package/dist/domains.d.ts +2 -0
- package/dist/domains.d.ts.map +1 -0
- package/dist/domains.js +6 -0
- package/dist/domains.js.map +1 -0
- package/dist/env.d.ts +4 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +17 -0
- package/dist/env.js.map +1 -0
- package/dist/env.test.d.ts +2 -0
- package/dist/env.test.d.ts.map +1 -0
- package/dist/env.test.js +16 -0
- package/dist/env.test.js.map +1 -0
- package/dist/eslint-rules/index.d.ts +157 -0
- package/dist/eslint-rules/index.d.ts.map +1 -0
- package/dist/eslint-rules/index.js +58 -0
- package/dist/eslint-rules/index.js.map +1 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.d.ts +4 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.d.ts.map +1 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.js +141 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.js.map +1 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.test.d.ts +2 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.test.d.ts.map +1 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.test.js +258 -0
- package/dist/eslint-rules/no-restricted-imports-from-exports.test.js.map +1 -0
- package/dist/eslint-rules/sort-yaml-arrays.d.ts +39 -0
- package/dist/eslint-rules/sort-yaml-arrays.d.ts.map +1 -0
- package/dist/eslint-rules/sort-yaml-arrays.js +74 -0
- package/dist/eslint-rules/sort-yaml-arrays.js.map +1 -0
- package/dist/eslint-rules/sort-yaml-arrays.test.d.ts +2 -0
- package/dist/eslint-rules/sort-yaml-arrays.test.d.ts.map +1 -0
- package/dist/eslint-rules/sort-yaml-arrays.test.js +621 -0
- package/dist/eslint-rules/sort-yaml-arrays.test.js.map +1 -0
- package/dist/ids.d.ts +20 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +42 -0
- package/dist/ids.js.map +1 -0
- package/dist/ids.test.d.ts +2 -0
- package/dist/ids.test.d.ts.map +1 -0
- package/dist/ids.test.js +39 -0
- package/dist/ids.test.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/logging.d.ts +32 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +146 -0
- package/dist/logging.js.map +1 -0
- package/dist/logging.test.d.ts +2 -0
- package/dist/logging.test.d.ts.map +1 -0
- package/dist/logging.test.js +35 -0
- package/dist/logging.test.js.map +1 -0
- package/dist/math.d.ts +6 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +21 -0
- package/dist/math.js.map +1 -0
- package/dist/math.test.d.ts +2 -0
- package/dist/math.test.d.ts.map +1 -0
- package/dist/math.test.js +45 -0
- package/dist/math.test.js.map +1 -0
- package/dist/messages.d.ts +22 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +64 -0
- package/dist/messages.js.map +1 -0
- package/dist/multisig.d.ts +4 -0
- package/dist/multisig.d.ts.map +1 -0
- package/dist/multisig.js +53 -0
- package/dist/multisig.js.map +1 -0
- package/dist/objects.d.ts +74 -0
- package/dist/objects.d.ts.map +1 -0
- package/dist/objects.js +331 -0
- package/dist/objects.js.map +1 -0
- package/dist/objects.test.d.ts +2 -0
- package/dist/objects.test.d.ts.map +1 -0
- package/dist/objects.test.js +655 -0
- package/dist/objects.test.js.map +1 -0
- package/dist/result.d.ts +11 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +7 -0
- package/dist/result.js.map +1 -0
- package/dist/sets.d.ts +5 -0
- package/dist/sets.d.ts.map +1 -0
- package/dist/sets.js +33 -0
- package/dist/sets.js.map +1 -0
- package/dist/sets.test.d.ts +2 -0
- package/dist/sets.test.d.ts.map +1 -0
- package/dist/sets.test.js +35 -0
- package/dist/sets.test.js.map +1 -0
- package/dist/strings.d.ts +11 -0
- package/dist/strings.d.ts.map +1 -0
- package/dist/strings.js +49 -0
- package/dist/strings.js.map +1 -0
- package/dist/strings.test.d.ts +2 -0
- package/dist/strings.test.d.ts.map +1 -0
- package/dist/strings.test.js +42 -0
- package/dist/strings.test.js.map +1 -0
- package/dist/typeof.d.ts +3 -0
- package/dist/typeof.d.ts.map +1 -0
- package/dist/typeof.js +7 -0
- package/dist/typeof.js.map +1 -0
- package/dist/typeof.test.d.ts +2 -0
- package/dist/typeof.test.d.ts.map +1 -0
- package/dist/typeof.test.js +34 -0
- package/dist/typeof.test.js.map +1 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +23 -0
- package/dist/types.js.map +1 -0
- package/dist/url.d.ts +4 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +34 -0
- package/dist/url.js.map +1 -0
- package/dist/url.test.d.ts +2 -0
- package/dist/url.test.d.ts.map +1 -0
- package/dist/url.test.js +29 -0
- package/dist/url.test.js.map +1 -0
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +6 -0
- package/dist/validation.js.map +1 -0
- package/dist/validation.test.d.ts +2 -0
- package/dist/validation.test.d.ts.map +1 -0
- package/dist/validation.test.js +11 -0
- package/dist/validation.test.js.map +1 -0
- package/dist/validator.d.ts +30 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +76 -0
- package/dist/validator.js.map +1 -0
- package/dist/yaml.d.ts +22 -0
- package/dist/yaml.d.ts.map +1 -0
- package/dist/yaml.js +293 -0
- package/dist/yaml.js.map +1 -0
- package/dist/yaml.test.d.ts +2 -0
- package/dist/yaml.test.d.ts.map +1 -0
- package/dist/yaml.test.js +519 -0
- package/dist/yaml.test.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import yamlParser from 'yaml-eslint-parser';
|
|
2
|
+
export declare const importRestrictionsPlugin: {
|
|
3
|
+
name: string;
|
|
4
|
+
rules: {
|
|
5
|
+
'no-restricted-imports-from-exports': import("eslint").Rule.RuleModule;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const sortYamlArraysPlugin: {
|
|
9
|
+
name: string;
|
|
10
|
+
rules: {
|
|
11
|
+
'sort-yaml-arrays': {
|
|
12
|
+
meta: {
|
|
13
|
+
type: string;
|
|
14
|
+
docs: {
|
|
15
|
+
description: string;
|
|
16
|
+
category: string;
|
|
17
|
+
recommended: boolean;
|
|
18
|
+
url: null;
|
|
19
|
+
};
|
|
20
|
+
fixable: string;
|
|
21
|
+
schema: {
|
|
22
|
+
type: string;
|
|
23
|
+
properties: {
|
|
24
|
+
arrays: {
|
|
25
|
+
type: string;
|
|
26
|
+
items: {
|
|
27
|
+
type: string;
|
|
28
|
+
properties: {
|
|
29
|
+
path: {
|
|
30
|
+
type: string;
|
|
31
|
+
};
|
|
32
|
+
sortKey: {
|
|
33
|
+
type: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
required: string[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
additionalProperties: boolean;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
create(context: import("eslint").Rule.RuleContext): {
|
|
44
|
+
Program(node: import("eslint").Rule.Node): void;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export declare const yamlEslintConfig: ({
|
|
50
|
+
plugins: {
|
|
51
|
+
readonly yml: import("eslint").ESLint.Plugin;
|
|
52
|
+
};
|
|
53
|
+
files?: undefined;
|
|
54
|
+
languageOptions?: undefined;
|
|
55
|
+
rules?: undefined;
|
|
56
|
+
} | {
|
|
57
|
+
files: string[];
|
|
58
|
+
languageOptions: {
|
|
59
|
+
parser: typeof yamlParser;
|
|
60
|
+
};
|
|
61
|
+
rules: {
|
|
62
|
+
"no-irregular-whitespace": "off";
|
|
63
|
+
"no-unused-vars": "off";
|
|
64
|
+
"spaced-comment": "off";
|
|
65
|
+
};
|
|
66
|
+
plugins?: undefined;
|
|
67
|
+
} | {
|
|
68
|
+
rules: {
|
|
69
|
+
"yml/block-mapping-question-indicator-newline": "error";
|
|
70
|
+
"yml/block-mapping": "error";
|
|
71
|
+
"yml/block-sequence-hyphen-indicator-newline": "error";
|
|
72
|
+
"yml/block-sequence": "error";
|
|
73
|
+
"yml/flow-mapping-curly-newline": "error";
|
|
74
|
+
"yml/flow-mapping-curly-spacing": "error";
|
|
75
|
+
"yml/flow-sequence-bracket-newline": "error";
|
|
76
|
+
"yml/flow-sequence-bracket-spacing": "error";
|
|
77
|
+
"yml/indent": "error";
|
|
78
|
+
"yml/key-spacing": "error";
|
|
79
|
+
"yml/no-empty-document": "error";
|
|
80
|
+
"yml/no-empty-key": "error";
|
|
81
|
+
"yml/no-empty-mapping-value": "error";
|
|
82
|
+
"yml/no-empty-sequence-entry": "error";
|
|
83
|
+
"yml/no-irregular-whitespace": "error";
|
|
84
|
+
"yml/no-tab-indent": "error";
|
|
85
|
+
"yml/plain-scalar": "error";
|
|
86
|
+
"yml/quotes": "error";
|
|
87
|
+
"yml/spaced-comment": "error";
|
|
88
|
+
"yml/vue-custom-block/no-parsing-error": "error";
|
|
89
|
+
};
|
|
90
|
+
} | {
|
|
91
|
+
languageOptions: {
|
|
92
|
+
parser: typeof yamlParser;
|
|
93
|
+
};
|
|
94
|
+
plugins: {
|
|
95
|
+
hyperlane: {
|
|
96
|
+
name: string;
|
|
97
|
+
rules: {
|
|
98
|
+
'sort-yaml-arrays': {
|
|
99
|
+
meta: {
|
|
100
|
+
type: string;
|
|
101
|
+
docs: {
|
|
102
|
+
description: string;
|
|
103
|
+
category: string;
|
|
104
|
+
recommended: boolean;
|
|
105
|
+
url: null;
|
|
106
|
+
};
|
|
107
|
+
fixable: string;
|
|
108
|
+
schema: {
|
|
109
|
+
type: string;
|
|
110
|
+
properties: {
|
|
111
|
+
arrays: {
|
|
112
|
+
type: string;
|
|
113
|
+
items: {
|
|
114
|
+
type: string;
|
|
115
|
+
properties: {
|
|
116
|
+
path: {
|
|
117
|
+
type: string;
|
|
118
|
+
};
|
|
119
|
+
sortKey: {
|
|
120
|
+
type: string;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
required: string[];
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
additionalProperties: boolean;
|
|
128
|
+
}[];
|
|
129
|
+
};
|
|
130
|
+
create(context: import("eslint").Rule.RuleContext): {
|
|
131
|
+
Program(node: import("eslint").Rule.Node): void;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
rules: {
|
|
138
|
+
'yml/sort-keys': string[];
|
|
139
|
+
'yml/flow-mapping-curly-spacing': string[];
|
|
140
|
+
'yml/sort-sequence-values': (string | {
|
|
141
|
+
pathPattern: string;
|
|
142
|
+
order: {
|
|
143
|
+
type: string;
|
|
144
|
+
caseSensitive: boolean;
|
|
145
|
+
natural: boolean;
|
|
146
|
+
};
|
|
147
|
+
minValues: number;
|
|
148
|
+
})[];
|
|
149
|
+
'hyperlane/sort-yaml-arrays': (string | {
|
|
150
|
+
arrays: {
|
|
151
|
+
path: string;
|
|
152
|
+
sortKey: string;
|
|
153
|
+
}[];
|
|
154
|
+
})[];
|
|
155
|
+
};
|
|
156
|
+
})[];
|
|
157
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eslint-rules/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAK5C,eAAO,MAAM,wBAAwB;;;;;CAKpC,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAKhC,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwC5B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import eslintPluginYml from 'eslint-plugin-yml';
|
|
2
|
+
import yamlParser from 'yaml-eslint-parser';
|
|
3
|
+
import noRestrictedImportsFromExports from './no-restricted-imports-from-exports.js';
|
|
4
|
+
import sortYamlArrays from './sort-yaml-arrays.js';
|
|
5
|
+
export const importRestrictionsPlugin = {
|
|
6
|
+
name: '@hyperlane/import-restrictions',
|
|
7
|
+
rules: {
|
|
8
|
+
'no-restricted-imports-from-exports': noRestrictedImportsFromExports,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export const sortYamlArraysPlugin = {
|
|
12
|
+
name: '@hyperlane/sort-yaml-arrays',
|
|
13
|
+
rules: {
|
|
14
|
+
'sort-yaml-arrays': sortYamlArrays,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const yamlEslintConfig = [
|
|
18
|
+
...eslintPluginYml.configs['flat/standard'],
|
|
19
|
+
{
|
|
20
|
+
languageOptions: {
|
|
21
|
+
parser: yamlParser,
|
|
22
|
+
},
|
|
23
|
+
plugins: {
|
|
24
|
+
hyperlane: sortYamlArraysPlugin,
|
|
25
|
+
},
|
|
26
|
+
rules: {
|
|
27
|
+
'yml/sort-keys': ['error'],
|
|
28
|
+
'yml/flow-mapping-curly-spacing': ['error', 'always'],
|
|
29
|
+
'yml/sort-sequence-values': [
|
|
30
|
+
'error',
|
|
31
|
+
{
|
|
32
|
+
pathPattern: '.*',
|
|
33
|
+
order: {
|
|
34
|
+
type: 'asc',
|
|
35
|
+
caseSensitive: true,
|
|
36
|
+
natural: false,
|
|
37
|
+
},
|
|
38
|
+
minValues: 2,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
'hyperlane/sort-yaml-arrays': [
|
|
42
|
+
'error',
|
|
43
|
+
{
|
|
44
|
+
arrays: [
|
|
45
|
+
{ path: 'tokens', sortKey: 'chainName' },
|
|
46
|
+
{ path: 'tokens[].connections', sortKey: 'token' },
|
|
47
|
+
{ path: '*.interchainSecurityModule.modules', sortKey: 'type' },
|
|
48
|
+
{
|
|
49
|
+
path: '*.interchainSecurityModule.modules[].domains.*.modules',
|
|
50
|
+
sortKey: 'type',
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eslint-rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAE5C,OAAO,8BAA8B,MAAM,yCAAyC,CAAC;AACrF,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAEnD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,IAAI,EAAE,gCAAgC;IACtC,KAAK,EAAE;QACL,oCAAoC,EAAE,8BAA8B;KACrE;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,6BAA6B;IACnC,KAAK,EAAE;QACL,kBAAkB,EAAE,cAAc;KACnC;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,GAAG,eAAe,CAAC,OAAO,CAAC,eAAe,CAAC;IAC3C;QACE,eAAe,EAAE;YACf,MAAM,EAAE,UAAU;SACnB;QACD,OAAO,EAAE;YACP,SAAS,EAAE,oBAAoB;SAChC;QACD,KAAK,EAAE;YACL,eAAe,EAAE,CAAC,OAAO,CAAC;YAC1B,gCAAgC,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;YACrD,0BAA0B,EAAE;gBAC1B,OAAO;gBACP;oBACE,WAAW,EAAE,IAAI;oBACjB,KAAK,EAAE;wBACL,IAAI,EAAE,KAAK;wBACX,aAAa,EAAE,IAAI;wBACnB,OAAO,EAAE,KAAK;qBACf;oBACD,SAAS,EAAE,CAAC;iBACb;aACF;YACD,4BAA4B,EAAE;gBAC5B,OAAO;gBACP;oBACE,MAAM,EAAE;wBACN,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE;wBACxC,EAAE,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,OAAO,EAAE;wBAClD,EAAE,IAAI,EAAE,oCAAoC,EAAE,OAAO,EAAE,MAAM,EAAE;wBAC/D;4BACE,IAAI,EAAE,wDAAwD;4BAC9D,OAAO,EAAE,MAAM;yBAChB;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-restricted-imports-from-exports.d.ts","sourceRoot":"","sources":["../../src/eslint-rules/no-restricted-imports-from-exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAgC9B,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,UA8JhB,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// eslint-disable-next-line no-restricted-imports
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
|
+
import path from 'path';
|
|
5
|
+
const NODE_BUILTIN_MODULES = [
|
|
6
|
+
'fs',
|
|
7
|
+
'path',
|
|
8
|
+
'child_process',
|
|
9
|
+
'os',
|
|
10
|
+
'process',
|
|
11
|
+
'http',
|
|
12
|
+
'https',
|
|
13
|
+
'net',
|
|
14
|
+
'dgram',
|
|
15
|
+
'dns',
|
|
16
|
+
'crypto',
|
|
17
|
+
'tls',
|
|
18
|
+
'cluster',
|
|
19
|
+
'stream',
|
|
20
|
+
'vm',
|
|
21
|
+
'readline',
|
|
22
|
+
];
|
|
23
|
+
const rule = {
|
|
24
|
+
meta: {
|
|
25
|
+
type: 'problem',
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Disallow client-restricted imports in files exported from specified entry points',
|
|
28
|
+
category: 'Best Practices',
|
|
29
|
+
recommended: true,
|
|
30
|
+
},
|
|
31
|
+
messages: {
|
|
32
|
+
restrictedFsImport: 'Files exported from {{ mainEntry }} should not import "{{ moduleName }}" which is exported from {{ restrictedEntry }}',
|
|
33
|
+
restrictedNodeImport: 'Files exported from {{ mainEntry }} should not import Node.js built-in module "{{ moduleName }}"',
|
|
34
|
+
},
|
|
35
|
+
schema: [
|
|
36
|
+
{
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
mainEntry: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
default: './src/index.ts',
|
|
42
|
+
},
|
|
43
|
+
restrictedEntry: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
default: './src/index-fs.ts',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
create(context) {
|
|
53
|
+
const options = (context.options[0] || {});
|
|
54
|
+
const mainEntry = options.mainEntry || './src/index.ts';
|
|
55
|
+
const restrictedEntry = options.restrictedEntry || './src/index-fs.ts';
|
|
56
|
+
const resolvePathFromCwd = (relativePath) => path.resolve(context.cwd, relativePath);
|
|
57
|
+
const extractNamedExports = (content) => {
|
|
58
|
+
const exportBlocks = content.match(/export\s+\{[^}]+\}/g) || [];
|
|
59
|
+
const namedExports = exportBlocks.join(' ').match(/[a-zA-Z0-9_]+(?=\s*[,}])/g) || [];
|
|
60
|
+
return namedExports.map((name) => name.trim());
|
|
61
|
+
};
|
|
62
|
+
const extractReExports = (content, basePath) => {
|
|
63
|
+
const reExportMatches = content.match(/export\s+(?:[\s\S]*?)\s+from\s+['"](.+)['"]/g) || [];
|
|
64
|
+
const reExportPaths = reExportMatches
|
|
65
|
+
.map((match) => {
|
|
66
|
+
const pathMatch = match.match(/from\s+['"](.+)['"]/);
|
|
67
|
+
return pathMatch ? pathMatch[1] : null;
|
|
68
|
+
})
|
|
69
|
+
.filter((path) => path !== null && (path.startsWith('./') || path.startsWith('../')));
|
|
70
|
+
return reExportPaths.map((exportPath) => {
|
|
71
|
+
const resolvedPath = exportPath.endsWith('.js')
|
|
72
|
+
? exportPath.replace(/\.js$/, '.ts')
|
|
73
|
+
: exportPath;
|
|
74
|
+
return path.resolve(path.dirname(basePath), resolvedPath);
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const extractExportsFromFile = (filePath) => {
|
|
78
|
+
try {
|
|
79
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
80
|
+
return [
|
|
81
|
+
...extractNamedExports(content),
|
|
82
|
+
...extractReExports(content, filePath),
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
catch (_) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const isPathPartOfExport = (filePath, exportPath) => typeof exportPath === 'string' &&
|
|
90
|
+
exportPath.includes('/') &&
|
|
91
|
+
filePath.includes(exportPath.replace(/\.ts$/, ''));
|
|
92
|
+
const indexTsPath = resolvePathFromCwd(mainEntry);
|
|
93
|
+
const indexFsPath = resolvePathFromCwd(restrictedEntry);
|
|
94
|
+
const indexExports = extractExportsFromFile(indexTsPath);
|
|
95
|
+
const fsIndexExports = extractExportsFromFile(indexFsPath);
|
|
96
|
+
const isFileExportedFromIndex = (filePath) => indexExports.some((exportPath) => isPathPartOfExport(filePath, exportPath));
|
|
97
|
+
const isExportedFromFsIndex = (importPath) => fsIndexExports.some((fsExport) => isPathPartOfExport(importPath, fsExport));
|
|
98
|
+
const isNodeBuiltinModuleOrSubpath = (importSource) => {
|
|
99
|
+
if (NODE_BUILTIN_MODULES.includes(importSource)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
const parts = importSource.split('/');
|
|
103
|
+
return (NODE_BUILTIN_MODULES.includes(parts[0]) &&
|
|
104
|
+
parts.length > 1);
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
ImportDeclaration(node) {
|
|
108
|
+
const currentFilePath = context.getFilename();
|
|
109
|
+
if (!isFileExportedFromIndex(currentFilePath))
|
|
110
|
+
return;
|
|
111
|
+
const importSource = node.source.value;
|
|
112
|
+
if (isNodeBuiltinModuleOrSubpath(importSource)) {
|
|
113
|
+
context.report({
|
|
114
|
+
node,
|
|
115
|
+
messageId: 'restrictedNodeImport',
|
|
116
|
+
data: {
|
|
117
|
+
moduleName: importSource,
|
|
118
|
+
mainEntry,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (typeof importSource === 'string' && importSource.startsWith('.')) {
|
|
123
|
+
const resolvedImportPath = path.resolve(path.dirname(currentFilePath), importSource);
|
|
124
|
+
if (isExportedFromFsIndex(resolvedImportPath)) {
|
|
125
|
+
context.report({
|
|
126
|
+
node,
|
|
127
|
+
messageId: 'restrictedFsImport',
|
|
128
|
+
data: {
|
|
129
|
+
moduleName: importSource,
|
|
130
|
+
mainEntry,
|
|
131
|
+
restrictedEntry,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
export default rule;
|
|
141
|
+
//# sourceMappingURL=no-restricted-imports-from-exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-restricted-imports-from-exports.js","sourceRoot":"","sources":["../../src/eslint-rules/no-restricted-imports-from-exports.ts"],"names":[],"mappings":"AACA,iDAAiD;AACjD,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,iDAAiD;AACjD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,oBAAoB,GAAG;IAC3B,IAAI;IACJ,MAAM;IACN,eAAe;IACf,IAAI;IACJ,SAAS;IACT,MAAM;IACN,OAAO;IACP,KAAK;IACL,OAAO;IACP,KAAK;IACL,QAAQ;IACR,KAAK;IACL,SAAS;IACT,QAAQ;IACR,IAAI;IACJ,UAAU;CACF,CAAC;AASX,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EACT,kFAAkF;YACpF,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,IAAI;SAClB;QACD,QAAQ,EAAE;YACR,kBAAkB,EAChB,uHAAuH;YACzH,oBAAoB,EAClB,kGAAkG;SACrG;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,SAAS,EAAE;wBACT,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,gBAAgB;qBAC1B;oBACD,eAAe,EAAE;wBACf,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,mBAAmB;qBAC7B;iBACF;gBACD,oBAAoB,E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YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBACrE,MAAM,kBAAkB,GAAG,IAAI,CAAC,OAAO,CACrC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAC7B,YAAY,CACb,CAAC;oBAEF,IAAI,qBAAqB,CAAC,kBAAkB,CAAC,EAAE,CAAC;wBAC9C,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,oBAAoB;4BAC/B,IAAI,EAAE;gCACJ,UAAU,EAAE,YAAY;gCACxB,SAAS;gCACT,eAAe;6BAChB;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-restricted-imports-from-exports.test.d.ts","sourceRoot":"","sources":["../../src/eslint-rules/no-restricted-imports-from-exports.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import sinon from 'sinon';
|
|
5
|
+
import rule from './no-restricted-imports-from-exports.js';
|
|
6
|
+
describe('no-restricted-imports-from-exports rule', () => {
|
|
7
|
+
// Mock file contents to simulate index exports
|
|
8
|
+
const exportedFileContents = {
|
|
9
|
+
'./src/index.ts': "export { componentA } from './components/componentA';\nexport { componentB } from './components/componentB';",
|
|
10
|
+
'./src/index-fs.ts': "export { fileUtil } from './utils/fileUtil';",
|
|
11
|
+
};
|
|
12
|
+
// Path mapping for test fixtures
|
|
13
|
+
const pathMappings = {
|
|
14
|
+
'./src/index.ts': './src/index.ts',
|
|
15
|
+
'./src/index-fs.ts': './src/index-fs.ts',
|
|
16
|
+
'components/componentA': './src/components/componentA',
|
|
17
|
+
'components/componentB': './src/components/componentB',
|
|
18
|
+
'components/nested/componentA': './src/components/nested/componentA',
|
|
19
|
+
'utils/fileUtil': './src/utils/fileUtil',
|
|
20
|
+
'utils/otherUtil': './src/utils/otherUtil',
|
|
21
|
+
};
|
|
22
|
+
function setupStubs() {
|
|
23
|
+
// Stub fs.readFileSync to return mock file contents
|
|
24
|
+
sinon
|
|
25
|
+
.stub(fs, 'readFileSync')
|
|
26
|
+
.callsFake((filePath) => typeof filePath === 'string'
|
|
27
|
+
? exportedFileContents[filePath] || ''
|
|
28
|
+
: '');
|
|
29
|
+
// Stub path.resolve to simplify path resolution in tests
|
|
30
|
+
sinon.stub(path, 'resolve').callsFake(function (...args) {
|
|
31
|
+
const lastArg = args[args.length - 1];
|
|
32
|
+
if (typeof lastArg !== 'string') {
|
|
33
|
+
return String(lastArg);
|
|
34
|
+
}
|
|
35
|
+
for (const [pattern, mapping] of Object.entries(pathMappings)) {
|
|
36
|
+
if (lastArg.includes(pattern)) {
|
|
37
|
+
return mapping;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return lastArg;
|
|
41
|
+
});
|
|
42
|
+
sinon
|
|
43
|
+
.stub(path, 'dirname')
|
|
44
|
+
.callsFake((filePath) => filePath.substring(0, filePath.lastIndexOf('/') || 0));
|
|
45
|
+
}
|
|
46
|
+
// Helper function to test import validations in different scenarios
|
|
47
|
+
function verifyImport({ sourceFile, importPath, expectedError, shouldPass = false, options = {}, }) {
|
|
48
|
+
const errors = [];
|
|
49
|
+
const context = {
|
|
50
|
+
getFilename: () => sourceFile,
|
|
51
|
+
cwd: () => '.',
|
|
52
|
+
report: (err) => errors.push(err),
|
|
53
|
+
options: [options],
|
|
54
|
+
};
|
|
55
|
+
const ruleInstance = rule.create(context);
|
|
56
|
+
if (ruleInstance?.ImportDeclaration) {
|
|
57
|
+
ruleInstance.ImportDeclaration({
|
|
58
|
+
type: 'ImportDeclaration',
|
|
59
|
+
source: {
|
|
60
|
+
type: 'Literal',
|
|
61
|
+
value: importPath,
|
|
62
|
+
raw: `'${importPath}'`,
|
|
63
|
+
},
|
|
64
|
+
specifiers: [],
|
|
65
|
+
parent: {},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (expectedError || !shouldPass) {
|
|
69
|
+
expect(errors.length).to.equal(1, `Import from ${sourceFile} to ${importPath} should report an error`);
|
|
70
|
+
if (expectedError) {
|
|
71
|
+
expect(errors[0].messageId).to.equal(expectedError, `Import should report error type ${expectedError}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
expect(errors.length).to.equal(0, `Import from ${sourceFile} to ${importPath} should not report any errors`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
setupStubs();
|
|
80
|
+
});
|
|
81
|
+
afterEach(() => {
|
|
82
|
+
// Restore all stubs
|
|
83
|
+
sinon.restore();
|
|
84
|
+
});
|
|
85
|
+
describe('Non-exported files - Files not included in index exports', () => {
|
|
86
|
+
it('should allow importing node modules in non-exported files', () => {
|
|
87
|
+
verifyImport({
|
|
88
|
+
sourceFile: './src/other.ts',
|
|
89
|
+
importPath: 'fs',
|
|
90
|
+
shouldPass: true,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
it('should allow importing any modules in non-exported files without restrictions', () => {
|
|
94
|
+
const sourceFile = './src/other.ts';
|
|
95
|
+
verifyImport({
|
|
96
|
+
sourceFile,
|
|
97
|
+
importPath: './components/other',
|
|
98
|
+
shouldPass: true,
|
|
99
|
+
});
|
|
100
|
+
verifyImport({
|
|
101
|
+
sourceFile,
|
|
102
|
+
importPath: './utils/fileUtil',
|
|
103
|
+
shouldPass: true,
|
|
104
|
+
});
|
|
105
|
+
verifyImport({
|
|
106
|
+
sourceFile,
|
|
107
|
+
importPath: 'path',
|
|
108
|
+
shouldPass: true,
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('Exported files - Files that are exported through index.ts', () => {
|
|
113
|
+
const exportedComponentFile = './src/components/componentA.ts';
|
|
114
|
+
it('should allow importing regular modules from exported files', () => {
|
|
115
|
+
verifyImport({
|
|
116
|
+
sourceFile: exportedComponentFile,
|
|
117
|
+
importPath: './components/other',
|
|
118
|
+
shouldPass: true,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it('should disallow importing node modules from exported files to prevent side effects', () => {
|
|
122
|
+
verifyImport({
|
|
123
|
+
sourceFile: exportedComponentFile,
|
|
124
|
+
importPath: 'fs',
|
|
125
|
+
expectedError: 'restrictedNodeImport',
|
|
126
|
+
});
|
|
127
|
+
verifyImport({
|
|
128
|
+
sourceFile: exportedComponentFile,
|
|
129
|
+
importPath: 'path',
|
|
130
|
+
expectedError: 'restrictedNodeImport',
|
|
131
|
+
});
|
|
132
|
+
verifyImport({
|
|
133
|
+
sourceFile: exportedComponentFile,
|
|
134
|
+
importPath: 'crypto',
|
|
135
|
+
expectedError: 'restrictedNodeImport',
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
it('should disallow importing from fs-indexed modules in exported components', () => {
|
|
139
|
+
verifyImport({
|
|
140
|
+
sourceFile: exportedComponentFile,
|
|
141
|
+
importPath: './utils/fileUtil',
|
|
142
|
+
expectedError: 'restrictedFsImport',
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
it('should handle relative imports correctly and detect restricted fs imports', () => {
|
|
146
|
+
verifyImport({
|
|
147
|
+
sourceFile: exportedComponentFile,
|
|
148
|
+
importPath: '../utils/fileUtil',
|
|
149
|
+
expectedError: 'restrictedFsImport',
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
it('should allow importing scoped packages even from exported components', () => {
|
|
153
|
+
verifyImport({
|
|
154
|
+
sourceFile: exportedComponentFile,
|
|
155
|
+
importPath: '@scoped/fs-module',
|
|
156
|
+
shouldPass: true,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it('should allow files exported from index-fs.ts to import node modules directly', () => {
|
|
160
|
+
const fileUtilPath = './src/utils/fileUtil.ts';
|
|
161
|
+
verifyImport({
|
|
162
|
+
sourceFile: fileUtilPath,
|
|
163
|
+
importPath: 'fs',
|
|
164
|
+
shouldPass: true,
|
|
165
|
+
});
|
|
166
|
+
verifyImport({
|
|
167
|
+
sourceFile: fileUtilPath,
|
|
168
|
+
importPath: 'crypto',
|
|
169
|
+
shouldPass: true,
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('Edge cases', () => {
|
|
174
|
+
const exportedComponentFile = './src/components/componentA.ts';
|
|
175
|
+
it('should handle subpaths of node modules correctly and restrict them in exported files', () => {
|
|
176
|
+
verifyImport({
|
|
177
|
+
sourceFile: exportedComponentFile,
|
|
178
|
+
importPath: 'fs/promises',
|
|
179
|
+
expectedError: 'restrictedNodeImport',
|
|
180
|
+
});
|
|
181
|
+
verifyImport({
|
|
182
|
+
sourceFile: exportedComponentFile,
|
|
183
|
+
importPath: 'path/posix',
|
|
184
|
+
expectedError: 'restrictedNodeImport',
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
it('should allow similarly named packages that are not actual node modules', () => {
|
|
188
|
+
verifyImport({
|
|
189
|
+
sourceFile: exportedComponentFile,
|
|
190
|
+
importPath: 'fstest',
|
|
191
|
+
shouldPass: true,
|
|
192
|
+
});
|
|
193
|
+
verifyImport({
|
|
194
|
+
sourceFile: exportedComponentFile,
|
|
195
|
+
importPath: 'fs-test',
|
|
196
|
+
shouldPass: true,
|
|
197
|
+
});
|
|
198
|
+
verifyImport({
|
|
199
|
+
sourceFile: exportedComponentFile,
|
|
200
|
+
importPath: 'path-extra',
|
|
201
|
+
shouldPass: true,
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
it('should handle non-existent files gracefully without throwing errors', () => {
|
|
205
|
+
verifyImport({
|
|
206
|
+
sourceFile: exportedComponentFile,
|
|
207
|
+
importPath: './non-existent-file',
|
|
208
|
+
shouldPass: true,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('Custom entry points', () => {
|
|
213
|
+
const customExportedFileContents = {
|
|
214
|
+
'./src/main.ts': "export { customComponent } from './components/customComponent';",
|
|
215
|
+
'./src/restricted.ts': "export { restrictedUtil } from './utils/restrictedUtil';",
|
|
216
|
+
};
|
|
217
|
+
beforeEach(() => {
|
|
218
|
+
// Add custom file contents to the existing exportedFileContents
|
|
219
|
+
Object.assign(exportedFileContents, customExportedFileContents);
|
|
220
|
+
// Add custom path mappings
|
|
221
|
+
Object.assign(pathMappings, {
|
|
222
|
+
'./src/main.ts': './src/main.ts',
|
|
223
|
+
'./src/restricted.ts': './src/restricted.ts',
|
|
224
|
+
'components/customComponent': './src/components/customComponent',
|
|
225
|
+
'utils/restrictedUtil': './src/utils/restrictedUtil',
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
it('should respect custom main and restricted entry points', () => {
|
|
229
|
+
const options = {
|
|
230
|
+
mainEntry: './src/main.ts',
|
|
231
|
+
restrictedEntry: './src/restricted.ts',
|
|
232
|
+
};
|
|
233
|
+
// Test with custom entry points
|
|
234
|
+
verifyImport({
|
|
235
|
+
sourceFile: './src/components/customComponent.ts',
|
|
236
|
+
importPath: './utils/restrictedUtil',
|
|
237
|
+
expectedError: 'restrictedFsImport',
|
|
238
|
+
options,
|
|
239
|
+
});
|
|
240
|
+
// Should still work for node modules
|
|
241
|
+
verifyImport({
|
|
242
|
+
sourceFile: './src/components/customComponent.ts',
|
|
243
|
+
importPath: 'fs',
|
|
244
|
+
expectedError: 'restrictedNodeImport',
|
|
245
|
+
options,
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
it('should fall back to defaults when no options provided', () => {
|
|
249
|
+
// Test with default entry points
|
|
250
|
+
verifyImport({
|
|
251
|
+
sourceFile: './src/components/componentA.ts',
|
|
252
|
+
importPath: './utils/fileUtil',
|
|
253
|
+
expectedError: 'restrictedFsImport',
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
//# sourceMappingURL=no-restricted-imports-from-exports.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-restricted-imports-from-exports.test.js","sourceRoot":"","sources":["../../src/eslint-rules/no-restricted-imports-from-exports.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,IAAI,MAAM,yCAAyC,CAAC;AAkB3D,QAAQ,CAAC,yCAAyC,EAAE,GAAG,EAAE;IACvD,+CAA+C;IAC/C,MAAM,oBAAoB,GAAyB;QACjD,gBAAgB,EACd,8GAA8G;QAChH,mBAAmB,EAAE,8CAA8C;KACpE,CAAC;IAEF,iCAAiC;IACjC,MAAM,YAAY,GAAiB;QACjC,gBAAgB,EAAE,gBAAgB;QAClC,mBAAmB,EAAE,mBAAmB;QAExC,uBAAuB,EAAE,6BAA6B;QACtD,uBAAuB,EAAE,6BAA6B;QACtD,8BAA8B,EAAE,oCAAoC;QAEpE,gBAAgB,EAAE,sBAAsB;QACxC,iBAAiB,EAAE,uBAAuB;KAC3C,CAAC;IAEF,SAAS,UAAU;QACjB,oDAAoD;QACpD,KAAK;aACF,IAAI,CAAC,EAAE,EAAE,cAAc,CAAC;aACxB,SAAS,CAAC,CAAC,QAAiC,EAAE,EAAE,CAC/C,OAAO,QAAQ,KAAK,QAAQ;YAC1B,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,IAAI,EAAE;YACtC,CAAC,CAAC,EAAE,CACP,CAAC;QAEJ,yDAAyD;QACzD,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,SAAS,CAAC,UACpC,GAAG,IAAe;YAElB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YA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