import/enforce-node-protocol-usage broken (original) (raw)

The rule import/enforce-node-protocol-usage is not working with code containing the export keyword.

How to reproduce:

  1. Install @jirimoravcik/eslint-plugin-import with version 2.32.0-beta.0 as the rule was merged after 2.31.0 was released.
  2. Do 'import/enforce-node-protocol-usage': ['error', 'always'], in your eslint config
  3. Create a TS file with the following content:

export class Thing { constructor(public readonly name: string) { // Do nothing. }

public sayHello(): void {
    console.log(`Hello, ${this.name}!`);
}

}

  1. Try to lint it
  2. You'll get an error:
TypeError: Cannot read properties of null (reading 'type')
Rule: "import-fixed/enforce-node-protocol-usage"
at checkAndReport (/Users/jirimoravcik/.../node_modules/@jirimoravcik/eslint-plugin-import/lib/rules/enforce-node-protocol-usage.js:47:11)

I fixed by doing an early return in jirimoravcik@272d471, but I'm not sure if that's the proper solution.

Thanks for looking into it.