Skip to content

ESlint-plugin-compat doesn't seem to be able to accurately flag errors for methods on HTMLElements #651

@gwyneplaine

Description

@gwyneplaine

It seems at the very least the plugin has trouble detecting callExpressions on HTMLElements.

/* This errors as expected with:
HTMLElement.attachInternals() is not supported in iOS Safari 15.6-15.8eslint[compat/compat](https://github.com/amilajack/eslint-plugin-compat/blob/master/docs/rules/compat.md)
*/

globalThis.HTMLElement.attachInternals();

/* None of these cases error despite clearly either:
*  a) extending the `HTMLElement` object interface or 
*  b) straight up being an instance of HTMLElement 
*/
const x = globalThis.HTMLElement;
new x().attachInternals();

const foo = document.createElement('custom-element');
foo.attachInternals();

class y extends HTMLElement {
    constructor () {
        this.attachInternals();
    }
}

new y().attachInternals();

Looking through the source code, it seems like the algorithm we're using to match for failing rules in lintMemberExpression isn't able to match failingRules on these cases.

  const foo = document.createElement('custom-element');
  foo.attachInternals();

The expected rule.object here is HTMLElement, rule.property attachInternals()
The evaluated node object name is foo, node property attachInternals()
This fails the failingRule check on line 170

class y extends HTMLElement {
    constructor () {
        this.attachInternals();
    }
}

The expected protochainId here is HTMLElement.attachInternals() the evaluated protochainId is attachInternals()
It seems we're unable to evaluate / not evaluating the superclass of the ClassDeclaration represented by the ThisExpression. This fails the failingRule check on line 156

Notably I get the same issue with other callexpressions on HTMLElement such as hidePopover and showPopover

Though given the above examples I've given, this may be a larger problem with matching failing rules on memberExpressions.

I've created a minimal reproduction case here.
This leverages the latest version of this package with eslint@8.57.1, notably the same issue occurs with eslint@9.23.0

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