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 Enhancement Proposal: func-names with never #6059

Closed
mysticatea opened this issue May 3, 2016 · 10 comments
Closed

Rule Enhancement Proposal: func-names with never #6059

mysticatea opened this issue May 3, 2016 · 10 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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@mysticatea
Copy link
Member

mysticatea commented May 3, 2016

EDIT: this proposal was updated in #6059 (comment)


From requireAnonymousFunctions and requireMatchingFunctionName.

This proposal is to add some options.

{
    "func-names": [
        "error",
        "always" or "never",
        {
            "sameAsVariable": false
        }
}
  • "always" (default) - This is the current behavior.
  • "never" - This will disallow a use of function expression names.
  • sameAsVariable (default is false) - If this is true, the function expression name must be the same as the variable name which is the destination of the assignment. For example: let foo = function foo() {};. But if the destination is module.exports, this rule will ignore it.
@mysticatea mysticatea added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels May 3, 2016
@mysticatea mysticatea added this to the JSCS Compatibility milestone May 3, 2016
@platinumazure
Copy link
Member

Should sameAsVariable: true also check for assignment to a MemberExpression at all? (e.g., foo.bar = function baz () { })

Should we allow a "tolerate" value for the first option, so that a user can decide that s/he does not always want function names, but when a function name is specified, it must match the assigned variable name?

@mysticatea
Copy link
Member Author

mysticatea commented May 3, 2016

Should sameAsVariable: true also check for assignment to a MemberExpression at all? (e.g., foo.bar = function baz () { })

Yes.

Should we allow a "tolerate" value for the first option, so that a user can decide that s/he does not always want function names, but when a function name is specified, it must match the assigned variable name?

Ah, interesting.
Maybe requireMatchingFunctionName should not merge with func-names rule.

@platinumazure
Copy link
Member

platinumazure commented May 3, 2016

Should sameAsVariable: true also check for assignment to a MemberExpression at all? (e.g., foo.bar = function baz () { })

Yes.

So if sameAsVariable: true, does this mean users cannot assign functions to object members at all?

Ah, interesting.
Maybe requireMatchingFunctionName should not merge with func-names rule.

I think I agree-- that could be a separate rule, which wouldn't do much if function expressions don't have names, but it would execute safely and not confuse the options schema of this proposed rule.

@mysticatea
Copy link
Member Author

mysticatea commented May 4, 2016

From requireAnonymousFunctions.

This proposal is to add "never" option to func-names rule.

{
    "func-names": [
        "error",
        "always" or "never"
    ]
}
  • "always" (default) - This is the current behavior.
  • "never" - This will disallow a use of function expression names.

Valid:

/*eslint func-names: ["error", "never"]*/

function foo() {
}
var foo = function() {
};

Invalid:

/*eslint func-names: ["error", "never"]*/

var foo = function foo() {
};

@mysticatea mysticatea changed the title Rule Enhancement Proposal: func-names with never, sameAsVariable Rule Enhancement Proposal: func-names with never May 4, 2016
@Mouvedia
Copy link

related: #938

@alberto
Copy link
Member

alberto commented May 27, 2016

@eslint/eslint-team opinions?

I can champion this one

@alberto alberto self-assigned this May 27, 2016
@mikesherov
Copy link
Contributor

👍

@Mouvedia
Copy link

Mouvedia commented May 28, 2016

👍

Here's another reason—if you care about cross-browser issues—to make this happen: https://kangax.github.io/nfe/#safari-bug

Would it be asking for too much to have a only if not part of an assignment expression option for never?

@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 Jun 7, 2016
@nzakas
Copy link
Member

nzakas commented Jun 7, 2016

Looks like we are good to move forward here.

@Mouvedia this issue is for creating an option that is compatible with JSCS functionality. If you want more than that, please open a new issue.

@Mouvedia
Copy link

Mouvedia commented Jun 7, 2016

@nzakas after 3 refusals, I don't think Ill submit a new one…
I learned my lesson :)

@nzakas nzakas closed this as completed in 1316db0 Jun 15, 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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
No open projects
Development

No branches or pull requests

6 participants