Skip to content

Commit ed0ad8c

Browse files
Upgrade rubocop and address lints
1 parent 550b6f7 commit ed0ad8c

File tree

13 files changed

+83
-82
lines changed

13 files changed

+83
-82
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ AllCops:
1313
- 'spec/integration/**/*'
1414
NewCops: enable
1515

16+
Lint/FormatParameterMismatch:
17+
Enabled: false
18+
1619
Metrics/BlockLength:
1720
Exclude:
1821
- 'spec/**/*.rb'

Gemfile

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

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

27-
2827
gem 'overcommit'
2928

3029
platforms :mri, :mingw do

annotate.gemspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ Gem::Specification.new do |s|
1818
s.homepage = 'https://github.com/ctran/annotate_models'
1919
s.licenses = ['Ruby']
2020
s.require_paths = ['lib']
21-
s.rubygems_version = '2.1.11'
2221
s.summary = 'Annotates Rails Models, routes, fixtures, and others based on the database schema.'
2322

24-
s.specification_version = 4 if s.respond_to? :specification_version
2523
s.add_runtime_dependency(%q<rake>, '>= 10.4', '< 14.0')
2624
s.add_runtime_dependency(%q<activerecord>, ['>= 3.2', '< 8.0'])
2725

2826
s.metadata = {
2927
"bug_tracker_uri" => "https://github.com/ctran/annotate_models/issues/",
30-
"source_code_uri" => "https://github.com/ctran/annotate_models.git"
28+
"source_code_uri" => "https://github.com/ctran/annotate_models.git",
29+
'rubygems_mfa_required' => 'true'
3130
}
3231
end

bin/annotate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ options_result = Annotate::Parser.parse(ARGV)
2424
exit if options_result[:exit]
2525

2626
options = Annotate.setup_options(
27-
is_rake: ENV['is_rake'] && !ENV['is_rake'].empty?
27+
is_rake: ENV.fetch('is_rake', nil) && !ENV['is_rake'].empty?
2828
)
2929
Annotate.eager_load(options) if Annotate::Helpers.include_models?
3030

lib/annotate.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def self.set_defaults(options = {})
4444
#
4545
def self.setup_options(options = {})
4646
Constants::POSITION_OPTIONS.each do |key|
47-
options[key] = Annotate::Helpers.fallback(ENV[key.to_s], ENV['position'], 'before')
47+
options[key] = Annotate::Helpers.fallback(ENV.fetch(key.to_s, nil), ENV.fetch('position', nil), 'before')
4848
end
4949
Constants::FLAG_OPTIONS.each do |key|
50-
options[key] = Annotate::Helpers.true?(ENV[key.to_s])
50+
options[key] = Annotate::Helpers.true?(ENV.fetch(key.to_s, nil))
5151
end
5252
Constants::OTHER_OPTIONS.each do |key|
53-
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s] : nil
53+
options[key] = !ENV[key.to_s].blank? ? ENV.fetch(key.to_s, nil) : nil
5454
end
5555
Constants::PATH_OPTIONS.each do |key|
5656
options[key] = !ENV[key.to_s].blank? ? ENV[key.to_s].split(',') : []

lib/annotate/annotate_models.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
155155
with_comments_column = with_comments_column?(klass, options)
156156

157157
# Precalculate Values
158-
cols_meta = cols.map do |col|
158+
cols_meta = cols.to_h do |col|
159159
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)
@@ -166,7 +166,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
166166
end
167167
simple_formatted_attrs = attrs.join(", ")
168168
[col.name, { col_type: col_type, attrs: attrs, col_name: col_name, simple_formatted_attrs: simple_formatted_attrs, col_comment: col_comment }]
169-
end.to_h
169+
end
170170

171171
# Output annotation
172172
bare_max_attrs_length = cols_meta.map { |_, m| m[:simple_formatted_attrs].length }.max
@@ -179,15 +179,15 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
179179
col_comment = cols_meta[col.name][:col_comment]
180180

181181
if options[:format_rdoc]
182-
info << sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n"
182+
info << (sprintf("# %-#{max_size}.#{max_size}s<tt>%s</tt>", "*#{col_name}*::", attrs.unshift(col_type).join(", ")).rstrip + "\n")
183183
elsif options[:format_yard]
184-
info << sprintf("# @!attribute #{col_name}") + "\n"
184+
info << (sprintf("# @!attribute #{col_name}") + "\n")
185185
ruby_class = col.respond_to?(:array) && col.array ? "Array<#{map_col_type_to_ruby_classes(col_type)}>": map_col_type_to_ruby_classes(col_type)
186-
info << sprintf("# @return [#{ruby_class}]") + "\n"
186+
info << (sprintf("# @return [#{ruby_class}]") + "\n")
187187
elsif options[:format_markdown]
188188
name_remainder = max_size - col_name.length - non_ascii_length(col_name)
189189
type_remainder = (md_type_allowance - 2) - col_type.length
190-
info << (sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n"
190+
info << ((sprintf("# **`%s`**%#{name_remainder}s | `%s`%#{type_remainder}s | `%s`", col_name, " ", col_type, " ", attrs.join(", ").rstrip)).gsub('``', ' ').rstrip + "\n")
191191
elsif with_comments_column
192192
info << format_default(col_name, max_size, col_type, bare_type_allowance, simple_formatted_attrs, bare_max_attrs_length, col_comment)
193193
else

lib/annotate/annotate_routes/header_generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def routes_map(options)
2929
# Skip routes which match given regex
3030
# Note: it matches the complete line (route_name, path, controller/action)
3131
if regexp_for_ignoring_routes
32-
result.reject { |line| line =~ regexp_for_ignoring_routes }
32+
result.grep_v(regexp_for_ignoring_routes)
3333
else
3434
result
3535
end
@@ -53,9 +53,9 @@ def generate
5353

5454
out << comment(options[:wrapper_open]) if options[:wrapper_open]
5555

56-
out << comment(markdown? ? PREFIX_MD : PREFIX) + timestamp_if_required
56+
out << (comment(markdown? ? PREFIX_MD : PREFIX) + timestamp_if_required)
5757
out << comment
58-
return out if contents_without_magic_comments.size.zero?
58+
return out if contents_without_magic_comments.empty?
5959

6060
maxs = [HEADER_ROW.map(&:size)] + contents_without_magic_comments[1..-1].map { |line| line.split.map(&:size) }
6161

lib/annotate/helpers.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ module Annotate
33
class Helpers
44
class << self
55
def skip_on_migration?
6-
ENV['ANNOTATE_SKIP_ON_DB_MIGRATE'] =~ Constants::TRUE_RE || ENV['skip_on_db_migrate'] =~ Constants::TRUE_RE
6+
ENV.fetch('ANNOTATE_SKIP_ON_DB_MIGRATE', nil) =~ Constants::TRUE_RE || ENV.fetch('skip_on_db_migrate', nil) =~ Constants::TRUE_RE
77
end
88

99
def include_routes?
10-
ENV['routes'] =~ Constants::TRUE_RE
10+
ENV.fetch('routes', nil) =~ Constants::TRUE_RE
1111
end
1212

1313
def include_models?
14-
ENV['models'] =~ Constants::TRUE_RE
14+
ENV.fetch('models', nil) =~ Constants::TRUE_RE
1515
end
1616

1717
def true?(val)

lib/tasks/annotate_models.rake

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@ task annotate_models: :environment do
1111
require "#{annotate_lib}/annotate/active_record_patch"
1212

1313
options = {is_rake: true}
14-
ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV['position'], 'before')
14+
ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV.fetch('position', nil), 'before')
1515
options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : []
16-
options[:position_in_class] = Annotate::Helpers.fallback(ENV['position_in_class'], ENV['position'])
17-
options[:position_in_fixture] = Annotate::Helpers.fallback(ENV['position_in_fixture'], ENV['position'])
18-
options[:position_in_factory] = Annotate::Helpers.fallback(ENV['position_in_factory'], ENV['position'])
19-
options[:position_in_test] = Annotate::Helpers.fallback(ENV['position_in_test'], ENV['position'])
20-
options[:position_in_serializer] = Annotate::Helpers.fallback(ENV['position_in_serializer'], ENV['position'])
21-
options[:show_check_constraints] = Annotate::Helpers.true?(ENV['show_check_constraints'])
22-
options[:show_foreign_keys] = Annotate::Helpers.true?(ENV['show_foreign_keys'])
23-
options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV['show_complete_foreign_keys'])
24-
options[:show_indexes] = Annotate::Helpers.true?(ENV['show_indexes'])
25-
options[:simple_indexes] = Annotate::Helpers.true?(ENV['simple_indexes'])
16+
options[:position_in_class] = Annotate::Helpers.fallback(ENV.fetch('position_in_class', nil), ENV.fetch('position', nil))
17+
options[:position_in_fixture] = Annotate::Helpers.fallback(ENV.fetch('position_in_fixture', nil), ENV.fetch('position', nil))
18+
options[:position_in_factory] = Annotate::Helpers.fallback(ENV.fetch('position_in_factory', nil), ENV.fetch('position', nil))
19+
options[:position_in_test] = Annotate::Helpers.fallback(ENV.fetch('position_in_test', nil), ENV.fetch('position', nil))
20+
options[:position_in_serializer] = Annotate::Helpers.fallback(ENV.fetch('position_in_serializer', nil), ENV.fetch('position', nil))
21+
options[:show_check_constraints] = Annotate::Helpers.true?(ENV.fetch('show_check_constraints', nil))
22+
options[:show_foreign_keys] = Annotate::Helpers.true?(ENV.fetch('show_foreign_keys', nil))
23+
options[:show_complete_foreign_keys] = Annotate::Helpers.true?(ENV.fetch('show_complete_foreign_keys', nil))
24+
options[:show_indexes] = Annotate::Helpers.true?(ENV.fetch('show_indexes', nil))
25+
options[:simple_indexes] = Annotate::Helpers.true?(ENV.fetch('simple_indexes', nil))
2626
options[:model_dir] = ENV['model_dir'] ? ENV['model_dir'].split(',') : ['app/models']
27-
options[:root_dir] = ENV['root_dir']
28-
options[:include_version] = Annotate::Helpers.true?(ENV['include_version'])
27+
options[:root_dir] = ENV.fetch('root_dir', nil)
28+
options[:include_version] = Annotate::Helpers.true?(ENV.fetch('include_version', nil))
2929
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
30-
options[:exclude_tests] = Annotate::Helpers.true?(ENV['exclude_tests'])
31-
options[:exclude_factories] = Annotate::Helpers.true?(ENV['exclude_factories'])
32-
options[:exclude_fixtures] = Annotate::Helpers.true?(ENV['exclude_fixtures'])
33-
options[:exclude_serializers] = Annotate::Helpers.true?(ENV['exclude_serializers'])
34-
options[:exclude_scaffolds] = Annotate::Helpers.true?(ENV['exclude_scaffolds'])
30+
options[:exclude_tests] = Annotate::Helpers.true?(ENV.fetch('exclude_tests', nil))
31+
options[:exclude_factories] = Annotate::Helpers.true?(ENV.fetch('exclude_factories', nil))
32+
options[:exclude_fixtures] = Annotate::Helpers.true?(ENV.fetch('exclude_fixtures', nil))
33+
options[:exclude_serializers] = Annotate::Helpers.true?(ENV.fetch('exclude_serializers', nil))
34+
options[:exclude_scaffolds] = Annotate::Helpers.true?(ENV.fetch('exclude_scaffolds', nil))
3535
options[:exclude_controllers] = Annotate::Helpers.true?(ENV.fetch('exclude_controllers', 'true'))
3636
options[:exclude_helpers] = Annotate::Helpers.true?(ENV.fetch('exclude_helpers', 'true'))
37-
options[:exclude_sti_subclasses] = Annotate::Helpers.true?(ENV['exclude_sti_subclasses'])
38-
options[:ignore_model_sub_dir] = Annotate::Helpers.true?(ENV['ignore_model_sub_dir'])
39-
options[:format_bare] = Annotate::Helpers.true?(ENV['format_bare'])
40-
options[:format_rdoc] = Annotate::Helpers.true?(ENV['format_rdoc'])
41-
options[:format_yard] = Annotate::Helpers.true?(ENV['format_yard'])
42-
options[:format_markdown] = Annotate::Helpers.true?(ENV['format_markdown'])
43-
options[:sort] = Annotate::Helpers.true?(ENV['sort'])
44-
options[:force] = Annotate::Helpers.true?(ENV['force'])
45-
options[:frozen] = Annotate::Helpers.true?(ENV['frozen'])
46-
options[:classified_sort] = Annotate::Helpers.true?(ENV['classified_sort'])
47-
options[:trace] = Annotate::Helpers.true?(ENV['trace'])
48-
options[:wrapper_open] = Annotate::Helpers.fallback(ENV['wrapper_open'], ENV['wrapper'])
49-
options[:wrapper_close] = Annotate::Helpers.fallback(ENV['wrapper_close'], ENV['wrapper'])
37+
options[:exclude_sti_subclasses] = Annotate::Helpers.true?(ENV.fetch('exclude_sti_subclasses', nil))
38+
options[:ignore_model_sub_dir] = Annotate::Helpers.true?(ENV.fetch('ignore_model_sub_dir', nil))
39+
options[:format_bare] = Annotate::Helpers.true?(ENV.fetch('format_bare', nil))
40+
options[:format_rdoc] = Annotate::Helpers.true?(ENV.fetch('format_rdoc', nil))
41+
options[:format_yard] = Annotate::Helpers.true?(ENV.fetch('format_yard', nil))
42+
options[:format_markdown] = Annotate::Helpers.true?(ENV.fetch('format_markdown', nil))
43+
options[:sort] = Annotate::Helpers.true?(ENV.fetch('sort', nil))
44+
options[:force] = Annotate::Helpers.true?(ENV.fetch('force', nil))
45+
options[:frozen] = Annotate::Helpers.true?(ENV.fetch('frozen', nil))
46+
options[:classified_sort] = Annotate::Helpers.true?(ENV.fetch('classified_sort', nil))
47+
options[:trace] = Annotate::Helpers.true?(ENV.fetch('trace', nil))
48+
options[:wrapper_open] = Annotate::Helpers.fallback(ENV.fetch('wrapper_open', nil), ENV.fetch('wrapper', nil))
49+
options[:wrapper_close] = Annotate::Helpers.fallback(ENV.fetch('wrapper_close', nil), ENV.fetch('wrapper', nil))
5050
options[:ignore_columns] = ENV.fetch('ignore_columns', nil)
5151
options[:ignore_routes] = ENV.fetch('ignore_routes', nil)
52-
options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV['hide_limit_column_types'], '')
53-
options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV['hide_default_column_types'], '')
54-
options[:with_comment] = Annotate::Helpers.true?(ENV['with_comment'])
55-
options[:with_comment_column] = Annotate::Helpers.true?(ENV['with_comment_column'])
52+
options[:hide_limit_column_types] = Annotate::Helpers.fallback(ENV.fetch('hide_limit_column_types', nil), '')
53+
options[:hide_default_column_types] = Annotate::Helpers.fallback(ENV.fetch('hide_default_column_types', nil), '')
54+
options[:with_comment] = Annotate::Helpers.true?(ENV.fetch('with_comment', nil))
55+
options[:with_comment_column] = Annotate::Helpers.true?(ENV.fetch('with_comment_column', nil))
5656
options[:ignore_unknown_models] = Annotate::Helpers.true?(ENV.fetch('ignore_unknown_models', 'false'))
5757

