@so1ve/eslint-plugin 0.30.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/antfu>
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.
package/dist/index.cjs ADDED
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ const utils = require('@typescript-eslint/utils');
4
+
5
+ const createEslintRule = utils.ESLintUtils.RuleCreator(
6
+ (ruleName) => ruleName
7
+ );
8
+
9
+ const RULE_NAME$1 = "generic-spacing";
10
+ const genericSpacing = createEslintRule({
11
+ name: RULE_NAME$1,
12
+ meta: {
13
+ type: "suggestion",
14
+ docs: {
15
+ description: "Spaces around generic type parameters",
16
+ recommended: "error"
17
+ },
18
+ fixable: "code",
19
+ schema: [],
20
+ messages: {
21
+ genericSpacingMismatch: "Generic spaces mismatch"
22
+ }
23
+ },
24
+ defaultOptions: [],
25
+ create: (context) => {
26
+ const sourceCode = context.getSourceCode();
27
+ return {
28
+ TSTypeParameterDeclaration: (node) => {
29
+ if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression"].includes(node.parent.type)) {
30
+ const pre = sourceCode.text.slice(0, node.range[0]);
31
+ const preSpace = pre.match(/(\s+)$/)?.[0];
32
+ if (preSpace && preSpace.length) {
33
+ context.report({
34
+ node,
35
+ messageId: "genericSpacingMismatch",
36
+ *fix(fixer) {
37
+ yield fixer.replaceTextRange([node.range[0] - preSpace.length, node.range[0]], "");
38
+ }
39
+ });
40
+ }
41
+ }
42
+ const params = node.params;
43
+ for (let i = 1; i < params.length; i++) {
44
+ const prev = params[i - 1];
45
+ const current = params[i];
46
+ const from = prev.range[1];
47
+ const to = current.range[0];
48
+ const span = sourceCode.text.slice(from, to);
49
+ if (span !== ", " && !span.match(/,\n/)) {
50
+ context.report({
51
+ *fix(fixer) {
52
+ yield fixer.replaceTextRange([from, to], ", ");
53
+ },
54
+ loc: {
55
+ start: prev.loc.end,
56
+ end: current.loc.start
57
+ },
58
+ messageId: "genericSpacingMismatch",
59
+ node
60
+ });
61
+ }
62
+ }
63
+ },
64
+ TSTypeParameter: (node) => {
65
+ if (!node.default) {
66
+ return;
67
+ }
68
+ const endNode = node.constraint || node.name;
69
+ const from = endNode.range[1];
70
+ const to = node.default.range[0];
71
+ if (sourceCode.text.slice(from, to) !== " = ") {
72
+ context.report({
73
+ *fix(fixer) {
74
+ yield fixer.replaceTextRange([from, to], " = ");
75
+ },
76
+ loc: {
77
+ start: endNode.loc.end,
78
+ end: node.default.loc.start
79
+ },
80
+ messageId: "genericSpacingMismatch",
81
+ node
82
+ });
83
+ }
84
+ }
85
+ };
86
+ }
87
+ });
88
+
89
+ const RULE_NAME = "import-dedupe";
90
+ const importDedupe = createEslintRule({
91
+ name: RULE_NAME,
92
+ meta: {
93
+ type: "problem",
94
+ docs: {
95
+ description: "Fix duplication in imports",
96
+ recommended: "error"
97
+ },
98
+ fixable: "code",
99
+ schema: [],
100
+ messages: {
101
+ importDedupe: "Expect no duplication in imports"
102
+ }
103
+ },
104
+ defaultOptions: [],
105
+ create: (context) => {
106
+ return {
107
+ ImportDeclaration(node) {
108
+ if (node.specifiers.length <= 1) {
109
+ return;
110
+ }
111
+ const names = /* @__PURE__ */ new Set();
112
+ node.specifiers.forEach((n) => {
113
+ const id = n.local.name;
114
+ if (names.has(id)) {
115
+ context.report({
116
+ node,
117
+ loc: {
118
+ start: n.loc.end,
119
+ end: n.loc.start
120
+ },
121
+ messageId: "importDedupe",
122
+ fix(fixer) {
123
+ const s = n.range[0];
124
+ let e = n.range[1];
125
+ if (context.getSourceCode().text[e] === ",") {
126
+ e += 1;
127
+ }
128
+ return fixer.removeRange([s, e]);
129
+ }
130
+ });
131
+ }
132
+ names.add(id);
133
+ });
134
+ }
135
+ };
136
+ }
137
+ });
138
+
139
+ const index = {
140
+ rules: {
141
+ "import-dedupe": importDedupe,
142
+ "generic-spacing": genericSpacing
143
+ }
144
+ };
145
+
146
+ module.exports = index;
@@ -0,0 +1,10 @@
1
+ import * as _typescript_eslint_utils_dist_ts_eslint_Rule from '@typescript-eslint/utils/dist/ts-eslint/Rule';
2
+
3
+ declare const _default: {
4
+ rules: {
5
+ "import-dedupe": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"importDedupe", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
6
+ "generic-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"genericSpacingMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
7
+ };
8
+ };
9
+
10
+ export { _default as default };
package/dist/index.mjs ADDED
@@ -0,0 +1,144 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+
3
+ const createEslintRule = ESLintUtils.RuleCreator(
4
+ (ruleName) => ruleName
5
+ );
6
+
7
+ const RULE_NAME$1 = "generic-spacing";
8
+ const genericSpacing = createEslintRule({
9
+ name: RULE_NAME$1,
10
+ meta: {
11
+ type: "suggestion",
12
+ docs: {
13
+ description: "Spaces around generic type parameters",
14
+ recommended: "error"
15
+ },
16
+ fixable: "code",
17
+ schema: [],
18
+ messages: {
19
+ genericSpacingMismatch: "Generic spaces mismatch"
20
+ }
21
+ },
22
+ defaultOptions: [],
23
+ create: (context) => {
24
+ const sourceCode = context.getSourceCode();
25
+ return {
26
+ TSTypeParameterDeclaration: (node) => {
27
+ if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression"].includes(node.parent.type)) {
28
+ const pre = sourceCode.text.slice(0, node.range[0]);
29
+ const preSpace = pre.match(/(\s+)$/)?.[0];
30
+ if (preSpace && preSpace.length) {
31
+ context.report({
32
+ node,
33
+ messageId: "genericSpacingMismatch",
34
+ *fix(fixer) {
35
+ yield fixer.replaceTextRange([node.range[0] - preSpace.length, node.range[0]], "");
36
+ }
37
+ });
38
+ }
39
+ }
40
+ const params = node.params;
41
+ for (let i = 1; i < params.length; i++) {
42
+ const prev = params[i - 1];
43
+ const current = params[i];
44
+ const from = prev.range[1];
45
+ const to = current.range[0];
46
+ const span = sourceCode.text.slice(from, to);
47
+ if (span !== ", " && !span.match(/,\n/)) {
48
+ context.report({
49
+ *fix(fixer) {
50
+ yield fixer.replaceTextRange([from, to], ", ");
51
+ },
52
+ loc: {
53
+ start: prev.loc.end,
54
+ end: current.loc.start
55
+ },
56
+ messageId: "genericSpacingMismatch",
57
+ node
58
+ });
59
+ }
60
+ }
61
+ },
62
+ TSTypeParameter: (node) => {
63
+ if (!node.default) {
64
+ return;
65
+ }
66
+ const endNode = node.constraint || node.name;
67
+ const from = endNode.range[1];
68
+ const to = node.default.range[0];
69
+ if (sourceCode.text.slice(from, to) !== " = ") {
70
+ context.report({
71
+ *fix(fixer) {
72
+ yield fixer.replaceTextRange([from, to], " = ");
73
+ },
74
+ loc: {
75
+ start: endNode.loc.end,
76
+ end: node.default.loc.start
77
+ },
78
+ messageId: "genericSpacingMismatch",
79
+ node
80
+ });
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+
87
+ const RULE_NAME = "import-dedupe";
88
+ const importDedupe = createEslintRule({
89
+ name: RULE_NAME,
90
+ meta: {
91
+ type: "problem",
92
+ docs: {
93
+ description: "Fix duplication in imports",
94
+ recommended: "error"
95
+ },
96
+ fixable: "code",
97
+ schema: [],
98
+ messages: {
99
+ importDedupe: "Expect no duplication in imports"
100
+ }
101
+ },
102
+ defaultOptions: [],
103
+ create: (context) => {
104
+ return {
105
+ ImportDeclaration(node) {
106
+ if (node.specifiers.length <= 1) {
107
+ return;
108
+ }
109
+ const names = /* @__PURE__ */ new Set();
110
+ node.specifiers.forEach((n) => {
111
+ const id = n.local.name;
112
+ if (names.has(id)) {
113
+ context.report({
114
+ node,
115
+ loc: {
116
+ start: n.loc.end,
117
+ end: n.loc.start
118
+ },
119
+ messageId: "importDedupe",
120
+ fix(fixer) {
121
+ const s = n.range[0];
122
+ let e = n.range[1];
123
+ if (context.getSourceCode().text[e] === ",") {
124
+ e += 1;
125
+ }
126
+ return fixer.removeRange([s, e]);
127
+ }
128
+ });
129
+ }
130
+ names.add(id);
131
+ });
132
+ }
133
+ };
134
+ }
135
+ });
136
+
137
+ const index = {
138
+ rules: {
139
+ "import-dedupe": importDedupe,
140
+ "generic-spacing": genericSpacing
141
+ }
142
+ };
143
+
144
+ export { index as default };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@so1ve/eslint-plugin",
3
+ "version": "0.30.0",
4
+ "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
5
+ "contributors": [
6
+ {
7
+ "name": "Ray <nn_201312@163.com> (https://github.com/so1ve/)"
8
+ }
9
+ ],
10
+ "keywords": [
11
+ "eslint",
12
+ "eslint-config",
13
+ "eslint-plugin"
14
+ ],
15
+ "homepage": "https://github.com/so1ve/eslint-config#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/so1ve/eslint-config.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/so1ve/eslint-config/issues"
22
+ },
23
+ "license": "MIT",
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "@typescript-eslint/utils": "^5.42.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^18.11.9",
38
+ "unbuild": "^0.9.4",
39
+ "vitest": "^0.24.5"
40
+ },
41
+ "scripts": {
42
+ "build": "rimraf dist && unbuild",
43
+ "stub": "unbuild --stub",
44
+ "test": "vitest"
45
+ }
46
+ }