@shuvi/eslint-plugin-shuvi 1.0.32 → 1.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +4 -2
- package/lib/rules/no-export-loader-default-from-same-module.d.ts +2 -0
- package/lib/rules/no-export-loader-default-from-same-module.js +62 -0
- package/lib/rules/no-typos-page.js +2 -2
- package/lib/utils/is-page.d.ts +1 -0
- package/lib/utils/is-page.js +8 -0
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -5,7 +5,8 @@ module.exports = {
|
|
|
5
5
|
'no-html-link-for-pages': require('./rules/no-html-link-for-pages').default,
|
|
6
6
|
'no-typos-page': require('./rules/no-typos-page').default,
|
|
7
7
|
'no-typos-custom-app': require('./rules/no-typos-custom-app').default,
|
|
8
|
-
'no-typos-custom-server': require('./rules/no-typos-custom-server').default
|
|
8
|
+
'no-typos-custom-server': require('./rules/no-typos-custom-server').default,
|
|
9
|
+
'no-export-loader-default-from-same-module': require('./rules/no-export-loader-default-from-same-module').default
|
|
9
10
|
},
|
|
10
11
|
configs: {
|
|
11
12
|
recommended: {
|
|
@@ -16,7 +17,8 @@ module.exports = {
|
|
|
16
17
|
'@shuvi/shuvi/no-typos-page': 'error',
|
|
17
18
|
'@shuvi/shuvi/no-typos-custom-app': 'error',
|
|
18
19
|
'@shuvi/shuvi/no-typos-custom-server': 'error',
|
|
19
|
-
'@shuvi/shuvi/no-html-link-for-pages': 'error'
|
|
20
|
+
'@shuvi/shuvi/no-html-link-for-pages': 'error',
|
|
21
|
+
'@shuvi/shuvi/no-export-loader-default-from-same-module': 'error'
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const define_rule_1 = require("../utils/define-rule");
|
|
4
|
+
const is_page_1 = require("../utils/is-page");
|
|
5
|
+
const WHITELIST = ['loader', 'default'];
|
|
6
|
+
exports.default = (0, define_rule_1.defineRule)({
|
|
7
|
+
meta: {
|
|
8
|
+
docs: {
|
|
9
|
+
description: `Prohibit exporting ${WHITELIST.join(',')} module from a single module, please export separately from different modules.`,
|
|
10
|
+
recommended: true
|
|
11
|
+
},
|
|
12
|
+
type: 'problem',
|
|
13
|
+
schema: []
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
const exported = {};
|
|
17
|
+
const nodes = new Set();
|
|
18
|
+
return {
|
|
19
|
+
ExportNamedDeclaration(node) {
|
|
20
|
+
const fileName = context.getFilename();
|
|
21
|
+
if (!fileName || !(0, is_page_1.isPage)(fileName)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!node.source) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!node.specifiers || node.specifiers.length === 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const sourceValue = node.source.value;
|
|
31
|
+
node.specifiers.forEach(specifier => {
|
|
32
|
+
const name = specifier.exported.name;
|
|
33
|
+
if (WHITELIST.includes(name)) {
|
|
34
|
+
if (exported[name]) {
|
|
35
|
+
context.report({
|
|
36
|
+
node,
|
|
37
|
+
message: `${name} duplicate export from ${sourceValue}`
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exported[name] = sourceValue;
|
|
41
|
+
nodes.add(node);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
'Program:exit': function onExit() {
|
|
46
|
+
const sourceValues = Object.values(exported);
|
|
47
|
+
const length = sourceValues.length;
|
|
48
|
+
if (!length) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (new Set(sourceValues).size !== length) {
|
|
52
|
+
nodes.forEach(node => {
|
|
53
|
+
context.report({
|
|
54
|
+
node,
|
|
55
|
+
message: `Prohibit exporting ${WHITELIST.join(', ')} module from a single module, please export separately from different modules. https://shuvijs.github.io/shuvijs.org/docs/guides/Data%20Fetching#import-loader-from-other-modules`
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const define_rule_1 = require("../utils/define-rule");
|
|
4
4
|
const url_1 = require("../utils/url");
|
|
5
|
+
const is_page_1 = require("../utils/is-page");
|
|
5
6
|
const EXPORT_FUNCTIONS = ['loader'];
|
|
6
|
-
const PAGEREG = /routes\/.*page\.(j|t)sx?$/;
|
|
7
7
|
exports.default = (0, define_rule_1.defineRule)({
|
|
8
8
|
meta: {
|
|
9
9
|
docs: {
|
|
@@ -35,7 +35,7 @@ exports.default = (0, define_rule_1.defineRule)({
|
|
|
35
35
|
ExportNamedDeclaration(node) {
|
|
36
36
|
var _a;
|
|
37
37
|
const fileName = context.getFilename();
|
|
38
|
-
if (!fileName || !
|
|
38
|
+
if (!fileName || !(0, is_page_1.isPage)(fileName)) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
const decl = node.declaration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isPage(path: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/eslint-plugin-shuvi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"description": "ESLint plugin for Shuvi.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"build": "tsc -p tsconfig.json"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@shuvi/router": "1.0.
|
|
22
|
-
"@shuvi/platform-shared": "1.0.
|
|
21
|
+
"@shuvi/router": "1.0.34",
|
|
22
|
+
"@shuvi/platform-shared": "1.0.34"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/eslint": "7.28.0",
|