@so1ve/eslint-plugin 3.22.1 → 3.22.2
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/dist/index.js +9 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,16 +3,18 @@ import { AST_TOKEN_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
|
3
3
|
|
|
4
4
|
//#region src/utils/index.ts
|
|
5
5
|
const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
6
|
-
function
|
|
6
|
+
function getSiblingNode(node, offset) {
|
|
7
7
|
if (!node) return;
|
|
8
8
|
const { parent } = node;
|
|
9
9
|
if (parent && "body" in parent) {
|
|
10
10
|
const { body } = parent;
|
|
11
11
|
if (!Array.isArray(body)) return;
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
12
|
+
const targetIndex = body.indexOf(node) + offset;
|
|
13
|
+
if (targetIndex >= 0 && targetIndex < body.length) return body[targetIndex];
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
+
const getPreviousNode = (node) => getSiblingNode(node, -1);
|
|
17
|
+
const getNextNode = (node) => getSiblingNode(node, 1);
|
|
16
18
|
|
|
17
19
|
//#endregion
|
|
18
20
|
//#region src/rules/function-style.ts
|
|
@@ -175,14 +177,14 @@ const rule$9 = createEslintRule({
|
|
|
175
177
|
if (node.value?.type !== "CommentContent") return;
|
|
176
178
|
const rawValue = node.value.value;
|
|
177
179
|
if (rawValue.trim().length === 0) return;
|
|
178
|
-
if (!rawValue.startsWith(" ")) context.report({
|
|
180
|
+
if (!rawValue.startsWith(" ") && !rawValue.startsWith("\n")) context.report({
|
|
179
181
|
node: node.value,
|
|
180
182
|
messageId: "expectedSpaceBefore",
|
|
181
183
|
fix(fixer) {
|
|
182
184
|
return fixer.insertTextBefore(node.value, " ");
|
|
183
185
|
}
|
|
184
186
|
});
|
|
185
|
-
if (!rawValue.endsWith(" ")) context.report({
|
|
187
|
+
if (!rawValue.endsWith(" ") && !rawValue.endsWith("\n")) context.report({
|
|
186
188
|
node: node.value,
|
|
187
189
|
messageId: "expectedSpaceAfter",
|
|
188
190
|
fix(fixer) {
|
|
@@ -236,14 +238,6 @@ var import_dedupe_default = rule$8;
|
|
|
236
238
|
//#region src/rules/import-export-newline.ts
|
|
237
239
|
const RULE_NAME$6 = "import-export-newline";
|
|
238
240
|
const isExportDeclaration = (node) => node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration" || node.type === "ExportAllDeclaration";
|
|
239
|
-
function getSiblingNode(node, direction) {
|
|
240
|
-
const parent = node.parent;
|
|
241
|
-
if (!parent || !("body" in parent) || !Array.isArray(parent.body)) return null;
|
|
242
|
-
const body = parent.body;
|
|
243
|
-
const index = body.indexOf(node);
|
|
244
|
-
if (index === -1) return null;
|
|
245
|
-
return direction === "prev" ? index > 0 ? body[index - 1] : null : index < body.length - 1 ? body[index + 1] : null;
|
|
246
|
-
}
|
|
247
241
|
const rule$7 = createEslintRule({
|
|
248
242
|
name: RULE_NAME$6,
|
|
249
243
|
meta: {
|
|
@@ -297,13 +291,13 @@ const rule$7 = createEslintRule({
|
|
|
297
291
|
fix: (fixer) => fixer.insertTextAfter(lastImportNode, "\n")
|
|
298
292
|
});
|
|
299
293
|
for (const node of exportNodes) {
|
|
300
|
-
const prevNode =
|
|
294
|
+
const prevNode = getPreviousNode(node);
|
|
301
295
|
if ((!prevNode || !isExportDeclaration(prevNode)) && !(lastImportNode && prevNode === lastImportNode) && shouldHaveNewline(node, "before")) context.report({
|
|
302
296
|
node,
|
|
303
297
|
messageId: "newlineBeforeExport",
|
|
304
298
|
fix: (fixer) => fixer.insertTextBefore(node, "\n")
|
|
305
299
|
});
|
|
306
|
-
const nextNode =
|
|
300
|
+
const nextNode = getNextNode(node);
|
|
307
301
|
if (nextNode && !isExportDeclaration(nextNode) && shouldHaveNewline(node, "after")) context.report({
|
|
308
302
|
node,
|
|
309
303
|
messageId: "newlineAfterExport",
|