question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule Proposal: object-curly-newline

See original GitHub issue

From requirePaddingNewLinesInObjects and disallowPaddingNewLinesInObjects.

This will require/disallow line breaks after open object curlies and before close object curlies.

Options

{
    "object-curly-newline": [
        "error", 
        "always" or "never" or {"multiline": <boolean>, "minItems": <integer>}
    ]
}
  • "always" - Requires line breaks always.
  • "never" - Disallows line breaks always.
  • An object - Requires line breaks if any of properties is satisfied. Otherwise, disallows line breaks.
    • multiline (default is false) - Requires line breaks if the content is multiline. If this is false, this condition is disabled.
    • minItems (default is 0) - Requires line breaks if the number of properties is more than the given integer. If this is 0, this condition is disabled.

Examples

/*eslint object-curly-newline: ["error", "always"]*/

// ✔ GOOD
let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

// ✘ BAD
let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {foo() {
    dosomething();
}};
/*eslint object-curly-newline: ["error", "never"]*/

// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};

// ✘ BAD
let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};
/*eslint object-curly-newline: ["error", {"multiline": true}]*/

// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

// ✘ BAD
let a = {
};
let b = {
    foo: 1
};
let c = {
    foo: 1, bar: 2
};
let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};
/*eslint object-curly-newline: ["error", {"minItems": 2}]*/

// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {foo: function() {
    dosomething();
}};

// ✘ BAD
let a = {
};
let b = {
    foo: 1
};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {
    foo: function() {
        dosomething();
    }
};
/*eslint object-curly-newline: ["error", {"multiline": true "minItems": 2}]*/

// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {
    foo: 1, bar: 2
};
let d = {
    foo: 1,
    bar: 2
};
let e = {
    foo: function() {
        dosomething();
    }
};

// ✘ BAD
let a = {
};
let b = {
    foo: 1
};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
    bar: 2};
let e = {foo: function() {
    dosomething();
}};

Related Rules

brace style space style line break style
block brace-style block-spacing max-statements-per-line
object #6072 object-curly-newline object-curly-spacing object-property-newline
array #6073 array-bracket-newline array-bracket-spacing #6075 array-element-newline

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mysticateacommented, May 14, 2016

I updated this proposal. If there are not objection opinions, I want to implement this.

0reactions
PhiLhoSoftcommented, May 31, 2016

Yes, I was answering the comment https://github.com/eslint/eslint/issues/6072#issuecomment-219219579 actually, referring to the above issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

object-curly-newline - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
[Meta] Use Prettier for formatting JavaScript in Thunderbird
Current eslint rule: // Enforce consistent line breaks inside braces "object-curly-newline": [2, { multiline: true }],. Proposed Prettier-friendly change:
Read more >
A brand new website interface for an even better experience!
Proposal: "object-curly-newline" add configuration for named imports and exports (or create new rule for import/export specifiers)
Read more >
Eslint rule to put a new line inside import - Stack Overflow
I was looking for such a rule for both import and export declaration. ... Add the object-curly-newline rule to your .eslintrc.json , where ......
Read more >
vue/object-curly-newline - eslint-plugin-vue
This rule is the same rule as core object-curly-newline rule but it applies to the expressions in <template> .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found