@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.
@@ -0,0 +1,128 @@
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
+ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
32
+ meta: {
33
+ type: "layout",
34
+ fixable: "whitespace",
35
+ messages: {
36
+ 'default': "No spacing required around `:` except in type aliases.",
37
+ 'before-in-type-alias': "No spacing required before `:` in type aliases.",
38
+ 'after-in-type-alias': "Spacing required after `:` in type aliases."
39
+ },
40
+ schema: []
41
+ },
42
+ defaultOptions: [],
43
+ create: function (context) {
44
+ var sourceCode = context.getSourceCode();
45
+ return {
46
+ TSTypeAnnotation: function (node) {
47
+ var _a, _b, _c, _d;
48
+ if (((_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.TSTypeLiteral) {
49
+ return;
50
+ }
51
+ var _e = sourceCode.getFirstTokens(node, { count: 2 }), colon = _e[0], after = _e[1];
52
+ if (colon.value !== ":") {
53
+ return;
54
+ }
55
+ var before = sourceCode.getTokenBefore(colon);
56
+ var hasSpaceBefore = before && ((_c = sourceCode.isSpaceBetween) === null || _c === void 0 ? void 0 : _c.call(sourceCode, before, colon));
57
+ var hasSpaceAfter = (_d = sourceCode.isSpaceBetween) === null || _d === void 0 ? void 0 : _d.call(sourceCode, colon, after);
58
+ if (!hasSpaceBefore && !hasSpaceAfter) {
59
+ return;
60
+ }
61
+ context.report({
62
+ node: colon,
63
+ messageId: "default",
64
+ fix: function (fixer) {
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ if (!hasSpaceBefore) return [3 /*break*/, 2];
69
+ return [4 /*yield*/, fixer.removeRange([before.range[1], colon.range[0]])];
70
+ case 1:
71
+ _a.sent();
72
+ _a.label = 2;
73
+ case 2:
74
+ if (!hasSpaceAfter) return [3 /*break*/, 4];
75
+ return [4 /*yield*/, fixer.removeRange([colon.range[1], after.range[0]])];
76
+ case 3:
77
+ _a.sent();
78
+ _a.label = 4;
79
+ case 4: return [2 /*return*/];
80
+ }
81
+ });
82
+ }
83
+ });
84
+ },
85
+ 'TSTypeLiteral>TSPropertySignature': function (_a) {
86
+ var _b, _c;
87
+ var typeAnnotation = _a.typeAnnotation;
88
+ if (!typeAnnotation) {
89
+ return;
90
+ }
91
+ var _d = sourceCode.getFirstTokens(typeAnnotation, { count: 2 }), colon = _d[0], after = _d[1];
92
+ var before = sourceCode.getTokenBefore(colon);
93
+ if (before && ((_b = sourceCode.isSpaceBetween) === null || _b === void 0 ? void 0 : _b.call(sourceCode, before, colon))) {
94
+ context.report({
95
+ node: colon,
96
+ messageId: "before-in-type-alias",
97
+ fix: function (fixer) {
98
+ return __generator(this, function (_a) {
99
+ switch (_a.label) {
100
+ case 0: return [4 /*yield*/, fixer.removeRange([before.range[1], colon.range[0]])];
101
+ case 1:
102
+ _a.sent();
103
+ return [2 /*return*/];
104
+ }
105
+ });
106
+ }
107
+ });
108
+ }
109
+ if (!((_c = sourceCode.isSpaceBetween) === null || _c === void 0 ? void 0 : _c.call(sourceCode, colon, after))) {
110
+ context.report({
111
+ node: colon,
112
+ messageId: "after-in-type-alias",
113
+ fix: function (fixer) {
114
+ return __generator(this, function (_a) {
115
+ switch (_a.label) {
116
+ case 0: return [4 /*yield*/, fixer.insertTextAfter(colon, " ")];
117
+ case 1:
118
+ _a.sent();
119
+ return [2 /*return*/];
120
+ }
121
+ });
122
+ }
123
+ });
124
+ }
125
+ }
126
+ };
127
+ }
128
+ });
@@ -0,0 +1,200 @@
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 text_1 = require("../utils/text");
33
+ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
34
+ meta: {
35
+ type: "layout",
36
+ fixable: "whitespace",
37
+ messages: {
38
+ 'default': "Type operator `{{operator}}` should not be spaced in single-line style.",
39
+ 'in-arrow-function': "Spacing required around `=>`.",
40
+ 'in-multiline': "Type operator `{{operator}}` should be spaced in multiline style.",
41
+ 'in-multiline-ending': "Line cannot be ended with `{{operator}}`.",
42
+ 'in-multiline-indent': "Line starting with a type operator should be indented."
43
+ },
44
+ schema: []
45
+ },
46
+ defaultOptions: [],
47
+ create: function (context) {
48
+ var sourceCode = context.getSourceCode();
49
+ return {
50
+ TSFunctionType: function (node) {
51
+ var _a, _b;
52
+ if (!node.returnType) {
53
+ return;
54
+ }
55
+ var _c = sourceCode.getFirstTokens(node.returnType, { count: 2 }), arrow = _c[0], after = _c[1];
56
+ var before = sourceCode.getTokenBefore(arrow);
57
+ var hasSpaceBefore = before && ((_a = sourceCode.isSpaceBetween) === null || _a === void 0 ? void 0 : _a.call(sourceCode, before, arrow));
58
+ var hasSpaceAfter = (_b = sourceCode.isSpaceBetween) === null || _b === void 0 ? void 0 : _b.call(sourceCode, arrow, after);
59
+ if (hasSpaceBefore && hasSpaceAfter) {
60
+ return;
61
+ }
62
+ context.report({
63
+ node: arrow,
64
+ messageId: "in-arrow-function",
65
+ fix: function (fixer) {
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0:
69
+ if (!!hasSpaceBefore) return [3 /*break*/, 2];
70
+ return [4 /*yield*/, fixer.insertTextBefore(arrow, " ")];
71
+ case 1:
72
+ _a.sent();
73
+ _a.label = 2;
74
+ case 2:
75
+ if (!!hasSpaceAfter) return [3 /*break*/, 4];
76
+ return [4 /*yield*/, fixer.insertTextAfter(arrow, " ")];
77
+ case 3:
78
+ _a.sent();
79
+ _a.label = 4;
80
+ case 4: return [2 /*return*/];
81
+ }
82
+ });
83
+ }
84
+ });
85
+ },
86
+ 'TSUnionType, TSIntersectionType': function (node) {
87
+ var _a, _b;
88
+ var _loop_1 = function (i) {
89
+ var a = node.types[i];
90
+ var b = node.types[i + 1];
91
+ var aLast = sourceCode.getLastToken(a);
92
+ var bFirst = sourceCode.getFirstToken(b);
93
+ var operator = aLast && sourceCode.getTokenAfter(aLast);
94
+ if (!aLast || !bFirst || !operator)
95
+ return "continue";
96
+ if (aLast.loc.end.line === bFirst.loc.start.line) {
97
+ if (!((_a = sourceCode.isSpaceBetween) === null || _a === void 0 ? void 0 : _a.call(sourceCode, aLast, bFirst))) {
98
+ return "continue";
99
+ }
100
+ context.report({
101
+ node: operator,
102
+ messageId: "default",
103
+ data: { operator: operator.value },
104
+ fix: function (fixer) {
105
+ return __generator(this, function (_a) {
106
+ switch (_a.label) {
107
+ case 0: return [4 /*yield*/, fixer.replaceTextRange([aLast.range[1], bFirst.range[0]], operator.value)];
108
+ case 1:
109
+ _a.sent();
110
+ return [2 /*return*/];
111
+ }
112
+ });
113
+ }
114
+ });
115
+ }
116
+ else {
117
+ var aLineIndentation_1 = (0, code_1.getIndentation)(sourceCode, aLast.loc.end.line);
118
+ var bLineIndentation = (0, code_1.getIndentation)(sourceCode, bFirst.loc.start.line);
119
+ if (aLast.loc.end.line === operator.loc.start.line) {
120
+ context.report({
121
+ node: operator,
122
+ messageId: "in-multiline-ending",
123
+ data: { operator: operator.value },
124
+ fix: function (fixer) {
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0: return [4 /*yield*/, fixer.replaceTextRange([operator.range[0], bFirst.range[0]], "\n".concat(operator.value, " "))];
128
+ case 1:
129
+ _a.sent();
130
+ return [2 /*return*/];
131
+ }
132
+ });
133
+ }
134
+ });
135
+ }
136
+ if (i === 0 && aLineIndentation_1.length >= bLineIndentation.length) {
137
+ context.report({
138
+ node: bFirst,
139
+ messageId: "in-multiline-indent",
140
+ fix: function (fixer) {
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0: return [4 /*yield*/, fixer.replaceTextRange([
144
+ sourceCode.lineStartIndices[bFirst.loc.start.line - 1],
145
+ operator.range[0]
146
+ ], aLineIndentation_1 + text_1.INDENTATION_UNIT)];
147
+ case 1:
148
+ _a.sent();
149
+ return [2 /*return*/];
150
+ }
151
+ });
152
+ }
153
+ });
154
+ }
155
+ if (i > 0 && aLineIndentation_1.length !== bLineIndentation.length) {
156
+ context.report({
157
+ node: bFirst,
158
+ messageId: "in-multiline-indent",
159
+ fix: function (fixer) {
160
+ return __generator(this, function (_a) {
161
+ switch (_a.label) {
162
+ case 0: return [4 /*yield*/, fixer.replaceTextRange([
163
+ sourceCode.lineStartIndices[bFirst.loc.start.line - 1],
164
+ operator.range[0]
165
+ ], aLineIndentation_1)];
166
+ case 1:
167
+ _a.sent();
168
+ return [2 /*return*/];
169
+ }
170
+ });
171
+ }
172
+ });
173
+ }
174
+ if ((_b = sourceCode.isSpaceBetween) === null || _b === void 0 ? void 0 : _b.call(sourceCode, operator, bFirst)) {
175
+ return "continue";
176
+ }
177
+ context.report({
178
+ node: operator,
179
+ messageId: "in-multiline",
180
+ data: { operator: operator.value },
181
+ fix: function (fixer) {
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0: return [4 /*yield*/, fixer.insertTextAfter(operator, " ")];
185
+ case 1:
186
+ _a.sent();
187
+ return [2 /*return*/];
188
+ }
189
+ });
190
+ }
191
+ });
192
+ }
193
+ };
194
+ for (var i = 0; i < node.types.length - 1; i++) {
195
+ _loop_1(i);
196
+ }
197
+ }
198
+ };
199
+ }
200
+ });
@@ -0,0 +1,253 @@
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
+ var CASE_TABLE = {
7
+ camelCase: patterns_1.camelCasePattern,
8
+ PascalCase: patterns_1.pascalCasePattern,
9
+ UPPER_SNAKE_CASE: patterns_1.upperSnakeCasePattern
10
+ };
11
+ var CASE_TABLE_KEYS = Object.keys(CASE_TABLE);
12
+ var allGenericsPattern = /<.+>/g;
13
+ var reactComponentTypePattern = /^(ComponentType|ComponentClass|FunctionComponent|ForwardRefExoticComponent|NextPage)\b/;
14
+ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
15
+ meta: {
16
+ type: "layout",
17
+ messages: {
18
+ 'for-const': "Constant name should follow {{list}}.",
19
+ 'for-constructible': "Constructible object's name should follow {{list}}.",
20
+ 'for-enum': "Enumerator name should follow {{list}}.",
21
+ 'for-enumValue': "Enumerator value's name should follow {{list}}.",
22
+ 'for-function': "Function name should follow {{list}}.",
23
+ 'for-generic': "Generic name should follow {{list}}.",
24
+ 'for-interface': "Interface name should follow {{list}}.",
25
+ 'for-mappedKey': "Mapped key name should follow {{list}}.",
26
+ 'for-parameter': "Parameter name should follow {{list}}.",
27
+ 'for-reactComponent': "React component's name should follow {{list}}.",
28
+ 'for-typeAlias': "Type alias name should follow {{list}}.",
29
+ 'for-variable': "Variable name should follow {{list}}.",
30
+ 'for-catchParameter': "Catch parameter name should follow the pattern `{{pattern}}`.",
31
+ 'for-domVariable': "Name of the DOM-typed variable `{{type}}` should follow the pattern `{{pattern}}`."
32
+ },
33
+ schema: [{
34
+ type: "object",
35
+ properties: {
36
+ cases: {
37
+ type: "object",
38
+ properties: [
39
+ "const",
40
+ "variable",
41
+ "function",
42
+ "constructible",
43
+ "reactComponent",
44
+ "parameter",
45
+ "typeAlias",
46
+ "interface",
47
+ "generic",
48
+ "mappedKey",
49
+ "enum",
50
+ "enumValue"
51
+ ].reduce(function (pv, v) {
52
+ pv[v] = { type: "array", items: { type: "string", enum: CASE_TABLE_KEYS } };
53
+ return pv;
54
+ }, {})
55
+ },
56
+ names: {
57
+ type: "object",
58
+ properties: {
59
+ domVariable: { type: "string" },
60
+ catchParameter: { type: "string" }
61
+ }
62
+ },
63
+ domTypePatterns: { type: "array", items: { type: "string" } },
64
+ exceptions: { type: "array", items: { type: "string" } }
65
+ }
66
+ }]
67
+ },
68
+ defaultOptions: [{
69
+ cases: {
70
+ const: ["camelCase", "UPPER_SNAKE_CASE"],
71
+ constructible: ["PascalCase"],
72
+ enum: ["PascalCase"],
73
+ enumValue: ["UPPER_SNAKE_CASE"],
74
+ function: ["camelCase"],
75
+ generic: ["PascalCase"],
76
+ interface: ["PascalCase"],
77
+ mappedKey: ["camelCase"],
78
+ parameter: ["camelCase"],
79
+ reactComponent: ["PascalCase"],
80
+ typeAlias: ["PascalCase"],
81
+ variable: ["camelCase"]
82
+ },
83
+ names: {
84
+ domVariable: /^\$/.source,
85
+ catchParameter: /^error$/.source
86
+ },
87
+ domTypePatterns: patterns_1.domTypePatterns.map(function (v) { return v.source; }),
88
+ exceptions: ["_", "R", "$R"]
89
+ }],
90
+ create: function (context, _a) {
91
+ var _b = _a[0], cases = _b.cases, names = _b.names, domTypePatternStrings = _b.domTypePatterns, exceptions = _b.exceptions;
92
+ var NAME_TABLE = {
93
+ domVariable: new RegExp(names.domVariable),
94
+ catchParameter: new RegExp(names.catchParameter)
95
+ };
96
+ var domTypePatterns = domTypePatternStrings.map(function (v) { return new RegExp(v); });
97
+ var isConstructible = function (type) { return type.getConstructSignatures().length > 0; };
98
+ var isDOMObject = function (type) {
99
+ var typeString = (0, type_1.typeToString)(context, type);
100
+ if (typeString.startsWith("(")
101
+ || typeString.startsWith("{")
102
+ || typeString.startsWith("<")) {
103
+ return false;
104
+ }
105
+ var filteredTypeString = typeString.replace(allGenericsPattern, "");
106
+ return domTypePatterns.some(function (v) { return v.test(filteredTypeString); });
107
+ };
108
+ var getSemanticType = function (node) {
109
+ var _a, _b;
110
+ if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.CatchClause)
111
+ return ['names', 'catchParameter'];
112
+ var tsType = (0, type_1.getTSTypeByNode)(context, node).getNonNullableType();
113
+ if (isConstructible(tsType))
114
+ return ['cases', 'constructible'];
115
+ if ((0, type_1.isDOMReturningFunction)(context, tsType, domTypePatterns)
116
+ || reactComponentTypePattern.test((0, type_1.typeToString)(context, tsType)))
117
+ return ['cases', 'reactComponent'];
118
+ if (((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) !== utils_1.AST_NODE_TYPES.TSTypeAliasDeclaration && isDOMObject(tsType)) {
119
+ return ['names', 'domVariable'];
120
+ }
121
+ return null;
122
+ };
123
+ var checkCase = function (type, node) {
124
+ var _a;
125
+ var name;
126
+ switch (node.type) {
127
+ case utils_1.AST_NODE_TYPES.Identifier:
128
+ name = node.name;
129
+ break;
130
+ case utils_1.AST_NODE_TYPES.ArrayPattern:
131
+ for (var _i = 0, _b = node.elements; _i < _b.length; _i++) {
132
+ var v = _b[_i];
133
+ if (!v)
134
+ continue;
135
+ checkCase(type, v);
136
+ }
137
+ return;
138
+ case utils_1.AST_NODE_TYPES.ObjectPattern:
139
+ for (var _c = 0, _d = node.properties; _c < _d.length; _c++) {
140
+ var v = _d[_c];
141
+ checkCase(type, v);
142
+ }
143
+ return;
144
+ case utils_1.AST_NODE_TYPES.AssignmentPattern:
145
+ checkCase(type, node.left);
146
+ return;
147
+ case utils_1.AST_NODE_TYPES.Property:
148
+ checkCase(type, node.value);
149
+ return;
150
+ case utils_1.AST_NODE_TYPES.RestElement:
151
+ checkCase(type, node.argument);
152
+ return;
153
+ default: return;
154
+ }
155
+ if (exceptions.includes(name)) {
156
+ return;
157
+ }
158
+ var actualType = getSemanticType(node) || ['cases', type];
159
+ var data;
160
+ switch (actualType[0]) {
161
+ case "cases":
162
+ if (cases[actualType[1]].some(function (v) { return CASE_TABLE[v].test(name); })) {
163
+ return;
164
+ }
165
+ data = { list: cases[actualType[1]].map(function (v) { return "`".concat(v, "`"); }).join(' or ') };
166
+ break;
167
+ case "names":
168
+ if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Property && node.parent.shorthand) {
169
+ return;
170
+ }
171
+ if (NAME_TABLE[actualType[1]].test(name)) {
172
+ return;
173
+ }
174
+ data = {
175
+ pattern: NAME_TABLE[actualType[1]].source,
176
+ type: (0, type_1.typeToString)(context, (0, type_1.getTSTypeByNode)(context, node))
177
+ };
178
+ break;
179
+ }
180
+ context.report({ node: node, messageId: "for-".concat(actualType[1]), data: data });
181
+ };
182
+ (0, type_1.useTypeChecker)(context);
183
+ return {
184
+ ':function': function (node) {
185
+ if (node.id) {
186
+ checkCase('function', node.id);
187
+ }
188
+ for (var _i = 0, _a = node.params; _i < _a.length; _i++) {
189
+ var v = _a[_i];
190
+ checkCase('parameter', v);
191
+ }
192
+ },
193
+ ClassDeclaration: function (node) {
194
+ if (!node.id) {
195
+ return;
196
+ }
197
+ checkCase('constructible', node.id);
198
+ },
199
+ MethodDefinition: function (node) {
200
+ checkCase('function', node.key);
201
+ },
202
+ PropertyDefinition: function (node) {
203
+ checkCase(node.readonly ? 'const' : 'variable', node.key);
204
+ },
205
+ VariableDeclarator: function (node) {
206
+ var _a;
207
+ if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) !== utils_1.AST_NODE_TYPES.VariableDeclaration) {
208
+ return;
209
+ }
210
+ if (node.parent.kind === "const") {
211
+ checkCase('const', node.id);
212
+ }
213
+ else {
214
+ checkCase('variable', node.id);
215
+ }
216
+ },
217
+ TSEnumDeclaration: function (node) {
218
+ checkCase('enum', node.id);
219
+ for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
220
+ var v = _a[_i];
221
+ checkCase('enumValue', v.id);
222
+ }
223
+ },
224
+ TSFunctionType: function (node) {
225
+ for (var _i = 0, _a = node.params; _i < _a.length; _i++) {
226
+ var v = _a[_i];
227
+ checkCase('parameter', v);
228
+ }
229
+ },
230
+ TSInterfaceDeclaration: function (node) {
231
+ checkCase('interface', node.id);
232
+ },
233
+ TSMethodSignature: function (node) {
234
+ checkCase('function', node.key);
235
+ },
236
+ TSPropertySignature: function (node) {
237
+ checkCase('variable', node.key);
238
+ },
239
+ TSTypeAliasDeclaration: function (node) {
240
+ checkCase('typeAlias', node.id);
241
+ },
242
+ TSTypeParameter: function (node) {
243
+ var _a;
244
+ if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.TSMappedType) {
245
+ checkCase('mappedKey', node.name);
246
+ }
247
+ else {
248
+ checkCase('generic', node.name);
249
+ }
250
+ }
251
+ };
252
+ }
253
+ });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIndentation = getIndentation;
4
+ exports.hasEmptyLineBefore = hasEmptyLineBefore;
5
+ var patterns_1 = require("./patterns");
6
+ function getIndentation(sourceCode, line) {
7
+ return sourceCode.lines[line - 1].match(patterns_1.indentationPattern)[0];
8
+ }
9
+ function hasEmptyLineBefore(sourceCode, node) {
10
+ var prevToken = sourceCode.getTokenBefore(node);
11
+ var token = sourceCode.getFirstToken(node);
12
+ if (!prevToken || !token) {
13
+ return true;
14
+ }
15
+ for (var i = prevToken.loc.end.line + 1; i < token.loc.start.line; i++) {
16
+ if (patterns_1.emptyLinePattern.test(sourceCode.lines[i - 1])) {
17
+ return true;
18
+ }
19
+ }
20
+ return false;
21
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.domTypePatterns = exports.valueishNamePattern = exports.keyListLikeNamePattern = exports.keyishNamePattern = exports.upperSnakeCasePattern = exports.pascalCasePattern = exports.camelCasePattern = exports.closingLinePattern = exports.indentationPattern = exports.emptyLinePattern = void 0;
4
+ exports.emptyLinePattern = /^\s*$/;
5
+ exports.indentationPattern = /^\s*/;
6
+ exports.closingLinePattern = /^(\s*)(\)|}|]|<?\/\w*?>)/;
7
+ exports.camelCasePattern = /^[$_]?[\da-z]+?(?:[A-Z][\da-z]*?)*$/;
8
+ exports.pascalCasePattern = /^(?:[A-Z][\da-z]*?)+$/;
9
+ exports.upperSnakeCasePattern = /^[\dA-Z_]+$/;
10
+ exports.keyishNamePattern = /^(id|key|index|separator|delimiter)$|(Id|Key|Index|Separator|Delimiter)$/;
11
+ exports.keyListLikeNamePattern = /^(idList|keyList|keys|indices)$|(IdList|KeyList|Keys|Indices)$/;
12
+ exports.valueishNamePattern = /^(value|name)$|(Value|Name)$/;
13
+ exports.domTypePatterns = [
14
+ /\b(?:HTML\w*|SVG\w*|React)?Element\b/,
15
+ /\b(?:Mutable)?RefObject\b/
16
+ ];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INDENTATION_UNIT = void 0;
4
+ exports.toOrdinal = toOrdinal;
5
+ var pluralRules = new Intl.PluralRules("en", { type: "ordinal" });
6
+ var suffixes = {
7
+ one: "st",
8
+ two: "nd",
9
+ few: "rd",
10
+ other: "th"
11
+ };
12
+ exports.INDENTATION_UNIT = " ";
13
+ function toOrdinal(value) {
14
+ return "".concat(value).concat(suffixes[pluralRules.select(value)]);
15
+ }