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

normalcase for VariableNumber doesn't allow foo_bar1? #3516

Closed
backus opened this issue Sep 19, 2016 · 5 comments
Closed

normalcase for VariableNumber doesn't allow foo_bar1? #3516

backus opened this issue Sep 19, 2016 · 5 comments
Labels

Comments

@backus
Copy link
Contributor

backus commented Sep 19, 2016

The new VariableNumber cop flags variables like user_name_1 when the enforced style is normalcase. I would imagine that user_name1 would be make the style check pass but this isn't valid either apparently. The only thing I can do to get this to pass with normalcase is userName1 which is odd.


Expected behavior

$ cat example.rb
foo_bar1 = 1
$ bundle exec rubocop --only VariableNumber example.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Actual behavior

$ cat example.rb
foo_bar1 = 1
$ bundle exec rubocop --only VariableNumber example.rb
Inspecting 1 file
C

Offenses:

example.rb:1:1: C: Use normalcase for variable numbers.
foo_bar1 = 1
^^^^^^^^

1 file inspected, 1 offense detected

Steps to reproduce the problem

Run the VariableNumber cop against any source file with a variable name which contains an underscore between two words and a trailing number (like foo_bar1).

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.43.0 (using Parser 2.3.1.3, running on ruby 2.3.1 x86_64-darwin15)
@bbatsov bbatsov added the bug label Sep 19, 2016
@jaredbeck
Copy link
Contributor

It also thinks expected_h1_text is not a valid variable name.

spec/redacted.rb:109:9: C: Style/VariableNumber: Use normalcase for variable numbers.
        expected_h1_text =
        ^^^^^^^^^^^^^^^^

@backus
Copy link
Contributor Author

backus commented Sep 19, 2016

Yeah @jaredbeck see #3514 for that issue

@onurozgurozkan
Copy link

generic_3_digits is also not a valid variable name. Regards.

@reitermarkus
Copy link
Contributor

Having the same problem with variables ending in _sha1 and _sha256, while variables starting with sha1_ and sha256_ pass the default cop. In my opinion the former should also pass the default cop.

@NobodysNightmare
Copy link
Contributor

I believe the rule should only apply to how the number is appended to its preceeding text.

So for normalcase:

user1_id # valid
user_1_id # invalid
sha256 # valid
sha_256 #invalid

for snake_case:

user1_id # invalid
user_1_id # valid
sha256 # invalid
sha_256 #valid

Even though, I believe that h1, sha256 and md5 are good examples of "names", that I would never want to snake-case...

The problem is, that the cop only "wants" to address counting (user 1, user 2, etc), but it matches anything that contains a number....

b-t-g pushed a commit to b-t-g/rubocop that referenced this issue Sep 22, 2016
kyrylo added a commit to airbrake/airbrake-ruby that referenced this issue Sep 23, 2016
b-t-g pushed a commit to b-t-g/rubocop that referenced this issue Sep 24, 2016
…fines normal case by allowing numbers after the first underscore.
kyrylo added a commit to airbrake/airbrake-ruby that referenced this issue Sep 28, 2016
mikezter added a commit to mikezter/rubocop that referenced this issue Sep 28, 2016
* bbatsov/master: (80 commits)
  [Fix rubocop#3540] Make `Style/GuardClause` register offense for instance & singleton methods
  [Fix rubocop#3436] issue related to Rails/SaveBang when returning non-bang call from the parent method
  Allow `#to_yml` to produce single-quoted strings
  Add support for StyleGuideBaseURL and update rules
  Add spec for the existing style guide URL implementation
  Fix the changelog
  Edited regular expression for normal case to fix issues rubocop#3514 and rubocop#3516 (rubocop#3524)
  Add a rake task for generation a new cop (rubocop#3533)
  [Fix rubocop#3510] Various bug fixes for SafeNavigation (rubocop#3517)
  [Fix rubocop#3512] Change error message of `Lint/UnneededSplatExpansion` for array (rubocop#3526)
  Fix false positive in `Lint/AssignmentInCondition` (rubocop#3520) (rubocop#3529)
  Rename a mismatched filename (rubocop#3523)
  Fix a broken changelog entry
  [Fix rubocop#3511] Style/TernaryParentheses false positive (rubocop#3513)
  Fix the release notes for 0.43
  Cut 0.43.0
  [Fix rubocop#3462] Don't flag single-line methods
  Fix false negatives in `Rails/NotNullColumn` cop (rubocop#3508)
  Remove unused doubled methods (rubocop#3509)
  [Fix rubocop#3485] Make OneLineConditional cop ignore empty else (rubocop#3487)
  ...
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
…and rubocop#3516 (rubocop#3524)

[Fix rubocop#3514][Fix rubocop#3516] Edit regular expression which defines normal case by allowing numbers after the first underscore.

This also fixes the normal case analog to issue rubocop#3519 - changed and simplified normal case definition to allow multi-digit numbers.
rwx788 pushed a commit to rwx788/ruby-yui-rest-client that referenced this issue Nov 9, 2020
Rubocop has raised this error, renaming, so that `_` is not added in
front of the digit if last symbol before it is a letter.

See rubocop/rubocop#3516
rwx788 pushed a commit to rwx788/ruby-yui-rest-client that referenced this issue Nov 9, 2020
Rubocop has raised this error, renaming, so that `_` is not added in
front of the digit.

See rubocop/rubocop#3516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants