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 new Naming/InclusiveLanguage cop #9842
Conversation
a3d3a6b
to
1aeba9f
Compare
Thanks for tackling this! Two points from me:
|
@bbatsov Thanks for taking a look!
What do you think about a |
I get your point, but I'm concerned that some words like |
In the past, I worked on #7469. What I remember as a task at that time was searching for the target term in the text files with |
@bbatsov To handle
@koic I see your point that this cop does not rely on parsing the code. The benefit that I see to including it in RuboCop is everything else that Rubcop already provides. I.e. the tooling is already setup in build pipelines, possibly across hundreds or thousands of repos for large companies. Building something on top of grep or another static analysis tool would also require defining all of the configuration conventions, writing formatters for reporting offenses, inventing mechanisms for disabling offenses and managing TODO lists. Though this doesn't use the AST it benefits from everything else RuboCop provides. |
I've removed the file path check, as a separate commit for now. |
This will be super handy in our project. Thanks for creating it @tjwp |
Overall I'm happy with the current code of the cop, but I want to make it more configurable - e.g. to have Sorry about the slow feedback here - I had a couple of busy weeks on my end. |
@bbatsov No problem! Thanks for the review. I'll start on making the requested changes. |
Recommends the use of inclusive language instead of problematic terms.
64b3b44
to
50990e4
Compare
50990e4
to
c73b83a
Compare
The implementation is certainly a bit unorthodox, as Koichi already pointed out. I don't mind it conceptually, but matching regular expressions on every token does sound like it could significantly affect the execution time. Some benchmark around this would be nice. I certainly think that this cop should either be 1) disabled by default, or 2) be shipped with a minimal configuration. As the author pointed out, the general capability is more important than a specific configuration. RuboCop is used by many people, and like with the other cops, we leave it to them to define their own policies. |
@Drenmi Thanks for taking a look!
A small update on this. The implementation has been updated based on feedback to look at specific types of tokens, and all of those are now individually configurable.
👍🏻 |
I ran a very simple benchmark around this using the rubocop code base. The following 3 scenarios were tested:
Each scenario was run 3 times with the cache disabled:
My interpretation of those results is that the impact on the execution time is not large. With the current default configuration from the change, the increase was small, with the fastest execution falling within the range of the baseline executions. With the config included for the rubocop repo, the effect of the cop was larger, but still a small percentage increase for the overall execution time. |
Great work! Thanks for working on this! |
Thank you! It's been several years since my last contribution to rubocop, but a pleasure to be back here and able to contribute! |
I don't agree with forcing human language into cultural limits and therefore propose to disable the cop introduced by rubocop/rubocop#9842. My code normally offends people in a lot of different non-cultural ways already 😉 . It's fine if Rubocop complains about those. But please talk to me in person if my code offends you by cultural issues.
I don't agree with forcing human language into cultural limits and therefore propose to disable the cop introduced by rubocop/rubocop#9842. My code normally offends people in a lot of different non-cultural ways already 😉 . It's fine if Rubocop complains about those. But please talk to me in person if my code offends you by cultural issues.
This pull request adds a new cop (
Naming/InclusiveLanguage
) that recommends the use of inclusive language instead of problematic terms.Following this comment, the cop is generic and can target different terms based on configuration. Suggested replacements can be configured in addition to exceptions for allowed use of a term.
The implementation is inspired by some of the ideas found in https://github.com/flexport/inclusive-code/tree/main/ruby.
Auto-correct is not implemented because too much context is required to choose an appropriate replacement suggestion and many renames would be unsafe.