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

Add optional static enum lint #36759

Merged
merged 4 commits into from
Nov 5, 2021
Merged

Conversation

jridgewell
Copy link
Contributor

This adds an optional enum linter that ensures that an enum is only used in a statically DCE-able way. Enums opt-into this behavior by using the _Enum suffix in their name.

Depends on #36755
Partial for #36754

@jridgewell jridgewell requested a review from samouri November 4, 2021 03:47
@amp-owners-bot
Copy link

amp-owners-bot bot commented Nov 4, 2021

Hey @erwinmombay! These files were changed:

build-system/eslint-rules/enums.js

Copy link
Member

@samouri samouri left a comment

Choose a reason for hiding this comment

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

IMO this is not worth disabling for build-system. In fact, build-system should likely never use @enum since it isn't compiled and therefore the annotation has no meaning

if (callee.type === 'Identifier') {
const {name} = callee;
if (
name === 'isEnumValue' // ||
Copy link
Member

Choose a reason for hiding this comment

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

either:

  • a) remove comments? same for lower down ones
  • b) add a TODO line w/ a small explanation of why this is here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

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

buid-system/ uses the funky Closure dialect of Typescript, so they do have @enums that are named FOO_ENUM and will not pass the linter. So I disabled.

if (callee.type === 'Identifier') {
const {name} = callee;
if (
name === 'isEnumValue' // ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

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.

3 participants