Skip to content

Commit 35965ee

Browse files
committed
Run bundle exec rubocop autocorrect
1 parent f12c57a commit 35965ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+324
-239
lines changed

lib/erb_lint/cache.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get(filename, file_content)
1616
file_checksum = checksum(filename, file_content)
1717
begin
1818
cache_file_contents_as_offenses = JSON.parse(
19-
File.read(File.join(@cache_dir, file_checksum))
19+
File.read(File.join(@cache_dir, file_checksum)),
2020
).map do |offense_hash|
2121
ERBLint::CachedOffense.new(offense_hash)
2222
end
@@ -76,7 +76,7 @@ def checksum(filename, file_content)
7676
mode = File.stat(filename).mode
7777

7878
digester.update(
79-
"#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}"
79+
"#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}",
8080
)
8181
digester.hexdigest
8282
rescue Errno::ENOENT

lib/erb_lint/cached_offense.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def self.new_from_offense(offense)
3838
last_line: offense.last_line,
3939
last_column: offense.last_column,
4040
length: offense.length,
41-
}
41+
},
4242
)
4343
end
4444

lib/erb_lint/cli.rb

+10-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def run(args = ARGV)
8787
rescue => e
8888
@stats.exceptions += 1
8989
puts "Exception occurred when processing: #{relative_filename(filename)}"
90-
puts "If this file cannot be processed by erb-lint, "\
90+
puts "If this file cannot be processed by erb-lint, " \
9191
"you can exclude it in your configuration file."
9292
puts e.message
9393
puts Rainbow(e.backtrace.join("\n")).red
@@ -303,7 +303,7 @@ def runner_config_override
303303
ERBLint::LinterRegistry.linters.map do |klass|
304304
linters[klass.simple_name] = { "enabled" => enabled_linter_classes.include?(klass) }
305305
end
306-
end
306+
end,
307307
)
308308
end
309309

@@ -348,8 +348,12 @@ def option_parser
348348
@options[:clear_cache] = config
349349
end
350350

351-
opts.on("--enable-linters LINTER[,LINTER,...]", Array,
352-
"Only use specified linter", "Known linters are: #{known_linter_names.join(", ")}") do |linters|
351+
opts.on(
352+
"--enable-linters LINTER[,LINTER,...]",
353+
Array,
354+
"Only use specified linter",
355+
"Known linters are: #{known_linter_names.join(", ")}",
356+
) do |linters|
353357
linters.each do |linter|
354358
unless known_linter_names.include?(linter)
355359
failure!("#{linter}: not a valid linter name (#{known_linter_names.join(", ")})")
@@ -382,7 +386,7 @@ def option_parser
382386
opts.on(
383387
"-sFILE",
384388
"--stdin FILE",
385-
"Pipe source from STDIN. Takes the path to be used to check which rules to apply."
389+
"Pipe source from STDIN. Takes the path to be used to check which rules to apply.",
386390
) do |file|
387391
@options[:stdin] = [file]
388392
end
@@ -398,7 +402,7 @@ def option_parser
398402
end
399403

400404
def format_options_help
401-
"Report offenses in the given format: "\
405+
"Report offenses in the given format: " \
402406
"(#{Reporter.available_formats.join(", ")}) (default: multiline)"
403407
end
404408

lib/erb_lint/linter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def support_autocorrect?
3838
def initialize(file_loader, config)
3939
@file_loader = file_loader
4040
@config = config
41-
raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, "\
41+
raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, " \
4242
"not #{config.class}" unless config.is_a?(self.class.config_schema)
4343
@offenses = []
4444
end

lib/erb_lint/linters/allowed_script_type.rb

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class AllowedScriptType < Linter
1212
include LinterRegistry
1313

1414
class ConfigSchema < LinterConfig
15-
property :allowed_types, accepts: array_of?(String),
15+
property :allowed_types,
16+
accepts: array_of?(String),
1617
default: -> { ["text/javascript"] }
1718
property :allow_blank, accepts: [true, false], default: true, reader: :allow_blank?
1819
property :disallow_inline_scripts, accepts: [true, false], default: false, reader: :disallow_inline_scripts?
@@ -30,8 +31,8 @@ def run(processed_source)
3031
name_node = tag_node.to_a[1]
3132
add_offense(
3233
name_node.loc,
33-
"Avoid using inline `<script>` tags altogether. "\
34-
"Instead, move javascript code into a static file."
34+
"Avoid using inline `<script>` tags altogether. " \
35+
"Instead, move javascript code into a static file.",
3536
)
3637
next
3738
end
@@ -44,14 +45,14 @@ def run(processed_source)
4445
add_offense(
4546
name_node.loc,
4647
"Missing a `type=\"text/javascript\"` attribute to `<script>` tag.",
47-
[type_attribute]
48+
[type_attribute],
4849
)
4950
elsif type_present && !@config.allowed_types.include?(type_attribute.value)
5051
add_offense(
5152
type_attribute.loc,
52-
"Avoid using #{type_attribute.value.inspect} as type for `<script>` tag. "\
53-
"Must be one of: #{@config.allowed_types.join(", ")}"\
54-
"#{" (or no type attribute)" if @config.allow_blank?}."
53+
"Avoid using #{type_attribute.value.inspect} as type for `<script>` tag. " \
54+
"Must be one of: #{@config.allowed_types.join(", ")}" \
55+
"#{" (or no type attribute)" if @config.allow_blank?}.",
5556
)
5657
end
5758
end

lib/erb_lint/linters/closing_erb_tag_indent.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ def run(processed_source)
2525
add_offense(
2626
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
2727
"Remove newline before `%>` to match start of tag.",
28-
" "
28+
" ",
2929
)
3030
elsif start_with_newline && !end_with_newline
3131
add_offense(
3232
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
3333
"Insert newline before `%>` to match start of tag.",
34-
"\n"
34+
"\n",
3535
)
3636
elsif start_with_newline && end_with_newline
3737
current_indent = end_spaces.split("\n", -1).last
3838
if erb_node.loc.column != current_indent.size
3939
add_offense(
4040
code_node.loc.end.adjust(begin_pos: -current_indent.size),
4141
"Indent `%>` on column #{erb_node.loc.column} to match start of tag.",
42-
" " * erb_node.loc.column
42+
" " * erb_node.loc.column,
4343
)
4444
end
4545
end

lib/erb_lint/linters/comment_syntax.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def run(processed_source)
3131

3232
add_offense(
3333
source_range,
34-
<<~EOF.chomp
34+
<<~EOF.chomp,
3535
Bad ERB comment syntax. Should be #{correct_erb_tag} without a space between.
3636
Leaving a space between ERB tags and the Ruby comment character can cause parser errors.
3737
EOF

lib/erb_lint/linters/deprecated_classes.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def process_nested_offenses(source:, offset:, parent_source:)
4949
process_nested_offenses(
5050
source: sub_source,
5151
offset: offset + content_node.loc.begin_pos,
52-
parent_source: parent_source
52+
parent_source: parent_source,
5353
)
5454
end
5555
end
@@ -99,7 +99,7 @@ def generate_offenses(class_name, range)
9999

100100
add_offense(
101101
range,
102-
format(message, class_name, violated_rule[:class_expr], suggestion)
102+
format(message, class_name, violated_rule[:class_expr], suggestion),
103103
)
104104
end
105105
end

lib/erb_lint/linters/erb_safety.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run(processed_source)
2626
tester.errors.each do |error|
2727
add_offense(
2828
error.location,
29-
error.message
29+
error.message,
3030
)
3131
end
3232
end

lib/erb_lint/linters/extra_newline.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def run(processed_source)
1515
add_offense(
1616
processed_source
1717
.to_source_range((matches.begin(index) + 2)...matches.end(index)),
18-
"Extra blank line detected."
18+
"Extra blank line detected.",
1919
)
2020
end
2121
end

lib/erb_lint/linters/final_newline.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ def run(processed_source)
2929
add_offense(
3030
processed_source.to_source_range(file_content.size...file_content.size),
3131
"Missing a trailing newline at the end of the file.",
32-
:insert
32+
:insert,
3333
)
3434
else
3535
add_offense(
3636
processed_source.to_source_range(
37-
(file_content.size - final_newline.size + 1)...file_content.size
37+
(file_content.size - final_newline.size + 1)...file_content.size,
3838
),
3939
"Remove multiple trailing newline at the end of the file.",
40-
:remove
40+
:remove,
4141
)
4242
end
4343
elsif !@new_lines_should_be_present && !final_newline.empty?
4444
add_offense(
4545
processed_source.to_source_range(match.begin(0)...match.end(0)),
4646
"Remove #{final_newline.size} trailing newline at the end of the file.",
47-
:remove
47+
:remove,
4848
)
4949
end
5050
end

lib/erb_lint/linters/hard_coded_string.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(processed_source)
6767

6868
add_offense(
6969
source_range,
70-
message(source_range.source)
70+
message(source_range.source),
7171
)
7272
end
7373
end
@@ -84,7 +84,7 @@ def find_range(node, str)
8484
def autocorrect(processed_source, offense)
8585
string = offense.source_range.source
8686
return unless (klass = load_corrector)
87-
return unless string.strip.length > 1
87+
return if string.strip.length <= 1
8888

8989
node = ::RuboCop::AST::StrNode.new(:str, [string])
9090
corrector = klass.new(node, processed_source.filename, corrector_i18n_load_path, offense.source_range)

lib/erb_lint/linters/no_javascript_tag_helper.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def run(processed_source)
3838

3939
add_offense(
4040
erb_node.loc,
41-
"Avoid using 'javascript_tag do' as it confuses tests "\
41+
"Avoid using 'javascript_tag do' as it confuses tests " \
4242
"that validate html, use inline <script> instead",
43-
[erb_node, send_node]
43+
[erb_node, send_node],
4444
)
4545
end
4646
end
@@ -82,8 +82,10 @@ def correct_offense(processed_source, offense, corrector)
8282
corrector.replace(end_node.loc, end_content)
8383
elsif script_content
8484
script_content = "\n//<![CDATA[\n#{script_content}\n//]]>\n" if @config.correction_style == :cdata
85-
corrector.replace(begin_node.loc,
86-
"<script#{arguments}>#{script_content}</script>")
85+
corrector.replace(
86+
begin_node.loc,
87+
"<script#{arguments}>#{script_content}</script>",
88+
)
8789
end
8890
rescue Utils::RubyToERB::Error, Utils::BlockMap::ParseError
8991
nil

lib/erb_lint/linters/no_unused_disable.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def run(processed_source, offenses)
3535

3636
disabled_rules_and_line_number.each do |rule, line_numbers|
3737
line_numbers.each do |line_number|
38-
add_offense(processed_source.source_buffer.line_range(line_number),
39-
"Unused erblint:disable comment for #{rule}")
38+
add_offense(
39+
processed_source.source_buffer.line_range(line_number),
40+
"Unused erblint:disable comment for #{rule}",
41+
)
4042
end
4143
end
4244
end

lib/erb_lint/linters/parser_errors.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def run(processed_source)
99
processed_source.parser.parser_errors.each do |error|
1010
add_offense(
1111
error.loc,
12-
"#{error.message} (at #{error.loc.source})"
12+
"#{error.message} (at #{error.loc.source})",
1313
)
1414
end
1515
end

lib/erb_lint/linters/partial_instance_variable.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ def run(processed_source)
1313

1414
add_offense(
1515
processed_source.to_source_range(
16-
processed_source.file_content =~ instance_variable_regex..processed_source.file_content.size
16+
processed_source.file_content =~ instance_variable_regex..processed_source.file_content.size,
1717
),
18-
"Instance variable detected in partial."
18+
"Instance variable detected in partial.",
1919
)
2020
end
2121
end

lib/erb_lint/linters/require_input_autocomplete.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def find_html_input_tags(parser)
6262

6363
add_offense(
6464
tag_node.to_a[1].loc,
65-
"Input tag is missing an autocomplete attribute. If no "\
65+
"Input tag is missing an autocomplete attribute. If no " \
6666
"autocomplete behaviour is desired, use the value `off` or `nope`.",
67-
[autocomplete_attribute]
67+
[autocomplete_attribute],
6868
)
6969
end
7070
end
@@ -96,9 +96,9 @@ def find_rails_helper_input_tags(parser)
9696

9797
add_offense(
9898
erb_node.loc,
99-
"Input field helper is missing an autocomplete attribute. If no "\
99+
"Input field helper is missing an autocomplete attribute. If no " \
100100
"autocomplete behaviour is desired, use the value `off` or `nope`.",
101-
[erb_node, send_node]
101+
[erb_node, send_node],
102102
)
103103
end
104104
end

lib/erb_lint/linters/require_script_nonce.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def find_html_script_tags(parser)
2929
add_offense(
3030
tag_node.to_a[1].loc,
3131
"Missing a nonce attribute. Use request.content_security_policy_nonce",
32-
[nonce_attribute]
32+
[nonce_attribute],
3333
)
3434
end
3535
end
@@ -67,7 +67,7 @@ def find_rails_helper_script_tags(parser)
6767
add_offense(
6868
erb_node.loc,
6969
"Missing a nonce attribute. Use nonce: true",
70-
[erb_node, send_node]
70+
[erb_node, send_node],
7171
)
7272
end
7373
end

lib/erb_lint/linters/right_trim.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def run(processed_source)
1919

2020
add_offense(
2121
trim_node.loc,
22-
"Prefer #{@config.enforced_style}%> instead of #{trim_node.loc.source}%> for trimming on the right."
22+
"Prefer #{@config.enforced_style}%> instead of #{trim_node.loc.source}%> for trimming on the right.",
2323
)
2424
end
2525
end

lib/erb_lint/linters/rubocop.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def rubocop_processed_source(content, filename)
134134
source = ::RuboCop::ProcessedSource.new(
135135
content,
136136
@rubocop_config.target_ruby_version,
137-
filename
137+
filename,
138138
)
139139
if ::RuboCop::Version::STRING.to_f >= 1.38
140140
registry = RuboCop::Cop::Registry.global

0 commit comments

Comments
 (0)