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

All: Enable ESLint indent rule (one-tab indent for outer IIFE bodies) #1143

Merged

Conversation

platinumazure
Copy link
Contributor

This enables the ESLint "indent" rule.

There are some limitations of this rule which would force us to deviate from the jQuery style guide, especially around full file closures (whether IIFEs or factory functions). This PR chooses to have pure IIFEs be indented 1 tab, which is further from the style guide but results in consistent indentation between pure IIFEs and factory functions.

PR #1142 is the zero-tab IIFE version.

Copy link
Member

@trentmwillis trentmwillis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I prefer this approach. I prefer consistent style over special cases. At this point, I think it should be fine for us to deviate from the jQuery style guide.

@@ -10,6 +10,14 @@
"arrow-spacing": ["error", { "before": true, "after": true }],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"constructor-super": "error",
"indent": ["error", "tab", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what ways does this deviate from the "normal" indent rule? Or, why do we need the complicated object config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CallExpression indenting isn't on by default. Setting it as I have done forces arguments to function calls on subsequent lines to be indented one tab.

QUnit.on(
    "event", // <-- poor man's tab
    doSomething);

MemberExpression does a similar thing with property accesses and would also be off by default:

return myString
    .replace("foo", "bar")
    .replace("baz", "quux");

SwitchCase enforces this style of case statements (it's set same as default, but since it was called out in the style guide I thought it was good to include in case the default changes upstream):

switch (x) {
case "foo":
    return true;
case "bar":
    return false;

And outerIIFEBody is for full file closures... at least, those that are actually pure IIFEs. Setting it to 1 means basically all function declarations/expressions/IIFEs require 1 tab indent of statements in the body.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great explanation! Thank you, seems good to me then!

.eslintrc.json Outdated
},
"MemberExpression": 1,
"SwitchCase": 0,
"outerIIFEBody": 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blast, these two lines need to be tabified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆 the irony

@trentmwillis
Copy link
Member

@platinumazure after a rebase and fixing the whitespace issue called out above, I'm 👍 to land this unless anyone else from @qunitjs/qunit-team disagrees with this approach.

@platinumazure platinumazure force-pushed the eslint-indent-outeriifebody-1 branch from b530264 to 0099856 Compare April 9, 2017 05:07
@platinumazure
Copy link
Contributor Author

@trentmwillis Issues fixed and branch is rebased, please review at your convenience.

One thing I'll note: ESLint 3.x's indent rule (i.e., what I've configured) doesn't auto-fix comments correctly so they might not be aligned. When ESLint 4.0 comes out, the indent rule is rewritten to be a lot smarter and will handle comments correctly. I mention this because, if you're okay with the comments being a little off for now, the 4.0 indent rule will auto-fix them in one go. Or, if getting the comments correctly aligned is super important, feel free to request changes when reviewing. Thanks!

Copy link
Member

@leobalter leobalter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR chooses to have pure IIFEs be indented 1 tab, which is further from the style guide but results in consistent indentation between pure IIFEs and factory functions.

This is reasonable now that we can use ES modules. It simplifies the rules and makes IIFEs more visible.

@leobalter leobalter merged commit bddf858 into qunitjs:master Apr 9, 2017
@platinumazure
Copy link
Contributor Author

Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants