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

feat: support named exports in ESM/TS #449

Merged
merged 2 commits into from
Feb 26, 2024

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Feb 20, 2024

This adds support for named exports in ESM (whether it be TS or not).

For example:

export const rule: RuleModule = {
  create: () => { ... };
};

Also, exported symbols:

const rule = { ... };

export {rule};

While ESLint plugins are still usually CJS at time of writing this, many are written as ESM sources, and an increasing number are using named exports.

Reviewer notes

You'll want to hide whitespace changes when reviewing this, as prettier reformatted a bunch of it thanks to changing the level of nesting/chaining.

Fixes #375

This adds support for named exports in ESM (whether it be TS or not).

For example:

```ts
export const rule: RuleModule = {
  create: () => { ... };
};
```

Also, exported symbols:

```ts
const rule = { ... };

export {rule};
```

While ESLint plugins are still usually CJS at time of writing this, many
are written as ESM sources, and an increasing number are using named
exports.
lib/utils.js Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you speak to the possibility of this causing additional false positives as I mentioned in #375 (comment)? Do you anticipate any? It may be worth testing on a few top ESLint plugins for a change like this. Is there anything else we should do to mitigate this from detecting named exports that aren't ESLint rules?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the eslint-remote-tester's result, no false positives were found. We can start with this implementation and improve it if we receive feedback. thoughts?

https://github.com/eslint-community/eslint-plugin-eslint-plugin/actions/runs/7980943358/job/21791683343?pr=449

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very primitive idea is allowing configuring the esquery selectors for the possible rules:

{
  settings: {
    // to allow "export const rule = ..."
    "eslint-plugin": {"rule-selectors": ["ExportNamedDeclaration[declaration.type="VariableDeclaration"][declaration.declarations.0.id.name="rule"]"]}
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aladdin-add is eslint-remote-tester actually showing us new lint violations (which could be false positives), or just crashes? It says Results: No errors but I'd be kind of surprised if there really are no lint violations in any of those repositories. We may also want to add more ESM plugins to the list it tests against.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@43081j can you manually test this on a few larger/top ESM plugins? I don't think eslint-remote-tester, which runs during CI, detects false positives for us, only crashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll have a look into it 👍

tests/lib/utils.js Show resolved Hide resolved
@43081j
Copy link
Contributor Author

43081j commented Feb 20, 2024

Thanks for the quick review @bmish , I'll sort the changes tomorrow 👍

@43081j
Copy link
Contributor Author

43081j commented Feb 21, 2024

FYI i have at least resolved the two changes

not sure what you want to do about the testing. since it seems like @aladdin-add already ran the remote tester successfully

@43081j
Copy link
Contributor Author

43081j commented Feb 25, 2024

@bmish i ran it against:

  • eslint-plugin-compat
  • eslint-plugin-jest
  • TSESLint
  • eslint-plugin-vue
  • eslint-plugin-prettier

and all seemed well

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@aladdin-add aladdin-add merged commit aa15471 into eslint-community:main Feb 26, 2024
6 checks passed
@43081j 43081j deleted the named-exports branch February 26, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rules do not work with named exports
3 participants