Skip to content

Commit 30cb78d

Browse files
committed
fix: fix obvious cop violations
1 parent 8111e0f commit 30cb78d

File tree

7 files changed

+539
-543
lines changed

7 files changed

+539
-543
lines changed

lib/annotate.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
require 'active_support/core_ext/blank'
1818
end
1919

20-
module Annotate
20+
# Defines the Annotate module
21+
module Annotate # rubocop:disable Metrics/ModuleLength
2122
##
2223
# Set default values that can be overridden via environment variables.
2324
#
@@ -95,7 +96,7 @@ def self.eager_load(options)
9596
if Rails.version.split('.').first.to_i < 3
9697
Rails.configuration.eager_load_paths.each do |load_path|
9798
matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/
98-
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
99+
Dir.glob("#{load_path}/**/*.rb").each do |file|
99100
require_dependency file.sub(matcher, '\1')
100101
end
101102
end

lib/annotate/annotate_models.rb

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

158158
# Precalculate Values
159-
cols_meta = cols.map do |col|
159+
cols_meta = cols.to_h do |col|
160160
col_comment = with_comments || with_comments_column ? col.comment&.gsub("\n", '\\n') : nil
161161
col_type = get_col_type(col)
162162
attrs = get_attributes(col, col_type, klass, options)
@@ -172,7 +172,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
172172
col_name: col_name,
173173
simple_formatted_attrs: simple_formatted_attrs,
174174
col_comment: col_comment }]
175-
end.to_h
175+
end
176176

177177
# Output annotation
178178
bare_max_attrs_length = cols_meta.map { |_, m| m[:simple_formatted_attrs].length }.max
@@ -215,7 +215,7 @@ def get_schema_info(klass, header, options = {}) # rubocop:disable Metrics/Metho
215215
end
216216

217217
def get_schema_header_text(klass, options = {})
218-
info = String.new("#\n") # Create a new mutable string
218+
info = String.new("#\n") # Create a new mutable string
219219
if options[:format_markdown]
220220
info << "# Table name: `#{klass.table_name}`\n"
221221
info << "#\n"
@@ -658,7 +658,7 @@ def get_model_class(file)
658658
if File.file?(file_path) && Kernel.require(file_path)
659659
retry
660660
elsif model_path =~ %r{/}
661-
model_path = model_path.split('/')[1..-1].join('/').to_s
661+
model_path = model_path.split('/')[1..].join('/').to_s
662662
retry
663663
else
664664
raise

lib/annotate/annotate_routes/header_generator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def generate
5959
out << comment
6060
return out if contents_without_magic_comments.size.zero?
6161

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

6464
if markdown?
6565
max = maxs.map(&:max).compact.max
@@ -70,7 +70,7 @@ def generate
7070
out << comment(content(contents_without_magic_comments[0], maxs))
7171
end
7272

73-
out += contents_without_magic_comments[1..-1].map do |line|
73+
out += contents_without_magic_comments[1..].map do |line|
7474
comment(content(markdown? ? line.split(' ') : line, maxs))
7575
end
7676
out << comment(options[:wrapper_close]) if options[:wrapper_close]

lib/annotate/parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module Annotate
66
# Class for handling command line arguments
7-
class Parser # rubocop:disable Metrics/ClassLength
7+
class Parser
88
def self.parse(args, env = {})
99
new(args, env).parse
1010
end

spec/lib/annotate/annotate_models/file_patterns_spec.rb

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
describe AnnotateModels::FilePatterns do
77
describe '.by_pattern' do
8-
subject { AnnotateModels::FilePatterns.generate(root_directory, pattern_type, options) }
8+
let(:file_patterns) { described_class.generate(root_directory, pattern_type, options) }
99

1010
let(:root_directory) { '/root' }
1111
let(:options) { {} }
@@ -14,70 +14,70 @@
1414
let(:pattern_type) { 'test' }
1515

