Babel-eslint: 11.0.0-beta.2 - Private method is not defined. (eslintno-undef)

Created on 30 Mar 2020  路  7Comments  路  Source: babel/babel-eslint

Hello,
I'm using experimental implementation of babel's private methods proposal and getting following error:

'setType' is not defined (no-undef)

for the following linted file:

export default class Ship {
  #type = null;

  constructor(type) {
    this.#setType(type);
  }

  #setType(type) {        // error raised on this line
    this.#type = type;
  }
}

Config files:

package.json - devDependencies (more dependencies included as I'm using NeutrinoJS):

...
"@babel/plugin-proposal-private-methods": "^7.8.3",
"babel-eslint": "^11.0.0-beta.2",
"eslint": "^6.8.0",
...

.eslintrc.js

module.exports = {
    ...
    "parser": "babel-eslint",
    ...
};

babel.config.js (actually have more presents and plugins, but the error persist even when omitted)

module.exports = {
    babelrc: false,
    presets: [],
    plugins: [
        ['@babel/plugin-proposal-class-properties', { loose: true }],
        ['@babel/plugin-proposal-private-methods', { loose: true }],
    ]
};

Furthermore, no linting occurs in the whole method marked as not defined.

Most helpful comment

Is there any solution for that? Private methods are correctly working on babel, but workflow is blocked due to linter...

All 7 comments

I'm getting the same issue, also it looks like any code within the private method is ignored so the linter thinks that imported methods used inside the private method is not used and asks me to remove the imports, which are needed.

private-methods-linter-issues

I think this has discussed in here https://github.com/babel/babel-eslint/issues/746 but still there is no valid solution for the problem

I think this has discussed in here #746 but still there is no valid solution for the problem

tnx, I believe it's fixed, but waiting for next major Babel release according https://github.com/babel/babel/issues/10752

Same here. I don't believe this. I'm struggling with this private method since early 2019! Babel v8 completion is at 38%, so when we got this working properly?

Is there any solution for that? Private methods are correctly working on babel, but workflow is blocked due to linter...

So we have to wait for Babel 8 to be out for this to be fixed? No workarounds available?

Fixed in @babel/eslint-parser 7.11.0, see https://babel.dev/blog/2020/07/13/the-state-of-babel-eslint#the-future for the renaming guide.

Was this page helpful?
0 / 5 - 0 ratings