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

Port JSCS rules for: requireSpacesInFunction, etc. #6099

Closed
meister opened this issue May 6, 2016 · 6 comments
Closed

Port JSCS rules for: requireSpacesInFunction, etc. #6099

meister opened this issue May 6, 2016 · 6 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@meister
Copy link

meister commented May 6, 2016

When does this rule warn? Please describe and show example code:
The rule allows enforcing or preventing spaces after function parens and before curly bracers. Currently it’s possible to control the space between keyword and parenthesis (function ()), but not after keyword+parenthesis. Examples:

function doSomething(){
//                    ^--- Missing/extra space not checked
    return;
}

for (var i = 0; i < items.length; i++){
//                                    ^--- Missing/extra space not checked
}

try {
    doSomething();
} catch (err){
//           ^--- Missing/extra space not checked
    throw new Error('message');
}

switch (local){
//            ^--- Missing/extra space
  case 1:
    doSomething();
}

Is this rule preventing an error or is it stylistic?
Stylistic

Why is this rule a candidate for inclusion instead of creating a custom rule?
Compatibility with JSCS:

{
    "requireSpacesInAnonymousFunctionExpression": {
        "beforeOpeningCurlyBrace": true
    },
    "requireSpacesInFunctionDeclaration": {
        "beforeOpeningCurlyBrace": true
    },
    "requireSpacesInFunction": {
        "beforeOpeningCurlyBrace": true
    }
}

Are you willing to create the rule yourself?

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label May 6, 2016
@mysticatea
Copy link
Member

Thank you for this issue.

Is space-before-blocks rule not enough?

@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 and removed triage An ESLint team member will look at this issue soon labels May 6, 2016
@meister
Copy link
Author

meister commented May 6, 2016

Wow.. I thought I had checked all the rules. I guess I hadn’t – I can indeed use that rule for this specific use case. Closing my issue.

@meister meister closed this as completed May 6, 2016
@mysticatea
Copy link
Member

FYI: There is a table to identify gap between JSCS and ESLint: #5856 (comment)

@meister
Copy link
Author

meister commented May 9, 2016

Thanks so much for feedback and help. Would you also have any idea about the progress of #4680?

It’s the last rule for our company’s requirements. There doesn’t seem to be a good way to port the rules for code like this:

// Required one-var for consecutive declarations
var a = 1,
    b = 2,
    items = [];

// JSCS throws a warning for rule 'requireMultipleVarDecl:true'
// ESLint throws a warning for rule 'one-var'
var c = a;

doSomething(a, b);

// JSCS does not throw a warning, since a statement was in between var declarations
// ESLint throws a warning
var d = c + b;

// Another block with var
// JSCS does not throw a warning for i
// ESLint throws a warning for i
for (var i = 0; i < items.length; i++) {
    // Another block of consecutive vars
    // JSCS does not throw a warning
    // ESLint throws a warning
    var temp1 = a + c,
        temp2 = b + d;

    doSomething(temp1, temp2);
}

@mysticatea
Copy link
Member

mysticatea commented May 9, 2016

I'm not sure.
I feel that the responsibility of one-var and vars-on-top is overlapping from your example.

@meister
Copy link
Author

meister commented May 9, 2016

Yes, that was exactly my concern. If one-var was more relaxed (like JSCS), but vars-on-top was enforced, the outcome would be almost exactly how it is now (all vars on top, with 1 var declaration). Otherwise, separated blocks of vars (if there are statements in the middle) would be allowed, thus making my example and those of issue #4680 possible.

@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
archived due to age This issue has been archived; please open a new issue for any further discussion evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants