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

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 babel-bot commented Aug 21, 2020

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

@codesandbox
Copy link

@codesandbox codesandbox 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.

@kaicataldo
Copy link
Member

@kaicataldo kaicataldo commented Aug 22, 2020

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

@JLHwung JLHwung merged commit 304eea4 into babel:main Aug 24, 2020
10 of 11 checks passed
10 of 11 checks passed
test
Details
legacy-node-version-test (6.x)
Details
legacy-node-version-test (8.x)
Details
test262-pr Workflow: test262-pr
Details
Gitpod Open an online workspace in Gitpod
Details
Travis CI - Pull Request Build Passed
Details
babel/repl REPL preview is available
Details
build-standalone Workflow: build-standalone
Details
ci/codesandbox Building packages succeeded.
Details
codecov/project 91.69% (target 90.00%)
Details
e2e Workflow: e2e
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.