Skip to content

Commit

Permalink
[Fix rubocop#2643] MagicComment uppercase and dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegee committed Jan 23, 2017
1 parent d76dc90 commit 8e779f7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

* [#3923](https://github.com/bbatsov/rubocop/issues/3923): Allow asciibetical sorting in `Bundler/OrderedGems`. ([@mikegee][])
* [#3855](https://github.com/bbatsov/rubocop/issues/3855): Make `Lint/NonLocalExitFromIterator` aware of method definitions. ([@drenmi][])
* [#2643](https://github.com/bbatsov/rubocop/issues/2643): Allow uppercase and dashes in `MagicComment`. ([@mikegee][])

## 0.47.1 (2017-01-18)

Expand Down
7 changes: 5 additions & 2 deletions lib/rubocop/magic_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def frozen_string_literal; end
class SimpleComment < MagicComment
# Match `encoding` or `coding`
def encoding
extract(/\b(?:en)?coding: (#{TOKEN})/)
extract(/\b(?:en)?coding: (#{TOKEN})/i)
end

private
Expand All @@ -188,8 +188,11 @@ def encoding
#
# The `frozen_string_literal` magic comment only works if it
# is the only text in the comment.
#
# Case-insensitive and dashes/underscores are acceptable.
# @see https://git.io/vM7Mg
def extract_frozen_string_literal
extract(/^#\s*frozen_string_literal:\s*(#{TOKEN})\s*$/)
extract(/\A#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/i)
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/rubocop/magic_comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
'# encoding: utf-8',
encoding: 'utf-8'

include_examples 'magic comment',
'# ENCODING: utf-8',
encoding: 'utf-8'

include_examples 'magic comment',
'# eNcOdInG: utf-8',
encoding: 'utf-8'

include_examples 'magic comment',
'# coding: utf-8',
encoding: 'utf-8'
Expand All @@ -47,6 +55,18 @@
'# frozen_string_literal: false',
frozen_string_literal: false

include_examples 'magic comment',
'# frozen-string-literal: true',
frozen_string_literal: true

include_examples 'magic comment',
'# FROZEN-STRING-LITERAL: true',
frozen_string_literal: true

include_examples 'magic comment',
'# fRoZeN-sTrInG_lItErAl: true',
frozen_string_literal: true

include_examples 'magic comment',
'# frozen_string_literal: invalid',
frozen_string_literal: 'invalid'
Expand Down

0 comments on commit 8e779f7

Please sign in to comment.