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

[Fix #8683] Make naming cops work with non-ascii characters #8693

Merged
merged 1 commit into from Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@
* [#8682](https://github.com/rubocop-hq/rubocop/pull/8682): Fix a positive for `Style/HashTransformKeys` and `Style/HashTransformValues` when the `each_with_object` hash is used in the transformed key or value. ([@eugeneius][])
* [#8688](https://github.com/rubocop-hq/rubocop/issues/8688): Mark `Style/GlobalStdStream` as unsafe autocorrection. ([@marcandre][])
* [#8642](https://github.com/rubocop-hq/rubocop/issues/8642): Fix a false negative for `Style/SpaceInsideHashLiteralBraces` when a correct empty hash precedes the incorrect hash. ([@dvandersluis][])
* [#8683](https://github.com/rubocop-hq/rubocop/issues/8683): Make naming cops work with non-ascii characters. ([@tejasbubane][])

### Changes

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/mixin/configurable_naming.rb
Expand Up @@ -8,8 +8,8 @@ module ConfigurableNaming
include ConfigurableFormatting

FORMATS = {
snake_case: /^@{0,2}[\da-z_]+[!?=]?$/,
camelCase: /^@{0,2}(?:_|_?[a-z][\da-zA-Z]*)[!?=]?$/
snake_case: /^@{0,2}[\d[[:lower:]]_]+[!?=]?$/,
camelCase: /^@{0,2}(?:_|_?[[[:lower:]]][\d[[:lower:]][[:upper:]]]*)[!?=]?$/
}.freeze
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/naming/file_name.rb
Expand Up @@ -33,7 +33,7 @@ class FileName < Base
'called `%<namespace>s`.'
MSG_REGEX = '`%<basename>s` should match `%<regex>s`.'

SNAKE_CASE = /^[\da-z_.?!]+$/.freeze
SNAKE_CASE = /^[\d[[:lower:]]_.?!]+$/.freeze

def on_new_investigation
file_path = processed_source.file_path
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/naming/file_name_spec.rb
Expand Up @@ -468,4 +468,12 @@ class HTTPServer
expect(offenses.empty?).to be(true)
end
end

context 'with non-ascii characters in filename' do
let(:filename) { '/some/dir/ünbound_sérvér.rb' }

it 'reports an offense' do
expect(offenses.empty?).to be(true)
end
end
end
6 changes: 6 additions & 0 deletions spec/rubocop/cop/naming/method_name_spec.rb
Expand Up @@ -344,4 +344,10 @@ def self.foo_bar
include_examples 'never accepted', 'camelCase'
include_examples 'multiple attr methods', 'camelCase'
end

it 'works for non-ascii characters' do
expect_no_offenses(<<~RUBY)
def última_vista; end
RUBY
end
end
4 changes: 4 additions & 0 deletions spec/rubocop/cop/naming/variable_name_spec.rb
Expand Up @@ -213,6 +213,10 @@ def foo(&block_arg); end
RUBY
end

it 'works with non-ascii characters' do
expect_no_offenses('léo = 1')
end

include_examples 'always accepted'
end
end