Files
NapCatQQ/.pnpm-store/v3/files/4e/9924964354f2ede0b84501eb1354523e3c5a31751c5afb0dca2b1f7003865f5bd2c020b970374a8900c3fd5e475fc643786456c8a2883ef90090ab02649d73
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

58 lines
1.5 KiB
Plaintext

'use strict';
var utils = require('../utils.js');
require('eslint-visitor-keys');
require('espree');
require('estraverse');
var oneVarDeclarationPerLine = utils.createRule({
name: "one-var-declaration-per-line",
package: "js",
meta: {
type: "layout",
docs: {
description: "Require or disallow newlines around variable declarations"
},
schema: [
{
type: "string",
enum: ["always", "initializations"]
}
],
fixable: "whitespace",
messages: {
expectVarOnNewline: "Expected variable declaration to be on a new line."
}
},
create(context) {
const always = context.options[0] === "always";
function isForTypeSpecifier(keyword) {
return keyword === "ForStatement" || keyword === "ForInStatement" || keyword === "ForOfStatement";
}
function checkForNewLine(node) {
if (isForTypeSpecifier(node.parent.type))
return;
const declarations = node.declarations;
let prev;
declarations.forEach((current) => {
if (prev && prev.loc.end.line === current.loc.start.line) {
if (always || prev.init || current.init) {
context.report({
node,
messageId: "expectVarOnNewline",
loc: current.loc,
fix: (fixer) => fixer.insertTextBefore(current, "\n")
});
}
}
prev = current;
});
}
return {
VariableDeclaration: checkForNewLine
};
}
});
module.exports = oneVarDeclarationPerLine;