Skip to content

New Rule Proposal: no-class-fields #66

@ota-meshi

Description

@ota-meshi

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) {
    // ...
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions