@daldalso/eslint-plugin 1.2.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 +21 -0
- package/README.md +29 -0
- package/dist/configs/all.js +320 -0
- package/dist/index.js +18 -0
- package/dist/rules/_template.js +17 -0
- package/dist/rules/function-type-annotation-style.js +138 -0
- package/dist/rules/homing-instinct.js +61 -0
- package/dist/rules/iterator-name.js +315 -0
- package/dist/rules/jsx-expression-condition-type.js +76 -0
- package/dist/rules/jsx-indent.js +220 -0
- package/dist/rules/key-quotation-style.js +150 -0
- package/dist/rules/lone-semicolon-indent.js +92 -0
- package/dist/rules/multiline-expression-spacing.js +130 -0
- package/dist/rules/no-class-expression.js +20 -0
- package/dist/rules/no-type-name-affix.js +62 -0
- package/dist/rules/no-unsafe-unquoted-key.js +80 -0
- package/dist/rules/no-useless-template-literal.js +81 -0
- package/dist/rules/one-exported-react-component.js +50 -0
- package/dist/rules/parenthesis-spacing.js +206 -0
- package/dist/rules/prefer-const.js +123 -0
- package/dist/rules/return-type.js +96 -0
- package/dist/rules/semantic-quotes.js +240 -0
- package/dist/rules/sort-keys.js +411 -0
- package/dist/rules/ternary-spacing.js +155 -0
- package/dist/rules/type-colon-spacing.js +128 -0
- package/dist/rules/type-operator-spacing.js +200 -0
- package/dist/rules/variable-name.js +253 -0
- package/dist/utils/code.js +21 -0
- package/dist/utils/patterns.js +16 -0
- package/dist/utils/text.js +15 -0
- package/dist/utils/type.js +82 -0
- package/package.json +40 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
31
|
+
var simpleNamePattern = /^\w+$/;
|
|
32
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
33
|
+
meta: {
|
|
34
|
+
type: "layout",
|
|
35
|
+
fixable: "code",
|
|
36
|
+
messages: {
|
|
37
|
+
'for-type-alias': "Simple key name in a type alias should be quoted with `{{quotation}}`.",
|
|
38
|
+
'for-interface': "Simple key name in an interface should be quoted with `{{quotation}}`.",
|
|
39
|
+
'for-object': "Simple key name in an object should be quoted with `{{quotation}}`."
|
|
40
|
+
},
|
|
41
|
+
schema: [{
|
|
42
|
+
type: "object",
|
|
43
|
+
properties: {
|
|
44
|
+
typeAlias: { type: "string", enum: ["none", "'", "\""] },
|
|
45
|
+
object: { type: "string", enum: ["none", "'", "\""] },
|
|
46
|
+
interface: { type: "string", enum: ["none", "'", "\""] }
|
|
47
|
+
}
|
|
48
|
+
}]
|
|
49
|
+
},
|
|
50
|
+
defaultOptions: [{
|
|
51
|
+
forTypeAlias: "'",
|
|
52
|
+
forObject: "none",
|
|
53
|
+
forInterface: "none"
|
|
54
|
+
}],
|
|
55
|
+
create: function (context, _a) {
|
|
56
|
+
var _b = _a[0], forTypeAlias = _b.forTypeAlias, forObject = _b.forObject, forInterface = _b.forInterface;
|
|
57
|
+
var isSimple = function (node) {
|
|
58
|
+
switch (node.type) {
|
|
59
|
+
case utils_1.AST_NODE_TYPES.Identifier: return simpleNamePattern.test(node.name);
|
|
60
|
+
case utils_1.AST_NODE_TYPES.Literal: return typeof node.value === "string" && simpleNamePattern.test(node.value);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
64
|
+
var getKeyQuotationStyle = function (node) {
|
|
65
|
+
if (node.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
66
|
+
if (!simpleNamePattern.test(node.name)) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return { style: "none", name: node.name };
|
|
70
|
+
}
|
|
71
|
+
if (node.type === utils_1.AST_NODE_TYPES.Literal && typeof node.value === "string") {
|
|
72
|
+
if (!simpleNamePattern.test(node.value)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return { style: node.raw[0], name: node.value };
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
};
|
|
79
|
+
var checkMembers = function (list, as, messageId) {
|
|
80
|
+
var _loop_1 = function (v) {
|
|
81
|
+
if (v.computed) {
|
|
82
|
+
return { value: void 0 };
|
|
83
|
+
}
|
|
84
|
+
var style = getKeyQuotationStyle(v.key);
|
|
85
|
+
if (style === null) {
|
|
86
|
+
return { value: void 0 };
|
|
87
|
+
}
|
|
88
|
+
if (style.style === as) {
|
|
89
|
+
return { value: void 0 };
|
|
90
|
+
}
|
|
91
|
+
context.report({
|
|
92
|
+
node: v.key,
|
|
93
|
+
messageId: messageId,
|
|
94
|
+
data: { quotation: as },
|
|
95
|
+
fix: function (fixer) {
|
|
96
|
+
var actualAs;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
switch (_a.label) {
|
|
99
|
+
case 0:
|
|
100
|
+
actualAs = as === "none" ? "" : as;
|
|
101
|
+
return [4 /*yield*/, fixer.replaceText(v.key, actualAs + style.name + actualAs)];
|
|
102
|
+
case 1:
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [2 /*return*/];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
111
|
+
var v = list_1[_i];
|
|
112
|
+
var state_1 = _loop_1(v);
|
|
113
|
+
if (typeof state_1 === "object")
|
|
114
|
+
return state_1.value;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
TSTypeLiteral: function (node) {
|
|
119
|
+
var filteredMembers = node.members.filter(function (v) { return v.type === utils_1.AST_NODE_TYPES.TSPropertySignature; });
|
|
120
|
+
if (filteredMembers.length <= 1) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!filteredMembers.every(function (v) { return isSimple(v.key); })) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
checkMembers(filteredMembers, forTypeAlias, 'for-type-alias');
|
|
127
|
+
},
|
|
128
|
+
TSInterfaceBody: function (node) {
|
|
129
|
+
var filteredMembers = node.body.filter(function (v) { return v.type === utils_1.AST_NODE_TYPES.TSPropertySignature; });
|
|
130
|
+
if (filteredMembers.length <= 1) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (!filteredMembers.every(function (v) { return isSimple(v.key); })) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
checkMembers(filteredMembers, forInterface, 'for-interface');
|
|
137
|
+
},
|
|
138
|
+
ObjectExpression: function (node) {
|
|
139
|
+
var filteredMembers = node.properties.filter(function (v) { return v.type === utils_1.AST_NODE_TYPES.Property; });
|
|
140
|
+
if (filteredMembers.length <= 1) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (!filteredMembers.every(function (v) { return isSimple(v.key); })) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
checkMembers(filteredMembers, forObject, 'for-object');
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
31
|
+
var code_1 = require("../utils/code");
|
|
32
|
+
var patterns_1 = require("../utils/patterns");
|
|
33
|
+
var text_1 = require("../utils/text");
|
|
34
|
+
var loneSemicolonPattern = /^\s*;$/;
|
|
35
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
36
|
+
meta: {
|
|
37
|
+
type: "layout",
|
|
38
|
+
fixable: "whitespace",
|
|
39
|
+
messages: {
|
|
40
|
+
'default': "Lone semicolon should be indented less than the previous line."
|
|
41
|
+
},
|
|
42
|
+
schema: []
|
|
43
|
+
},
|
|
44
|
+
defaultOptions: [],
|
|
45
|
+
create: function (context) {
|
|
46
|
+
var sourceCode = context.getSourceCode();
|
|
47
|
+
return {
|
|
48
|
+
Program: function () {
|
|
49
|
+
var _loop_1 = function (i) {
|
|
50
|
+
if (!loneSemicolonPattern.test(sourceCode.lines[i])) {
|
|
51
|
+
return "continue";
|
|
52
|
+
}
|
|
53
|
+
var prevIndentation = (0, code_1.getIndentation)(sourceCode, i);
|
|
54
|
+
var indentation = (0, code_1.getIndentation)(sourceCode, i + 1);
|
|
55
|
+
if (prevIndentation.length > indentation.length) {
|
|
56
|
+
return "continue";
|
|
57
|
+
}
|
|
58
|
+
var semicolon = sourceCode.getTokenByRangeStart(sourceCode.lineStartIndices[i] + indentation.length);
|
|
59
|
+
if (!semicolon) {
|
|
60
|
+
throw Error("There must exist one semicolon");
|
|
61
|
+
}
|
|
62
|
+
var isPrevLineClosing = patterns_1.closingLinePattern.test(sourceCode.lines[i - 1]);
|
|
63
|
+
var prevToken = sourceCode.getTokenBefore(semicolon);
|
|
64
|
+
context.report({
|
|
65
|
+
node: semicolon,
|
|
66
|
+
messageId: 'default',
|
|
67
|
+
fix: function (fixer) {
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!(isPrevLineClosing && prevToken)) return [3 /*break*/, 2];
|
|
72
|
+
return [4 /*yield*/, fixer.replaceTextRange([prevToken.range[1], semicolon.range[0]], "")];
|
|
73
|
+
case 1:
|
|
74
|
+
_a.sent();
|
|
75
|
+
return [3 /*break*/, 4];
|
|
76
|
+
case 2: return [4 /*yield*/, fixer.removeRange([semicolon.range[0] - text_1.INDENTATION_UNIT.length, semicolon.range[0]])];
|
|
77
|
+
case 3:
|
|
78
|
+
_a.sent();
|
|
79
|
+
_a.label = 4;
|
|
80
|
+
case 4: return [2 /*return*/];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
for (var i = 1; i < sourceCode.lines.length; i++) {
|
|
87
|
+
_loop_1(i);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
31
|
+
var patterns_1 = require("../utils/patterns");
|
|
32
|
+
var code_1 = require("../utils/code");
|
|
33
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
34
|
+
meta: {
|
|
35
|
+
type: "layout",
|
|
36
|
+
fixable: "whitespace",
|
|
37
|
+
messages: {
|
|
38
|
+
'for-conditional-expression': "Multiline conditional expression should finish the line.",
|
|
39
|
+
'for-call-expression': "Multiline function call should finish the line.",
|
|
40
|
+
'for-call-expression-consistency': "Both the parentheses of a function call should be indented equally.",
|
|
41
|
+
'for-member-expression': "Multiline property access should finish the line.",
|
|
42
|
+
'for-binary-expression': "Multiline binary expression should finish the line."
|
|
43
|
+
},
|
|
44
|
+
schema: []
|
|
45
|
+
},
|
|
46
|
+
defaultOptions: [],
|
|
47
|
+
create: function (context) {
|
|
48
|
+
var sourceCode = context.getSourceCode();
|
|
49
|
+
var checkExpression = function (node, messageId) {
|
|
50
|
+
var isMultiline = node.loc.start.line !== node.loc.end.line;
|
|
51
|
+
if (!isMultiline) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
var chunk = sourceCode.lines[node.loc.end.line - 1].match(patterns_1.closingLinePattern);
|
|
55
|
+
if (chunk && (0, code_1.getIndentation)(sourceCode, node.loc.start.line) === chunk[1]) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
var next = sourceCode.getTokenAfter(node);
|
|
59
|
+
if ((next === null || next === void 0 ? void 0 : next.loc.start.line) !== node.loc.end.line) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
context.report({
|
|
63
|
+
node: next,
|
|
64
|
+
messageId: messageId,
|
|
65
|
+
fix: function (fixer) {
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0: return [4 /*yield*/, fixer.insertTextAfter(node, "\n")];
|
|
69
|
+
case 1:
|
|
70
|
+
_a.sent();
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
ConditionalExpression: function (node) {
|
|
79
|
+
checkExpression(node, 'for-conditional-expression');
|
|
80
|
+
},
|
|
81
|
+
CallExpression: function (node) {
|
|
82
|
+
var openingParenthesis = sourceCode.getTokenAfter(node.callee);
|
|
83
|
+
var closingParenthesis = sourceCode.getLastToken(node);
|
|
84
|
+
if (!openingParenthesis || !closingParenthesis) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
var openingLineIndentation = (0, code_1.getIndentation)(sourceCode, openingParenthesis.loc.start.line);
|
|
88
|
+
var closingLineIndentation = (0, code_1.getIndentation)(sourceCode, closingParenthesis.loc.end.line);
|
|
89
|
+
checkExpression(node, 'for-call-expression');
|
|
90
|
+
if (openingLineIndentation !== closingLineIndentation) {
|
|
91
|
+
context.report({
|
|
92
|
+
node: closingParenthesis,
|
|
93
|
+
messageId: "for-call-expression-consistency",
|
|
94
|
+
fix: function (fixer) {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, fixer.insertTextBefore(closingParenthesis, "\n" + openingLineIndentation)];
|
|
98
|
+
case 1:
|
|
99
|
+
_a.sent();
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
MemberExpression: function (node) {
|
|
108
|
+
var _a;
|
|
109
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.CallExpression) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
checkExpression(node, 'for-member-expression');
|
|
113
|
+
},
|
|
114
|
+
'BinaryExpression, LogicalExpression': function (node) {
|
|
115
|
+
var leftEnd = sourceCode.getLastToken(node.left);
|
|
116
|
+
var rightStart = sourceCode.getFirstToken(node.right);
|
|
117
|
+
if (!leftEnd || !rightStart) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (leftEnd.loc.end.line === rightStart.loc.start.line) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
checkExpression(node, 'for-binary-expression');
|
|
124
|
+
},
|
|
125
|
+
'TSUnionType, TSIntersectionType': function (node) {
|
|
126
|
+
checkExpression(node, 'for-binary-expression');
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "layout",
|
|
7
|
+
messages: {
|
|
8
|
+
'default': "Class expression is not allowed."
|
|
9
|
+
},
|
|
10
|
+
schema: []
|
|
11
|
+
},
|
|
12
|
+
defaultOptions: [],
|
|
13
|
+
create: function (context) {
|
|
14
|
+
return {
|
|
15
|
+
ClassExpression: function (node) {
|
|
16
|
+
context.report({ node: node, messageId: "default" });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
5
|
+
meta: {
|
|
6
|
+
type: "layout",
|
|
7
|
+
fixable: "code",
|
|
8
|
+
messages: {
|
|
9
|
+
'for-type-alias': "Type alias name should not be `{{pattern}}`.",
|
|
10
|
+
'for-interface': "Interface name should not be `{{pattern}}`."
|
|
11
|
+
},
|
|
12
|
+
schema: [{
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
invalidTypeAliasNamePattern: { type: "string" },
|
|
16
|
+
invalidInterfaceNamePattern: { type: "string" },
|
|
17
|
+
validNames: {
|
|
18
|
+
type: "array",
|
|
19
|
+
items: { type: "string" }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}]
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [{
|
|
25
|
+
invalidTypeAliasNamePattern: /[^A-Z]T(?:ype)?$/.source,
|
|
26
|
+
invalidInterfaceNamePattern: /^I[A-Z][^A-Z]/.source,
|
|
27
|
+
validNames: []
|
|
28
|
+
}],
|
|
29
|
+
create: function (context, _a) {
|
|
30
|
+
var _b = _a[0], invalidTypeAliasNamePatternString = _b.invalidTypeAliasNamePattern, invalidInterfaceNamePatternString = _b.invalidInterfaceNamePattern, validNames = _b.validNames;
|
|
31
|
+
var invalidTypeAliasNamePattern = new RegExp(invalidTypeAliasNamePatternString);
|
|
32
|
+
var invalidInterfaceNamePattern = new RegExp(invalidInterfaceNamePatternString);
|
|
33
|
+
return {
|
|
34
|
+
TSTypeAliasDeclaration: function (node) {
|
|
35
|
+
if (!invalidTypeAliasNamePattern.test(node.id.name)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (validNames.includes(node.id.name)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
context.report({
|
|
42
|
+
node: node.id,
|
|
43
|
+
messageId: "for-type-alias",
|
|
44
|
+
data: { pattern: invalidTypeAliasNamePatternString }
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
TSInterfaceDeclaration: function (node) {
|
|
48
|
+
if (!invalidInterfaceNamePattern.test(node.id.name)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (validNames.includes(node.id.name)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
context.report({
|
|
55
|
+
node: node.id,
|
|
56
|
+
messageId: "for-interface",
|
|
57
|
+
data: { pattern: invalidInterfaceNamePatternString }
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
31
|
+
var type_1 = require("../utils/type");
|
|
32
|
+
var propertyPattern = /\.\s*(\w+)$/;
|
|
33
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
34
|
+
meta: {
|
|
35
|
+
type: "layout",
|
|
36
|
+
hasSuggestions: true,
|
|
37
|
+
messages: {
|
|
38
|
+
'default': "Access to the unsafe key `{{key}}` should use a string literal."
|
|
39
|
+
},
|
|
40
|
+
schema: []
|
|
41
|
+
},
|
|
42
|
+
defaultOptions: [],
|
|
43
|
+
create: function (context) {
|
|
44
|
+
var sourceCode = context.getSourceCode();
|
|
45
|
+
(0, type_1.useTypeChecker)(context);
|
|
46
|
+
return {
|
|
47
|
+
MemberExpression: function (node) {
|
|
48
|
+
if (node.property.type !== utils_1.AST_NODE_TYPES.Identifier) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (node.computed) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
var type = (0, type_1.getTSTypeByNode)(context, node.object).getNonNullableType();
|
|
55
|
+
var properties = context.settings.typeChecker.getPropertyOfType(type, node.property.name);
|
|
56
|
+
if (properties) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
context.report({
|
|
60
|
+
node: node.property,
|
|
61
|
+
messageId: 'default',
|
|
62
|
+
data: { key: node.property.name },
|
|
63
|
+
suggest: [{
|
|
64
|
+
messageId: 'default',
|
|
65
|
+
fix: function (fixer) {
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0: return [4 /*yield*/, fixer.replaceText(node, sourceCode.getText(node).replace(propertyPattern, "['$1']"))];
|
|
69
|
+
case 1:
|
|
70
|
+
_a.sent();
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
31
|
+
var backtickPattern = /^`|`$/g;
|
|
32
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
33
|
+
meta: {
|
|
34
|
+
type: "suggestion",
|
|
35
|
+
fixable: "code",
|
|
36
|
+
messages: {
|
|
37
|
+
'default': "Template literal should contain at least one expression."
|
|
38
|
+
},
|
|
39
|
+
schema: [{
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
to: { type: "string", enum: ['\'', '"'] }
|
|
43
|
+
}
|
|
44
|
+
}]
|
|
45
|
+
},
|
|
46
|
+
defaultOptions: [{
|
|
47
|
+
to: '"'
|
|
48
|
+
}],
|
|
49
|
+
create: function (context, _a) {
|
|
50
|
+
var to = _a[0].to;
|
|
51
|
+
var sourceCode = context.getSourceCode();
|
|
52
|
+
return {
|
|
53
|
+
TemplateLiteral: function (node) {
|
|
54
|
+
var _a;
|
|
55
|
+
if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (node.expressions.length) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (node.loc.start.line !== node.loc.end.line) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
context.report({
|
|
65
|
+
node: node,
|
|
66
|
+
messageId: "default",
|
|
67
|
+
fix: function (fixer) {
|
|
68
|
+
return __generator(this, function (_a) {
|
|
69
|
+
switch (_a.label) {
|
|
70
|
+
case 0: return [4 /*yield*/, fixer.replaceText(node, sourceCode.getText(node).replace(backtickPattern, to))];
|
|
71
|
+
case 1:
|
|
72
|
+
_a.sent();
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
var patterns_1 = require("../utils/patterns");
|
|
5
|
+
var type_1 = require("../utils/type");
|
|
6
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion",
|
|
9
|
+
messages: {
|
|
10
|
+
'default': "Only one React component is allowed to be exported in a file."
|
|
11
|
+
},
|
|
12
|
+
schema: []
|
|
13
|
+
},
|
|
14
|
+
defaultOptions: [],
|
|
15
|
+
create: function (context) {
|
|
16
|
+
var alreadyExported = false;
|
|
17
|
+
(0, type_1.useTypeChecker)(context);
|
|
18
|
+
return {
|
|
19
|
+
ExportNamedDeclaration: function (node) {
|
|
20
|
+
var _a;
|
|
21
|
+
if (((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.type) !== utils_1.AST_NODE_TYPES.VariableDeclaration) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (var _i = 0, _b = node.declaration.declarations; _i < _b.length; _i++) {
|
|
25
|
+
var v = _b[_i];
|
|
26
|
+
var tsType = (0, type_1.getTSTypeByNode)(context, v.id);
|
|
27
|
+
if (!(0, type_1.isDOMReturningFunction)(context, tsType, patterns_1.domTypePatterns)) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!alreadyExported) {
|
|
31
|
+
alreadyExported = true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
context.report({ node: v, messageId: "default" });
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
ExportSpecifier: function (node) {
|
|
38
|
+
var tsType = (0, type_1.getTSTypeByNode)(context, node.local);
|
|
39
|
+
if (!(0, type_1.isDOMReturningFunction)(context, tsType, patterns_1.domTypePatterns)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (!alreadyExported) {
|
|
43
|
+
alreadyExported = true;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
context.report({ node: node.local, messageId: "default" });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|