1616
it 'returns patterns of test files' do
17-
is_expected.to eq([
18-
'/root/test/unit/%MODEL_NAME%_test.rb',
19-
'/root/test/models/%MODEL_NAME%_test.rb',
20-
'/root/spec/models/%MODEL_NAME%_spec.rb'
21-
])
17+
expect(file_patterns).to eq([
18+
'/root/test/unit/%MODEL_NAME%_test.rb',
19+
'/root/test/models/%MODEL_NAME%_test.rb',
20+
'/root/spec/models/%MODEL_NAME%_spec.rb'
21+
])
2222
end
2323
end
2424

2525
context 'when pattern_type is "fixture"' do
2626
let(:pattern_type) { 'fixture' }
2727

2828
it 'returns patterns of fixture files' do
29-
is_expected.to eq([
30-
'/root/test/fixtures/%TABLE_NAME%.yml',
31-
'/root/spec/fixtures/%TABLE_NAME%.yml',
32-
'/root/test/fixtures/%PLURALIZED_MODEL_NAME%.yml',
33-
'/root/spec/fixtures/%PLURALIZED_MODEL_NAME%.yml'
34-
])
29+
expect(file_patterns).to eq([
30+
'/root/test/fixtures/%TABLE_NAME%.yml',
31+
'/root/spec/fixtures/%TABLE_NAME%.yml',
32+
'/root/test/fixtures/%PLURALIZED_MODEL_NAME%.yml',
33+
'/root/spec/fixtures/%PLURALIZED_MODEL_NAME%.yml'
34+
])
3535
end
3636
end
3737

3838
context 'when pattern_type is "scaffold"' do
3939
let(:pattern_type) { 'scaffold' }
4040

4141
it 'returns patterns of scaffold files' do
42-
is_expected.to eq([
43-
'/root/test/controllers/%PLURALIZED_MODEL_NAME%_controller_test.rb',
44-
'/root/spec/controllers/%PLURALIZED_MODEL_NAME%_controller_spec.rb',
45-
'/root/spec/requests/%PLURALIZED_MODEL_NAME%_spec.rb',
46-
'/root/spec/routing/%PLURALIZED_MODEL_NAME%_routing_spec.rb'
47-
])
42+
expect(file_patterns).to eq([
43+
'/root/test/controllers/%PLURALIZED_MODEL_NAME%_controller_test.rb',
44+
'/root/spec/controllers/%PLURALIZED_MODEL_NAME%_controller_spec.rb',
45+
'/root/spec/requests/%PLURALIZED_MODEL_NAME%_spec.rb',
46+
'/root/spec/routing/%PLURALIZED_MODEL_NAME%_routing_spec.rb'
47+
])
4848
end
4949
end
5050

5151
context 'when pattern_type is "factory"' do
5252
let(:pattern_type) { 'factory' }
5353

5454
it 'returns patterns of factory files' do
55-
is_expected.to eq([
56-
'/root/test/exemplars/%MODEL_NAME%_exemplar.rb',
57-
'/root/spec/exemplars/%MODEL_NAME%_exemplar.rb',
58-
'/root/test/blueprints/%MODEL_NAME%_blueprint.rb',
59-
'/root/spec/blueprints/%MODEL_NAME%_blueprint.rb',
60-
'/root/test/factories/%MODEL_NAME%_factory.rb',
61-
'/root/spec/factories/%MODEL_NAME%_factory.rb',
62-
'/root/test/factories/%TABLE_NAME%.rb',
63-
'/root/spec/factories/%TABLE_NAME%.rb',
64-
'/root/test/factories/%PLURALIZED_MODEL_NAME%.rb',
65-
'/root/spec/factories/%PLURALIZED_MODEL_NAME%.rb',
66-
'/root/test/fabricators/%MODEL_NAME%_fabricator.rb',
67-
'/root/spec/fabricators/%MODEL_NAME%_fabricator.rb'
68-
])
55+
expect(file_patterns).to eq([
56+
'/root/test/exemplars/%MODEL_NAME%_exemplar.rb',
57+
'/root/spec/exemplars/%MODEL_NAME%_exemplar.rb',
58+
'/root/test/blueprints/%MODEL_NAME%_blueprint.rb',
59+
'/root/spec/blueprints/%MODEL_NAME%_blueprint.rb',
60+
'/root/test/factories/%MODEL_NAME%_factory.rb',
61+
'/root/spec/factories/%MODEL_NAME%_factory.rb',
62+
'/root/test/factories/%TABLE_NAME%.rb',
63+
'/root/spec/factories/%TABLE_NAME%.rb',
64+
'/root/test/factories/%PLURALIZED_MODEL_NAME%.rb',
65+
'/root/spec/factories/%PLURALIZED_MODEL_NAME%.rb',
66+
'/root/test/fabricators/%MODEL_NAME%_fabricator.rb',
67+
'/root/spec/fabricators/%MODEL_NAME%_fabricator.rb'
68+
])
6969
end
7070
end
7171

7272
context 'when pattern_type is "serializer"' do
7373
let(:pattern_type) { 'serializer' }
7474

7575
it 'returns patterns of serializer files' do
76-
is_expected.to eq([
77-
'/root/app/serializers/%MODEL_NAME%_serializer.rb',
78-
'/root/test/serializers/%MODEL_NAME%_serializer_test.rb',
79-
'/root/spec/serializers/%MODEL_NAME%_serializer_spec.rb'
80-
])
76+
expect(file_patterns).to eq([
77+
'/root/app/serializers/%MODEL_NAME%_serializer.rb',
78+
'/root/test/serializers/%MODEL_NAME%_serializer_test.rb',
79+
'/root/spec/serializers/%MODEL_NAME%_serializer_spec.rb'
80+
])
8181
end
8282
end
8383

@@ -95,15 +95,15 @@
9595
let(:options) { { additional_file_patterns: } }
9696

9797
it 'returns additional_file_patterns in the argument "options"' do
98-
is_expected.to eq(additional_file_patterns)
98+
expect(file_patterns).to eq(additional_file_patterns)
9999
end
100100
end
101101

102102
context 'when additional_file_patterns is not specified in the options' do
103103
let(:options) { {} }
104104

105105
it 'returns an empty array' do
106-
is_expected.to eq([])
106+
expect(file_patterns).to eq([])
107107
end
108108
end
109109
end
@@ -112,27 +112,27 @@
112112
let(:pattern_type) { 'controller' }
113113

114114
it 'returns patterns of controller files' do
115-
is_expected.to eq([
116-
'/root/app/controllers/%PLURALIZED_MODEL_NAME%_controller.rb'
117-
])
115+
expect(file_patterns).to eq([
116+
'/root/app/controllers/%PLURALIZED_MODEL_NAME%_controller.rb'
117+
])
118118
end
119119
end
120120

121121
context 'when pattern_type is "admin"' do
122122
let(:pattern_type) { 'admin' }
123123

124124
it 'returns both singular and pluralized model names' do
125-
is_expected.to eq(['/root/app/admin/%MODEL_NAME%.rb', '/root/app/admin/%PLURALIZED_MODEL_NAME%.rb'])
125+
expect(file_patterns).to eq(['/root/app/admin/%MODEL_NAME%.rb', '/root/app/admin/%PLURALIZED_MODEL_NAME%.rb'])
126126
end
127127
end
128128

129129
context 'when pattern_type is "helper"' do
130130
let(:pattern_type) { 'helper' }
131131

132132
it 'returns patterns of helper files' do
133-
is_expected.to eq([
134-
'/root/app/helpers/%PLURALIZED_MODEL_NAME%_helper.rb'
135-
])
133+
expect(file_patterns).to eq([
134+
'/root/app/helpers/%PLURALIZED_MODEL_NAME%_helper.rb'
135+
])
136136
end
137137
end
138138
end

0 commit comments

Comments
 (0)