eslint-plugin-light 1.0.22 → 1.0.24
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/CHANGELOG.md +14 -0
- package/README.md +84 -2
- package/lib/rules/img-v-lazy.js +48 -24
- package/lib/rules/no-barrel-import.js +116 -0
- package/lib/test/img-v-lazy.js +87 -0
- package/lib/test/index.js +2 -0
- package/lib/test/no-barrel-import.js +92 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## <small>1.0.24 (2026-06-02)</small>
|
|
2
|
+
|
|
3
|
+
* feat(eslint-plugin-light): add no-barrel-import ([38dfe30](https://github.com/novlan1/plugin-light/commits/38dfe30))
|
|
4
|
+
* chore: update plugin-light docs address ([9c7d627](https://github.com/novlan1/plugin-light/commits/9c7d627))
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## <small>1.0.23 (2026-04-27)</small>
|
|
9
|
+
|
|
10
|
+
* feat(plugin-light): 三元表达式不修复 ([ecabda4](https://github.com/novlan1/plugin-light/commits/ecabda4))
|
|
11
|
+
* chore: update docs ([84adc98](https://github.com/novlan1/plugin-light/commits/84adc98))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
1
15
|
## <small>1.0.22 (2026-03-24)</small>
|
|
2
16
|
|
|
3
17
|
* feat: add no-complex-style-class rule ([2cc25ee](https://github.com/novlan1/plugin-light/commits/2cc25ee))
|
package/README.md
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<img src="https://img.shields.io/npm/unpacked-size/eslint-plugin-light">
|
|
6
6
|
<img src="https://img.shields.io/npm/v/eslint-plugin-light">
|
|
7
7
|
<img src="https://img.shields.io/npm/l/eslint-plugin-light">
|
|
8
|
-
<img src="https://img.shields.io/
|
|
9
|
-
<img src="https://img.shields.io/
|
|
8
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-blue?logo=typescript&logoColor=white" alt="TypeScript strict">
|
|
9
|
+
<img src="https://img.shields.io/badge/created-2022--01-blue?logo=github&logoColor=white">
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
简单、易用的 ESLint 插件库。
|
|
@@ -870,6 +870,88 @@ module.exports = {
|
|
|
870
870
|
<div :style="{ color: getColor() }" />
|
|
871
871
|
```
|
|
872
872
|
|
|
873
|
+
### 4.20. no-barrel-import
|
|
874
|
+
|
|
875
|
+
禁止从指定包的入口(barrel / 桶文件)直接 `import`,必须按子路径引入。
|
|
876
|
+
|
|
877
|
+
背景:
|
|
878
|
+
|
|
879
|
+
> 从包入口直接 `import` 时,webpack 解析阶段会把整个包(含 `file-loader` 引入的图片资源)全量打入产物,tree-shaking 也无法消除这部分体积。按子路径引入可以只打包真正用到的子模块,显著减小产物体积。
|
|
880
|
+
|
|
881
|
+
默认目标包是 `press-pix`,其目录结构为:包根目录下直接是 kebab-case 组件目录,每个组件目录里有同名入口文件,并且是 `export default`。
|
|
882
|
+
|
|
883
|
+
错误示例:
|
|
884
|
+
|
|
885
|
+
```js
|
|
886
|
+
// ❌ 从 barrel 入口引入
|
|
887
|
+
import { CdnImage } from 'press-pix';
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
正确示例:
|
|
891
|
+
|
|
892
|
+
```js
|
|
893
|
+
// ✅ 按子路径引入
|
|
894
|
+
import CdnImage from 'press-pix/cdn-image/cdn-image';
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
如果加了 `--fix`,命名导入会被自动转换为子路径的默认导入:
|
|
898
|
+
|
|
899
|
+
```js
|
|
900
|
+
// 转换前
|
|
901
|
+
import { CdnImage, IconButton } from 'press-pix';
|
|
902
|
+
|
|
903
|
+
// 转换后
|
|
904
|
+
import CdnImage from 'press-pix/cdn-image/cdn-image';
|
|
905
|
+
import IconButton from 'press-pix/icon-button/icon-button';
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
Usage:
|
|
909
|
+
|
|
910
|
+
```js
|
|
911
|
+
// .eslintrc.js
|
|
912
|
+
|
|
913
|
+
module.exports = {
|
|
914
|
+
plugins: [
|
|
915
|
+
'light',
|
|
916
|
+
],
|
|
917
|
+
rules: {
|
|
918
|
+
'light/no-barrel-import': 2,
|
|
919
|
+
},
|
|
920
|
+
}
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
配置选项:
|
|
924
|
+
|
|
925
|
+
| 字段 | 说明 | 默认值 |
|
|
926
|
+
| ------------- | -------- | --------- |
|
|
927
|
+
| packages | 受限的包名列表(barrel 入口) | `['press-pix']` |
|
|
928
|
+
| pathTemplate | 子路径模板,支持 `{pkg}` 和 `{name}` 占位符 | `'{pkg}/{name}/{name}'` |
|
|
929
|
+
| defaultExport | 子模块是否默认导出(`true` 时 `--fix` 会写成 default import)| `true` |
|
|
930
|
+
| mapping | 个别命名的硬编码覆盖映射(`{ 导入名: 完整子路径 }` | `{}` |
|
|
931
|
+
|
|
932
|
+
自定义配置示例:
|
|
933
|
+
|
|
934
|
+
```js
|
|
935
|
+
// .eslintrc.js
|
|
936
|
+
|
|
937
|
+
module.exports = {
|
|
938
|
+
plugins: [
|
|
939
|
+
'light',
|
|
940
|
+
],
|
|
941
|
+
rules: {
|
|
942
|
+
'light/no-barrel-import': [2, {
|
|
943
|
+
packages: ['press-pix', 'some-other-pkg'],
|
|
944
|
+
pathTemplate: '{pkg}/{name}/{name}',
|
|
945
|
+
defaultExport: true,
|
|
946
|
+
mapping: {
|
|
947
|
+
// 对于命名不规则的子模块,可以单独指定路径
|
|
948
|
+
SpecialIcon: 'press-pix/icons/special',
|
|
949
|
+
},
|
|
950
|
+
}],
|
|
951
|
+
},
|
|
952
|
+
}
|
|
953
|
+
```
|
|
954
|
+
|
|
873
955
|
## 5. 更新日志
|
|
874
956
|
|
|
875
957
|
[点此查看](./CHANGELOG.md)
|
package/lib/rules/img-v-lazy.js
CHANGED
|
@@ -9,11 +9,25 @@ module.exports = {
|
|
|
9
9
|
recommended: true,
|
|
10
10
|
},
|
|
11
11
|
fixable: 'code',
|
|
12
|
+
messages: {
|
|
13
|
+
useVLazy: 'Use v-lazy instead of :src for image loading',
|
|
14
|
+
useVLazyManual: 'Use v-lazy instead of :src for image loading (manual replacement required: conditional or fallback expression detected)',
|
|
15
|
+
},
|
|
12
16
|
schema: [],
|
|
13
17
|
},
|
|
14
18
|
create(context) {
|
|
15
19
|
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
16
20
|
|
|
21
|
+
// 判断一个节点是否含有字符串字面量(递归检查 || 链)
|
|
22
|
+
function hasStringLiteral(n) {
|
|
23
|
+
if (!n) return false;
|
|
24
|
+
if (n.type === 'Literal' && typeof n.value === 'string') return true;
|
|
25
|
+
if (n.type === 'LogicalExpression' && n.operator === '||') {
|
|
26
|
+
return hasStringLiteral(n.left) || hasStringLiteral(n.right);
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
17
31
|
const parserServices = getParserServices(context);
|
|
18
32
|
if (!parserServices?.defineTemplateBodyVisitor) {
|
|
19
33
|
return {};
|
|
@@ -32,30 +46,40 @@ module.exports = {
|
|
|
32
46
|
&& attr.key.name.name === 'lazy');
|
|
33
47
|
|
|
34
48
|
if (srcBinding && !hasVLazy) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const expr = srcBinding.value && srcBinding.value.expression;
|
|
50
|
+
|
|
51
|
+
const isConditional = expr && expr.type === 'ConditionalExpression';
|
|
52
|
+
const isLogicalOr = expr && expr.type === 'LogicalExpression' && expr.operator === '||';
|
|
53
|
+
const isLiteral = expr && expr.type === 'Literal';
|
|
54
|
+
|
|
55
|
+
// 三元表达式 → 手动
|
|
56
|
+
// 顶层字符串字面量 → 手动
|
|
57
|
+
// || 且含字符串字面量 → 用反引号自动修复
|
|
58
|
+
// || 且不含字符串字面量 → 正常双引号自动修复
|
|
59
|
+
if (isConditional || isLiteral) {
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
messageId: 'useVLazyManual',
|
|
63
|
+
});
|
|
64
|
+
} else if (isLogicalOr && hasStringLiteral(expr)) {
|
|
65
|
+
context.report({
|
|
66
|
+
node,
|
|
67
|
+
messageId: 'useVLazy',
|
|
68
|
+
fix(fixer) {
|
|
69
|
+
const srcText = sourceCode.getText(expr);
|
|
70
|
+
return fixer.replaceText(srcBinding, `v-lazy=\`${srcText}\``);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
context.report({
|
|
75
|
+
node,
|
|
76
|
+
messageId: 'useVLazy',
|
|
77
|
+
fix(fixer) {
|
|
78
|
+
const srcText = sourceCode.getText(expr);
|
|
79
|
+
return fixer.replaceText(srcBinding, `v-lazy="${srcText}"`);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
59
83
|
}
|
|
60
84
|
},
|
|
61
85
|
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 禁止从指定包的入口(barrel / 桶文件)直接 import,必须按子路径引入,
|
|
5
|
+
* 否则 webpack 解析阶段会把整个包(含 file-loader 引入的图片资源)
|
|
6
|
+
* 全量打入产物,tree-shaking 也救不回来。
|
|
7
|
+
*
|
|
8
|
+
* 默认配置以 press-pix 为目标包:
|
|
9
|
+
* 错误:import { CdnImage } from 'press-pix';
|
|
10
|
+
* 正确:import CdnImage from 'press-pix/cdn-image/cdn-image';
|
|
11
|
+
*
|
|
12
|
+
* press-pix 的实际目录结构:包根目录下直接是 kebab-case 组件目录,
|
|
13
|
+
* 每个组件目录里有同名入口文件,并且是 `export default`。
|
|
14
|
+
*
|
|
15
|
+
* 配置:
|
|
16
|
+
* {
|
|
17
|
+
* packages: ['press-pix'], // 受限的包名(barrel 入口)
|
|
18
|
+
* pathTemplate: '{pkg}/{name}/{name}', // 子路径模板
|
|
19
|
+
* defaultExport: true, // 子模块是否默认导出(true 时 fix 会写成 default import)
|
|
20
|
+
* mapping: { Foo: 'press-pix/foo/foo' } // 个别命名硬编码覆盖
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function toKebabCase(str) {
|
|
25
|
+
return String(str)
|
|
26
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
27
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
|
|
28
|
+
.replace(/_/g, '-')
|
|
29
|
+
.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function buildSubPath(pkg, specifierName, options) {
|
|
33
|
+
if (options.mapping && options.mapping[specifierName]) {
|
|
34
|
+
return options.mapping[specifierName];
|
|
35
|
+
}
|
|
36
|
+
const tpl = options.pathTemplate || '{pkg}/{name}/{name}';
|
|
37
|
+
const kebab = toKebabCase(specifierName);
|
|
38
|
+
return tpl.replace(/\{pkg\}/g, pkg).replace(/\{name\}/g, kebab);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
meta: {
|
|
43
|
+
type: 'problem',
|
|
44
|
+
docs: {
|
|
45
|
+
description: '禁止从包入口(barrel)直接 import,必须按子路径引入',
|
|
46
|
+
category: 'Best Practices',
|
|
47
|
+
recommended: true,
|
|
48
|
+
},
|
|
49
|
+
fixable: 'code',
|
|
50
|
+
schema: [
|
|
51
|
+
{
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
packages: { type: 'array', items: { type: 'string' } },
|
|
55
|
+
pathTemplate: { type: 'string' },
|
|
56
|
+
defaultExport: { type: 'boolean' },
|
|
57
|
+
mapping: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
additionalProperties: { type: 'string' },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
messages: {
|
|
66
|
+
noEntryImport: '禁止从 \'{{pkg}}\' 入口直接引入,请按子路径引入(如 \'{{pkg}}/cdn-image/cdn-image\'),否则 webpack 会把整个包打进产物。',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
create(context) {
|
|
71
|
+
const options = (context.options && context.options[0]) || {};
|
|
72
|
+
const packages = options.packages && options.packages.length
|
|
73
|
+
? options.packages
|
|
74
|
+
: ['press-pix'];
|
|
75
|
+
// press-pix 的子模块都是 default 导出,所以默认 true
|
|
76
|
+
const useDefault = options.defaultExport !== false;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
ImportDeclaration(node) {
|
|
80
|
+
const importPath = node.source.value;
|
|
81
|
+
if (!packages.includes(importPath)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const specifiers = node.specifiers || [];
|
|
86
|
+
// 只对 named import 提供 autofix(最常见、最安全的场景)
|
|
87
|
+
const allNamed = specifiers.length > 0
|
|
88
|
+
&& specifiers.every(s => s.type === 'ImportSpecifier');
|
|
89
|
+
|
|
90
|
+
context.report({
|
|
91
|
+
node,
|
|
92
|
+
messageId: 'noEntryImport',
|
|
93
|
+
data: { pkg: importPath },
|
|
94
|
+
fix: allNamed
|
|
95
|
+
? (fixer) => {
|
|
96
|
+
const lines = specifiers.map((s) => {
|
|
97
|
+
const importedName = s.imported.name;
|
|
98
|
+
const localName = s.local.name;
|
|
99
|
+
const subPath = buildSubPath(importPath, importedName, options);
|
|
100
|
+
if (useDefault) {
|
|
101
|
+
// import LocalName from 'xxx';
|
|
102
|
+
return `import ${localName} from '${subPath}';`;
|
|
103
|
+
}
|
|
104
|
+
const part = importedName === localName
|
|
105
|
+
? `{ ${importedName} }`
|
|
106
|
+
: `{ ${importedName} as ${localName} }`;
|
|
107
|
+
return `import ${part} from '${subPath}';`;
|
|
108
|
+
});
|
|
109
|
+
return fixer.replaceText(node, lines.join('\n'));
|
|
110
|
+
}
|
|
111
|
+
: null,
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const { RuleTester } = require('eslint');
|
|
2
|
+
|
|
3
|
+
const rule = require('../rules/img-v-lazy');
|
|
4
|
+
|
|
5
|
+
const FILENAME = 'test.vue';
|
|
6
|
+
|
|
7
|
+
const ruleTester = new RuleTester({
|
|
8
|
+
parser: require.resolve('vue-eslint-parser'),
|
|
9
|
+
parserOptions: {
|
|
10
|
+
ecmaVersion: 'latest',
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
ruleTester.run('img-v-lazy', rule, {
|
|
16
|
+
valid: [
|
|
17
|
+
// 已使用 v-lazy,合法
|
|
18
|
+
{
|
|
19
|
+
code: '<template><img v-lazy="imgUrl" /></template>',
|
|
20
|
+
filename: FILENAME,
|
|
21
|
+
},
|
|
22
|
+
// 静态 src(非绑定),合法
|
|
23
|
+
{
|
|
24
|
+
code: '<template><img src="https://example.com/image.png" /></template>',
|
|
25
|
+
filename: FILENAME,
|
|
26
|
+
},
|
|
27
|
+
// 已同时有 :src 和 v-lazy,合法
|
|
28
|
+
{
|
|
29
|
+
code: '<template><img :src="imgUrl" v-lazy="imgUrl" /></template>',
|
|
30
|
+
filename: FILENAME,
|
|
31
|
+
},
|
|
32
|
+
// 非 img 标签,合法
|
|
33
|
+
{
|
|
34
|
+
code: '<template><div :src="imgUrl"></div></template>',
|
|
35
|
+
filename: FILENAME,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
invalid: [
|
|
39
|
+
// 普通变量绑定,可自动修复
|
|
40
|
+
{
|
|
41
|
+
code: '<template><img :src="imgUrl" /></template>',
|
|
42
|
+
filename: FILENAME,
|
|
43
|
+
errors: [{ messageId: 'useVLazy' }],
|
|
44
|
+
output: '<template><img v-lazy="imgUrl" /></template>',
|
|
45
|
+
},
|
|
46
|
+
// 成员表达式,可自动修复
|
|
47
|
+
{
|
|
48
|
+
code: '<template><img :src="item.imageUrl" /></template>',
|
|
49
|
+
filename: FILENAME,
|
|
50
|
+
errors: [{ messageId: 'useVLazy' }],
|
|
51
|
+
output: '<template><img v-lazy="item.imageUrl" /></template>',
|
|
52
|
+
},
|
|
53
|
+
// 字符串字面量,需手动替换(无 output / fix)
|
|
54
|
+
{
|
|
55
|
+
code: '<template><img :src="\'https://example.com/img.png\'" /></template>',
|
|
56
|
+
filename: FILENAME,
|
|
57
|
+
errors: [{ messageId: 'useVLazyManual' }],
|
|
58
|
+
},
|
|
59
|
+
// 三元表达式,需手动替换(无 output / fix)
|
|
60
|
+
{
|
|
61
|
+
code: '<template><img :src="item.img ? item.img : \'https://example.com/default.png\'" /></template>',
|
|
62
|
+
filename: FILENAME,
|
|
63
|
+
errors: [{ messageId: 'useVLazyManual' }],
|
|
64
|
+
},
|
|
65
|
+
// 逻辑或 + 字符串字面量,用反引号自动修复
|
|
66
|
+
{
|
|
67
|
+
code: '<template><img :src="item.img || \'https://example.com/default.png\'" /></template>',
|
|
68
|
+
filename: FILENAME,
|
|
69
|
+
errors: [{ messageId: 'useVLazy' }],
|
|
70
|
+
output: '<template><img v-lazy=`item.img || \'https://example.com/default.png\'` /></template>',
|
|
71
|
+
},
|
|
72
|
+
// 逻辑或 + 两侧都是变量,正常双引号自动修复
|
|
73
|
+
{
|
|
74
|
+
code: '<template><img :src="item.img || fallbackImg" /></template>',
|
|
75
|
+
filename: FILENAME,
|
|
76
|
+
errors: [{ messageId: 'useVLazy' }],
|
|
77
|
+
output: '<template><img v-lazy="item.img || fallbackImg" /></template>',
|
|
78
|
+
},
|
|
79
|
+
// v-bind:src 写法,可自动修复
|
|
80
|
+
{
|
|
81
|
+
code: '<template><img v-bind:src="imgUrl" /></template>',
|
|
82
|
+
filename: FILENAME,
|
|
83
|
+
errors: [{ messageId: 'useVLazy' }],
|
|
84
|
+
output: '<template><img v-lazy="imgUrl" /></template>',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
package/lib/test/index.js
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const { RuleTester } = require('eslint');
|
|
2
|
+
|
|
3
|
+
const rule = require('../rules/no-barrel-import');
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester({
|
|
6
|
+
parserOptions: {
|
|
7
|
+
ecmaVersion: 2020,
|
|
8
|
+
sourceType: 'module',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
ruleTester.run('no-barrel-import', rule, {
|
|
13
|
+
valid: [
|
|
14
|
+
// 子路径引入 —— 允许
|
|
15
|
+
'import CdnImage from \'press-pix/cdn-image/cdn-image\';',
|
|
16
|
+
'import DateTimePicker from \'press-pix/date-time-picker/date-time-picker\';',
|
|
17
|
+
'import PmgMatchingCountdown from \'press-pix/pmg-matching-countdown/pmg-matching-countdown\';',
|
|
18
|
+
|
|
19
|
+
// 不相关的包 —— 不应报错
|
|
20
|
+
'import React from \'react\';',
|
|
21
|
+
'import { something } from \'./local\';',
|
|
22
|
+
'import { CdnImage } from \'press-ui\';',
|
|
23
|
+
'import { CdnImage } from \'press-pix\';', // 没带 不在默认列表
|
|
24
|
+
|
|
25
|
+
// 自定义 packages 列表时,原默认包不应受限
|
|
26
|
+
{
|
|
27
|
+
code: 'import { CdnImage } from \'press-pix\';',
|
|
28
|
+
options: [{ packages: ['some-other-pkg'] }],
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
|
|
32
|
+
invalid: [
|
|
33
|
+
// 默认配置:press-pix 入口引入 —— 报错并 autofix 成 default import
|
|
34
|
+
{
|
|
35
|
+
code: 'import { CdnImage } from \'press-pix\';',
|
|
36
|
+
output: 'import CdnImage from \'press-pix/cdn-image/cdn-image\';',
|
|
37
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
38
|
+
},
|
|
39
|
+
// 多个 specifier,按行拆分
|
|
40
|
+
{
|
|
41
|
+
code: 'import { CdnImage, DateTimePicker } from \'press-pix\';',
|
|
42
|
+
output: 'import CdnImage from \'press-pix/cdn-image/cdn-image\';\nimport DateTimePicker from \'press-pix/date-time-picker/date-time-picker\';',
|
|
43
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
44
|
+
},
|
|
45
|
+
// 多段大写:PmgMatchingCountdown -> pmg-matching-countdown
|
|
46
|
+
{
|
|
47
|
+
code: 'import { PmgMatchingCountdown } from \'press-pix\';',
|
|
48
|
+
output: 'import PmgMatchingCountdown from \'press-pix/pmg-matching-countdown/pmg-matching-countdown\';',
|
|
49
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
50
|
+
},
|
|
51
|
+
// 带别名:保持 default import 形态,local name 优先
|
|
52
|
+
{
|
|
53
|
+
code: 'import { CdnImage as Img } from \'press-pix\';',
|
|
54
|
+
output: 'import Img from \'press-pix/cdn-image/cdn-image\';',
|
|
55
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
56
|
+
},
|
|
57
|
+
// 默认导入:报错但不自动修复
|
|
58
|
+
{
|
|
59
|
+
code: 'import PressPix from \'press-pix\';',
|
|
60
|
+
output: null,
|
|
61
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
62
|
+
},
|
|
63
|
+
// namespace 导入:报错但不自动修复
|
|
64
|
+
{
|
|
65
|
+
code: 'import * as PressPix from \'press-pix\';',
|
|
66
|
+
output: null,
|
|
67
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
68
|
+
},
|
|
69
|
+
// 副作用引入:报错但不自动修复
|
|
70
|
+
{
|
|
71
|
+
code: 'import \'press-pix\';',
|
|
72
|
+
output: null,
|
|
73
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
74
|
+
},
|
|
75
|
+
// mapping 覆盖
|
|
76
|
+
{
|
|
77
|
+
code: 'import { Foo } from \'press-pix\';',
|
|
78
|
+
options: [{
|
|
79
|
+
mapping: { Foo: 'press-pix/foo/index' },
|
|
80
|
+
}],
|
|
81
|
+
output: 'import Foo from \'press-pix/foo/index\';',
|
|
82
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
83
|
+
},
|
|
84
|
+
// defaultExport: false 时回退到 named import
|
|
85
|
+
{
|
|
86
|
+
code: 'import { Foo } from \'press-pix\';',
|
|
87
|
+
options: [{ defaultExport: false }],
|
|
88
|
+
output: 'import { Foo } from \'press-pix/foo/foo\';',
|
|
89
|
+
errors: [{ messageId: 'noEntryImport' }],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-light",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.24",
|
|
4
|
+
"description": "ESLint 插件",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
7
7
|
"eslint plugin",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@tdesign/uniapp-chat": "^0.2.1",
|
|
30
30
|
"minimatch": "^10.0.1",
|
|
31
31
|
"requireindex": "^1.2.0",
|
|
32
|
-
"t-comm": "^3.
|
|
32
|
+
"t-comm": "^3.2.42"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@babel/core": "^7.18.9",
|