5858
AnnotateModels.do_annotations(options)
@@ -64,9 +64,9 @@ task remove_annotation: :environment do
6464
require "#{annotate_lib}/annotate/active_record_patch"
6565

6666
options = {is_rake: true}
67-
options[:model_dir] = ENV['model_dir']
68-
options[:root_dir] = ENV['root_dir']
67+
options[:model_dir] = ENV.fetch('model_dir', nil)
68+
options[:root_dir] = ENV.fetch('root_dir', nil)
6969
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
70-
options[:trace] = Annotate::Helpers.true?(ENV['trace'])
70+
options[:trace] = Annotate::Helpers.true?(ENV.fetch('trace', nil))
7171
AnnotateModels.remove_annotations(options)
7272
end

lib/tasks/annotate_routes.rake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ task :annotate_routes => :environment do
1010
require "#{annotate_lib}/annotate/annotate_routes"
1111

1212
options={}
13-
ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV['position'], 'before')
14-
options[:position_in_routes] = Annotate::Helpers.fallback(ENV['position_in_routes'], ENV['position'])
15-
options[:ignore_routes] = Annotate::Helpers.fallback(ENV['ignore_routes'], nil)
13+
ENV['position'] = options[:position] = Annotate::Helpers.fallback(ENV.fetch('position', nil), 'before')
14+
options[:position_in_routes] = Annotate::Helpers.fallback(ENV.fetch('position_in_routes', nil), ENV.fetch('position', nil))
15+
options[:ignore_routes] = Annotate::Helpers.fallback(ENV.fetch('ignore_routes', nil), nil)
1616
options[:require] = ENV['require'] ? ENV['require'].split(',') : []
17-
options[:frozen] = Annotate::Helpers.true?(ENV['frozen'])
18-
options[:wrapper_open] = Annotate::Helpers.fallback(ENV['wrapper_open'], ENV['wrapper'])
19-
options[:wrapper_close] = Annotate::Helpers.fallback(ENV['wrapper_close'], ENV['wrapper'])
17+
options[:frozen] = Annotate::Helpers.true?(ENV.fetch('frozen', nil))
18+
options[:wrapper_open] = Annotate::Helpers.fallback(ENV.fetch('wrapper_open', nil), ENV.fetch('wrapper', nil))
19+
options[:wrapper_close] = Annotate::Helpers.fallback(ENV.fetch('wrapper_close', nil), ENV.fetch('wrapper', nil))
2020
AnnotateRoutes.do_annotations(options)
2121
end
2222

0 commit comments

Comments
 (0)