eslint-plugin-semi-design 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,83 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 DouyinFE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ The code implementation of the external library is referenced by DouyinFe are:
24
+
25
+ - animate.css
26
+
27
+ The MIT License (MIT)
28
+
29
+ Copyright (c) 2020 Daniel Eden
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining a copy
32
+ of this software and associated documentation files (the "Software"), to deal
33
+ in the Software without restriction, including without limitation the rights
34
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
35
+ copies of the Software, and to permit persons to whom the Software is
36
+ furnished to do so, subject to the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be included in all
39
+ copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
44
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47
+ SOFTWARE.
48
+
49
+ - Ant Design
50
+ MIT LICENSE
51
+
52
+ Copyright (c) 2015-present Ant UED, https://xtech.antfin.com/
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ "Software"), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
68
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
69
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
70
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
71
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
72
+
73
+ - rc-tree
74
+
75
+ MIT LICENSE
76
+
77
+ Copyright (c) 2015-present Alipay.com, https://www.alipay.com/
78
+
79
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # eslint-plugin-semi-design
2
+
3
+ Semi 仓库使用的 eslint 插件
4
+
5
+ ## eslint 规则
6
+
7
+ ### ✅ 不能在 semi-foundation 里引用 semi-ui
8
+
9
+ semi-ui 不应该作为 semi-foundation 的依赖。
10
+
11
+ 原因:根据 Semi 的 foundation 和 adapter 设计,foundation 不应依赖 adapter。点击查看 [F/A 设计](https://bytedance.feishu.cn/wiki/wikcnOVYexosCS1Rmvb5qCsWT1f)。
12
+
13
+ ### ✅ 不能在 semi-ui 和 semi-foundation 引用 lodash-es
14
+
15
+ 使用 lodash 而不是 lodash-es。
16
+
17
+ 原因:为了兼容 next,而 lodash-es 只提供了 es module 的产物。
18
+
19
+ ![image](https://user-images.githubusercontent.com/26477537/172051379-30b42f31-b677-43be-982f-1e8f5345cfc9.png)
20
+
21
+ 点击查看[详情](https://github.com/vercel/next.js/issues/2259)。
22
+
23
+ ### ✅ 不能在 semi-ui 或 semi-foundation 使用相对路径引用 pacakges 下的包
24
+
25
+ monorepo 下各个包之间的 import 请使用包名而不是相对路径。
26
+
27
+ 原因:这两个包在用户项目的安装路径可能不在同一文件夹下,使用相对路径会找不到对应的包。
28
+
29
+ ```javascript
30
+ // ❌ 不推荐
31
+ // semi-ui/input/index.tsx
32
+ import inputFoundation from '../semi-foundation/input/foundation';
33
+
34
+ // ✅ 推荐
35
+ // semi-ui/input/index.tsx
36
+ import inputFoundation from '@douyinfe/semi-foundation/input/foundation';
37
+ ```
38
+
39
+ ### ✅ 不推荐在同个包下使用包名加路径引用其他模块
40
+
41
+ 同一个包 import 请使用相对路径而不是引用包名。
42
+
43
+ ```javascript
44
+ // ❌ 不推荐
45
+ // semi-ui/modal/Modal.tsx
46
+ import { Button } from '@douyinfe/semi-ui';
47
+
48
+ // ✅ 推荐
49
+ // semi-ui/modal/Modal.tsx
50
+ import Button from '../button';
51
+ ```
52
+
53
+ ## 相关资料
54
+
55
+ - eslint plugin 文档:https://eslint.org/docs/developer-guide/working-with-plugins
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # `semi-eslint-plugin`
2
+
3
+ eslint plugin for semi design
4
+
5
+ ## Rules
6
+
7
+ ### ✅ Should not reference semi-ui in semi-foundation
8
+
9
+ semi-ui should not be used as a dependency of semi-foundation.
10
+
11
+ Why: According to Semi's foundation and adapter design, foundation should not depend on adapter. Click to view the [F/A design](https://bytedance.feishu.cn/wiki/wikcnOVYexosCS1Rmvb5qCsWT1f).
12
+
13
+ ### ✅ Should not import lodash-es in semi-ui and semi-foundation
14
+
15
+ Use lodash instead of lodash-es.
16
+
17
+ Why: In order to be compatible with next, lodash-es only provides the product of es module.
18
+
19
+ ![image](https://user-images.githubusercontent.com/26477537/172051379-30b42f31-b677-43be-982f-1e8f5345cfc9.png)
20
+
21
+ See more [here](https://github.com/vercel/next.js/issues/2259)。
22
+
23
+ ### ✅ Should not use relative paths to import a package under pacakges in semi-ui or semi-foundation
24
+
25
+ For imports between packages under monorepo, use package names instead of relative paths.
26
+
27
+ Why: These two packages may not be in the same folder in the installation path of the user project, and the corresponding package cannot be found using the relative path.
28
+
29
+ ```javascript
30
+ // ❌ Not recommend
31
+ // semi-ui/input/index.tsx
32
+ import inputFoundation from '../semi-foundation/input/foundation';
33
+
34
+ // ✅ Recommend
35
+ // semi-ui/input/index.tsx
36
+ import inputFoundation from '@douyinfe/semi-foundation/input/foundation';
37
+ ```
38
+
39
+ ### ✅ Should not use the package name and path to import other modules under the same package
40
+ When importing the same package, use relative paths instead of referencing the package name.
41
+
42
+ ```javascript
43
+ // ❌ Not recommend
44
+ // semi-ui/modal/Modal.tsx
45
+ import { Button } from '@douyinfe/semi-ui';
46
+
47
+ // ✅ Recommend
48
+ // semi-ui/modal/Modal.tsx
49
+ import Button from '../button';
50
+
51
+ ```
52
+
53
+ ## Related docs
54
+
55
+ - eslint plugin doc:https://eslint.org/docs/developer-guide/working-with-plugins
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rules = void 0;
4
+ const rules_1 = require("./rules");
5
+ exports.rules = rules_1.default;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const no_import_1 = require("./no-import");
4
+ exports.default = {
5
+ 'no-import': no_import_1.default,
6
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const SEMI_PACKAGE_REG = /(?<=packages\/|@douyinfe\/|\.\.\/)(semi-[\w-]+)/;
4
+ const RELATIVE_PATH_REG = /(..\/)+semi-[\w-]+/;
5
+ const rule = {
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "disable import statement",
10
+ recommended: true,
11
+ url: "https://github.com/DouyinFE/semi-design"
12
+ },
13
+ fixable: "code",
14
+ messages: {
15
+ unexpected: "Unexpected import statement, semi ui should not be used as a dependency of semi foundation",
16
+ unexpectedLodashES: "Unexpected import statement, please use lodash instead of lodash-es.",
17
+ unexpectedRelativeImport: "Unexpected import statement, please use module name instead of relative path.",
18
+ unexpectedImportSelf: 'Unexpected import statement, please use relative paths to import modules in the same package.'
19
+ },
20
+ schema: [],
21
+ },
22
+ create(context) {
23
+ return {
24
+ ImportDeclaration: (node) => {
25
+ const fileName = context.getFilename();
26
+ const sourceCode = context.getSourceCode();
27
+ const importName = node.source.raw;
28
+ const isFoundationFile = fileName.includes('semi-foundation');
29
+ const isUIFile = fileName.includes('semi-ui');
30
+ const importText = sourceCode.getText(node);
31
+ if (isFoundationFile) {
32
+ if (importName.includes('semi-ui')) {
33
+ context.report({ node, messageId: "unexpected" });
34
+ }
35
+ }
36
+ if (isFoundationFile || isUIFile) {
37
+ if (importName.includes('lodash-es')) {
38
+ const fixedSource = importText.replace('lodash-es', 'lodash');
39
+ context.report({
40
+ node,
41
+ messageId: "unexpectedLodashES",
42
+ fix: (fixer) => {
43
+ return fixer.replaceText(node, fixedSource);
44
+ }
45
+ });
46
+ }
47
+ else if (importName.includes('semi-')) {
48
+ if (isImportRelativePackage({ path: importName, fileName })) {
49
+ const importPackageName = SEMI_PACKAGE_REG.exec(importName)[0];
50
+ const fixedSource = importText.replace(RELATIVE_PATH_REG, `@douyinfe/${importPackageName}`);
51
+ context.report({
52
+ node,
53
+ messageId: "unexpectedRelativeImport",
54
+ fix: (fixer) => {
55
+ return fixer.replaceText(node, fixedSource);
56
+ }
57
+ });
58
+ }
59
+ else if (isImportSelf({ path: importName, fileName })) {
60
+ context.report({
61
+ node,
62
+ messageId: "unexpectedImportSelf",
63
+ });
64
+ }
65
+ }
66
+ }
67
+ }
68
+ };
69
+ }
70
+ };
71
+ function isRelativePath(path) {
72
+ return path.includes('../');
73
+ }
74
+ function isImportRelativePackage(options) {
75
+ const { path, fileName } = options;
76
+ const currentPackageName = SEMI_PACKAGE_REG.exec(fileName)[0];
77
+ const importPackageName = SEMI_PACKAGE_REG.exec(path)[0];
78
+ return currentPackageName !== importPackageName && isRelativePath(path);
79
+ }
80
+ function isImportSelf(options) {
81
+ const { path, fileName } = options;
82
+ const currentPackageName = SEMI_PACKAGE_REG.exec(fileName)[0];
83
+ const importPackageName = SEMI_PACKAGE_REG.exec(path)[0];
84
+ return currentPackageName === importPackageName;
85
+ }
86
+ exports.default = rule;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "eslint-plugin-semi-design",
3
+ "version": "0.0.1",
4
+ "description": "semi ui eslint plugin",
5
+ "keywords": [
6
+ "semi",
7
+ "eslint"
8
+ ],
9
+ "author": "shijia.me <shijia.me@bytedance.com>",
10
+ "homepage": "https://semi.design",
11
+ "license": "MIT",
12
+ "main": "lib/index.js",
13
+ "directories": {
14
+ "lib": "lib",
15
+ "test": "__tests__"
16
+ },
17
+ "files": [
18
+ "lib",
19
+ "README.md",
20
+ "README-zh_CN.md"
21
+ ],
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/DouyinFE/semi-design.git"
28
+ },
29
+ "scripts": {
30
+ "build:lib": "rm -rf lib && tsc",
31
+ "prepublishOnly": "npm run build:lib",
32
+ "test": "node __tests__/index.js"
33
+ },
34
+ "devDependencies": {
35
+ "typescript": "^4"
36
+ },
37
+ "peerDependencies": {
38
+ "eslint": ">=0.8.0"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/DouyinFE/semi-design/issues"
42
+ },
43
+ "gitHead": "2484e493d4a9b1914f6fca4a890cb967420c4524"
44
+ }