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

Added linting support for private class methods #11993

Merged
merged 3 commits into from Aug 24, 2020
Merged

Added linting support for private class methods #11993

merged 3 commits into from Aug 24, 2020

Conversation

giovannicalo
Copy link
Contributor

@giovannicalo giovannicalo commented Aug 21, 2020

Q                       A
Fixed Issues? No
Patch: Bug Fix? Yes
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? Yes
Documentation PR Link No
Any Dependency Changes? No
License MIT

The ESLint plugin claims its @babel/no-invalid-this rule handles private class methods correctly, however that doesn't seem to be the case.

Running

eslint -f pretty a.js

on

class A {

    #a() {
        return this.b;
    }

}

with ESLint settings

module.exports = {
    parser: "@babel/eslint-parser",
    plugins: ["@babel"],
    rules: { "@babel/no-invalid-this": 2 }
};

and Babel settings

module.exports = {
    presets: [["@babel/env", {
        shippedProposals: true
    }]]
};

prints

  a.js:4:10
  ×  4:10  Unexpected this.  @babel/no-invalid-this

  1 error

even though that this is perfectly valid.

This fixes the issue.

@babel-bot
Copy link
Collaborator

babel-bot commented Aug 21, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/27779/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 21, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@JLHwung JLHwung added area: eslint PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Aug 22, 2020
@kaicataldo
Copy link
Member

One suggestion for a clearer variable name, but otherwise LGTM!

@JLHwung JLHwung merged commit 304eea4 into babel:main Aug 24, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 26, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: eslint outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants