Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Proposal: object-curly-newline #6072

Closed
mysticatea opened this issue May 4, 2016 · 13 comments
Closed

Rule Proposal: object-curly-newline #6072

mysticatea opened this issue May 4, 2016 · 13 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

mysticatea commented May 4, 2016

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
@mysticatea mysticatea added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 4, 2016
@mysticatea mysticatea added this to the JSCS Compatibility milestone May 4, 2016
@ilyavolodin
Copy link
Member

I think we already have an issue opened for something like that, having trouble finding it now. I think proposal was to add option to brace-style for object literals.

@mysticatea
Copy link
Member Author

For spacing, rules are separated each kind of braces. So my proposals are, too.

object-curly-spacingnewline-object-curly
array-bracket-spacingnewline-array-bracket
block-spacingbrace-style

Indeed, brace-style rule is doing more things than spacing rules, so my proposals may not be enough.

@mysticatea mysticatea changed the title Rule Proposal: newline-in-object-curly Rule Proposal: object-curly-newline May 14, 2016
@mysticatea
Copy link
Member Author

@ilyavolodin It seems to be closed already: #5203

@mysticatea
Copy link
Member Author

mysticatea commented May 14, 2016

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

@mysticatea mysticatea self-assigned this May 14, 2016
@ilyavolodin
Copy link
Member

👍

@nzakas
Copy link
Member

nzakas commented May 20, 2016

@eslint/eslint-team need some more feedback here.

👍

@BYK
Copy link
Member

BYK commented May 21, 2016

👍

@kaicataldo
Copy link
Member

Unless there's already a convention to use items when referring to object props, I wonder if there is a better name for the minItems option. minProps/minProperties? A little more verbose, but that's the terminology I'm used to using/seeing.

Otherwise, 👍 from me

@nzakas
Copy link
Member

nzakas commented May 21, 2016

@kaicataldo agreed, we should use "props" or "properties" for consistency

@nzakas nzakas added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 21, 2016
@mysticatea
Copy link
Member Author

Thank you!

I'll update my PR by feedback.

@PhiLhoSoft
Copy link

#5203 isn't actually covered by this proposal.
For this, we would need a rule to "require/disallow line breaks BEFORE open object curlies" (and brackets too, in the other proposals).
Not sure if this must be included in this rule or addressed by a different rule.

mysticatea added a commit that referenced this issue May 27, 2016
@nzakas
Copy link
Member

nzakas commented May 30, 2016

@PhiLhoSoft the goal here is not to implement a solution for #5203, it's to create an ESLint rule that is equivalent to two JSCS rules. Those rules only deal with inserting newlines inside of braces and that's what this issue is implementing.

@PhiLhoSoft
Copy link

Yes, I was answering the comment #6072 (comment) actually, referring to the above issue.

mysticatea added a commit that referenced this issue Jun 2, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
No open projects
Development

No branches or pull requests

6 participants