@ms-cloudpack/eslint-plugin 0.4.1 → 0.5.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 +78 -57
- package/lib/configs/classic.d.ts +9 -0
- package/lib/configs/classic.d.ts.map +1 -0
- package/lib/configs/classic.js +31 -0
- package/lib/configs/classic.js.map +1 -0
- package/lib/configs/flat.d.ts +4 -0
- package/lib/configs/flat.d.ts.map +1 -0
- package/lib/configs/flat.js +24 -0
- package/lib/configs/flat.js.map +1 -0
- package/lib/flat.d.mts +12 -0
- package/lib/flat.d.mts.map +1 -0
- package/lib/flat.mjs +8 -0
- package/lib/flat.mjs.map +1 -0
- package/lib/index.d.ts +11 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -16
- package/lib/index.js.map +1 -1
- package/lib/plugin.d.ts +6 -0
- package/lib/plugin.d.ts.map +1 -0
- package/lib/plugin.js +19 -0
- package/lib/plugin.js.map +1 -0
- package/lib/rules/no-test-exports.d.ts.map +1 -1
- package/lib/rules/no-test-exports.js +0 -1
- package/lib/rules/no-test-exports.js.map +1 -1
- package/lib/rules/no-unsupported-imports.d.ts.map +1 -1
- package/lib/rules/no-unsupported-imports.js +0 -1
- package/lib/rules/no-unsupported-imports.js.map +1 -1
- package/lib/utils/createRule.d.ts +1 -5
- package/lib/utils/createRule.d.ts.map +1 -1
- package/lib/utils/createRule.js.map +1 -1
- package/lib/utils/testExports/extractIdentifiersFromExport.js +1 -1
- package/lib/utils/testExports/extractIdentifiersFromExport.js.map +1 -1
- package/lib/utils/unsupportedImports/parseImportIfRelevant.d.ts.map +1 -1
- package/lib/utils/unsupportedImports/parseImportIfRelevant.js.map +1 -1
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.d.ts.map +1 -1
- package/lib/utils/unsupportedImports/pathSatisfiesAnyExport.js.map +1 -1
- package/lib/utils/unsupportedImports/resolvePackageRoot.js.map +1 -1
- package/package.json +23 -12
- package/lib/configs/onboarding-requiring-type-checking.d.ts +0 -3
- package/lib/configs/onboarding-requiring-type-checking.d.ts.map +0 -1
- package/lib/configs/onboarding-requiring-type-checking.js +0 -10
- package/lib/configs/onboarding-requiring-type-checking.js.map +0 -1
- package/lib/configs/onboarding.d.ts +0 -3
- package/lib/configs/onboarding.d.ts.map +0 -1
- package/lib/configs/onboarding.js +0 -10
- package/lib/configs/onboarding.js.map +0 -1
- package/lib/configs/recommended-requiring-type-checking.d.ts +0 -3
- package/lib/configs/recommended-requiring-type-checking.d.ts.map +0 -1
- package/lib/configs/recommended-requiring-type-checking.js +0 -11
- package/lib/configs/recommended-requiring-type-checking.js.map +0 -1
- package/lib/configs/recommended.d.ts +0 -3
- package/lib/configs/recommended.d.ts.map +0 -1
- package/lib/configs/recommended.js +0 -12
- package/lib/configs/recommended.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,71 +4,92 @@
|
|
|
4
4
|
|
|
5
5
|
## Included configs
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
`@ms-cloudpack/recommended-requiring-type-checking` includes the following rules:
|
|
45
|
-
|
|
46
|
-
- [`@typescript-eslint/consistent-type-exports`](https://typescript-eslint.io/rules/consistent-type-exports)
|
|
47
|
-
- [`@typescript-eslint/consistent-type-imports`](https://typescript-eslint.io/rules/consistent-type-imports)
|
|
48
|
-
|
|
49
|
-
### Onboarding
|
|
50
|
-
|
|
51
|
-
The `@ms-cloudpack/onboarding` config includes the same rules as `@ms-cloudpack/recommended`, but at `warn` level.
|
|
52
|
-
|
|
53
|
-
### Onboarding requiring type checking
|
|
54
|
-
|
|
55
|
-
The `@ms-cloudpack/onboarding-requiring-type-checking` config includes the same rules as `@ms-cloudpack/recommended-requiring-type-checking`, but at `warn` level. Following the pattern of typescript-eslint, this config **does not** include the rules from the basic "onboarding" config.
|
|
7
|
+
This plugin includes the following configs:
|
|
8
|
+
|
|
9
|
+
- `recommended`: Includes rules that are recommended for helping Cloudpack work better in your repo. None of these rules require type checking.
|
|
10
|
+
- [`@ms-cloudpack/no-unsupported-imports`](#no-unsupported-imports)
|
|
11
|
+
- [`@rnx-kit/no-const-enum`](https://www.npmjs.com/package/@rnx-kit/eslint-plugin)
|
|
12
|
+
- [`@rnx-kit/no-export-all`](https://www.npmjs.com/package/@rnx-kit/eslint-plugin)
|
|
13
|
+
- `recommended-requiring-type-checking`: Includes additional rules which are helpful for Cloudpack but require type information.
|
|
14
|
+
- All `recommended` rules
|
|
15
|
+
- [`@typescript-eslint/consistent-type-exports`](https://typescript-eslint.io/rules/consistent-type-exports)
|
|
16
|
+
- [`@typescript-eslint/consistent-type-imports`](https://typescript-eslint.io/rules/consistent-type-imports)
|
|
17
|
+
- `onboarding`: Includes the same rules as `recommended`, but at warn level.
|
|
18
|
+
- `onboarding-requiring-type-checking`: As above.
|
|
19
|
+
|
|
20
|
+
### Using a config
|
|
21
|
+
|
|
22
|
+
1. Install required peers: `@rnx-kit/eslint-plugin @typescript-eslint/eslint-plugin @typescript-eslint/parser typescript`
|
|
23
|
+
- For flat config, also install `typescript-eslint`
|
|
24
|
+
1. If using a `*-requiring-type-checking` config, follow the instructions for [linting with type information](https://typescript-eslint.io/linting/typed-linting).
|
|
25
|
+
1. Add to your config:
|
|
26
|
+
- Classic:
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"plugins": ["@ms-cloudpack"],
|
|
30
|
+
"extends": ["plugin:@ms-cloudpack/config-name-here"]
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
- Flat:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import tseslint from 'typescript-eslint';
|
|
37
|
+
// Note the "/flat" path (configs at the package root are classic only)
|
|
38
|
+
import cloudpack from '@ms-cloudpack/eslint-plugin/flat';
|
|
39
|
+
|
|
40
|
+
export default tseslint.config(cloudpack.configs['config-name-here']);
|
|
41
|
+
```
|
|
56
42
|
|
|
57
43
|
## Included rules
|
|
58
44
|
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
|
|
62
|
-
| ✓ |
|
|
63
|
-
| :-: |
|
|
64
|
-
| |
|
|
65
|
-
| ✓ |
|
|
45
|
+
- These rules do not require type checking
|
|
46
|
+
- ✓: Enabled with `@ms-cloudpack/recommended` config
|
|
47
|
+
|
|
48
|
+
| ✓ | Rule | Description |
|
|
49
|
+
| :-: | :------------------------------------- | :-------------------------------------------------------- |
|
|
50
|
+
| | `@ms-cloudpack/no-test-exports` | Ban test, mock, and fixture exports from index files |
|
|
51
|
+
| ✓ | `@ms-cloudpack/no-unsupported-imports` | Ban deep imports that are not defined in an `exports` map |
|
|
52
|
+
|
|
53
|
+
### Enabling rules
|
|
54
|
+
|
|
55
|
+
1. Install required peers: `@typescript-eslint/eslint-plugin @typescript-eslint/parser typescript`
|
|
56
|
+
- For flat config, also install `typescript-eslint`
|
|
57
|
+
2. Reference the plugin and enable the rules:
|
|
58
|
+
- Classic:
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"plugins": ["@ms-cloudpack"],
|
|
62
|
+
"rules": {
|
|
63
|
+
"@ms-cloudpack/rule-name-here": "error"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
- Flat:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import tseslint from 'typescript-eslint';
|
|
71
|
+
// If you're only enabling @ms-cloudpack rules (not extending a config),
|
|
72
|
+
// import from the package root to avoid imports of optional peers.
|
|
73
|
+
import cloudpack from '@ms-cloudpack/eslint-plugin';
|
|
74
|
+
// If you're also extending a config, import from here instead:
|
|
75
|
+
// import cloudpack from '@ms-cloudpack/eslint-plugin/flat';
|
|
76
|
+
|
|
77
|
+
export default tseslint.config({
|
|
78
|
+
plugins: {
|
|
79
|
+
// Omit if extending a config (the configs already include this)
|
|
80
|
+
'@ms-cloudpack': cloudpack,
|
|
81
|
+
},
|
|
82
|
+
rules: {
|
|
83
|
+
'@ms-cloudpack/rule-name-here': 'error',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
```
|
|
66
87
|
|
|
67
88
|
### `no-test-exports`
|
|
68
89
|
|
|
69
90
|
This rule bans exporting paths or names which appear to be test-related from index files (unless the index file is also under a test-related path).
|
|
70
91
|
|
|
71
|
-
Note that this rule checks the filename being linted and will **only** run on `index.*` files. Files under paths that appear test-related (based on the `testPathPatterns` setting) If you have the rule enabled for a whole repo, you'll need to disable it for any test-related packages.
|
|
92
|
+
Note that this rule checks the filename being linted and will **only** run on `index.*` files. Files under paths that appear test-related (based on the `testPathPatterns` setting) will be ignored. If you have the rule enabled for a whole repo, you'll need to disable it for any test-related packages.
|
|
72
93
|
|
|
73
94
|
Mixing test and "production" exports in a single package entry point is not recommended for several reasons:
|
|
74
95
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
export type CloudpackClassicConfig = Required<Pick<TSESLint.ClassicConfig.Config, 'plugins' | 'rules'>>;
|
|
3
|
+
export declare const configs: {
|
|
4
|
+
recommended: Required<Pick<TSESLint.ClassicConfig.Config, "rules" | "plugins">>;
|
|
5
|
+
'recommended-requiring-type-checking': Required<Pick<TSESLint.ClassicConfig.Config, "rules" | "plugins">>;
|
|
6
|
+
onboarding: Required<Pick<TSESLint.ClassicConfig.Config, "rules" | "plugins">>;
|
|
7
|
+
'onboarding-requiring-type-checking': Required<Pick<TSESLint.ClassicConfig.Config, "rules" | "plugins">>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=classic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classic.d.ts","sourceRoot":"","sources":["../../src/configs/classic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;AAyBxG,eAAO,MAAM,OAAO;;;;;CAKnB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configs = void 0;
|
|
4
|
+
function makeConfig(level) {
|
|
5
|
+
return {
|
|
6
|
+
plugins: ['@ms-cloudpack', '@rnx-kit', '@typescript-eslint'],
|
|
7
|
+
rules: {
|
|
8
|
+
'@ms-cloudpack/no-unsupported-imports': level,
|
|
9
|
+
'@rnx-kit/no-const-enum': level,
|
|
10
|
+
'@rnx-kit/no-export-all': level,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function makeTypeCheckedConfig(level) {
|
|
15
|
+
const baseConfig = makeConfig(level);
|
|
16
|
+
return {
|
|
17
|
+
...baseConfig,
|
|
18
|
+
rules: {
|
|
19
|
+
...baseConfig.rules,
|
|
20
|
+
'@typescript-eslint/consistent-type-imports': level,
|
|
21
|
+
'@typescript-eslint/consistent-type-exports': level,
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.configs = {
|
|
26
|
+
recommended: makeConfig('error'),
|
|
27
|
+
'recommended-requiring-type-checking': makeTypeCheckedConfig('error'),
|
|
28
|
+
onboarding: makeConfig('warn'),
|
|
29
|
+
'onboarding-requiring-type-checking': makeTypeCheckedConfig('warn'),
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=classic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classic.js","sourceRoot":"","sources":["../../src/configs/classic.ts"],"names":[],"mappings":";;;AAIA,SAAS,UAAU,CAAC,KAAuB;IACzC,OAAO;QACL,OAAO,EAAE,CAAC,eAAe,EAAE,UAAU,EAAE,oBAAoB,CAAC;QAC5D,KAAK,EAAE;YACL,sCAAsC,EAAE,KAAK;YAC7C,wBAAwB,EAAE,KAAK;YAC/B,wBAAwB,EAAE,KAAK;SAChC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAuB;IACpD,MAAM,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,OAAO;QACL,GAAG,UAAU;QACb,KAAK,EAAE;YACL,GAAG,UAAU,CAAC,KAAK;YACnB,4CAA4C,EAAE,KAAK;YACnD,4CAA4C,EAAE,KAAK;SACpD;KACF,CAAC;AACJ,CAAC;AAEY,QAAA,OAAO,GAAG;IACrB,WAAW,EAAE,UAAU,CAAC,OAAO,CAAC;IAChC,qCAAqC,EAAE,qBAAqB,CAAC,OAAO,CAAC;IACrE,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC;IAC9B,oCAAoC,EAAE,qBAAqB,CAAC,MAAM,CAAC;CACpE,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\n\nexport type CloudpackClassicConfig = Required<Pick<TSESLint.ClassicConfig.Config, 'plugins' | 'rules'>>;\n\nfunction makeConfig(level: 'error' | 'warn'): CloudpackClassicConfig {\n return {\n plugins: ['@ms-cloudpack', '@rnx-kit', '@typescript-eslint'],\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 };\n}\n\nfunction makeTypeCheckedConfig(level: 'error' | 'warn'): CloudpackClassicConfig {\n const baseConfig = makeConfig(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 },\n };\n}\n\nexport const configs = {\n recommended: makeConfig('error'),\n 'recommended-requiring-type-checking': makeTypeCheckedConfig('error'),\n onboarding: makeConfig('warn'),\n 'onboarding-requiring-type-checking': makeTypeCheckedConfig('warn'),\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat.d.ts","sourceRoot":"","sources":["../../src/configs/flat.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,IAAI,cAAc,EAA+B,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAgBzD,eAAO,MAAM,OAAO,EAEf,GACF,CAAC,IAAI,MAAM,OAAO,cAAc,GAAG,QAAQ,CAAC,UAAU,CAAC,MAAM,GAC/D,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.configs = void 0;
|
|
4
|
+
// @ts-expect-error -- missing types but we know it's a plugin
|
|
5
|
+
const rnxKit = require("@rnx-kit/eslint-plugin");
|
|
6
|
+
const tseslint = require("@typescript-eslint/eslint-plugin");
|
|
7
|
+
const parser = require("@typescript-eslint/parser");
|
|
8
|
+
const plugin_1 = require("../plugin");
|
|
9
|
+
const classic_1 = require("./classic");
|
|
10
|
+
function makeFlatConfig(name, classicConfig) {
|
|
11
|
+
return {
|
|
12
|
+
name: `@ms-cloudpack/${name}`,
|
|
13
|
+
plugins: {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
15
|
+
'@rnx-kit': rnxKit,
|
|
16
|
+
'@ms-cloudpack': plugin_1.basePlugin,
|
|
17
|
+
'@typescript-eslint': tseslint,
|
|
18
|
+
},
|
|
19
|
+
languageOptions: { parser },
|
|
20
|
+
rules: { ...classicConfig.rules },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.configs = Object.fromEntries(Object.entries(classic_1.configs).map(([name, classicConfig]) => [name, makeFlatConfig(name, classicConfig)]));
|
|
24
|
+
//# sourceMappingURL=flat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat.js","sourceRoot":"","sources":["../../src/configs/flat.ts"],"names":[],"mappings":";;;AAAA,8DAA8D;AAC9D,iDAAiD;AACjD,6DAA6D;AAC7D,oDAAoD;AACpD,sCAAuC;AACvC,uCAAmF;AAGnF,SAAS,cAAc,CAAC,IAAY,EAAE,aAAqC;IACzE,OAAO;QACL,IAAI,EAAE,iBAAiB,IAAI,EAAE;QAC7B,OAAO,EAAE;YACP,mEAAmE;YACnE,UAAU,EAAE,MAAM;YAClB,eAAe,EAAE,mBAAU;YAC3B,oBAAoB,EAAE,QAAQ;SAC/B;QACD,eAAe,EAAE,EAAE,MAAM,EAAE;QAC3B,KAAK,EAAE,EAAE,GAAG,aAAa,CAAC,KAAK,EAAE;KAClC,CAAC;AACJ,CAAC;AAEY,QAAA,OAAO,GAAG,MAAM,CAAC,WAAW,CACvC,MAAM,CAAC,OAAO,CAAC,iBAAc,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAG3G,CAAC","sourcesContent":["// @ts-expect-error -- missing types but we know it's a plugin\nimport * as rnxKit from '@rnx-kit/eslint-plugin';\nimport * as tseslint from '@typescript-eslint/eslint-plugin';\nimport * as parser from '@typescript-eslint/parser';\nimport { basePlugin } from '../plugin';\nimport { configs as classicConfigs, type CloudpackClassicConfig } from './classic';\nimport type { TSESLint } from '@typescript-eslint/utils';\n\nfunction makeFlatConfig(name: string, classicConfig: CloudpackClassicConfig): TSESLint.FlatConfig.Config {\n return {\n name: `@ms-cloudpack/${name}`,\n plugins: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n '@rnx-kit': rnxKit,\n '@ms-cloudpack': basePlugin,\n '@typescript-eslint': tseslint,\n },\n languageOptions: { parser },\n rules: { ...classicConfig.rules },\n };\n}\n\nexport const configs = Object.fromEntries(\n Object.entries(classicConfigs).map(([name, classicConfig]) => [name, makeFlatConfig(name, classicConfig)]),\n) as {\n [k in keyof typeof classicConfigs]: TSESLint.FlatConfig.Config;\n};\n"]}
|
package/lib/flat.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const plugin: {
|
|
2
|
+
configs: {
|
|
3
|
+
recommended: import("@typescript-eslint/utils/ts-eslint").FlatConfig.Config;
|
|
4
|
+
'recommended-requiring-type-checking': import("@typescript-eslint/utils/ts-eslint").FlatConfig.Config;
|
|
5
|
+
onboarding: import("@typescript-eslint/utils/ts-eslint").FlatConfig.Config;
|
|
6
|
+
'onboarding-requiring-type-checking': import("@typescript-eslint/utils/ts-eslint").FlatConfig.Config;
|
|
7
|
+
};
|
|
8
|
+
meta: { [K in keyof import("@typescript-eslint/utils/ts-eslint").FlatConfig.PluginMeta]?: import("@typescript-eslint/utils/ts-eslint").FlatConfig.PluginMeta[K] | undefined; };
|
|
9
|
+
rules: Record<string, import("@typescript-eslint/utils/ts-eslint").LooseRuleDefinition>;
|
|
10
|
+
};
|
|
11
|
+
export default plugin;
|
|
12
|
+
//# sourceMappingURL=flat.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat.d.mts","sourceRoot":"","sources":["../src/flat.mts"],"names":[],"mappings":"AAGA,QAAA,MAAM,MAAM;;;;;;;2FAK68J,CAAC;;CAFz9J,CAAC;AACF,eAAe,MAAM,CAAC"}
|
package/lib/flat.mjs
ADDED
package/lib/flat.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat.mjs","sourceRoot":"","sources":["../src/flat.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,MAAM,GAAG;IACb,GAAG,UAAU;IACb,OAAO;CACR,CAAC;AACF,eAAe,MAAM,CAAC","sourcesContent":["import { configs } from './configs/flat.js';\nimport { basePlugin } from './plugin.js';\n\nconst plugin = {\n ...basePlugin,\n configs,\n};\nexport default plugin;\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare const plugin: {
|
|
2
|
+
/** DO NOT use these for flat config! Import from `@ms-cloudpack/eslint-plugin/flat` instead. */
|
|
3
|
+
configs: {
|
|
4
|
+
recommended: Required<Pick<import("@typescript-eslint/utils/ts-eslint").ClassicConfig.Config, "rules" | "plugins">>;
|
|
5
|
+
'recommended-requiring-type-checking': Required<Pick<import("@typescript-eslint/utils/ts-eslint").ClassicConfig.Config, "rules" | "plugins">>;
|
|
6
|
+
onboarding: Required<Pick<import("@typescript-eslint/utils/ts-eslint").ClassicConfig.Config, "rules" | "plugins">>;
|
|
7
|
+
'onboarding-requiring-type-checking': Required<Pick<import("@typescript-eslint/utils/ts-eslint").ClassicConfig.Config, "rules" | "plugins">>;
|
|
8
|
+
};
|
|
9
|
+
meta: { [K in keyof import("@typescript-eslint/utils/ts-eslint").FlatConfig.PluginMeta]?: import("@typescript-eslint/utils/ts-eslint").FlatConfig.PluginMeta[K] | undefined; };
|
|
10
|
+
rules: Record<string, import("@typescript-eslint/utils/ts-eslint").LooseRuleDefinition>;
|
|
11
|
+
};
|
|
3
12
|
export = plugin;
|
|
4
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,MAAM;IAEV,gGAAgG;;;;;;;2FAKwuJ,CAAC;;CAH10J,CAAC;AAEF,SAAS,MAAM,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const recommended_1 = require("./configs/recommended");
|
|
5
|
-
const recommended_requiring_type_checking_1 = require("./configs/recommended-requiring-type-checking");
|
|
6
|
-
const no_test_exports_1 = require("./rules/no-test-exports");
|
|
7
|
-
const no_unsupported_imports_1 = require("./rules/no-unsupported-imports");
|
|
2
|
+
const classic_1 = require("./configs/classic");
|
|
3
|
+
const plugin_1 = require("./plugin");
|
|
8
4
|
const plugin = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
recommended: recommended_1.recommended,
|
|
13
|
-
'recommended-requiring-type-checking': recommended_requiring_type_checking_1.recommendedRequiringTypeChecking,
|
|
14
|
-
},
|
|
15
|
-
rules: {
|
|
16
|
-
'no-test-exports': no_test_exports_1.rule,
|
|
17
|
-
'no-unsupported-imports': no_unsupported_imports_1.rule,
|
|
18
|
-
},
|
|
5
|
+
...plugin_1.basePlugin,
|
|
6
|
+
/** DO NOT use these for flat config! Import from `@ms-cloudpack/eslint-plugin/flat` instead. */
|
|
7
|
+
configs: classic_1.configs,
|
|
19
8
|
};
|
|
20
9
|
module.exports = plugin;
|
|
21
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,+CAA4C;AAC5C,qCAAsC;AAEtC,MAAM,MAAM,GAAG;IACb,GAAG,mBAAU;IACb,gGAAgG;IAChG,OAAO,EAAP,iBAAO;CACR,CAAC;AAEF,iBAAS,MAAM,CAAC","sourcesContent":["import { configs } from './configs/classic';\nimport { basePlugin } from './plugin';\n\nconst plugin = {\n ...basePlugin,\n /** DO NOT use these for flat config! Import from `@ms-cloudpack/eslint-plugin/flat` instead. */\n configs,\n};\n// This export format is required for ESLint plugins\nexport = plugin;\n"]}
|
package/lib/plugin.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
/**
|
|
3
|
+
* Plugin metadata and rules. Omits the configs to avoid circular dependencies.
|
|
4
|
+
*/
|
|
5
|
+
export declare const basePlugin: Required<Pick<TSESLint.FlatConfig.Plugin, 'meta' | 'rules'>>;
|
|
6
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AASzD;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAMnF,CAAC"}
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.basePlugin = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const no_test_exports_1 = require("./rules/no-test-exports");
|
|
7
|
+
const no_unsupported_imports_1 = require("./rules/no-unsupported-imports");
|
|
8
|
+
const { name, version } = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf8'));
|
|
9
|
+
/**
|
|
10
|
+
* Plugin metadata and rules. Omits the configs to avoid circular dependencies.
|
|
11
|
+
*/
|
|
12
|
+
exports.basePlugin = {
|
|
13
|
+
meta: { name, version },
|
|
14
|
+
rules: {
|
|
15
|
+
'no-test-exports': no_test_exports_1.rule,
|
|
16
|
+
'no-unsupported-imports': no_unsupported_imports_1.rule,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,6DAAgE;AAChE,2EAA8E;AAE9E,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE,MAAM,CAAC,CAGvG,CAAC;AAEF;;GAEG;AACU,QAAA,UAAU,GAAiE;IACtF,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;IACvB,KAAK,EAAE;QACL,iBAAiB,EAAE,sBAAa;QAChC,wBAAwB,EAAE,6BAAoB;KAC/C;CACF,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport type { TSESLint } from '@typescript-eslint/utils';\nimport { rule as noTestExports } from './rules/no-test-exports';\nimport { rule as noUnsupportedImports } from './rules/no-unsupported-imports';\n\nconst { name, version } = JSON.parse(fs.readFileSync(path.resolve(__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: Required<Pick<TSESLint.FlatConfig.Plugin, 'meta' | 'rules'>> = {\n meta: { name, version },\n rules: {\n 'no-test-exports': noTestExports,\n 'no-unsupported-imports': noUnsupportedImports,\n },\n};\n"]}
|
|
@@ -1 +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,
|
|
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,mEA+Ef,CAAC"}
|
|
@@ -23,7 +23,6 @@ exports.rule = (0, createRule_1.createRule)({
|
|
|
23
23
|
type: 'problem',
|
|
24
24
|
docs: {
|
|
25
25
|
description: 'ban test, mock, and fixture exports from index files',
|
|
26
|
-
recommended: 'recommended',
|
|
27
26
|
},
|
|
28
27
|
messages: {
|
|
29
28
|
invalidPath: 'Contents of test-related path "{{invalidPath}}" should not be referenced from an index file; ' +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-test-exports.js","sourceRoot":"","sources":["../../src/rules/no-test-exports.ts"],"names":[],"mappings":";;;AACA,6BAA6B;AAC7B,gFAAkG;AAClG,oGAAiG;AACjG,0EAAuE;AACvE,kFAA+E;AAC/E,oDAAmE;AAoBtD,QAAA,gBAAgB,GAAa;IACxC,6GAA6G;IAC7G,4BAA4B;IAC5B,kCAAkC;IAClC,mBAAmB;CACpB,CAAC;AACF,qGAAqG;AACrG,MAAM,sBAAsB,GAAa,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,CAAC;AAC1E,QAAA,eAAe,GAAG,QAAQ,CAAC;AAYxC,MAAM,mBAAmB,GAAG,8DAA8D,CAAC;AAE9E,QAAA,IAAI,GAAG,IAAA,uBAAU,EAAqC;IACjE,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sDAAsD;YACnE,WAAW,EAAE,aAAa;SAC3B;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;qBA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AE,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,IAAA,2DAA4B,EAAC,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 * as path from 'path';\nimport { getImportPathLiteralNode, type ImportLikeNode } from '../utils/getImportPathLiteralNode';\nimport { extractIdentifiersFromExport } from '../utils/testExports/extractIdentifiersFromExport';\nimport { getRegexpsFromStrings } from '../utils/getRegexpsFromStrings';\nimport { isIncludedIndexFile } from '../utils/testExports/isIncludedIndexFile';\nimport { type RuleContext, createRule } from '../utils/createRule';\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: 'ban test, mock, and fixture exports from index files',\n recommended: 'recommended',\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 },\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) {\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"]}
|
|
1
|
+
{"version":3,"file":"no-test-exports.js","sourceRoot":"","sources":["../../src/rules/no-test-exports.ts"],"names":[],"mappings":";;;AACA,6BAA6B;AAC7B,gFAAkG;AAClG,oGAAiG;AACjG,0EAAuE;AACvE,kFAA+E;AAC/E,oDAAmE;AAoBtD,QAAA,gBAAgB,GAAa;IACxC,6GAA6G;IAC7G,4BAA4B;IAC5B,kCAAkC;IAClC,mBAAmB;CACpB,CAAC;AACF,qGAAqG;AACrG,MAAM,sBAAsB,GAAa,CAAC,sBAAsB,EAAE,mBAAmB,CAAC,CAAC;AAC1E,QAAA,eAAe,GAAG,QAAQ,CAAC;AAYxC,MAAM,mBAAmB,GAAG,8DAA8D,CAAC;AAE9E,QAAA,IAAI,GAAG,IAAA,uBAAU,EAAqC;IACjE,IAAI,EAAE,iBAAiB;IACvB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sDAAsD;SACpE;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,IAA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AAC,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,IAAA,2DAA4B,EAAC,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 * as path from 'path';\nimport { getImportPathLiteralNode, type ImportLikeNode } from '../utils/getImportPathLiteralNode';\nimport { extractIdentifiersFromExport } from '../utils/testExports/extractIdentifiersFromExport';\nimport { getRegexpsFromStrings } from '../utils/getRegexpsFromStrings';\nimport { isIncludedIndexFile } from '../utils/testExports/isIncludedIndexFile';\nimport { type RuleContext, createRule } from '../utils/createRule';\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: 'ban 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 },\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"]}
|
|
@@ -1 +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,
|
|
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,mEAiEf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unsupported-imports.js","sourceRoot":"","sources":["../../src/rules/no-unsupported-imports.ts"],"names":[],"mappings":";;;AAAA,gFAAkG;AAClG,4DAAyD;AACzD,6FAA0F;AAC1F,+FAA4F;AAC5F,uFAAoF;AACpF,0EAAuE;AACvE,oDAAqH;AA2BrH,MAAM,cAAc,GAAG,8DAA8D,CAAC;AACtF,MAAM,SAAS,GAAG,mFAAmF,GAAG,cAAc,CAAC;AACvH,MAAM,WAAW,GACf,yFAAyF,GAAG,cAAc,CAAC;AAC7G,MAAM,YAAY,GAChB,mFAAmF;IACnF,iEAAiE,CAAC;AAEvD,QAAA,IAAI,GAAG,IAAA,uBAAU,EAAqC;IACjE,IAAI,EAAE,wBAAwB;IAC9B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,uCAAuC;YACpD,WAAW,EAAE,aAAa;SAC3B;QACD,cAAc,EAAE,IAAI;QACpB,QAAQ,EAAE;YACR,SAAS;YACT,cAAc,EAAE,GAAG,SAAS,KAAK,YAAY,EAAE;YAC/C,WAAW;YACX,gBAAgB,EAAE,GAAG,WAAW,KAAK,YAAY,EAAE;YACnD,WAAW,EAAE,qDAAqD;SACnE;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,cAAc,EAAE;wBACd,IAAI,EAAE,OAAO;wBACb,WAAW,EAAE,4DAA4D;wBACzE,KAAK,EA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B;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kCAAkC;IAClC,MAAM,SAAS,GAAG,IAAA,+BAAc,EAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACzD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,6DAA6D;QAC7D,OAAO;YACL,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,WAAW;YAC7D,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;SAC/B,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,IAAI,CAAC,IAAA,+CAAsB,EAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QAC7D,OAAO;YACL,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa;YACjE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;SAC/B,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { getImportPathLiteralNode, type ImportLikeNode } from '../utils/getImportPathLiteralNode';\nimport { getPackageInfo } from '../utils/getPackageInfo';\nimport { parseImportIfRelevant } from '../utils/unsupportedImports/parseImportIfRelevant';\nimport { pathSatisfiesAnyExport } from '../utils/unsupportedImports/pathSatisfiesAnyExport';\nimport { resolvePackageRoot } from '../utils/unsupportedImports/resolvePackageRoot';\nimport { getRegexpsFromStrings } from '../utils/getRegexpsFromStrings';\nimport { createRule, type SuggestionDescriptor, type RuleContext, type ReportDescriptor } from '../utils/createRule';\n\n/** Rule options as specified in the config */\nexport type RuleOptions = {\n ignorePatterns?: string[];\n debug?: boolean;\n};\n\ntype Context = {\n /** Original rule context */\n ruleContext: RuleContext<RuleOptions, MessageIds, ErrorData>;\n /** Processed ignore patterns */\n ignorePatterns: RegExp[];\n debug: boolean;\n};\n\nexport type ErrorMessageIds = 'noExports' | 'noExportsLocal' | 'notExported' | 'notExportedLocal';\nexport type SuggestMessageIds = 'useTopLevel';\nexport type MessageIds = ErrorMessageIds | SuggestMessageIds;\n\nexport type ErrorData = {\n packageName: string;\n subPath?: string;\n};\n\ntype ErrorResult = Pick<ReportDescriptor<ErrorMessageIds, ErrorData>, 'messageId' | 'data'>;\n\nconst preferTopLevel = 'prefer importing directly from \"{{packageName}}\" if possible';\nconst noExports = '\"{{packageName}}\" doesn\\'t have an exports map, so deep imports aren\\'t allowed; ' + preferTopLevel;\nconst notExported =\n 'Path \"{{subPath}}\" is not exported by \"{{packageName}}\", according to its exports map; ' + preferTopLevel;\nconst localMessage =\n '(Consider updating \"{{packageName}}\" to export additional identifiers if needed, ' +\n 'or if deep imports are strictly necessary, add an exports map.)';\n\nexport const rule = createRule<RuleOptions, MessageIds, ErrorData>({\n name: 'no-unsupported-imports',\n meta: {\n type: 'problem',\n docs: {\n description: 'ban importing from non-exported paths',\n recommended: 'recommended',\n },\n hasSuggestions: true,\n messages: {\n noExports,\n noExportsLocal: `${noExports}. ${localMessage}`,\n notExported,\n notExportedLocal: `${notExported}. ${localMessage}`,\n useTopLevel: 'Import directly from \"{{packageName}}\", if possible',\n },\n schema: [\n {\n type: 'object',\n properties: {\n ignorePatterns: {\n type: 'array',\n description: 'Ignore imports matching these regular expression patterns.',\n items: { type: 'string' },\n },\n debug: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n ],\n },\n create: (ruleContext) => {\n const options = ruleContext.options?.[0] || {};\n const context: Context = {\n ruleContext,\n debug: options.debug ?? false,\n ignorePatterns: getRegexpsFromStrings(options.ignorePatterns),\n };\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) => checkImportOrExport(context, node),\n // await import('foo')\n ImportExpression: (node) => checkImportOrExport(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 checkImportOrExport(context, node);\n }\n },\n // export { foo } from 'foo'\n // export { foo as bar } from 'foo'\n ExportNamedDeclaration: (node) => checkImportOrExport(context, node),\n // export * from 'foo'\n // export * as foo from 'foo'\n ExportAllDeclaration: (node) => checkImportOrExport(context, node),\n // require('foo')\n // require.resolve('foo')\n CallExpression: (node) => checkImportOrExport(context, node),\n };\n },\n});\n\nfunction checkImportOrExport(context: Context, node: ImportLikeNode) {\n const { ruleContext } = context;\n\n const { importPath, pathNode } = getImportPathLiteralNode(node) || {};\n if (!(pathNode && importPath)) {\n return;\n }\n\n const errorData = checkImportPath(context, importPath);\n if (!errorData) {\n return; // Import is fine\n }\n\n // At this point, the import is probably invalid, so report it.\n // (Might still be a false positive if it's a local package that hasn't been built yet.)\n const { messageId, data } = errorData;\n\n // For named imports/exports or import *, suggest importing from the package root.\n // This is just a suggestion, so it doesn't have to be correct, but we also want to avoid\n // suggesting when it's likely to be misleading or might cause issues; for example:\n // - Default imports may refer to an actual default export or the entire module\n // - Side effect imports are likely specific to a particular file\n // - Async import()\n // - export * from an entire package might export a lot more things\n // - require() could be used in many ways (would have to look at more context)\n // - require.resolve() is typically used to find the path to a specific file\n let suggestion: SuggestionDescriptor<SuggestMessageIds, ErrorData> | undefined;\n if (\n // import { foo } from 'foo/bar'\n (node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportSpecifier') ||\n // import * as foo from 'foo/bar'\n (node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportNamespaceSpecifier') ||\n // import foo = require('foo/bar')\n node.type === 'TSImportEqualsDeclaration' ||\n // export { foo } from 'foo/bar'\n node.type === 'ExportNamedDeclaration'\n ) {\n suggestion = {\n messageId: 'useTopLevel',\n data,\n fix: (fixer) =>\n fixer.replaceTextRange(\n // Keep the quotes\n [pathNode.range[0] + 1, pathNode.range[1] - 1],\n data.packageName,\n ),\n };\n }\n\n ruleContext.report({\n node: pathNode,\n messageId,\n data,\n suggest: suggestion ? [suggestion] : undefined,\n });\n}\n\nfunction checkImportPath(context: Context, importPath: string): ErrorResult | null {\n const { ignorePatterns, debug, ruleContext } = context;\n\n const importParts = parseImportIfRelevant(importPath, ignorePatterns);\n if (!importParts) {\n // Import is relative, top-level, built-in, or ignored\n return null;\n }\n const { packageName, subPath } = importParts;\n\n // Find the root of the current file's package and read its package.json\n const currentPkg = getPackageInfo(ruleContext.filename, debug);\n if (!currentPkg || currentPkg.json.name === packageName) {\n // - If package.json for the current file's package wasn't found, ignore the import\n // (getPackageInfo already logged a debug message about it)\n // - If the import is a self-reference, ignore it\n return null;\n }\n\n // Resolve packageName's top-level import so we can find the package.json.\n // (This resolution must be done in the context of the current package in case eslint is running\n // in a different directory, e.g. monorepo root, where the package may not be installed or a\n // different version may be installed.)\n const resolvedPkgRoot = resolvePackageRoot(currentPkg.path, packageName, debug);\n if (!resolvedPkgRoot) {\n // Maybe an optional dep?\n return null;\n }\n\n // Read packageName's package.json\n const importPkg = getPackageInfo(resolvedPkgRoot, debug);\n if (!importPkg) {\n return null;\n }\n\n if (!importPkg.json.exports) {\n // Deep imports are always an error if there's no exports map\n return {\n messageId: importPkg.isLocal ? 'noExportsLocal' : 'noExports',\n data: { subPath, packageName },\n };\n }\n\n // Check if subPath matches any paths from exports (disregarding conditions)\n if (!pathSatisfiesAnyExport(importPkg.json.exports, subPath)) {\n return {\n messageId: importPkg.isLocal ? 'notExportedLocal' : 'notExported',\n data: { subPath, packageName },\n };\n }\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"no-unsupported-imports.js","sourceRoot":"","sources":["../../src/rules/no-unsupported-imports.ts"],"names":[],"mappings":";;;AAAA,gFAAkG;AAClG,4DAAyD;AACzD,6FAA0F;AAC1F,+FAA4F;AAC5F,uFAAoF;AACpF,0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IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QAC7D,OAAO;YACL,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa;YACjE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE;SAC/B,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { getImportPathLiteralNode, type ImportLikeNode } from '../utils/getImportPathLiteralNode';\nimport { getPackageInfo } from '../utils/getPackageInfo';\nimport { parseImportIfRelevant } from '../utils/unsupportedImports/parseImportIfRelevant';\nimport { pathSatisfiesAnyExport } from '../utils/unsupportedImports/pathSatisfiesAnyExport';\nimport { resolvePackageRoot } from '../utils/unsupportedImports/resolvePackageRoot';\nimport { getRegexpsFromStrings } from '../utils/getRegexpsFromStrings';\nimport { createRule, type SuggestionDescriptor, type RuleContext, type ReportDescriptor } from '../utils/createRule';\n\n/** Rule options as specified in the config */\nexport type RuleOptions = {\n ignorePatterns?: string[];\n debug?: boolean;\n};\n\ntype Context = {\n /** Original rule context */\n ruleContext: RuleContext<RuleOptions, MessageIds, ErrorData>;\n /** Processed ignore patterns */\n ignorePatterns: RegExp[];\n debug: boolean;\n};\n\nexport type ErrorMessageIds = 'noExports' | 'noExportsLocal' | 'notExported' | 'notExportedLocal';\nexport type SuggestMessageIds = 'useTopLevel';\nexport type MessageIds = ErrorMessageIds | SuggestMessageIds;\n\nexport type ErrorData = {\n packageName: string;\n subPath?: string;\n};\n\ntype ErrorResult = Pick<ReportDescriptor<ErrorMessageIds, ErrorData>, 'messageId' | 'data'>;\n\nconst preferTopLevel = 'prefer importing directly from \"{{packageName}}\" if possible';\nconst noExports = '\"{{packageName}}\" doesn\\'t have an exports map, so deep imports aren\\'t allowed; ' + preferTopLevel;\nconst notExported =\n 'Path \"{{subPath}}\" is not exported by \"{{packageName}}\", according to its exports map; ' + preferTopLevel;\nconst localMessage =\n '(Consider updating \"{{packageName}}\" to export additional identifiers if needed, ' +\n 'or if deep imports are strictly necessary, add an exports map.)';\n\nexport const rule = createRule<RuleOptions, MessageIds, ErrorData>({\n name: 'no-unsupported-imports',\n meta: {\n type: 'problem',\n docs: {\n description: 'ban importing from non-exported paths',\n },\n hasSuggestions: true,\n messages: {\n noExports,\n noExportsLocal: `${noExports}. ${localMessage}`,\n notExported,\n notExportedLocal: `${notExported}. ${localMessage}`,\n useTopLevel: 'Import directly from \"{{packageName}}\", if possible',\n },\n schema: [\n {\n type: 'object',\n properties: {\n ignorePatterns: {\n type: 'array',\n description: 'Ignore imports matching these regular expression patterns.',\n items: { type: 'string' },\n },\n debug: { type: 'boolean' },\n },\n additionalProperties: false,\n },\n ],\n },\n create: (ruleContext) => {\n const options = ruleContext.options?.[0] || {};\n const context: Context = {\n ruleContext,\n debug: options.debug ?? false,\n ignorePatterns: getRegexpsFromStrings(options.ignorePatterns),\n };\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) => checkImportOrExport(context, node),\n // await import('foo')\n ImportExpression: (node) => checkImportOrExport(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 checkImportOrExport(context, node);\n }\n },\n // export { foo } from 'foo'\n // export { foo as bar } from 'foo'\n ExportNamedDeclaration: (node) => checkImportOrExport(context, node),\n // export * from 'foo'\n // export * as foo from 'foo'\n ExportAllDeclaration: (node) => checkImportOrExport(context, node),\n // require('foo')\n // require.resolve('foo')\n CallExpression: (node) => checkImportOrExport(context, node),\n };\n },\n});\n\nfunction checkImportOrExport(context: Context, node: ImportLikeNode): void {\n const { ruleContext } = context;\n\n const { importPath, pathNode } = getImportPathLiteralNode(node) || {};\n if (!(pathNode && importPath)) {\n return;\n }\n\n const errorData = checkImportPath(context, importPath);\n if (!errorData) {\n return; // Import is fine\n }\n\n // At this point, the import is probably invalid, so report it.\n // (Might still be a false positive if it's a local package that hasn't been built yet.)\n const { messageId, data } = errorData;\n\n // For named imports/exports or import *, suggest importing from the package root.\n // This is just a suggestion, so it doesn't have to be correct, but we also want to avoid\n // suggesting when it's likely to be misleading or might cause issues; for example:\n // - Default imports may refer to an actual default export or the entire module\n // - Side effect imports are likely specific to a particular file\n // - Async import()\n // - export * from an entire package might export a lot more things\n // - require() could be used in many ways (would have to look at more context)\n // - require.resolve() is typically used to find the path to a specific file\n let suggestion: SuggestionDescriptor<SuggestMessageIds, ErrorData> | undefined;\n if (\n // import { foo } from 'foo/bar'\n (node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportSpecifier') ||\n // import * as foo from 'foo/bar'\n (node.type === 'ImportDeclaration' && node.specifiers[0]?.type === 'ImportNamespaceSpecifier') ||\n // import foo = require('foo/bar')\n node.type === 'TSImportEqualsDeclaration' ||\n // export { foo } from 'foo/bar'\n node.type === 'ExportNamedDeclaration'\n ) {\n suggestion = {\n messageId: 'useTopLevel',\n data,\n fix: (fixer) =>\n fixer.replaceTextRange(\n // Keep the quotes\n [pathNode.range[0] + 1, pathNode.range[1] - 1],\n data.packageName,\n ),\n };\n }\n\n ruleContext.report({\n node: pathNode,\n messageId,\n data,\n suggest: suggestion ? [suggestion] : undefined,\n });\n}\n\nfunction checkImportPath(context: Context, importPath: string): ErrorResult | null {\n const { ignorePatterns, debug, ruleContext } = context;\n\n const importParts = parseImportIfRelevant(importPath, ignorePatterns);\n if (!importParts) {\n // Import is relative, top-level, built-in, or ignored\n return null;\n }\n const { packageName, subPath } = importParts;\n\n // Find the root of the current file's package and read its package.json\n const currentPkg = getPackageInfo(ruleContext.filename, debug);\n if (!currentPkg || currentPkg.json.name === packageName) {\n // - If package.json for the current file's package wasn't found, ignore the import\n // (getPackageInfo already logged a debug message about it)\n // - If the import is a self-reference, ignore it\n return null;\n }\n\n // Resolve packageName's top-level import so we can find the package.json.\n // (This resolution must be done in the context of the current package in case eslint is running\n // in a different directory, e.g. monorepo root, where the package may not be installed or a\n // different version may be installed.)\n const resolvedPkgRoot = resolvePackageRoot(currentPkg.path, packageName, debug);\n if (!resolvedPkgRoot) {\n // Maybe an optional dep?\n return null;\n }\n\n // Read packageName's package.json\n const importPkg = getPackageInfo(resolvedPkgRoot, debug);\n if (!importPkg) {\n return null;\n }\n\n if (!importPkg.json.exports) {\n // Deep imports are always an error if there's no exports map\n return {\n messageId: importPkg.isLocal ? 'noExportsLocal' : 'noExports',\n data: { subPath, packageName },\n };\n }\n\n // Check if subPath matches any paths from exports (disregarding conditions)\n if (!pathSatisfiesAnyExport(importPkg.json.exports, subPath)) {\n return {\n messageId: importPkg.isLocal ? 'notExportedLocal' : 'notExported',\n data: { subPath, packageName },\n };\n }\n return null;\n}\n"]}
|
|
@@ -13,10 +13,6 @@ export type ReportDescriptor<TMessageIds extends string, TErrorData> = Omit<Writ
|
|
|
13
13
|
};
|
|
14
14
|
/** Fix suggestion with strongly typed data. */
|
|
15
15
|
export type SuggestionDescriptor<TMessageIds extends string, TErrorData> = Omit<ReportDescriptor<TMessageIds, TErrorData>, 'suggest' | 'node'>;
|
|
16
|
-
/** Fix suggestion output (for testing). */
|
|
17
|
-
export type SuggestionOutput<TMessageIds extends string, TErrorData> = Omit<TSESLint.SuggestionOutput<TMessageIds>, 'data'> & {
|
|
18
|
-
data?: TErrorData;
|
|
19
|
-
};
|
|
20
16
|
/**
|
|
21
17
|
* Rule context with strongly typed `report`.
|
|
22
18
|
* (This assumes all error/suggestion messages share a common data type.)
|
|
@@ -35,7 +31,7 @@ type CreateRuleOptions<TOptions, TMessageIds extends string, TErrorData> = Omit<
|
|
|
35
31
|
* This exported alias is just to avoid an error when exporting the `rule` returned from `createRule`
|
|
36
32
|
* ("the inferred type of 'rule' cannot be named without a reference to ...").
|
|
37
33
|
*/
|
|
38
|
-
export type RuleModule<TOptions, TMessageIds extends string> = ESLintUtils.RuleModule<TMessageIds, TOptions[]
|
|
34
|
+
export type RuleModule<TOptions, TMessageIds extends string> = ESLintUtils.RuleModule<TMessageIds, TOptions[]>;
|
|
39
35
|
/**
|
|
40
36
|
* Create a lint rule, with strongly typed data in `context.report`.
|
|
41
37
|
* (This assumes all error/suggestion messages share a common data type.)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRule.d.ts","sourceRoot":"","sources":["../../src/utils/createRule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEhF,KAAK,QAAQ,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,WAAW,SAAS,MAAM,EAAE,UAAU,IAAI,IAAI,CAEzE,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,EAChD,MAAM,GAAG,MAAM,GAAG,SAAS,CAC5B,GAAG;IACF,IAAI,EAAE,UAAU,CAAC;IAEjB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,oBAAoB,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC;CAClE,CAAC;AAEF,+CAA+C;AAC/C,MAAM,MAAM,oBAAoB,CAAC,WAAW,SAAS,MAAM,EAAE,UAAU,IAAI,IAAI,CAC7E,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,EACzC,SAAS,GAAG,MAAM,CACnB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"createRule.d.ts","sourceRoot":"","sources":["../../src/utils/createRule.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEhF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AAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC;CAC9G,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,QAAQ,EAAE,WAAW,SAAS,MAAM,IAAI,WAAW,CAAC,UAAU,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/G;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,WAAW,SAAS,MAAM,EAAE,UAAU,EACzE,MAAM,EAAE,iBAAiB,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,GAC3D,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC,CAyBnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRule.js","sourceRoot":"","sources":["../../src/utils/createRule.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"createRule.js","sourceRoot":"","sources":["../../src/utils/createRule.ts"],"names":[],"mappings":";;AAiEA,gCA2BC;AA/BD;;;GAGG;AACH,SAAgB,UAAU,CACxB,MAA4D;IAE5D,OAAO;QACL,GAAG,MAAM;QACT,IAAI,EAAE;YACJ,GAAG,MAAM,CAAC,IAAI;YACd,IAAI,EAAE;gBACJ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI;gBACnB,GAAG,EAAE,6DAA6D,MAAM,CAAC,IAAI,EAAE;aAChF;SACF;QACD,cAAc,EAAE,EAAE;QAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;YAClB,MAAM,WAAW,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;YAEnC,sDAAsD;YACtD,sCAAsC;YACtC,WAAW,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YACvC,WAAW,CAAC,QAAQ,KAAK,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;YACjD,WAAW,CAAC,gBAAgB,KAAK,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;YACjE,WAAW,CAAC,UAAU,KAAK,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;YACrD,qCAAqC;YAErC,OAAO,MAAM,CAAC,MAAM,CAAC,WAA6D,CAAC,CAAC;QACtF,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["//\n// This file contains wrappers for rule creation and related types.\n//\nimport type { ESLintUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';\n\ntype Writable<T> = { -readonly [K in keyof T]: T[K] };\n\n/**\n * Problem report descriptor with strongly typed error and suggestion data.\n * (This assumes all error/suggestion messages share a common data type.)\n */\nexport type ReportDescriptor<TMessageIds extends string, TErrorData> = Omit<\n // Make the descriptor writable for convenience (like conditionally adding a fix)\n Writable<TSESLint.ReportDescriptor<TMessageIds>>,\n 'data' | 'node' | 'suggest'\n> & {\n data: TErrorData;\n // have to re-declare `node` due to an oddity with union types (built-in ReportDescriptor is a union) and omit\n node: TSESTree.Node;\n suggest?: SuggestionDescriptor<TMessageIds, TErrorData>[] | null;\n};\n\n/** Fix suggestion with strongly typed data. */\nexport type SuggestionDescriptor<TMessageIds extends string, TErrorData> = Omit<\n ReportDescriptor<TMessageIds, TErrorData>,\n 'suggest' | 'node'\n>;\n\n/**\n * Rule context with strongly typed `report`.\n * (This assumes all error/suggestion messages share a common data type.)\n */\nexport type RuleContext<TOptions, TMessageIds extends string, TErrorData> = Omit<\n TSESLint.RuleContext<TMessageIds, TOptions[]>,\n 'report'\n> & {\n report: (descriptor: ReportDescriptor<TMessageIds, TErrorData>) => void;\n};\n\n/**\n * Rule info with better {@link RuleContext} type for the `create` function.\n * (This assumes all error/suggestion messages share a common data type.)\n */\ntype CreateRuleOptions<TOptions, TMessageIds extends string, TErrorData> = Omit<\n ESLintUtils.RuleWithMetaAndName<TOptions[], TMessageIds>,\n // Why remove defaultOptions (array): typescript-eslint merges this array with the original\n // options array and passes the merged array as the second argument to `create`. However,\n // this isn't reflected in the types, and its behavior is kind of weird (an empty `defaultOptions`\n // array will cause the provided options to be ignored). So remove it from the types\n // and fill in a default value in `createRule` instead.\n 'create' | 'defaultOptions'\n> & {\n create(this: void, context: Readonly<RuleContext<TOptions, TMessageIds, TErrorData>>): TSESLint.RuleListener;\n};\n\n/**\n * This exported alias is just to avoid an error when exporting the `rule` returned from `createRule`\n * (\"the inferred type of 'rule' cannot be named without a reference to ...\").\n */\nexport type RuleModule<TOptions, TMessageIds extends string> = ESLintUtils.RuleModule<TMessageIds, TOptions[]>;\n\n/**\n * Create a lint rule, with strongly typed data in `context.report`.\n * (This assumes all error/suggestion messages share a common data type.)\n */\nexport function createRule<TOptions, TMessageIds extends string, TErrorData>(\n params: CreateRuleOptions<TOptions, TMessageIds, TErrorData>,\n): RuleModule<TOptions, TMessageIds> {\n return {\n ...params,\n meta: {\n ...params.meta,\n docs: {\n ...params.meta.docs,\n url: `https://www.npmjs.com/package/@ms-cloudpack/eslint-plugin#${params.name}`,\n },\n },\n defaultOptions: [],\n create: (context) => {\n const contextCopy = { ...context };\n\n // Fill in properties that were added in eslint 8.40.0\n /* eslint-disable etc/no-deprecated */\n contextCopy.cwd ??= context.getCwd?.();\n contextCopy.filename ??= context.getFilename?.();\n contextCopy.physicalFilename ??= context.getPhysicalFilename?.();\n contextCopy.sourceCode ??= context.getSourceCode?.();\n /* eslint-enable etc/no-deprecated */\n\n return params.create(contextCopy as RuleContext<TOptions, TMessageIds, TErrorData>);\n },\n };\n}\n"]}
|
|
@@ -12,7 +12,7 @@ function extractIdentifiersFromExport(node) {
|
|
|
12
12
|
if (node.specifiers.length) {
|
|
13
13
|
// export { a, b }
|
|
14
14
|
// export { a, b } from 'foo'
|
|
15
|
-
return node.specifiers.map((s) => s.exported);
|
|
15
|
+
return node.specifiers.map((s) => s.exported).filter((s) => s.type === 'Identifier');
|
|
16
16
|
}
|
|
17
17
|
if (node.declaration && node.declaration?.type !== 'VariableDeclaration') {
|
|
18
18
|
// export import foo = require('foo')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractIdentifiersFromExport.js","sourceRoot":"","sources":["../../../src/utils/testExports/extractIdentifiersFromExport.ts"],"names":[],"mappings":";;AAKA,oEAoDC;AAvDD;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,IAAqE;IAErE,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QACzC,6BAA6B;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAC3B,kBAAkB;QAClB,6BAA6B;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"extractIdentifiersFromExport.js","sourceRoot":"","sources":["../../../src/utils/testExports/extractIdentifiersFromExport.ts"],"names":[],"mappings":";;AAKA,oEAoDC;AAvDD;;GAEG;AACH,SAAgB,4BAA4B,CAC1C,IAAqE;IAErE,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;QACzC,6BAA6B;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9C,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QAC3B,kBAAkB;QAClB,6BAA6B;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAA4B,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;IACjH,CAAC;IAED,IAAI,IAAI,CAAC,WA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AAI,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBACjE,0FAA0F;oBAC1F,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,CAAC;qBAAM,IAAI,IAAI,CAAC,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAC9E,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\n\n/**\n * Extract identifiers from an export declaration.\n */\nexport function extractIdentifiersFromExport(\n node: TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration,\n): TSESTree.Identifier[] {\n if (node.type === 'ExportAllDeclaration') {\n // export * as foo from 'foo'\n return node.exported ? [node.exported] : [];\n }\n\n if (node.specifiers.length) {\n // export { a, b }\n // export { a, b } from 'foo'\n return node.specifiers.map((s) => s.exported).filter((s): s is TSESTree.Identifier => s.type === 'Identifier');\n }\n\n if (node.declaration && node.declaration?.type !== 'VariableDeclaration') {\n // export import foo = require('foo')\n // also class, function, type, interface...\n return node.declaration.id?.type === 'Identifier' ? [node.declaration.id] : [];\n }\n\n const ids: TSESTree.Identifier[] = [];\n const declarations = node.declaration?.declarations || [];\n\n for (const decl of declarations) {\n if (decl.id.type === 'Identifier') {\n // export const foo = 'foo'\n ids.push(decl.id);\n } else if (decl.id.type === 'ArrayPattern') {\n // Unlikely array destructuring export (ignore any nested variants)\n // export const [foo, bar] = ['foo', 'bar']\n for (const elem of decl.id.elements) {\n if (elem?.type === 'Identifier') {\n ids.push(elem);\n } else if (elem?.type === 'RestElement' && elem.argument.type === 'Identifier') {\n ids.push(elem.argument);\n }\n }\n } else {\n // Unlikely object destructuring export (ignore any nested variants)\n // export const { foo, bar } = { foo: 'foo', bar: 'bar' }\n for (const prop of decl.id.properties) {\n if (prop.type === 'Property' && prop.value.type === 'Identifier') {\n // .value instead of .key handles renaming and prevents including non-exported nested keys\n ids.push(prop.value);\n } else if (prop.type === 'RestElement' && prop.argument.type === 'Identifier') {\n ids.push(prop.argument);\n }\n }\n }\n }\n\n return ids;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseImportIfRelevant.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/parseImportIfRelevant.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiBjD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"parseImportIfRelevant.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/parseImportIfRelevant.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiBjD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAOxF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseImportIfRelevant.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/parseImportIfRelevant.ts"],"names":[],"mappings":";;AAMA,sDAoBC;AAQD,sCAOC;AAzCD,mCAAwC;AAExC;;;GAGG;AACH,SAAgB,qBAAqB,CACn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E,CAAC;AAClC,CAAC","sourcesContent":["import { builtinModules } from 'module';\n\n/**\n * Verify that the import is relevant for the very specific purposes of the `no-unsupported-imports` rule,\n * and if so, find the package name and sub-path.\n */\nexport function parseImportIfRelevant(\n importPath: string,\n ignorePatterns: RegExp[],\n): { packageName: string; subPath: string } | null {\n // Remove any webpack loader prefix\n // (* is greedy, so it will work even if multiple loaders are specified)\n const normalizedImport = importPath.replace(/.*!/, '');\n\n // Ignore relative imports, internal imports, builtins, and data URLs\n // (builtinModules includes valid sub-paths like \"fs/promises\")\n if (!/^([.#]|node:|data:)/.test(normalizedImport) && !builtinModules.includes(normalizedImport)) {\n // Find the package name and sub-path (if any)\n const { packageName, subPath } = parseModuleId(normalizedImport);\n\n // Ignore top-level imports, or anything from an ignored package\n if (subPath && !ignorePatterns.some((r) => r.test(normalizedImport))) {\n return { packageName, subPath };\n }\n }\n return null;\n}\n\n/**\n * Parse a module ID which is assumed to point to an actual file in a package (no loader prefixes,\n * relative paths, node builtins, or data URIs).\n * @returns Package name and sub-path (if any). Sub-path does *not* include a leading `./`,\n * e.g. `@foo/bar/baz` returns `{ packageName: '@foo/bar', subPath: 'baz' }`.\n */\nexport function parseModuleId(moduleId: string) {\n const nameParts = moduleId.split('/');\n const hasScope = nameParts.length >= 2 && nameParts[0][0] === '@';\n\n const packageName = hasScope ? `${nameParts[0]}/${nameParts[1]}` : nameParts[0];\n const subPath = nameParts.slice(hasScope ? 2 : 1).join('/');\n return { packageName, subPath };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"parseImportIfRelevant.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/parseImportIfRelevant.ts"],"names":[],"mappings":";;AAMA,sDAoBC;AAQD,sCAOC;AAzCD,mCAAwC;AAExC;;;GAGG;AACH,SAAgB,qBAAqB,CACnC,UAAkB,EAClB,cAAwB;IAExB,mCAAmC;IACnC,wEAAwE;IACxE,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAEvD,qEAAqE;IACrE,+DAA+D;IAC/D,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,uBAAc,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChG,8CAA8C;QAC9C,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAEjE,gEAAgE;QAChE,IAAI,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC;YACrE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,QAAgB;IAC5C,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,IAAI,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;IAElE,MAAM,WAAW,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAChF,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5D,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AAClC,CAAC","sourcesContent":["import { builtinModules } from 'module';\n\n/**\n * Verify that the import is relevant for the very specific purposes of the `no-unsupported-imports` rule,\n * and if so, find the package name and sub-path.\n */\nexport function parseImportIfRelevant(\n importPath: string,\n ignorePatterns: RegExp[],\n): { packageName: string; subPath: string } | null {\n // Remove any webpack loader prefix\n // (* is greedy, so it will work even if multiple loaders are specified)\n const normalizedImport = importPath.replace(/.*!/, '');\n\n // Ignore relative imports, internal imports, builtins, and data URLs\n // (builtinModules includes valid sub-paths like \"fs/promises\")\n if (!/^([.#]|node:|data:)/.test(normalizedImport) && !builtinModules.includes(normalizedImport)) {\n // Find the package name and sub-path (if any)\n const { packageName, subPath } = parseModuleId(normalizedImport);\n\n // Ignore top-level imports, or anything from an ignored package\n if (subPath && !ignorePatterns.some((r) => r.test(normalizedImport))) {\n return { packageName, subPath };\n }\n }\n return null;\n}\n\n/**\n * Parse a module ID which is assumed to point to an actual file in a package (no loader prefixes,\n * relative paths, node builtins, or data URIs).\n * @returns Package name and sub-path (if any). Sub-path does *not* include a leading `./`,\n * e.g. `@foo/bar/baz` returns `{ packageName: '@foo/bar', subPath: 'baz' }`.\n */\nexport function parseModuleId(moduleId: string): { packageName: string; subPath: string } {\n const nameParts = moduleId.split('/');\n const hasScope = nameParts.length >= 2 && nameParts[0][0] === '@';\n\n const packageName = hasScope ? `${nameParts[0]}/${nameParts[1]}` : nameParts[0];\n const subPath = nameParts.slice(hasScope ? 2 : 1).join('/');\n return { packageName, subPath };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathSatisfiesAnyExport.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/pathSatisfiesAnyExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"pathSatisfiesAnyExport.d.ts","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/pathSatisfiesAnyExport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CA8B7G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pathSatisfiesAnyExport.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/pathSatisfiesAnyExport.ts"],"names":[],"mappings":";;AAOA,wDA8BC;AAnCD;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,UAAsC,EAAE,aAAqB;IAClG,wEAAwE;IACxE,oEAAoE;IACpE,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,aAAa,GAAG,KAAK,aAAa,EAAE,CAAC;IAErC,OAAO;IACL,yFAAyF;IACzF,kFAAkF;IAClF,mDAAmD;IAClD,UAAsC,CAAC,aAAa,CAAC,KAAK,IAAI;QAC/D,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACnC,wCAAwC;YACxC,yEAAyE;YACzE,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBAClC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC/F,CAAC;YACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC;YACD,oDAAoD;YACpD,OAAO,GAAG,KAAK,aAAa,CAAC;QAC/B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageExports } from '../PackageJson.js';\n\n/**\n * Determine whether `importSubPath` might satisfy any sub-path from the exports map,\n * disregarding conditions and file existence.\n * @param importSubPath Sub-path such as `lib/foo`\n */\nexport function pathSatisfiesAnyExport(exportsMap: PackageExports | undefined, importSubPath: string) {\n // If the exports map is a string, it's a shorthand for a single export.\n // If it's an array, the contents are fallbacks for a single export.\n if (!exportsMap || typeof exportsMap === 'string' || Array.isArray(exportsMap)) {\n return false;\n }\n\n importSubPath = `./${importSubPath}`;\n\n return (\n // Check for very basic exclusions. (Technically a path could also be excluded by setting\n // a condition to null, or by setting a later wildcard to override an earlier one.\n // Handling for this can be added later if needed.)\n (exportsMap as Record<string, unknown>)[importSubPath] !== null &&\n Object.keys(exportsMap).some((key) => {\n // . is the root import, not a sub-path.\n // Starting character other than . means this is a condition, not a path.\n if (key === '.' || key[0] !== '.') {\n return false;\n }\n if (key.includes('*')) {\n return new RegExp(`^${key.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*')}$`).test(importSubPath);\n }\n if (key.endsWith('/')) {\n return importSubPath.startsWith(key);\n }\n // Check if the path is a literal match for this key\n return key === importSubPath;\n })\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pathSatisfiesAnyExport.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/pathSatisfiesAnyExport.ts"],"names":[],"mappings":";;AAOA,wDA8BC;AAnCD;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,UAAsC,EAAE,aAAqB;IAClG,wEAAwE;IACxE,oEAAoE;IACpE,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,aAAa,GAAG,KAAK,aAAa,EAAE,CAAC;IAErC,OAAO;IACL,yFAAyF;IACzF,kFAAkF;IAClF,mDAAmD;IAClD,UAAsC,CAAC,aAAa,CAAC,KAAK,IAAI;QAC/D,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACnC,wCAAwC;YACxC,yEAAyE;YACzE,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBAClC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC/F,CAAC;YACD,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACvC,CAAC;YACD,oDAAoD;YACpD,OAAO,GAAG,KAAK,aAAa,CAAC;QAC/B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageExports } from '../PackageJson.js';\n\n/**\n * Determine whether `importSubPath` might satisfy any sub-path from the exports map,\n * disregarding conditions and file existence.\n * @param importSubPath Sub-path such as `lib/foo`\n */\nexport function pathSatisfiesAnyExport(exportsMap: PackageExports | undefined, importSubPath: string): boolean {\n // If the exports map is a string, it's a shorthand for a single export.\n // If it's an array, the contents are fallbacks for a single export.\n if (!exportsMap || typeof exportsMap === 'string' || Array.isArray(exportsMap)) {\n return false;\n }\n\n importSubPath = `./${importSubPath}`;\n\n return (\n // Check for very basic exclusions. (Technically a path could also be excluded by setting\n // a condition to null, or by setting a later wildcard to override an earlier one.\n // Handling for this can be added later if needed.)\n (exportsMap as Record<string, unknown>)[importSubPath] !== null &&\n Object.keys(exportsMap).some((key) => {\n // . is the root import, not a sub-path.\n // Starting character other than . means this is a condition, not a path.\n if (key === '.' || key[0] !== '.') {\n return false;\n }\n if (key.includes('*')) {\n return new RegExp(`^${key.replace(/\\./g, '\\\\.').replace(/\\*/g, '.*')}$`).test(importSubPath);\n }\n if (key.endsWith('/')) {\n return importSubPath.startsWith(key);\n }\n // Check if the path is a literal match for this key\n return key === importSubPath;\n })\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvePackageRoot.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/resolvePackageRoot.ts"],"names":[],"mappings":";;AAqBA,gDAyBC;AA9CD,6BAA6B;AAC7B,oCAAoC;AAEpC,sCAAsC;AACtC,0CAA0C;AAC1C,0CAA0C;AAC1C,8BAA8B;AAC9B,kGAAkG;AAClG,gGAAgG;AAChG,mFAAmF;AACnF,2BAA2B;AAC3B,MAAM,WAAW,GAAyB,QAAQ,CAAC,IAAI,IAAK,QAAgB,CAAC,OAAO,EAAE,IAAI,CAAC;AAE3F,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,WAAmB,
|
|
1
|
+
{"version":3,"file":"resolvePackageRoot.js","sourceRoot":"","sources":["../../../src/utils/unsupportedImports/resolvePackageRoot.ts"],"names":[],"mappings":";;AAqBA,gDAyBC;AA9CD,6BAA6B;AAC7B,oCAAoC;AAEpC,sCAAsC;AACtC,0CAA0C;AAC1C,0CAA0C;AAC1C,8BAA8B;AAC9B,kGAAkG;AAClG,gGAAgG;AAChG,mFAAmF;AACnF,2BAA2B;AAC3B,MAAM,WAAW,GAAyB,QAAQ,CAAC,IAAI,IAAK,QAAgB,CAAC,OAAO,EAAE,IAAI,CAAC;AAE3F,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,WAAmB,EAAU,EAAE,CAAC,GAAG,OAAO,KAAK,WAAW,EAAE,CAAC;AACnG,MAAM,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;AAEtD;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,OAAe,EAAE,WAAmB,EAAE,KAAc;IACrF,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,WAAW,GAAG,GAAG,WAAW,eAAe,CAAC;IAClD,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,IAAI,CAAC;QACH,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACnG,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,KAAK,EAAE,CAAC;YACV,2BAA2B;YAC3B,IAAK,GAAW,EAAE,IAAI,KAAK,kBAAkB,EAAE,CAAC;gBAC9C,OAAO,CAAC,KAAK,CAAC,qBAAqB,WAAW,SAAS,OAAO,qBAAqB,CAAC,CAAC;YACvF,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,qBAAqB,WAAW,SAAS,OAAO,KAAM,GAAa,CAAC,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC;YACtG,CAAC;QACH,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrC,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import * as path from 'path';\nimport * as _resolve from 'resolve';\n\n// 'resolve' index.js looks like this:\n// var async = require('./lib/async');\n// async.sync = require('./lib/sync');\n// module.exports = async;\n// This does not play nicely with at least one transpilation or interop step, possibly on specific\n// Node versions: `import * as resolve` *usually* gives the `resolve` function, but sometimes it\n// gives an object with property `default`... This is a workaround for either case.\n// eslint-disable-next-line\nconst resolveSync: typeof _resolve.sync = _resolve.sync || (_resolve as any).default?.sync;\n\nconst getCacheKey = (fromDir: string, packageName: string): string => `${fromDir}::${packageName}`;\nconst resolveCache = new Map<string, string | null>();\n\n/**\n * Resolve the root directory of `packageName` starting from `fromDir`, with caching.\n * This uses the basic `resolve` package (which doesn't respect exports maps) to resolve\n * `${packageName}/package.json`, which should always exist.\n */\nexport function resolvePackageRoot(fromDir: string, packageName: string, debug: boolean): string | null {\n const cacheKey = getCacheKey(fromDir, packageName);\n const cached = resolveCache.get(cacheKey);\n if (cached !== undefined) {\n return cached;\n }\n\n const resolvePath = `${packageName}/package.json`;\n let resolved: string | null = null;\n try {\n resolved = path.dirname(resolveSync(resolvePath, { basedir: fromDir, preserveSymlinks: false }));\n } catch (err) {\n if (debug) {\n // eslint-disable-next-line\n if ((err as any)?.code === 'MODULE_NOT_FOUND') {\n console.error(`Failed to resolve ${resolvePath} from ${fromDir} (module not found)`);\n } else {\n console.error(`Failed to resolve ${resolvePath} from ${fromDir}: ${(err as Error).message || err}`);\n }\n }\n }\n\n // Cache even if resolution failed so we don't waste time trying again\n resolveCache.set(cacheKey, resolved);\n return resolved;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A set of ESLint rules for Cloudpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"type": "commonjs",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./lib/index.d.ts",
|
|
11
|
+
"default": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./flat": {
|
|
14
|
+
"types": "./lib/flat.d.mts",
|
|
15
|
+
"import": "./lib/flat.mjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
8
18
|
"scripts": {
|
|
9
19
|
"build:watch": "cloudpack-scripts build-watch",
|
|
10
20
|
"build": "cloudpack-scripts build",
|
|
@@ -17,10 +27,11 @@
|
|
|
17
27
|
"resolve": "^1.22.0"
|
|
18
28
|
},
|
|
19
29
|
"peerDependencies": {
|
|
20
|
-
"@rnx-kit/eslint-plugin": "^0.
|
|
21
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
22
|
-
"@typescript-eslint/parser": "^
|
|
23
|
-
"eslint": "
|
|
30
|
+
"@rnx-kit/eslint-plugin": "^0.8.0",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
32
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
33
|
+
"eslint": "^8.0.0 || ^9.0.0",
|
|
34
|
+
"typescript": ">=5.0.0"
|
|
24
35
|
},
|
|
25
36
|
"peerDependenciesMeta": {
|
|
26
37
|
"@rnx-kit/eslint-plugin": {
|
|
@@ -28,16 +39,16 @@
|
|
|
28
39
|
}
|
|
29
40
|
},
|
|
30
41
|
"devDependencies": {
|
|
31
|
-
"@eslint/eslintrc": "^2.0.0",
|
|
32
42
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
33
43
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
34
44
|
"@ms-cloudpack/test-utilities": "^0.5.0",
|
|
35
|
-
"@
|
|
36
|
-
"@typescript-eslint/
|
|
37
|
-
"@typescript-eslint/
|
|
38
|
-
"@typescript-eslint/
|
|
39
|
-
"eslint": "^8.
|
|
40
|
-
"
|
|
45
|
+
"@rnx-kit/eslint-plugin": "^0.8.0",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
48
|
+
"@typescript-eslint/rule-tester": "^8.0.0",
|
|
49
|
+
"@typescript-eslint/utils": "^8.0.0",
|
|
50
|
+
"eslint": "^9.0.0",
|
|
51
|
+
"typescript": "~5.8.0"
|
|
41
52
|
},
|
|
42
53
|
"files": [
|
|
43
54
|
"lib/**/!(*.test.*)"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding-requiring-type-checking.d.ts","sourceRoot":"","sources":["../../src/configs/onboarding-requiring-type-checking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,aAAa,CAAC,MAIpE,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onboardingRequiringTypeChecking = void 0;
|
|
4
|
-
const recommended_requiring_type_checking_1 = require("./recommended-requiring-type-checking");
|
|
5
|
-
exports.onboardingRequiringTypeChecking = {
|
|
6
|
-
...recommended_requiring_type_checking_1.recommendedRequiringTypeChecking,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
8
|
-
rules: Object.fromEntries(Object.keys(recommended_requiring_type_checking_1.recommendedRequiringTypeChecking.rules).map((rule) => [rule, 'warn'])),
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=onboarding-requiring-type-checking.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding-requiring-type-checking.js","sourceRoot":"","sources":["../../src/configs/onboarding-requiring-type-checking.ts"],"names":[],"mappings":";;;AACA,+FAAyF;AAE5E,QAAA,+BAA+B,GAAkC;IAC5E,GAAG,sEAAgC;IACnC,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,sEAAgC,CAAC,KAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;CAC9G,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\nimport { recommendedRequiringTypeChecking } from './recommended-requiring-type-checking';\n\nexport const onboardingRequiringTypeChecking: TSESLint.ClassicConfig.Config = {\n ...recommendedRequiringTypeChecking,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n rules: Object.fromEntries(Object.keys(recommendedRequiringTypeChecking.rules!).map((rule) => [rule, 'warn'])),\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding.d.ts","sourceRoot":"","sources":["../../src/configs/onboarding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAGzD,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,MAI/C,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onboarding = void 0;
|
|
4
|
-
const recommended_1 = require("./recommended");
|
|
5
|
-
exports.onboarding = {
|
|
6
|
-
...recommended_1.recommended,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
8
|
-
rules: Object.fromEntries(Object.keys(recommended_1.recommended.rules).map((rule) => [rule, 'warn'])),
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=onboarding.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onboarding.js","sourceRoot":"","sources":["../../src/configs/onboarding.ts"],"names":[],"mappings":";;;AACA,+CAA4C;AAE/B,QAAA,UAAU,GAAkC;IACvD,GAAG,yBAAW;IACd,oEAAoE;IACpE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAW,CAAC,KAAM,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;CACzF,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\nimport { recommended } from './recommended';\n\nexport const onboarding: TSESLint.ClassicConfig.Config = {\n ...recommended,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n rules: Object.fromEntries(Object.keys(recommended.rules!).map((rule) => [rule, 'warn'])),\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recommended-requiring-type-checking.d.ts","sourceRoot":"","sources":["../../src/configs/recommended-requiring-type-checking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,eAAO,MAAM,gCAAgC,EAAE,QAAQ,CAAC,aAAa,CAAC,MAMrE,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recommendedRequiringTypeChecking = void 0;
|
|
4
|
-
exports.recommendedRequiringTypeChecking = {
|
|
5
|
-
plugins: ['@typescript-eslint'],
|
|
6
|
-
rules: {
|
|
7
|
-
'@typescript-eslint/consistent-type-imports': 'error',
|
|
8
|
-
'@typescript-eslint/consistent-type-exports': 'error',
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=recommended-requiring-type-checking.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recommended-requiring-type-checking.js","sourceRoot":"","sources":["../../src/configs/recommended-requiring-type-checking.ts"],"names":[],"mappings":";;;AAEa,QAAA,gCAAgC,GAAkC;IAC7E,OAAO,EAAE,CAAC,oBAAoB,CAAC;IAC/B,KAAK,EAAE;QACL,4CAA4C,EAAE,OAAO;QACrD,4CAA4C,EAAE,OAAO;KACtD;CACF,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\n\nexport const recommendedRequiringTypeChecking: TSESLint.ClassicConfig.Config = {\n plugins: ['@typescript-eslint'],\n rules: {\n '@typescript-eslint/consistent-type-imports': 'error',\n '@typescript-eslint/consistent-type-exports': 'error',\n },\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.d.ts","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,MAOhD,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recommended = void 0;
|
|
4
|
-
exports.recommended = {
|
|
5
|
-
plugins: ['@ms-cloudpack', '@rnx-kit', '@typescript-eslint'],
|
|
6
|
-
rules: {
|
|
7
|
-
'@ms-cloudpack/no-unsupported-imports': 'error',
|
|
8
|
-
'@rnx-kit/no-const-enum': 'error',
|
|
9
|
-
'@rnx-kit/no-export-all': 'error',
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=recommended.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.js","sourceRoot":"","sources":["../../src/configs/recommended.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAkC;IACxD,OAAO,EAAE,CAAC,eAAe,EAAE,UAAU,EAAE,oBAAoB,CAAC;IAC5D,KAAK,EAAE;QACL,sCAAsC,EAAE,OAAO;QAC/C,wBAAwB,EAAE,OAAO;QACjC,wBAAwB,EAAE,OAAO;KAClC;CACF,CAAC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/utils';\n\nexport const recommended: TSESLint.ClassicConfig.Config = {\n plugins: ['@ms-cloudpack', '@rnx-kit', '@typescript-eslint'],\n rules: {\n '@ms-cloudpack/no-unsupported-imports': 'error',\n '@rnx-kit/no-const-enum': 'error',\n '@rnx-kit/no-export-all': 'error',\n },\n};\n"]}
|