Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
New cop Style/SafeNavigation #3453
This addresses #2428.
I am just about done with this new cop. Functionally, I think that I am set. I have run into a name spacing issue though. The name spacing issue is the root of the test failures.
The solutions that I have considered are:
I am unsure of a good name to change either of these to. If anyone has ideas, please let me know.
This would fix occurrences that use the full cop name including the group. It would not fix occurrences where only the cop name is given. For example, how would we handle
I'd simply raise some error in such cases where some ambiguity exists.
changed the title from
New cop Style/SafeNavigation
[WIP] - New cop Style/SafeNavigation
Aug 31, 2016
I finally finished up this cop after having coded it incorrectly the first time.
The cop will check for and correct code in the following formats:
foo.bar if foo foo.bar if !foo.nil? foo.bar unless !foo foo.bar unless foo.nil? foo && foo.bar !foo.nil? && foo.nil? || foo.bar !foo || foo.bar
As with the
The cop name qualifier now checks for an exact match to the cop, including the group, before checking in the existing manner with the cop name only. This is so that we can have 2 cops with the same name in 2 different groups. If a cop name is found to be ambiguous, the names of the matching cops will be printed out in the error message. This also means that we finally get to enable the test for ambiguous cop names.