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

Validator fails ES2019 public field declaration #3062

Closed
erosman opened this issue Feb 28, 2020 · 13 comments · Fixed by #3984
Closed

Validator fails ES2019 public field declaration #3062

erosman opened this issue Feb 28, 2020 · 13 comments · Fixed by #3984
Assignees
Labels
priority:p3 state:verified_fixed type:syntax Issues related to JavaScript syntax (support).
Milestone

Comments

@erosman
Copy link
Contributor

erosman commented Feb 28, 2020

ref: 75.0a1 (2020-02-27) (64-bit)

Validator fails ES2019 public field declaration even though Firefox works fine with.

image

Example:

class MyClass {

  a = 1;
  b = 2;
  c = 3;

}

PS. If support was added to Firefox, which version is it from?

@Rob--W
Copy link
Member

Rob--W commented Feb 28, 2020

This is not a "variable outside the constructor". It is a (public) field declaration, supported in Firefox as of version 75 (and Chrome 74+), with the relevant bug being https://bugzilla.mozilla.org/show_bug.cgi?id=1499448 . The documentation is at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_fields#Public_fields (scroll a bit below to "Public instance fields" for your specific case).

@erosman erosman changed the title Validator fails ES2019 variable outside the constructor Validator fails ES2019 public field declaration Feb 28, 2020
@erosman
Copy link
Contributor Author

erosman commented Feb 28, 2020

Thank you Rob. Title updated.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Class_fields#Public_fields states support from Firefox 69 !!

@Rob--W
Copy link
Member

Rob--W commented Feb 28, 2020

I stand corrected; Public instance fields (what you're using here) have already been supported since 69 (https://bugzilla.mozilla.org/show_bug.cgi?id=1555464).

I had public static fields in mind (syntax is class {static name = value}), which differs from what you've reported here, and is supported in Firefox 75+ (https://bugzilla.mozilla.org/show_bug.cgi?id=1535804).

@lfilho
Copy link

lfilho commented Jun 14, 2020

Arrived here for the same reason.
Tried running the web-ext lint --ignore-files "**/.*js" in an attempt to let the addons-linter only lint the manifes.json file and leave all the .js files to my local eslint setup, but that --ignore-files argument is actually applied to web-ext and not only to the lint subcommand, failing the lint command completely with: "content script defined in the manifest could not be found at "content_script.js"".

Right now I'm just stopping to use web-ext lint anymore :-/

Ideally addons-linter would be able to identify an eslint already installed in the user's package.json and use that one instead?

Or maybe a even better idea is instead of having a customer linter here, you would create an eslint plugin/preset for WebExtensions instead?

Anyway, thanks!

@lfilho
Copy link

lfilho commented Jun 14, 2020

Another great workaround would be if we could just say: web-ext lint file-to-lint-1 file-to-lint-2. This way i could just point it to manifes.json while keeping the rest of of my .js files being linted by the eslint in my project.

@willdurand
Copy link
Member

see also: #2758

@devsecdan
Copy link

I stand corrected; Public instance fields (what you're using here) have already been supported since 69 (https://bugzilla.mozilla.org/show_bug.cgi?id=1555464).

I had public static fields in mind (syntax is class {static name = value}), which differs from what you've reported here, and is supported in Firefox 75+ (https://bugzilla.mozilla.org/show_bug.cgi?id=1535804).

Ran into this issue today. Unable to publish my extension because it makes use of static fields.

@rpl
Copy link
Member

rpl commented Oct 22, 2020

Unfortunately this issue is still blocked on an upstream change: eslint officially supporting the class fields tc39 proposal.

It looks that the class fields tc39 proposal is still at stage 3 (see https://github.com/tc39/proposal-class-fields) and I'm pretty sure that eslint does not usually introduce support for new javascript syntaxes until their tc39 proposal does reach stage 4.

@regseb
Copy link
Contributor

regseb commented Mar 20, 2021

You can use @babel/eslint-parser and @babel/plugin-proposal-class-properties in ESLint configuration to support class field.

{
    parser: "@babel/eslint-parser",
    parserOptions: {
        requireConfigFile: false,
        babelOptions: {
            plugins: [
                "@babel/plugin-proposal-class-properties"
            ]
        }
    }
}

gaeulbyul added a commit to gaeulbyul/Komposer that referenced this issue Apr 26, 2021
public class field declaration를 지원하지 않더라.
mozilla/addons-linter#3062
@muzuiget
Copy link

muzuiget commented May 15, 2021

Please fix this issue.

Currently "Class Fields" feature is on stage 4, and Webpack 5 already supports it a few days ago webpack/webpack#10216

@Rob--W
Copy link
Member

Rob--W commented Jun 10, 2021

Depends on eslint/eslint#14343

@lydell
Copy link

lydell commented Aug 28, 2021

ESLint v8.0.0-beta.0 (and ESLint v8.0.0-beta.1) have been released – with support for class fields – so if anyone would like to begin work on this, I guess it’s possible now!

@ioanarusiczki
Copy link

@willdurand
I verified this locally and with AMO dev using the example above and from docs

dev

linter 4 0 0

This was before:

stage

publicfield.zip
publicfield2.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p3 state:verified_fixed type:syntax Issues related to JavaScript syntax (support).
Projects
None yet
Development

Successfully merging a pull request may close this issue.