Skip to content

Commit ac92cb2

Browse files
Update Rubocop to latest and address lints.
1 parent ed0ad8c commit ac92cb2

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ AllCops:
1212
- 'tmp/**/*'
1313
- 'spec/integration/**/*'
1414
NewCops: enable
15+
TargetRubyVersion: 2.7
1516

1617
Lint/FormatParameterMismatch:
1718
Enabled: false
1819

1920
Metrics/BlockLength:
2021
Exclude:
2122
- 'spec/**/*.rb'
23+
24+
Metrics/ClassLength:
25+
Exclude:
26+
- 'lib/annotate/annotate_models.rb'

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ group :development, :test do
1818
gem 'guard-rspec', require: false
1919
gem 'rspec', require: false
2020

21-
gem 'rubocop', '~> 1.48.0', require: false
21+
gem 'rubocop', '~> 1.59.0', require: false
2222
gem 'rubocop-rake', require: false
23-
gem 'rubocop-rspec', '~> 2.19.0', require: false
23+
gem 'rubocop-rspec', '~> 2.25.0', require: false
2424
gem 'simplecov', require: false
2525
gem 'terminal-notifier-guard', require: false
2626

lib/annotate/annotate_models.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module AnnotateModels
3939
}
4040
}.freeze
4141

42-
MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/).freeze
42+
MAGIC_COMMENT_MATCHER = /(^#\s*encoding:.*(?:\n|r\n))|(^# coding:.*(?:\n|\r\n))|(^# -\*- coding:.*(?:\n|\r\n))|(^# -\*- encoding\s?:.*(?:\n|\r\n))|(^#\s*frozen_string_literal:.+(?:\n|\r\n))|(^# -\*- frozen_string_literal\s*:.+-\*-(?:\n|\r\n))/.freeze
4343

4444
class << self
4545
def annotate_pattern(options = {})
@@ -156,7 +156,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
156156

157157
# Precalculate Values
158158
cols_meta = cols.to_h do |col|
159-
col_comment = with_comments || with_comments_column ? col.comment&.gsub(/\n/, "\\n") : nil
159+
col_comment = with_comments || with_comments_column ? col.comment&.gsub("\n", "\\n") : nil
160160
col_type = get_col_type(col)
161161
attrs = get_attributes(col, col_type, klass, options)
162162
col_name = if with_comments && col_comment
@@ -694,7 +694,7 @@ def parse_options(options = {})
694694
end
695695

696696
def split_model_dir(option_value)
697-
option_value = option_value.is_a?(Array) ? option_value : option_value.split(',')
697+
option_value = option_value.split(',') unless option_value.is_a?(Array)
698698
option_value.map(&:strip).reject(&:empty?)
699699
end
700700

lib/annotate/annotate_routes.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# Released under the same license as Ruby. No Support. No Warranty.
1919
#
2020

21-
require_relative './annotate_routes/helpers'
22-
require_relative './annotate_routes/header_generator'
21+
require_relative 'annotate_routes/helpers'
22+
require_relative 'annotate_routes/header_generator'
2323

2424
module AnnotateRoutes
2525
class << self
@@ -95,7 +95,7 @@ def rewrite_contents(existing_text, new_text, frozen)
9595
def annotate_routes(header, content, header_position, options = {})
9696
magic_comments_map, content = Helpers.extract_magic_comments_from_array(content)
9797
if %w(before top).include?(options[:position_in_routes])
98-
header = header << '' if content.first != ''
98+
header <<= '' if content.first != ''
9999
magic_comments_map << '' if magic_comments_map.any?
100100
new_content = magic_comments_map + header + content
101101
else

lib/annotate/annotate_routes/header_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative './helpers'
1+
require_relative 'helpers'
22

33
module AnnotateRoutes
44
class HeaderGenerator
@@ -16,7 +16,7 @@ def generate(options = {})
1616
private
1717

1818
def routes_map(options)
19-
result = `rake routes`.chomp("\n").split(/\n/, -1)
19+
result = `rake routes`.chomp("\n").split("\n", -1)
2020

2121
# In old versions of Rake, the first line of output was the cwd. Not so
2222
# much in newer ones. We ditch that line if it exists, and if not, we

lib/annotate/annotate_routes/helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module AnnotateRoutes
22
module Helpers
3-
MAGIC_COMMENT_MATCHER = Regexp.new(/(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/).freeze
3+
MAGIC_COMMENT_MATCHER = /(^#\s*encoding:.*)|(^# coding:.*)|(^# -\*- coding:.*)|(^# -\*- encoding\s?:.*)|(^#\s*frozen_string_literal:.+)|(^# -\*- frozen_string_literal\s*:.+-\*-)/.freeze
44

55
class << self
66
# TODO: write the method doc using ruby rdoc formats
@@ -15,7 +15,7 @@ def strip_annotations(content)
1515
mode = :content
1616
header_position = 0
1717

18-
content.split(/\n/, -1).each_with_index do |line, line_number|
18+
content.split("\n", -1).each_with_index do |line, line_number|
1919
if mode == :header && line !~ /\s*#/
2020
mode = :content
2121
real_content << line unless line.blank?

spec/lib/annotate/helpers_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@
102102

103103
describe '.fallback' do
104104
subject { described_class.fallback(*args) }
105-
let(:args) { [arg_1, arg_2] }
105+
let(:args) { [first_arg, second_arg] }
106106

107-
let(:arg_1) { '' } # is considered blank
108-
let(:arg_2) { 'yes' }
107+
let(:first_arg) { '' } # is considered blank
108+
let(:second_arg) { 'yes' }
109109

110110
it 'returns the first non-blank argument' do
111-
is_expected.to eq(arg_2)
111+
is_expected.to eq(second_arg)
112112
end
113113

114114
context 'when the first argument is non-blank' do
115-
let(:arg_1) { 'yes' }
116-
let(:arg_2) { 'no' }
115+
let(:first_arg) { 'yes' }
116+
let(:second_arg) { 'no' }
117117

118-
it { is_expected.to eq(arg_1) }
118+
it { is_expected.to eq(first_arg) }
119119
end
120120
end
121121

0 commit comments

Comments
 (0)