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

Implement a rule to lint enum entry name #638

Merged
merged 3 commits into from
Nov 26, 2019

Conversation

yukukotani
Copy link
Contributor

Resolve #635

Implement an experimental rule to lint enum entry name.
This rule enforces enum entry names to

  1. contains no lower case letter if it contains under score.
  2. starts with upper case if it contains lower case letter.

So, "ENTRY_NAME" and "EntryName" are valid, "Entry_Name", "entry_name" and "entryName" are invalid.

Currently auto-format will convert entry name to all upper case, but this behavior is highly debatable.

Before format

enum class FirstEnum {
    enum_entry
}
enum class SecondEnum {
    entry
}

formatted

enum class FirstEnum {
    ENUM_ENTRY
}
enum class SecondEnum {
    ENTRY
}

@yukukotani
Copy link
Contributor Author

yukukotani commented Nov 9, 2019

I forgot an important thing. This format might causes compile error because enum entry identifier will be changed.
Maybe formatting should be disabled and just lint.

@Tapchicoma
Copy link
Collaborator

I would propose to disable formatting for now.

Generally it is interesting question how to handle such cases that makes code non-compilable. Maybe via some additional configuration flag - allowBreakingFormatting 🤔

@shashachu
Copy link
Contributor

Agree that we should disable formatting if it could cause compile errors.

@yukukotani
Copy link
Contributor Author

@Tapchicoma @shashachu
Thank you for your feedback. I disabled formatting for now, but leave formatting logic.
Also, created an issue #656 about supporting allowBreakingFormatting option.

Copy link
Collaborator

@Tapchicoma Tapchicoma left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this 👍

@Tapchicoma Tapchicoma merged commit 375509f into pinterest:master Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce enum names
3 participants