Skip to content

Commit 1a91514

Browse files
committed
fix eslint rule to add multiline when needed
1 parent 00b718b commit 1a91514

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tools/eslint-rules/set-proto-to-null-in-object.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
},
88
fixable: 'code',
99
},
10-
create: function(context) {
10+
create: function (context) {
1111
return {
1212
ObjectExpression(node) {
1313
// Not adding __proto__ to module.exports as it will break a lot of libraries
@@ -44,12 +44,23 @@ module.exports = {
4444
context.report({
4545
node,
4646
message: 'Every object must have __proto__: null',
47-
fix: function(fixer) {
47+
fix: function (fixer) {
4848
// Generate the fix suggestion to add __proto__: null
4949
const sourceCode = context.getSourceCode();
5050
const firstProperty = properties[0];
5151
const firstPropertyToken = sourceCode.getFirstToken(firstProperty);
52-
const fixText = '__proto__: null, ';
52+
53+
let fixText = `__proto__: null`;
54+
55+
if (properties.length > 1) {
56+
fixText += ',';
57+
58+
if (properties[0].loc.start.line !== properties[1].loc.start.line) {
59+
fixText += '\n';
60+
} else {
61+
fixText += ' ';
62+
}
63+
}
5364

5465
// Insert the fix suggestion before the first property
5566
return fixer.insertTextBefore(firstPropertyToken, fixText);
@@ -62,7 +73,7 @@ module.exports = {
6273
context.report({
6374
node,
6475
message: 'Every empty object must have __proto__: null',
65-
fix: function(fixer) {
76+
fix: function (fixer) {
6677
// Generate the fix suggestion to create the object with __proto__: null
6778
const fixText = '{ __proto__: null }';
6879

0 commit comments

Comments
 (0)