Skip to content

Commit

Permalink
[Fix #8683] Make naming cops work with non-ascii characters
Browse files Browse the repository at this point in the history
Closes #8683
  • Loading branch information
tejasbubane authored and marcandre committed Sep 10, 2020
1 parent 18a5162 commit d0bdb7c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
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

0 comments on commit d0bdb7c

Please sign in to comment.