Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Skipped
58 lines
2.1 KiB
Plaintext
58 lines
2.1 KiB
Plaintext
import { f as createRule, g as import_ast_utils } from "../utils.js";
|
|
var object_property_newline_default = createRule({
|
|
name: "object-property-newline",
|
|
meta: {
|
|
type: "layout",
|
|
docs: { description: "Enforce placing object properties on separate lines" },
|
|
fixable: "whitespace",
|
|
schema: [{
|
|
type: "object",
|
|
properties: { allowAllPropertiesOnSameLine: { type: "boolean" } },
|
|
additionalProperties: false
|
|
}],
|
|
defaultOptions: [{ allowAllPropertiesOnSameLine: false }],
|
|
messages: {
|
|
propertiesOnNewlineAll: "Object properties must go on a new line if they aren't all on the same line.",
|
|
propertiesOnNewline: "Object properties must go on a new line."
|
|
}
|
|
},
|
|
create(context, [options]) {
|
|
const allowSameLine = options.allowAllPropertiesOnSameLine;
|
|
const messageId = allowSameLine ? "propertiesOnNewlineAll" : "propertiesOnNewline";
|
|
const sourceCode = context.sourceCode;
|
|
function check(node, children) {
|
|
if (allowSameLine) {
|
|
if (children.length > 1) {
|
|
if ((0, import_ast_utils.isTokenOnSameLine)(sourceCode.getFirstToken(children[0]), sourceCode.getLastToken(children[children.length - 1]))) return;
|
|
}
|
|
}
|
|
for (let i = 1; i < children.length; i++) {
|
|
const lastTokenOfPreviousProperty = sourceCode.getLastToken(children[i - 1]);
|
|
const firstTokenOfCurrentProperty = sourceCode.getFirstToken(children[i]);
|
|
if ((0, import_ast_utils.isTokenOnSameLine)(lastTokenOfPreviousProperty, firstTokenOfCurrentProperty)) context.report({
|
|
node,
|
|
loc: firstTokenOfCurrentProperty.loc,
|
|
messageId,
|
|
fix(fixer) {
|
|
const rangeAfterComma = [sourceCode.getTokenBefore(firstTokenOfCurrentProperty).range[1], firstTokenOfCurrentProperty.range[0]];
|
|
if (sourceCode.text.slice(rangeAfterComma[0], rangeAfterComma[1]).trim()) return null;
|
|
return fixer.replaceTextRange(rangeAfterComma, "\n");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
return {
|
|
ObjectExpression(node) {
|
|
check(node, node.properties);
|
|
},
|
|
TSTypeLiteral(node) {
|
|
check(node, node.members);
|
|
},
|
|
TSInterfaceBody(node) {
|
|
check(node, node.body);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
export { object_property_newline_default as t };
|