@ms-cloudpack/eslint-plugin 0.7.0 → 0.8.1
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/lib/configs/index.d.ts +93 -0
- package/lib/configs/index.d.ts.map +1 -0
- package/lib/configs/index.js +36 -0
- package/lib/configs/index.js.map +1 -0
- package/lib/index.d.ts +105 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/plugin.d.ts +15 -0
- package/lib/plugin.d.ts.map +1 -0
- package/lib/plugin.js +16 -0
- package/lib/plugin.js.map +1 -0
- package/lib/rules/no-test-exports.d.ts +18 -0
- package/lib/rules/no-test-exports.d.ts.map +1 -0
- package/lib/rules/no-test-exports.js +131 -0
- package/lib/rules/no-test-exports.js.map +1 -0
- package/lib/rules/no-unsupported-imports.d.ts +14 -0
- package/lib/rules/no-unsupported-imports.d.ts.map +1 -0
- package/lib/rules/no-unsupported-imports.js +172 -0
- package/lib/rules/no-unsupported-imports.js.map +1 -0
- package/lib/utils/PackageJson.d.ts +43 -0
- package/lib/utils/PackageJson.d.ts.map +1 -0
- package/lib/utils/PackageJson.js +3 -0
- package/lib/utils/PackageJson.js.map +1 -0
- package/lib/utils/createRule.d.ts +41 -0
- package/lib/utils/createRule.d.ts.map +1 -0
- package/lib/utils/createRule.js +29 -0
- package/lib/utils/createRule.js.map +1 -0
- package/lib/utils/getImportPathLiteralNode.d.ts +11 -0
- package/lib/utils/getImportPathLiteralNode.d.ts.map +1 -0
- package/lib/utils/getImportPathLiteralNode.js +44 -0
- package/lib/utils/getImportPathLiteralNode.js.map +1 -0
- package/lib/utils/getPackageInfo.d.ts +16 -0
- package/lib/utils/getPackageInfo.d.ts.map +1 -0
- package/lib/utils/getPackageInfo.js +57 -0
- package/lib/utils/getPackageInfo.js.map +1 -0
- package/lib/utils/getRegexpsFromStrings.d.ts +6 -0
- package/lib/utils/getRegexpsFromStrings.d.ts.map +1 -0
- package/lib/utils/getRegexpsFromStrings.js +8 -0
- package/lib/utils/getRegexpsFromStrings.js.map +1 -0
- package/lib/utils/testExports/extractIdentifiersFromExport.d.ts +6 -0
- package/lib/utils/testExports/extractIdentifiersFromExport.d.ts.map +1 -0
- package/lib/utils/testExports/extractIdentifiersFromExport.js +54 -0
- package/lib/utils/testExports/extractIdentifiersFromExport.js.map +1 -0
- package/lib/utils/testExports/isIncludedIndexFile.d.ts +10 -0
- package/lib/utils/testExports/isIncludedIndexFile.d.ts.map +1 -0
- package/lib/utils/testExports/isIncludedIndexFile.js +24 -0
- package/lib/utils/testExports/isIncludedIndexFile.js.map +1 -0
- package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts +19 -0
- package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts.map +1 -0
- package/lib/utils/unsupportedImports/parseImportIfRelevant.js +35 -0
- package/lib/utils/unsupportedImports/parseImportIfRelevant.js.map +1 -0
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts +8 -0
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts.map +1 -0
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js +34 -0
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js.map +1 -0
- package/lib/utils/unsupportedImports/resolvePackageRoot.d.ts +7 -0
- package/lib/utils/unsupportedImports/resolvePackageRoot.d.ts.map +1 -0
- package/lib/utils/unsupportedImports/resolvePackageRoot.js +45 -0
- package/lib/utils/unsupportedImports/resolvePackageRoot.js.map +1 -0
- package/package.json +10 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export declare const configs: {
|
|
2
|
+
recommended: {
|
|
3
|
+
name: string;
|
|
4
|
+
plugins: {
|
|
5
|
+
'@ms-cloudpack': {
|
|
6
|
+
meta: {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
namespace: string;
|
|
10
|
+
};
|
|
11
|
+
rules: {
|
|
12
|
+
'no-test-exports': import("../utils/createRule.ts").RuleModule<import("../rules/no-test-exports.ts").RuleOptions, import("../rules/no-test-exports.ts").MessageIds>;
|
|
13
|
+
'no-unsupported-imports': import("../utils/createRule.ts").RuleModule<import("../rules/no-unsupported-imports.ts").RuleOptions, import("../rules/no-unsupported-imports.ts").MessageIds>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
rules: {
|
|
18
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
19
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
20
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
'recommended-requiring-type-checking': {
|
|
24
|
+
rules: {
|
|
25
|
+
'@typescript-eslint/consistent-type-imports': "error" | "warn";
|
|
26
|
+
'@typescript-eslint/consistent-type-exports': "error" | "warn";
|
|
27
|
+
'@typescript-eslint/no-import-type-side-effects': "error" | "warn";
|
|
28
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
29
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
30
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
31
|
+
};
|
|
32
|
+
name: string;
|
|
33
|
+
plugins: {
|
|
34
|
+
'@ms-cloudpack': {
|
|
35
|
+
meta: {
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
namespace: string;
|
|
39
|
+
};
|
|
40
|
+
rules: {
|
|
41
|
+
'no-test-exports': import("../utils/createRule.ts").RuleModule<import("../rules/no-test-exports.ts").RuleOptions, import("../rules/no-test-exports.ts").MessageIds>;
|
|
42
|
+
'no-unsupported-imports': import("../utils/createRule.ts").RuleModule<import("../rules/no-unsupported-imports.ts").RuleOptions, import("../rules/no-unsupported-imports.ts").MessageIds>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
onboarding: {
|
|
48
|
+
name: string;
|
|
49
|
+
plugins: {
|
|
50
|
+
'@ms-cloudpack': {
|
|
51
|
+
meta: {
|
|
52
|
+
name: string;
|
|
53
|
+
version: string;
|
|
54
|
+
namespace: string;
|
|
55
|
+
};
|
|
56
|
+
rules: {
|
|
57
|
+
'no-test-exports': import("../utils/createRule.ts").RuleModule<import("../rules/no-test-exports.ts").RuleOptions, import("../rules/no-test-exports.ts").MessageIds>;
|
|
58
|
+
'no-unsupported-imports': import("../utils/createRule.ts").RuleModule<import("../rules/no-unsupported-imports.ts").RuleOptions, import("../rules/no-unsupported-imports.ts").MessageIds>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
rules: {
|
|
63
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
64
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
65
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
'onboarding-requiring-type-checking': {
|
|
69
|
+
rules: {
|
|
70
|
+
'@typescript-eslint/consistent-type-imports': "error" | "warn";
|
|
71
|
+
'@typescript-eslint/consistent-type-exports': "error" | "warn";
|
|
72
|
+
'@typescript-eslint/no-import-type-side-effects': "error" | "warn";
|
|
73
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
74
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
75
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
76
|
+
};
|
|
77
|
+
name: string;
|
|
78
|
+
plugins: {
|
|
79
|
+
'@ms-cloudpack': {
|
|
80
|
+
meta: {
|
|
81
|
+
name: string;
|
|
82
|
+
version: string;
|
|
83
|
+
namespace: string;
|
|
84
|
+
};
|
|
85
|
+
rules: {
|
|
86
|
+
'no-test-exports': import("../utils/createRule.ts").RuleModule<import("../rules/no-test-exports.ts").RuleOptions, import("../rules/no-test-exports.ts").MessageIds>;
|
|
87
|
+
'no-unsupported-imports': import("../utils/createRule.ts").RuleModule<import("../rules/no-unsupported-imports.ts").RuleOptions, import("../rules/no-unsupported-imports.ts").MessageIds>;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/configs/index.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAKnB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { basePlugin } from "../plugin.js";
|
|
2
|
+
function makeConfig(name, level) {
|
|
3
|
+
return {
|
|
4
|
+
name: `@ms-cloudpack/${name}`,
|
|
5
|
+
plugins: {
|
|
6
|
+
'@ms-cloudpack': basePlugin,
|
|
7
|
+
// @typescript-eslint and @rnx-kit are intentionally omitted: consumers must register plugins
|
|
8
|
+
// themselves (e.g. via tseslint.configs.recommended*) to avoid "Cannot redefine plugin"
|
|
9
|
+
// errors when the same plugin key is registered from two different import paths.
|
|
10
|
+
},
|
|
11
|
+
rules: {
|
|
12
|
+
'@ms-cloudpack/no-unsupported-imports': level,
|
|
13
|
+
'@rnx-kit/no-const-enum': level,
|
|
14
|
+
'@rnx-kit/no-export-all': level,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function makeTypeCheckedConfig(name, level) {
|
|
19
|
+
const baseConfig = makeConfig(name + '-type-checked', level);
|
|
20
|
+
return {
|
|
21
|
+
...baseConfig,
|
|
22
|
+
rules: {
|
|
23
|
+
...baseConfig.rules,
|
|
24
|
+
'@typescript-eslint/consistent-type-imports': level,
|
|
25
|
+
'@typescript-eslint/consistent-type-exports': level,
|
|
26
|
+
'@typescript-eslint/no-import-type-side-effects': level,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export const configs = {
|
|
31
|
+
recommended: makeConfig('recommended', 'error'),
|
|
32
|
+
'recommended-requiring-type-checking': makeTypeCheckedConfig('recommended', 'error'),
|
|
33
|
+
onboarding: makeConfig('onboarding', 'warn'),
|
|
34
|
+
'onboarding-requiring-type-checking': makeTypeCheckedConfig('onboarding', 'warn'),
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/configs/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,SAAS,UAAU,CAAC,IAAY,EAAE,KAAuB;IACvD,OAAO;QACL,IAAI,EAAE,iBAAiB,IAAI,EAAE;QAC7B,OAAO,EAAE;YACP,eAAe,EAAE,UAAU;YAC3B,6FAA6F;YAC7F,wFAAwF;YACxF,iFAAiF;SAClF;QACD,KAAK,EAAE;YACL,sCAAsC,EAAE,KAAK;YAC7C,wBAAwB,EAAE,KAAK;YAC/B,wBAAwB,EAAE,KAAK;SAChC;KACmC,CAAC;AACzC,CAAC;AAED,SAAS,qBAAqB,CAAC,IAAY,EAAE,KAAuB;IAClE,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,GAAG,eAAe,EAAE,KAAK,CAAC,CAAC;IAC7D,OAAO;QACL,GAAG,UAAU;QACb,KAAK,EAAE;YACL,GAAG,UAAU,CAAC,KAAK;YACnB,4CAA4C,EAAE,KAAK;YACnD,4CAA4C,EAAE,KAAK;YACnD,gDAAgD,EAAE,KAAK;SACxD;KACmC,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,WAAW,EAAE,UAAU,CAAC,aAAa,EAAE,OAAO,CAAC;IAC/C,qCAAqC,EAAE,qBAAqB,CAAC,aAAa,EAAE,OAAO,CAAC;IACpF,UAAU,EAAE,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC;IAC5C,oCAAoC,EAAE,qBAAqB,CAAC,YAAY,EAAE,MAAM,CAAC;CAClF,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\nimport { basePlugin } from '../plugin.ts';\n\nfunction makeConfig(name: string, level: 'error' | 'warn') {\n return {\n name: `@ms-cloudpack/${name}`,\n plugins: {\n '@ms-cloudpack': basePlugin,\n // @typescript-eslint and @rnx-kit are intentionally omitted: consumers must register plugins\n // themselves (e.g. via tseslint.configs.recommended*) to avoid \"Cannot redefine plugin\"\n // errors when the same plugin key is registered from two different import paths.\n },\n rules: {\n '@ms-cloudpack/no-unsupported-imports': level,\n '@rnx-kit/no-const-enum': level,\n '@rnx-kit/no-export-all': level,\n },\n } satisfies TSESLint.FlatConfig.Config;\n}\n\nfunction makeTypeCheckedConfig(name: string, level: 'error' | 'warn') {\n const baseConfig = makeConfig(name + '-type-checked', level);\n return {\n ...baseConfig,\n rules: {\n ...baseConfig.rules,\n '@typescript-eslint/consistent-type-imports': level,\n '@typescript-eslint/consistent-type-exports': level,\n '@typescript-eslint/no-import-type-side-effects': level,\n },\n } satisfies TSESLint.FlatConfig.Config;\n}\n\nexport const configs = {\n recommended: makeConfig('recommended', 'error'),\n 'recommended-requiring-type-checking': makeTypeCheckedConfig('recommended', 'error'),\n onboarding: makeConfig('onboarding', 'warn'),\n 'onboarding-requiring-type-checking': makeTypeCheckedConfig('onboarding', 'warn'),\n};\n"]}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
configs: {
|
|
3
|
+
recommended: {
|
|
4
|
+
name: string;
|
|
5
|
+
plugins: {
|
|
6
|
+
'@ms-cloudpack': {
|
|
7
|
+
meta: {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
};
|
|
12
|
+
rules: {
|
|
13
|
+
'no-test-exports': import("./utils/createRule.ts").RuleModule<import("./rules/no-test-exports.ts").RuleOptions, import("./rules/no-test-exports.ts").MessageIds>;
|
|
14
|
+
'no-unsupported-imports': import("./utils/createRule.ts").RuleModule<import("./rules/no-unsupported-imports.ts").RuleOptions, import("./rules/no-unsupported-imports.ts").MessageIds>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
rules: {
|
|
19
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
20
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
21
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
'recommended-requiring-type-checking': {
|
|
25
|
+
rules: {
|
|
26
|
+
'@typescript-eslint/consistent-type-imports': "error" | "warn";
|
|
27
|
+
'@typescript-eslint/consistent-type-exports': "error" | "warn";
|
|
28
|
+
'@typescript-eslint/no-import-type-side-effects': "error" | "warn";
|
|
29
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
30
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
31
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
32
|
+
};
|
|
33
|
+
name: string;
|
|
34
|
+
plugins: {
|
|
35
|
+
'@ms-cloudpack': {
|
|
36
|
+
meta: {
|
|
37
|
+
name: string;
|
|
38
|
+
version: string;
|
|
39
|
+
namespace: string;
|
|
40
|
+
};
|
|
41
|
+
rules: {
|
|
42
|
+
'no-test-exports': import("./utils/createRule.ts").RuleModule<import("./rules/no-test-exports.ts").RuleOptions, import("./rules/no-test-exports.ts").MessageIds>;
|
|
43
|
+
'no-unsupported-imports': import("./utils/createRule.ts").RuleModule<import("./rules/no-unsupported-imports.ts").RuleOptions, import("./rules/no-unsupported-imports.ts").MessageIds>;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
onboarding: {
|
|
49
|
+
name: string;
|
|
50
|
+
plugins: {
|
|
51
|
+
'@ms-cloudpack': {
|
|
52
|
+
meta: {
|
|
53
|
+
name: string;
|
|
54
|
+
version: string;
|
|
55
|
+
namespace: string;
|
|
56
|
+
};
|
|
57
|
+
rules: {
|
|
58
|
+
'no-test-exports': import("./utils/createRule.ts").RuleModule<import("./rules/no-test-exports.ts").RuleOptions, import("./rules/no-test-exports.ts").MessageIds>;
|
|
59
|
+
'no-unsupported-imports': import("./utils/createRule.ts").RuleModule<import("./rules/no-unsupported-imports.ts").RuleOptions, import("./rules/no-unsupported-imports.ts").MessageIds>;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
rules: {
|
|
64
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
65
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
66
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
'onboarding-requiring-type-checking': {
|
|
70
|
+
rules: {
|
|
71
|
+
'@typescript-eslint/consistent-type-imports': "error" | "warn";
|
|
72
|
+
'@typescript-eslint/consistent-type-exports': "error" | "warn";
|
|
73
|
+
'@typescript-eslint/no-import-type-side-effects': "error" | "warn";
|
|
74
|
+
'@ms-cloudpack/no-unsupported-imports': "error" | "warn";
|
|
75
|
+
'@rnx-kit/no-const-enum': "error" | "warn";
|
|
76
|
+
'@rnx-kit/no-export-all': "error" | "warn";
|
|
77
|
+
};
|
|
78
|
+
name: string;
|
|
79
|
+
plugins: {
|
|
80
|
+
'@ms-cloudpack': {
|
|
81
|
+
meta: {
|
|
82
|
+
name: string;
|
|
83
|
+
version: string;
|
|
84
|
+
namespace: string;
|
|
85
|
+
};
|
|
86
|
+
rules: {
|
|
87
|
+
'no-test-exports': import("./utils/createRule.ts").RuleModule<import("./rules/no-test-exports.ts").RuleOptions, import("./rules/no-test-exports.ts").MessageIds>;
|
|
88
|
+
'no-unsupported-imports': import("./utils/createRule.ts").RuleModule<import("./rules/no-unsupported-imports.ts").RuleOptions, import("./rules/no-unsupported-imports.ts").MessageIds>;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
meta: {
|
|
95
|
+
name: string;
|
|
96
|
+
version: string;
|
|
97
|
+
namespace: string;
|
|
98
|
+
};
|
|
99
|
+
rules: {
|
|
100
|
+
'no-test-exports': import("./utils/createRule.ts").RuleModule<import("./rules/no-test-exports.ts").RuleOptions, import("./rules/no-test-exports.ts").MessageIds>;
|
|
101
|
+
'no-unsupported-imports': import("./utils/createRule.ts").RuleModule<import("./rules/no-unsupported-imports.ts").RuleOptions, import("./rules/no-unsupported-imports.ts").MessageIds>;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
export default _default;
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wBAGuC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,eAAe;IACb,GAAG,UAAU;IACb,OAAO;CAC6B,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\nimport { configs } from './configs/index.ts';\nimport { basePlugin } from './plugin.ts';\n\nexport default {\n ...basePlugin,\n configs,\n} satisfies TSESLint.FlatConfig.Plugin;\n"]}
|
package/lib/plugin.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin metadata and rules. Omits the configs to avoid circular dependencies.
|
|
3
|
+
*/
|
|
4
|
+
export declare const basePlugin: {
|
|
5
|
+
meta: {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
namespace: string;
|
|
9
|
+
};
|
|
10
|
+
rules: {
|
|
11
|
+
'no-test-exports': import("./utils/createRule.ts").RuleModule<import("./rules/no-test-exports.ts").RuleOptions, import("./rules/no-test-exports.ts").MessageIds>;
|
|
12
|
+
'no-unsupported-imports': import("./utils/createRule.ts").RuleModule<import("./rules/no-unsupported-imports.ts").RuleOptions, import("./rules/no-unsupported-imports.ts").MessageIds>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;CAMiD,CAAC"}
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { rule as noTestExports } from "./rules/no-test-exports.js";
|
|
4
|
+
import { rule as noUnsupportedImports } from "./rules/no-unsupported-imports.js";
|
|
5
|
+
const { name, version } = JSON.parse(fs.readFileSync(path.resolve(import.meta.dirname, '../package.json'), 'utf8'));
|
|
6
|
+
/**
|
|
7
|
+
* Plugin metadata and rules. Omits the configs to avoid circular dependencies.
|
|
8
|
+
*/
|
|
9
|
+
export const basePlugin = {
|
|
10
|
+
meta: { name, version, namespace: '@ms-cloudpack' },
|
|
11
|
+
rules: {
|
|
12
|
+
'no-test-exports': noTestExports,
|
|
13
|
+
'no-unsupported-imports': noUnsupportedImports,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,IAAI,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,IAAI,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC,CAGjH,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE;IACnD,KAAK,EAAE;QACL,iBAAiB,EAAE,aAAa;QAChC,wBAAwB,EAAE,oBAAoB;KAC/C;CACqE,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { TSESLint } from '@typescript-eslint/utils';\nimport { rule as noTestExports } from './rules/no-test-exports.ts';\nimport { rule as noUnsupportedImports } from './rules/no-unsupported-imports.ts';\n\nconst { name, version } = JSON.parse(fs.readFileSync(path.resolve(import.meta.dirname, '../package.json'), 'utf8')) as {\n name: string;\n version: string;\n};\n\n/**\n * Plugin metadata and rules. Omits the configs to avoid circular dependencies.\n */\nexport const basePlugin = {\n meta: { name, version, namespace: '@ms-cloudpack' },\n rules: {\n 'no-test-exports': noTestExports,\n 'no-unsupported-imports': noUnsupportedImports,\n },\n} satisfies Required<Pick<TSESLint.FlatConfig.Plugin, 'meta' | 'rules'>>;\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Rule options as specified in the config */
|
|
2
|
+
export type RuleOptions = {
|
|
3
|
+
testPathPatterns?: string[];
|
|
4
|
+
testExportNamePatterns?: string[];
|
|
5
|
+
maxDepth?: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const defaultTestPaths: RegExp[];
|
|
8
|
+
export declare const defaultMaxDepth: number;
|
|
9
|
+
/** Error message IDs corresponding to `rule.meta.messages` */
|
|
10
|
+
export type MessageIds = 'invalidPath' | 'invalidName';
|
|
11
|
+
/** Error data `{{substitutions}}` used in messages */
|
|
12
|
+
export type ErrorData = {
|
|
13
|
+
extension: string;
|
|
14
|
+
invalidPath?: string;
|
|
15
|
+
invalidName?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const rule: import("../utils/createRule.ts").RuleModule<RuleOptions, MessageIds>;
|
|
18
|
+
//# sourceMappingURL=no-test-exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-test-exports.d.ts","sourceRoot":"","sources":["../../src/rules/no-test-exports.ts"],"names":[],"mappings":"AAQA,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG;IACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAaF,eAAO,MAAM,gBAAgB,EAAE,MAAM,EAKpC,CAAC;AAGF,eAAO,MAAM,eAAe,QAAW,CAAC;AAExC,8DAA8D;AAC9D,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,aAAa,CAAC;AAEvD,sDAAsD;AACtD,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAIF,eAAO,MAAM,IAAI,sEAgFf,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { getImportPathLiteralNode } from "../utils/getImportPathLiteralNode.js";
|
|
3
|
+
import { extractIdentifiersFromExport } from "../utils/testExports/extractIdentifiersFromExport.js";
|
|
4
|
+
import { getRegexpsFromStrings } from "../utils/getRegexpsFromStrings.js";
|
|
5
|
+
import { isIncludedIndexFile } from "../utils/testExports/isIncludedIndexFile.js";
|
|
6
|
+
import { createRule } from "../utils/createRule.js";
|
|
7
|
+
export const defaultTestPaths = [
|
|
8
|
+
// Only match lowercase mock|test|fixture at the beginning of an import path segment to avoid false positives
|
|
9
|
+
/\/(__)?(mock|test|fixture)/,
|
|
10
|
+
/\.(mock|test|fixture)s?(\.\w+)?$/,
|
|
11
|
+
/Mock|Test|Fixture/,
|
|
12
|
+
];
|
|
13
|
+
// Only match lowercase mock|test|fixture at the beginning of an export name to avoid false positives
|
|
14
|
+
const defaultTestExportNames = [/^(mock|test|fixture)/, /Mock|Test|Fixture/];
|
|
15
|
+
export const defaultMaxDepth = Infinity;
|
|
16
|
+
const separateFileMessage = 'use a separate file such as index.mock.{{extension}} instead';
|
|
17
|
+
export const rule = createRule({
|
|
18
|
+
name: 'no-test-exports',
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'disallow test, mock, and fixture exports from index files',
|
|
23
|
+
},
|
|
24
|
+
messages: {
|
|
25
|
+
invalidPath: 'Contents of test-related path "{{invalidPath}}" should not be referenced from an index file; ' +
|
|
26
|
+
separateFileMessage,
|
|
27
|
+
invalidName: '"{{invalidName}}" appears to be test-related and should not be exported from an index file; ' +
|
|
28
|
+
separateFileMessage,
|
|
29
|
+
},
|
|
30
|
+
schema: [
|
|
31
|
+
{
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
testPathPatterns: {
|
|
35
|
+
type: 'array',
|
|
36
|
+
description: 'Ban exports from these paths (regex) from index files. Use "..." to include the default paths.',
|
|
37
|
+
items: { type: 'string' },
|
|
38
|
+
},
|
|
39
|
+
testExportNamePatterns: {
|
|
40
|
+
type: 'array',
|
|
41
|
+
description: 'Ban exports with these names (regex) from index files. Use "..." to include the default names.',
|
|
42
|
+
items: { type: 'string' },
|
|
43
|
+
},
|
|
44
|
+
maxDepth: {
|
|
45
|
+
type: 'number',
|
|
46
|
+
description: 'Maximum depth of index file (0-indexed; default Infinity)',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
defaultOptions: [{}],
|
|
53
|
+
},
|
|
54
|
+
create: (ruleContext) => {
|
|
55
|
+
const options = ruleContext.options[0] || {};
|
|
56
|
+
const testPathPatterns = getRegexpsFromStrings(options.testPathPatterns, defaultTestPaths);
|
|
57
|
+
const testExportNamePatterns = getRegexpsFromStrings(options.testExportNamePatterns, defaultTestExportNames);
|
|
58
|
+
const maxDepth = options.maxDepth ?? defaultMaxDepth;
|
|
59
|
+
const extension = path.extname(ruleContext.filename).slice(1);
|
|
60
|
+
if (!isIncludedIndexFile({ filename: ruleContext.filename, ignorePaths: testPathPatterns, maxDepth })) {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
const context = { ruleContext, testExportNamePatterns, testPathPatterns, extension };
|
|
64
|
+
return {
|
|
65
|
+
// import foo from 'foo'
|
|
66
|
+
// import * as foo from 'foo'
|
|
67
|
+
// import { foo } from 'foo'
|
|
68
|
+
// import { foo as bar } from 'foo'
|
|
69
|
+
// import 'foo'
|
|
70
|
+
ImportDeclaration: (node) => checkNode(context, node),
|
|
71
|
+
// import foo = require('foo')
|
|
72
|
+
TSImportEqualsDeclaration: (node) => {
|
|
73
|
+
// Skip "export import foo = require('foo')" because that will be handled by ExportNamedDeclaration
|
|
74
|
+
if (node.parent.type !== 'ExportNamedDeclaration') {
|
|
75
|
+
checkNode(context, node);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
// export { foo }
|
|
79
|
+
// export { foo } from 'foo'
|
|
80
|
+
// export { foo as bar } from 'foo'
|
|
81
|
+
// export import foo = require('foo')
|
|
82
|
+
// export const foo = 'foo';
|
|
83
|
+
// and other exported declarations
|
|
84
|
+
ExportNamedDeclaration: (node) => checkNode(context, node),
|
|
85
|
+
// export * from 'foo'
|
|
86
|
+
// export * as foo from 'foo'
|
|
87
|
+
ExportAllDeclaration: (node) => checkNode(context, node),
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
/** Check an import or export node for violations. */
|
|
92
|
+
function checkNode(context, node) {
|
|
93
|
+
const hasInvalidPath = checkInvalidPath(context, node);
|
|
94
|
+
// Invalid path errors take precedence, to avoid spamming errors.
|
|
95
|
+
if (!hasInvalidPath && (node.type === 'ExportAllDeclaration' || node.type === 'ExportNamedDeclaration')) {
|
|
96
|
+
checkInvalidName(context, node);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check an import or export for invalid paths.
|
|
101
|
+
* Returns true if a violation was found.
|
|
102
|
+
*/
|
|
103
|
+
function checkInvalidPath(context, node) {
|
|
104
|
+
const { ruleContext, testPathPatterns, extension } = context;
|
|
105
|
+
// If there's an import path, check it
|
|
106
|
+
const { importPath, pathNode } = getImportPathLiteralNode(node) || {};
|
|
107
|
+
if (importPath && pathNode && testPathPatterns.some((re) => re.test(importPath))) {
|
|
108
|
+
ruleContext.report({
|
|
109
|
+
node: pathNode,
|
|
110
|
+
messageId: 'invalidPath',
|
|
111
|
+
data: { extension, invalidPath: importPath },
|
|
112
|
+
});
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
/** Check an export for invalid names. */
|
|
118
|
+
function checkInvalidName(context, node) {
|
|
119
|
+
const { ruleContext, testExportNamePatterns, extension } = context;
|
|
120
|
+
const ids = extractIdentifiersFromExport(node);
|
|
121
|
+
for (const id of ids) {
|
|
122
|
+
if (testExportNamePatterns.some((re) => re.test(id.name))) {
|
|
123
|
+
ruleContext.report({
|
|
124
|
+
node: id,
|
|
125
|
+
messageId: 'invalidName',
|
|
126
|
+
data: { extension, invalidName: id.name },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=no-test-exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-test-exports.js","sourceRoot":"","sources":["../../src/rules/no-test-exports.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAuB,MAAM,sCAAsC,CAAC;AACrG,OAAO,EAAE,4BAA4B,EAAE,MAAM,sDAAsD,CAAC;AACpG,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,EAAoB,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAoBtE,MAAM,CAAC,MAAM,gBAAgB,GAAa;IACxC,6GAA6G;IAC7G,4BAA4B;IAC5B,kCAAkC;IAClC,mBAAmB;CACpB,CAAC;AACF,qGAAqG;AACrG,MAAM,sBAAsB,GAAa,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAYxC,MAAM,mBAAmB,GAAG,8DAA8D,CAAC;AAE3F,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAAqC;IACjE,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,2DAA2D;SACzE;QACD,QAAQ,EAAE;YACR,WAAW,EACT,+FAA+F;gBAC/F,mBAAmB;YACrB,WAAW,EACT,8FAA8F;gBAC9F,mBAAmB;SACtB;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,gBAAgB,EAAE;wBAChB,IAAI,EAAE,OAAO;wBACb,WAAW,EACT,gGAAgG;wBAClG,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;qBAC1B;oBACD,sBAAsB,EAAE;wBACtB,IAAI,EAAE,OAAO;wBACb,WAAW,EACT,gGAAgG;wBAClG,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;qBAC1B;oBACD,QAAQ,EAAE;wBACR,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,2DAA2D;qBACzE;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,cAAc,EAAE,CAAC,EAAE,CAAC;KACrB;IACD,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE;QACtB,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7C,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,OAAO,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;QAC3F,MAAM,sBAAsB,GAAG,qBAAqB,CAAC,OAAO,CAAC,sBAAsB,EAAE,sBAAsB,CAAC,CAAC;QAC7G,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC;QACrD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE9D,IAAI,CAAC,mBAAmB,CAAC,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;YACtG,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,OAAO,GAAY,EAAE,WAAW,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC;QAE9F,OAAO;YACL,wBAAwB;YACxB,6BAA6B;YAC7B,4BAA4B;YAC5B,mCAAmC;YACnC,eAAe;YACf,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC;YACrD,8BAA8B;YAC9B,yBAAyB,EAAE,CAAC,IAAI,EAAE,EAAE;gBAClC,mGAAmG;gBACnG,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,wBAAwB,EAAE,CAAC;oBAClD,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;YACD,iBAAiB;YACjB,4BAA4B;YAC5B,mCAAmC;YACnC,qCAAqC;YACrC,4BAA4B;YAC5B,kCAAkC;YAClC,sBAAsB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC;YAC1D,sBAAsB;YACtB,6BAA6B;YAC7B,oBAAoB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC;SACzD,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,qDAAqD;AACrD,SAAS,SAAS,CAChB,OAAgB,EAChB,IAAkF;IAElF,MAAM,cAAc,GAAG,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvD,iEAAiE;IACjE,IAAI,CAAC,cAAc,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,sBAAsB,IAAI,IAAI,CAAC,IAAI,KAAK,wBAAwB,CAAC,EAAE,CAAC;QACxG,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACvB,OAAgB,EAChB,IAAkF;IAElF,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAE7D,sCAAsC;IACtC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,wBAAwB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAEtE,IAAI,UAAU,IAAI,QAAQ,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACjF,WAAW,CAAC,MAAM,CAAC;YACjB,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,aAAa;YACxB,IAAI,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE;SAC7C,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,yCAAyC;AACzC,SAAS,gBAAgB,CACvB,OAAgB,EAChB,IAAqE;IAErE,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,GAAG,GAAG,4BAA4B,CAAC,IAAI,CAAC,CAAC;IAE/C,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC1D,WAAW,CAAC,MAAM,CAAC;gBACjB,IAAI,EAAE,EAAE;gBACR,SAAS,EAAE,aAAa;gBACxB,IAAI,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE;aAC1C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport path from 'path';\nimport { getImportPathLiteralNode, type ImportLikeNode } from '../utils/getImportPathLiteralNode.ts';\nimport { extractIdentifiersFromExport } from '../utils/testExports/extractIdentifiersFromExport.ts';\nimport { getRegexpsFromStrings } from '../utils/getRegexpsFromStrings.ts';\nimport { isIncludedIndexFile } from '../utils/testExports/isIncludedIndexFile.ts';\nimport { type RuleContext, createRule } from '../utils/createRule.ts';\n\n/** Rule options as specified in the config */\nexport type RuleOptions = {\n testPathPatterns?: string[];\n testExportNamePatterns?: string[];\n maxDepth?: number;\n};\n\ntype Context = {\n /** Original rule context */\n ruleContext: RuleContext<RuleOptions, MessageIds, ErrorData>;\n /** Processed test path patterns */\n testPathPatterns: RegExp[];\n /** Processed test export name patterns */\n testExportNamePatterns: RegExp[];\n /** Current filename extension (no leading .) */\n extension: string;\n};\n\nexport const defaultTestPaths: RegExp[] = [\n // Only match lowercase mock|test|fixture at the beginning of an import path segment to avoid false positives\n /\\/(__)?(mock|test|fixture)/,\n /\\.(mock|test|fixture)s?(\\.\\w+)?$/,\n /Mock|Test|Fixture/,\n];\n// Only match lowercase mock|test|fixture at the beginning of an export name to avoid false positives\nconst defaultTestExportNames: RegExp[] = [/^(mock|test|fixture)/, /Mock|Test|Fixture/];\nexport const defaultMaxDepth = Infinity;\n\n/** Error message IDs corresponding to `rule.meta.messages` */\nexport type MessageIds = 'invalidPath' | 'invalidName';\n\n/** Error data `{{substitutions}}` used in messages */\nexport type ErrorData = {\n extension: string;\n invalidPath?: string;\n invalidName?: string;\n};\n\nconst separateFileMessage = 'use a separate file such as index.mock.{{extension}} instead';\n\nexport const rule = createRule<RuleOptions, MessageIds, ErrorData>({\n name: 'no-test-exports',\n meta: {\n type: 'problem',\n docs: {\n description: 'disallow test, mock, and fixture exports from index files',\n },\n messages: {\n invalidPath:\n 'Contents of test-related path \"{{invalidPath}}\" should not be referenced from an index file; ' +\n separateFileMessage,\n invalidName:\n '\"{{invalidName}}\" appears to be test-related and should not be exported from an index file; ' +\n separateFileMessage,\n },\n schema: [\n {\n type: 'object',\n properties: {\n testPathPatterns: {\n type: 'array',\n description:\n 'Ban exports from these paths (regex) from index files. Use \"...\" to include the default paths.',\n items: { type: 'string' },\n },\n testExportNamePatterns: {\n type: 'array',\n description:\n 'Ban exports with these names (regex) from index files. Use \"...\" to include the default names.',\n items: { type: 'string' },\n },\n maxDepth: {\n type: 'number',\n description: 'Maximum depth of index file (0-indexed; default Infinity)',\n },\n },\n additionalProperties: false,\n },\n ],\n defaultOptions: [{}],\n },\n create: (ruleContext) => {\n const options = ruleContext.options[0] || {};\n const testPathPatterns = getRegexpsFromStrings(options.testPathPatterns, defaultTestPaths);\n const testExportNamePatterns = getRegexpsFromStrings(options.testExportNamePatterns, defaultTestExportNames);\n const maxDepth = options.maxDepth ?? defaultMaxDepth;\n const extension = path.extname(ruleContext.filename).slice(1);\n\n if (!isIncludedIndexFile({ filename: ruleContext.filename, ignorePaths: testPathPatterns, maxDepth })) {\n return {};\n }\n\n const context: Context = { ruleContext, testExportNamePatterns, testPathPatterns, extension };\n\n return {\n // import foo from 'foo'\n // import * as foo from 'foo'\n // import { foo } from 'foo'\n // import { foo as bar } from 'foo'\n // import 'foo'\n ImportDeclaration: (node) => checkNode(context, node),\n // import foo = require('foo')\n TSImportEqualsDeclaration: (node) => {\n // Skip \"export import foo = require('foo')\" because that will be handled by ExportNamedDeclaration\n if (node.parent.type !== 'ExportNamedDeclaration') {\n checkNode(context, node);\n }\n },\n // export { foo }\n // export { foo } from 'foo'\n // export { foo as bar } from 'foo'\n // export import foo = require('foo')\n // export const foo = 'foo';\n // and other exported declarations\n ExportNamedDeclaration: (node) => checkNode(context, node),\n // export * from 'foo'\n // export * as foo from 'foo'\n ExportAllDeclaration: (node) => checkNode(context, node),\n };\n },\n});\n\n/** Check an import or export node for violations. */\nfunction checkNode(\n context: Context,\n node: Exclude<ImportLikeNode, TSESTree.CallExpression | TSESTree.ImportExpression>,\n): void {\n const hasInvalidPath = checkInvalidPath(context, node);\n // Invalid path errors take precedence, to avoid spamming errors.\n if (!hasInvalidPath && (node.type === 'ExportAllDeclaration' || node.type === 'ExportNamedDeclaration')) {\n checkInvalidName(context, node);\n }\n}\n\n/**\n * Check an import or export for invalid paths.\n * Returns true if a violation was found.\n */\nfunction checkInvalidPath(\n context: Context,\n node: Exclude<ImportLikeNode, TSESTree.CallExpression | TSESTree.ImportExpression>,\n): boolean {\n const { ruleContext, testPathPatterns, extension } = context;\n\n // If there's an import path, check it\n const { importPath, pathNode } = getImportPathLiteralNode(node) || {};\n\n if (importPath && pathNode && testPathPatterns.some((re) => re.test(importPath))) {\n ruleContext.report({\n node: pathNode,\n messageId: 'invalidPath',\n data: { extension, invalidPath: importPath },\n });\n return true;\n }\n\n return false;\n}\n\n/** Check an export for invalid names. */\nfunction checkInvalidName(\n context: Context,\n node: TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration,\n): void {\n const { ruleContext, testExportNamePatterns, extension } = context;\n\n const ids = extractIdentifiersFromExport(node);\n\n for (const id of ids) {\n if (testExportNamePatterns.some((re) => re.test(id.name))) {\n ruleContext.report({\n node: id,\n messageId: 'invalidName',\n data: { extension, invalidName: id.name },\n });\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Rule options as specified in the config */
|
|
2
|
+
export type RuleOptions = {
|
|
3
|
+
ignorePatterns?: string[];
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type ErrorMessageIds = 'noExports' | 'noExportsLocal' | 'notExported' | 'notExportedLocal';
|
|
7
|
+
export type SuggestMessageIds = 'useTopLevel';
|
|
8
|
+
export type MessageIds = ErrorMessageIds | SuggestMessageIds;
|
|
9
|
+
export type ErrorData = {
|
|
10
|
+
packageName: string;
|
|
11
|
+
subPath?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const rule: import("../utils/createRule.ts").RuleModule<RuleOptions, MessageIds>;
|
|
14
|
+
//# sourceMappingURL=no-unsupported-imports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"no-unsupported-imports.d.ts","sourceRoot":"","sources":["../../src/rules/no-unsupported-imports.ts"],"names":[],"mappings":"AAQA,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAUF,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,gBAAgB,GAAG,aAAa,GAAG,kBAAkB,CAAC;AAClG,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAC9C,MAAM,MAAM,UAAU,GAAG,eAAe,GAAG,iBAAiB,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAYF,eAAO,MAAM,IAAI,sEAkEf,CAAC"}
|