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

New Rule Proposal: no-class-fields #66

Open
ota-meshi opened this issue Apr 21, 2021 · 2 comments · May be fixed by #67
Open

New Rule Proposal: no-class-fields #66

ota-meshi opened this issue Apr 21, 2021 · 2 comments · May be fixed by #67

Comments

@ota-meshi
Copy link
Contributor

Please describe what the rule should do:

Disallows Class Fields added in ES2022.

https://github.com/estree/estree/blob/master/es2022.md

Provide 2-3 code examples that this rule will warn about:

https://github.com/tc39/proposal-class-fields

class Counter  {
  x = 0;
}

https://github.com/tc39/proposal-private-methods

class Counter  {
  #xValue = 0;

  get #x() { return #xValue; }
  set #x(value) {
    this.#xValue = value;
    window.requestAnimationFrame(this.#render.bind(this));
  }

  #clicked() {
    this.#x++;
  }

  constructor() {
    super();
    this.onclick = this.#clicked.bind(this);
  }

  connectedCallback() { this.#render(); }

  #render() {
    this.textContent = this.#x.toString();
  }
}

https://github.com/tc39/proposal-static-class-features

class CustomDate {
  // ...
  static epoch = new CustomDate(0);
}
export class JSDOM {

  static async fromURL(url, options = {}) {
    return JSDOM.#finalizeFactoryCreated(new JSDOM(body, options), "fromURL");
  }

  static #finalizeFactoryCreated(jsdom, factoryName) {
    // ...
  }
}
@ota-meshi ota-meshi linked a pull request Apr 22, 2021 that will close this issue
@ota-meshi
Copy link
Contributor Author

Should this rule be split into three rules if it needs to be based on proposals?
(no-class-fields, no-static-class-features and no-private-methods ?)
What do you think?

@flowstate247
Copy link

Yes it would be nice to split this rule into multiple rules to have fine control over what we want or not in our code.
For example, personally I am only interested in disabling private methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants