Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # 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.

@yukukotani yukukotani force-pushed the feature/enforce-enum-name branch from b9af042 to 769313c Compare November 25, 2019 11:49
@yukukotani yukukotani force-pushed the feature/enforce-enum-name branch from 769313c to 2007e53 Compare November 25, 2019 11:56
@yukukotani yukukotani force-pushed the feature/enforce-enum-name branch from 2007e53 to 7c5ee78 Compare November 25, 2019 12:02
@yukukotani yukukotani force-pushed the feature/enforce-enum-name branch from e8c1663 to cf66393 Compare November 25, 2019 12:13
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce enum names
3 participants