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

fix: func-style false positive with arrow functions and super #18473

Merged
merged 1 commit into from
May 20, 2024

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment (npx eslint --env-info):

  • Node version: v20.12.0
  • npm version: 10.5.0
  • Local ESLint version: v9.3.0
  • Global ESLint version: no
  • Operating System: windows

What parser are you using (place an "X" next to just one item)?

[x] Default (Espree)
[ ] @typescript-eslint/parser
[ ] @babel/eslint-parser
[ ] vue-eslint-parser
[ ] @angular-eslint/template-parser
[ ] Other

Please show your full configuration:

Configuration
export default [];

What did you do? Please include the actual source code causing the issue.

/*eslint func-style: ["error", "declaration"]*/

class C {
    print() {
        console.log("I'm print of C");
    }
}

class D extends C {
    print() {
        console.log("I'm print of D");
    }

    test() {
        const arr1 = () => { // allowed
            this.print();
        }
        const arr2 = () => { // reported, false positive
            super.print();
        }

        arr1(); // logs "I'm print of D"
        arr2(); // logs "I'm print of C"
    }
}

new D().test();

What did you expect to happen?

No lint errors from func-style, because arr1 and arr2 cannot be replaced with function declarations.

What actually happened? Please include the actual, raw output from ESLint.

Error on arr2:

  18:15  error  Expected a function declaration  func-style

What changes did you make? (Give an overview)

Updated func-style rule to treat super the same as this.

Is there anything you'd like reviewers to focus on?

@mdjermanovic mdjermanovic requested a review from a team as a code owner May 18, 2024 14:43
@eslint-github-bot eslint-github-bot bot added the bug ESLint is working incorrectly label May 18, 2024
@github-actions github-actions bot added the rule Relates to ESLint's core rules label May 18, 2024
Copy link

netlify bot commented May 18, 2024

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 3c214b5
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/6648bea8daa002000860972c

@fasttime fasttime added the accepted There is consensus among the team that this change meets the criteria for inclusion label May 19, 2024
Copy link
Member

@fasttime fasttime left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open until the current release issue #18424 is closed.

@fasttime fasttime merged commit 70118a5 into main May 20, 2024
19 checks passed
@fasttime fasttime deleted the funcstyle-super branch May 20, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

None yet

2 participants