diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml
index 352fef56..cfb569da 100644
--- a/.github/workflows/linting.yml
+++ b/.github/workflows/linting.yml
@@ -9,7 +9,6 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
- ruby-version: '3.0'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Rubocop
run: bundle exec rubocop
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 44eca5d6..52cb4ee6 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -5,7 +5,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- ruby: [2.7, '3.0', 3.1, 3.2, 3.3, head]
+ ruby: [2.7, 3.0, 3.1, 3.2, 3.3, head]
gemfile: [rubocop-next, rubocop-old]
runs-on: ubuntu-latest
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
diff --git a/.rubocop.yml b/.rubocop.yml
index 87129906..09f6b589 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,8 +1,13 @@
inherit_gem:
rubocop-shopify: rubocop.yml
+Style/ClassMethodsDefinitions:
+ Enabled: false
+
+Style/ArrayIntersect:
+ Enabled: false
+
AllCops:
- TargetRubyVersion: 2.7
Exclude:
- 'vendor/**/*'
- 'gemfiles/vendor/**/*'
diff --git a/.ruby-version b/.ruby-version
new file mode 100644
index 00000000..be94e6f5
--- /dev/null
+++ b/.ruby-version
@@ -0,0 +1 @@
+3.2.2
diff --git a/Gemfile.lock b/Gemfile.lock
index 21f2e3ba..17eabd18 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -12,44 +12,57 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- actionview (7.0.7.2)
- activesupport (= 7.0.7.2)
+ actionview (7.1.3.2)
+ activesupport (= 7.1.3.2)
builder (~> 3.1)
- erubi (~> 1.4)
- rails-dom-testing (~> 2.0)
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
- activesupport (7.0.7.2)
+ erubi (~> 1.11)
+ rails-dom-testing (~> 2.2)
+ rails-html-sanitizer (~> 1.6)
+ activesupport (7.1.3.2)
+ base64
+ bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
+ connection_pool (>= 2.2.5)
+ drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
+ mutex_m
tzinfo (~> 2.0)
ast (2.4.2)
- better_html (2.0.2)
+ base64 (0.2.0)
+ better_html (2.1.1)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
+ bigdecimal (3.1.7)
builder (3.2.4)
- concurrent-ruby (1.2.2)
+ concurrent-ruby (1.2.3)
+ connection_pool (2.4.1)
crass (1.0.6)
diff-lcs (1.5.0)
+ drb (2.2.1)
erubi (1.12.0)
fakefs (1.5.1)
- i18n (1.14.1)
+ i18n (1.14.4)
concurrent-ruby (~> 1.0)
- loofah (2.21.3)
+ json (2.7.1)
+ language_server-protocol (3.17.0.3)
+ loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mini_portile2 (2.8.5)
- minitest (5.19.0)
- nokogiri (1.15.6)
+ minitest (5.22.3)
+ mutex_m (0.2.0)
+ nokogiri (1.16.3)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
- parallel (1.22.1)
- parser (3.1.2.1)
+ parallel (1.24.0)
+ parser (3.3.0.5)
ast (~> 2.4.1)
+ racc
racc (1.7.3)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
@@ -60,8 +73,8 @@ GEM
nokogiri (~> 1.14)
rainbow (3.1.1)
rake (13.0.6)
- regexp_parser (2.5.0)
- rexml (3.2.5)
+ regexp_parser (2.9.0)
+ rexml (3.2.6)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
@@ -75,24 +88,26 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
- rubocop (1.30.1)
+ rubocop (1.62.1)
+ json (~> 2.3)
+ language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
- parser (>= 3.1.0.0)
+ parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
- rubocop-ast (>= 1.18.0, < 2.0)
+ rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
- unicode-display_width (>= 1.4.0, < 3.0)
- rubocop-ast (1.18.0)
- parser (>= 3.1.1.0)
- rubocop-shopify (2.7.0)
- rubocop (~> 1.30)
- ruby-progressbar (1.11.0)
+ unicode-display_width (>= 2.4.0, < 3.0)
+ rubocop-ast (1.31.2)
+ parser (>= 3.3.0.4)
+ rubocop-shopify (2.15.1)
+ rubocop (~> 1.51)
+ ruby-progressbar (1.13.0)
smart_properties (1.17.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
- unicode-display_width (2.1.0)
+ unicode-display_width (2.5.0)
PLATFORMS
ruby
diff --git a/dev.yml b/dev.yml
index 25586185..003f5bac 100644
--- a/dev.yml
+++ b/dev.yml
@@ -1,7 +1,7 @@
name: erb-lint
up:
- - ruby: '3.2.2'
+ - ruby
- bundler
commands:
diff --git a/lib/erb_lint/cache.rb b/lib/erb_lint/cache.rb
index 94dde02d..928b209a 100644
--- a/lib/erb_lint/cache.rb
+++ b/lib/erb_lint/cache.rb
@@ -16,7 +16,7 @@ def get(filename, file_content)
file_checksum = checksum(filename, file_content)
begin
cache_file_contents_as_offenses = JSON.parse(
- File.read(File.join(@cache_dir, file_checksum))
+ File.read(File.join(@cache_dir, file_checksum)),
).map do |offense_hash|
ERBLint::CachedOffense.new(offense_hash)
end
@@ -76,7 +76,7 @@ def checksum(filename, file_content)
mode = File.stat(filename).mode
digester.update(
- "#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}"
+ "#{mode}#{config.to_hash}#{ERBLint::VERSION}#{file_content}",
)
digester.hexdigest
rescue Errno::ENOENT
diff --git a/lib/erb_lint/cached_offense.rb b/lib/erb_lint/cached_offense.rb
index 3c5fa74e..3f0736c9 100644
--- a/lib/erb_lint/cached_offense.rb
+++ b/lib/erb_lint/cached_offense.rb
@@ -38,7 +38,7 @@ def self.new_from_offense(offense)
last_line: offense.last_line,
last_column: offense.last_column,
length: offense.length,
- }
+ },
)
end
diff --git a/lib/erb_lint/cli.rb b/lib/erb_lint/cli.rb
index 932a2276..ee95c751 100644
--- a/lib/erb_lint/cli.rb
+++ b/lib/erb_lint/cli.rb
@@ -87,7 +87,7 @@ def run(args = ARGV)
rescue => e
@stats.exceptions += 1
puts "Exception occurred when processing: #{relative_filename(filename)}"
- puts "If this file cannot be processed by erb-lint, "\
+ puts "If this file cannot be processed by erb-lint, " \
"you can exclude it in your configuration file."
puts e.message
puts Rainbow(e.backtrace.join("\n")).red
@@ -303,7 +303,7 @@ def runner_config_override
ERBLint::LinterRegistry.linters.map do |klass|
linters[klass.simple_name] = { "enabled" => enabled_linter_classes.include?(klass) }
end
- end
+ end,
)
end
@@ -348,8 +348,12 @@ def option_parser
@options[:clear_cache] = config
end
- opts.on("--enable-linters LINTER[,LINTER,...]", Array,
- "Only use specified linter", "Known linters are: #{known_linter_names.join(", ")}") do |linters|
+ opts.on(
+ "--enable-linters LINTER[,LINTER,...]",
+ Array,
+ "Only use specified linter",
+ "Known linters are: #{known_linter_names.join(", ")}",
+ ) do |linters|
linters.each do |linter|
unless known_linter_names.include?(linter)
failure!("#{linter}: not a valid linter name (#{known_linter_names.join(", ")})")
@@ -382,7 +386,7 @@ def option_parser
opts.on(
"-sFILE",
"--stdin FILE",
- "Pipe source from STDIN. Takes the path to be used to check which rules to apply."
+ "Pipe source from STDIN. Takes the path to be used to check which rules to apply.",
) do |file|
@options[:stdin] = [file]
end
@@ -398,7 +402,7 @@ def option_parser
end
def format_options_help
- "Report offenses in the given format: "\
+ "Report offenses in the given format: " \
"(#{Reporter.available_formats.join(", ")}) (default: multiline)"
end
diff --git a/lib/erb_lint/linter.rb b/lib/erb_lint/linter.rb
index 4eec7fd2..0c8ceea0 100644
--- a/lib/erb_lint/linter.rb
+++ b/lib/erb_lint/linter.rb
@@ -38,7 +38,7 @@ def support_autocorrect?
def initialize(file_loader, config)
@file_loader = file_loader
@config = config
- raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, "\
+ raise ArgumentError, "expect `config` to be #{self.class.config_schema} instance, " \
"not #{config.class}" unless config.is_a?(self.class.config_schema)
@offenses = []
end
diff --git a/lib/erb_lint/linters/allowed_script_type.rb b/lib/erb_lint/linters/allowed_script_type.rb
index 7c6cc5d0..64a55c2b 100644
--- a/lib/erb_lint/linters/allowed_script_type.rb
+++ b/lib/erb_lint/linters/allowed_script_type.rb
@@ -12,7 +12,8 @@ class AllowedScriptType < Linter
include LinterRegistry
class ConfigSchema < LinterConfig
- property :allowed_types, accepts: array_of?(String),
+ property :allowed_types,
+ accepts: array_of?(String),
default: -> { ["text/javascript"] }
property :allow_blank, accepts: [true, false], default: true, reader: :allow_blank?
property :disallow_inline_scripts, accepts: [true, false], default: false, reader: :disallow_inline_scripts?
@@ -30,8 +31,8 @@ def run(processed_source)
name_node = tag_node.to_a[1]
add_offense(
name_node.loc,
- "Avoid using inline `")
+ corrector.replace(
+ begin_node.loc,
+ "",
+ )
end
rescue Utils::RubyToERB::Error, Utils::BlockMap::ParseError
nil
diff --git a/lib/erb_lint/linters/no_unused_disable.rb b/lib/erb_lint/linters/no_unused_disable.rb
index 91f37317..6c5dd902 100644
--- a/lib/erb_lint/linters/no_unused_disable.rb
+++ b/lib/erb_lint/linters/no_unused_disable.rb
@@ -35,8 +35,10 @@ def run(processed_source, offenses)
disabled_rules_and_line_number.each do |rule, line_numbers|
line_numbers.each do |line_number|
- add_offense(processed_source.source_buffer.line_range(line_number),
- "Unused erblint:disable comment for #{rule}")
+ add_offense(
+ processed_source.source_buffer.line_range(line_number),
+ "Unused erblint:disable comment for #{rule}",
+ )
end
end
end
diff --git a/lib/erb_lint/linters/parser_errors.rb b/lib/erb_lint/linters/parser_errors.rb
index 78de498c..6f509a19 100644
--- a/lib/erb_lint/linters/parser_errors.rb
+++ b/lib/erb_lint/linters/parser_errors.rb
@@ -9,7 +9,7 @@ def run(processed_source)
processed_source.parser.parser_errors.each do |error|
add_offense(
error.loc,
- "#{error.message} (at #{error.loc.source})"
+ "#{error.message} (at #{error.loc.source})",
)
end
end
diff --git a/lib/erb_lint/linters/partial_instance_variable.rb b/lib/erb_lint/linters/partial_instance_variable.rb
index 50c5ff27..55d3cda4 100644
--- a/lib/erb_lint/linters/partial_instance_variable.rb
+++ b/lib/erb_lint/linters/partial_instance_variable.rb
@@ -13,9 +13,9 @@ def run(processed_source)
add_offense(
processed_source.to_source_range(
- processed_source.file_content =~ instance_variable_regex..processed_source.file_content.size
+ processed_source.file_content =~ instance_variable_regex..processed_source.file_content.size,
),
- "Instance variable detected in partial."
+ "Instance variable detected in partial.",
)
end
end
diff --git a/lib/erb_lint/linters/require_input_autocomplete.rb b/lib/erb_lint/linters/require_input_autocomplete.rb
index 0e3151a3..4a779e5f 100644
--- a/lib/erb_lint/linters/require_input_autocomplete.rb
+++ b/lib/erb_lint/linters/require_input_autocomplete.rb
@@ -62,9 +62,9 @@ def find_html_input_tags(parser)
add_offense(
tag_node.to_a[1].loc,
- "Input tag is missing an autocomplete attribute. If no "\
+ "Input tag is missing an autocomplete attribute. If no " \
"autocomplete behaviour is desired, use the value `off` or `nope`.",
- [autocomplete_attribute]
+ [autocomplete_attribute],
)
end
end
@@ -96,9 +96,9 @@ def find_rails_helper_input_tags(parser)
add_offense(
erb_node.loc,
- "Input field helper is missing an autocomplete attribute. If no "\
+ "Input field helper is missing an autocomplete attribute. If no " \
"autocomplete behaviour is desired, use the value `off` or `nope`.",
- [erb_node, send_node]
+ [erb_node, send_node],
)
end
end
diff --git a/lib/erb_lint/linters/require_script_nonce.rb b/lib/erb_lint/linters/require_script_nonce.rb
index a68042cd..e575dfbb 100644
--- a/lib/erb_lint/linters/require_script_nonce.rb
+++ b/lib/erb_lint/linters/require_script_nonce.rb
@@ -29,7 +29,7 @@ def find_html_script_tags(parser)
add_offense(
tag_node.to_a[1].loc,
"Missing a nonce attribute. Use request.content_security_policy_nonce",
- [nonce_attribute]
+ [nonce_attribute],
)
end
end
@@ -67,7 +67,7 @@ def find_rails_helper_script_tags(parser)
add_offense(
erb_node.loc,
"Missing a nonce attribute. Use nonce: true",
- [erb_node, send_node]
+ [erb_node, send_node],
)
end
end
diff --git a/lib/erb_lint/linters/right_trim.rb b/lib/erb_lint/linters/right_trim.rb
index 5e36b392..c96301fb 100644
--- a/lib/erb_lint/linters/right_trim.rb
+++ b/lib/erb_lint/linters/right_trim.rb
@@ -19,7 +19,7 @@ def run(processed_source)
add_offense(
trim_node.loc,
- "Prefer #{@config.enforced_style}%> instead of #{trim_node.loc.source}%> for trimming on the right."
+ "Prefer #{@config.enforced_style}%> instead of #{trim_node.loc.source}%> for trimming on the right.",
)
end
end
diff --git a/lib/erb_lint/linters/rubocop.rb b/lib/erb_lint/linters/rubocop.rb
index 6f99058d..3bd1399d 100644
--- a/lib/erb_lint/linters/rubocop.rb
+++ b/lib/erb_lint/linters/rubocop.rb
@@ -134,7 +134,7 @@ def rubocop_processed_source(content, filename)
source = ::RuboCop::ProcessedSource.new(
content,
@rubocop_config.target_ruby_version,
- filename
+ filename,
)
if ::RuboCop::Version::STRING.to_f >= 1.38
registry = RuboCop::Cop::Registry.global
diff --git a/lib/erb_lint/linters/self_closing_tag.rb b/lib/erb_lint/linters/self_closing_tag.rb
index 384b2e54..e5fc4cd4 100644
--- a/lib/erb_lint/linters/self_closing_tag.rb
+++ b/lib/erb_lint/linters/self_closing_tag.rb
@@ -11,8 +11,25 @@ class ConfigSchema < LinterConfig
end
self.config_schema = ConfigSchema
- SELF_CLOSING_TAGS = ["area", "base", "br", "col", "command", "embed", "hr", "input", "keygen", "link",
- "menuitem", "meta", "param", "source", "track", "wbr", "img",]
+ SELF_CLOSING_TAGS = [
+ "area",
+ "base",
+ "br",
+ "col",
+ "command",
+ "embed",
+ "hr",
+ "input",
+ "keygen",
+ "link",
+ "menuitem",
+ "meta",
+ "param",
+ "source",
+ "track",
+ "wbr",
+ "img",
+ ]
def run(processed_source)
processed_source.ast.descendants(:tag).each do |tag_node|
@@ -24,7 +41,7 @@ def run(processed_source)
add_offense(
start_solidus.loc,
"Tag `#{tag.name}` is a void element, it must not start with ``.",
- ""
+ "",
)
end
@@ -32,7 +49,7 @@ def run(processed_source)
add_offense(
tag_node.loc.end.offset(-1),
"Tag `#{tag.name}` is self-closing, it must end with `/>`.",
- "/"
+ "/",
)
end
@@ -42,7 +59,7 @@ def run(processed_source)
add_offense(
end_solidus.loc,
"Tag `#{tag.name}` is a void element, it must end with `>` and not `/>`.",
- ""
+ "",
)
end
end
diff --git a/lib/erb_lint/linters/space_around_erb_tag.rb b/lib/erb_lint/linters/space_around_erb_tag.rb
index 2e11cac6..0a8ce7d3 100644
--- a/lib/erb_lint/linters/space_around_erb_tag.rb
+++ b/lib/erb_lint/linters/space_around_erb_tag.rb
@@ -23,17 +23,17 @@ def run(processed_source)
if start_spaces.size != 1 && !start_spaces.include?("\n")
add_offense(
code_node.loc.resize(start_spaces.size),
- "Use 1 space after `<%#{indicator}#{ltrim&.loc&.source}` "\
+ "Use 1 space after `<%#{indicator}#{ltrim&.loc&.source}` " \
"instead of #{start_spaces.size} space#{"s" if start_spaces.size > 1}.",
- " "
+ " ",
)
elsif start_spaces.count("\n") > 1
lines = start_spaces.split("\n", -1)
add_offense(
code_node.loc.resize(start_spaces.size),
- "Use 1 newline after `<%#{indicator&.loc&.source}#{ltrim&.loc&.source}` "\
+ "Use 1 newline after `<%#{indicator&.loc&.source}#{ltrim&.loc&.source}` " \
"instead of #{start_spaces.count("\n")}.",
- "#{lines.first}\n#{lines.last}"
+ "#{lines.first}\n#{lines.last}",
)
end
@@ -41,17 +41,17 @@ def run(processed_source)
if end_spaces.size != 1 && !end_spaces.include?("\n")
add_offense(
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
- "Use 1 space before `#{rtrim&.loc&.source}%>` "\
+ "Use 1 space before `#{rtrim&.loc&.source}%>` " \
"instead of #{end_spaces.size} space#{"s" if start_spaces.size > 1}.",
- " "
+ " ",
)
elsif end_spaces.count("\n") > 1
lines = end_spaces.split("\n", -1)
add_offense(
code_node.loc.end.adjust(begin_pos: -end_spaces.size),
- "Use 1 newline before `#{rtrim&.loc&.source}%>` "\
+ "Use 1 newline before `#{rtrim&.loc&.source}%>` " \
"instead of #{end_spaces.count("\n")}.",
- "#{lines.first}\n#{lines.last}"
+ "#{lines.first}\n#{lines.last}",
)
end
end
diff --git a/lib/erb_lint/linters/space_in_html_tag.rb b/lib/erb_lint/linters/space_in_html_tag.rb
index d422a227..44360c9b 100644
--- a/lib/erb_lint/linters/space_in_html_tag.rb
+++ b/lib/erb_lint/linters/space_in_html_tag.rb
@@ -50,7 +50,7 @@ def no_space(processed_source, range)
add_offense(
processed_source.to_source_range(range),
"Extra space detected where there should be no space.",
- ""
+ "",
)
end
@@ -69,24 +69,24 @@ def single_space(processed_source, range, accept_newline: false)
if non_space && !non_space.captures.empty?
add_offense(
processed_source.to_source_range(range),
- "Non-whitespace character(s) detected: "\
+ "Non-whitespace character(s) detected: " \
"#{non_space.captures.map(&:inspect).join(", ")}.",
- expected
+ expected,
)
elsif newlines && accept_newline
if expected != chars
add_offense(
processed_source.to_source_range(range),
- "#{chars.empty? ? "No" : "Extra"} space detected where there should be "\
+ "#{chars.empty? ? "No" : "Extra"} space detected where there should be " \
"a single space or a single line break.",
- expected
+ expected,
)
end
else
add_offense(
processed_source.to_source_range(range),
"#{chars.empty? ? "No" : "Extra"} space detected where there should be a single space.",
- expected
+ expected,
)
end
end
@@ -103,7 +103,7 @@ def process_attributes(processed_source, attributes)
single_space_or_newline(
processed_source,
- attribute.loc.end_pos...next_attribute.loc.begin_pos
+ attribute.loc.end_pos...next_attribute.loc.begin_pos,
)
end
end
diff --git a/lib/erb_lint/linters/space_indentation.rb b/lib/erb_lint/linters/space_indentation.rb
index 043860d0..f9d19215 100644
--- a/lib/erb_lint/linters/space_indentation.rb
+++ b/lib/erb_lint/linters/space_indentation.rb
@@ -23,7 +23,7 @@ def run(processed_source)
add_offense(
processed_source.to_source_range(document_pos...(document_pos + spaces.length)),
"Indent with spaces instead of tabs.",
- spaces.gsub("\t", " " * @config.tab_width)
+ spaces.gsub("\t", " " * @config.tab_width),
)
end
diff --git a/lib/erb_lint/linters/trailing_whitespace.rb b/lib/erb_lint/linters/trailing_whitespace.rb
index e2b5ddd3..08e3e883 100644
--- a/lib/erb_lint/linters/trailing_whitespace.rb
+++ b/lib/erb_lint/linters/trailing_whitespace.rb
@@ -18,7 +18,7 @@ def run(processed_source)
add_offense(
processed_source.to_source_range((document_pos - whitespace.length - 1)...(document_pos - 1)),
- "Extra whitespace detected at end of line."
+ "Extra whitespace detected at end of line.",
)
end
end
diff --git a/lib/erb_lint/offense.rb b/lib/erb_lint/offense.rb
index 07f9eef6..07e73bfd 100644
--- a/lib/erb_lint/offense.rb
+++ b/lib/erb_lint/offense.rb
@@ -23,9 +23,9 @@ def to_cached_offense_hash
end
def inspect
- "#<#{self.class.name} linter=#{linter.class.name} "\
- "source_range=#{source_range.begin_pos}...#{source_range.end_pos} "\
- "message=#{message}> "\
+ "#<#{self.class.name} linter=#{linter.class.name} " \
+ "source_range=#{source_range.begin_pos}...#{source_range.end_pos} " \
+ "message=#{message}> " \
"severity=#{severity}"
end
diff --git a/lib/erb_lint/processed_source.rb b/lib/erb_lint/processed_source.rb
index 8f9cf48b..1fcb3190 100644
--- a/lib/erb_lint/processed_source.rb
+++ b/lib/erb_lint/processed_source.rb
@@ -27,7 +27,7 @@ def to_source_range(range)
BetterHtml::Tokenizer::Location.new(
source_buffer,
range.begin,
- range.exclude_end? ? range.end : range.end + 1
+ range.exclude_end? ? range.end : range.end + 1,
)
end
end
diff --git a/lib/erb_lint/reporters/compact_reporter.rb b/lib/erb_lint/reporters/compact_reporter.rb
index 11d997ac..d4c42e0d 100644
--- a/lib/erb_lint/reporters/compact_reporter.rb
+++ b/lib/erb_lint/reporters/compact_reporter.rb
@@ -60,7 +60,7 @@ def report_corrected_offenses
if corrected_found_diff > 0
message = Rainbow(
- "#{stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files"
+ "#{stats.corrected} error(s) corrected and #{corrected_found_diff} error(s) remaining in ERB files",
).red
warn(message)
diff --git a/lib/erb_lint/reporters/gitlab_reporter.rb b/lib/erb_lint/reporters/gitlab_reporter.rb
index b9001bcb..83d47135 100644
--- a/lib/erb_lint/reporters/gitlab_reporter.rb
+++ b/lib/erb_lint/reporters/gitlab_reporter.rb
@@ -47,7 +47,7 @@ def format_offense(filename, offense)
def generate_fingerprint(filename, offense)
Digest::MD5.hexdigest(
- "#{offense.simple_name}@#{filename}:#{offense.line_number}:#{offense.last_line}"
+ "#{offense.simple_name}@#{filename}:#{offense.line_number}:#{offense.last_line}",
)
end
end
diff --git a/lib/erb_lint/runner.rb b/lib/erb_lint/runner.rb
index bdcdb346..ba399eea 100644
--- a/lib/erb_lint/runner.rb
+++ b/lib/erb_lint/runner.rb
@@ -57,7 +57,7 @@ def report_unused_disable(processed_source)
if no_unused_disable_enabled? && enable_inline_configs?
@no_unused_disable = ERBLint::Linters::NoUnusedDisable.new(
@file_loader,
- @config.for_linter(ERBLint::Linters::NoUnusedDisable)
+ @config.for_linter(ERBLint::Linters::NoUnusedDisable),
)
@no_unused_disable.run(processed_source, @offenses)
@offenses.concat(@no_unused_disable.offenses)
diff --git a/lib/erb_lint/utils/block_map.rb b/lib/erb_lint/utils/block_map.rb
index 1b789d79..32a4fe6f 100644
--- a/lib/erb_lint/utils/block_map.rb
+++ b/lib/erb_lint/utils/block_map.rb
@@ -60,7 +60,7 @@ def include?(other)
end
def inspect
- "\#<#{self.class.name} type=#{type.inspect} nodes=#{nodes.inspect}>"
+ "#<#{self.class.name} type=#{type.inspect} nodes=#{nodes.inspect}>"
end
def &(other)
@@ -102,7 +102,7 @@ def build_map
node.type,
extract_map_locations(node)
.map { |loc| find_entry(loc) }
- .compact.map(&:node)
+ .compact.map(&:node),
)
end
@@ -111,7 +111,7 @@ def build_map
:begin,
(extract_map_locations(node) + rescue_locations(node))
.map { |loc| find_entry(loc) }
- .compact.map(&:node)
+ .compact.map(&:node),
)
end
@@ -120,7 +120,7 @@ def build_map
node.type,
(extract_map_locations(node) + when_locations(node))
.map { |loc| find_entry(loc) }
- .compact.map(&:node)
+ .compact.map(&:node),
)
end
diff --git a/lib/erb_lint/utils/offset_corrector.rb b/lib/erb_lint/utils/offset_corrector.rb
index 0f475972..4f16659d 100644
--- a/lib/erb_lint/utils/offset_corrector.rb
+++ b/lib/erb_lint/utils/offset_corrector.rb
@@ -42,15 +42,12 @@ def range_with_offset(node_or_range)
range = to_range(node_or_range)
@processed_source.to_source_range(
- bound(@offset + range.begin_pos)..bound(@offset + (range.end_pos - 1))
+ bound(@offset + range.begin_pos)..bound(@offset + (range.end_pos - 1)),
)
end
def bound(pos)
- [
- [pos, @bound_range.min].max,
- @bound_range.max,
- ].min
+ pos.clamp(@bound_range.min, @bound_range.max)
end
private
diff --git a/lib/erb_lint/utils/severity_levels.rb b/lib/erb_lint/utils/severity_levels.rb
index 294a7b30..9ea72e7a 100644
--- a/lib/erb_lint/utils/severity_levels.rb
+++ b/lib/erb_lint/utils/severity_levels.rb
@@ -5,8 +5,14 @@ module Utils
module SeverityLevels
SEVERITY_NAMES = [:info, :refactor, :convention, :warning, :error, :fatal].freeze
- SEVERITY_CODE_TABLE = { I: :info, R: :refactor, C: :convention,
- W: :warning, E: :error, F: :fatal, }.freeze
+ SEVERITY_CODE_TABLE = {
+ I: :info,
+ R: :refactor,
+ C: :convention,
+ W: :warning,
+ E: :error,
+ F: :fatal,
+ }.freeze
def severity_level_for_name(name)
SEVERITY_NAMES.index(name || :error) + 1
diff --git a/spec/erb_lint/block_map_spec.rb b/spec/erb_lint/block_map_spec.rb
index c12642f0..6fc507c4 100644
--- a/spec/erb_lint/block_map_spec.rb
+++ b/spec/erb_lint/block_map_spec.rb
@@ -3,7 +3,7 @@
require "spec_helper"
describe ERBLint::Utils::BlockMap do
- include ::AST::Sexp
+ include AST::Sexp
describe "map" do
let(:processed_source) { ERBLint::ProcessedSource.new("file.rb", file) }
diff --git a/spec/erb_lint/cache_spec.rb b/spec/erb_lint/cache_spec.rb
index 5d6e5477..3a5eaab7 100644
--- a/spec/erb_lint/cache_spec.rb
+++ b/spec/erb_lint/cache_spec.rb
@@ -63,8 +63,8 @@
expect(File.exist?(
File.join(
cache_dir,
- checksum
- )
+ checksum,
+ ),
)).to(be(true))
expect(cache.send(:new_results)).to(include(checksum))
end
@@ -101,8 +101,8 @@
expect(File.exist?(
File.join(
cache_dir,
- checksum
- )
+ checksum,
+ ),
)).to(be(true))
end
@@ -118,8 +118,8 @@
expect(File.exist?(
File.join(
cache_dir,
- checksum
- )
+ checksum,
+ ),
)).to(be(true))
end
@@ -138,8 +138,8 @@
expect(File.exist?(
File.join(
cache_dir,
- "fake-checksum"
- )
+ "fake-checksum",
+ ),
)).to(be(false))
end
end
diff --git a/spec/erb_lint/cli_spec.rb b/spec/erb_lint/cli_spec.rb
index 9663a4a7..4d9c680c 100644
--- a/spec/erb_lint/cli_spec.rb
+++ b/spec/erb_lint/cli_spec.rb
@@ -22,10 +22,12 @@
before do
allow(ERBLint::LinterRegistry).to(receive(:linters)
- .and_return([ERBLint::Linters::LinterWithErrors,
- ERBLint::Linters::LinterWithInfoErrors,
- ERBLint::Linters::LinterWithoutErrors,
- ERBLint::Linters::FinalNewline,]))
+ .and_return([
+ ERBLint::Linters::LinterWithErrors,
+ ERBLint::Linters::LinterWithInfoErrors,
+ ERBLint::Linters::LinterWithoutErrors,
+ ERBLint::Linters::FinalNewline,
+ ]))
end
module ERBLint
@@ -34,7 +36,7 @@ class LinterWithErrors < Linter
def run(processed_source)
add_offense(
processed_source.to_source_range(1..1),
- "fake message from a fake linter"
+ "fake message from a fake linter",
)
end
end
@@ -67,7 +69,7 @@ def run(processed_source)
it "shows all known linters in stderr" do
expect { subject }.to(output(
- /Known linters are: linter_with_errors, linter_with_info_errors, linter_without_errors, final_newline/
+ /Known linters are: linter_with_errors, linter_with_info_errors, linter_without_errors, final_newline/,
).to_stderr)
end
@@ -92,7 +94,7 @@ def run(processed_source)
expect { subject }.to(
output(Regexp.new("Report offenses in the given format: " \
"\\(compact, gitlab, json, junit, multiline\\) " \
- "\\(default: multiline\\)")).to_stdout
+ "\\(default: multiline\\)")).to_stdout,
)
end
@@ -106,8 +108,10 @@ module ERBLint
module Linters
class FakeLinter < Linter
def run(processed_source)
- add_offense(SpecUtils.source_range_for_code(processed_source, ""),
- "#{self.class.name} error")
+ add_offense(
+ SpecUtils.source_range_for_code(processed_source, ""),
+ "#{self.class.name} error",
+ )
end
end
end
@@ -473,8 +477,10 @@ def run(processed_source)
context "with --format compact" do
let(:args) do
[
- "--enable-linter", "linter_with_errors,final_newline",
- "--format", "compact",
+ "--enable-linter",
+ "linter_with_errors,final_newline",
+ "--format",
+ "compact",
linted_dir,
]
end
@@ -494,8 +500,10 @@ def run(processed_source)
context "with invalid --format option" do
let(:args) do
[
- "--enable-linter", "linter_with_errors,final_newline",
- "--format", "nonexistentformat",
+ "--enable-linter",
+ "linter_with_errors,final_newline",
+ "--format",
+ "nonexistentformat",
linted_dir,
]
end
@@ -560,7 +568,7 @@ def run(processed_source)
it do
expect { subject }.to(output(
- /foo: not a valid linter name \(#{known_linters}\)/
+ /foo: not a valid linter name \(#{known_linters}\)/,
).to_stderr)
end
@@ -687,9 +695,12 @@ def run(processed_source)
context "allowing for no matching files" do
let(:args) do
[
- "--config", config_file,
- "--enable-linter", "linter_with_errors,final_newline",
- "--stdin", linted_file,
+ "--config",
+ config_file,
+ "--enable-linter",
+ "linter_with_errors,final_newline",
+ "--stdin",
+ linted_file,
"--allow-no-files",
]
end
diff --git a/spec/erb_lint/linter_config_spec.rb b/spec/erb_lint/linter_config_spec.rb
index a52718fa..52f4c673 100644
--- a/spec/erb_lint/linter_config_spec.rb
+++ b/spec/erb_lint/linter_config_spec.rb
@@ -82,11 +82,11 @@ class CustomConfig < described_class
context "when enabled key is not true or false" do
let(:config_hash) { { enabled: 42 } }
it do
- expect { subject }.to(\
+ expect { subject }.to(
raise_error(
described_class::Error,
- "ERBLint::LinterConfig does not accept 42 as value for the property enabled. Only accepts: [true, false]"
- )
+ "ERBLint::LinterConfig does not accept 42 as value for the property enabled. Only accepts: [true, false]",
+ ),
)
end
end
diff --git a/spec/erb_lint/linters/allowed_script_type_spec.rb b/spec/erb_lint/linters/allowed_script_type_spec.rb
index be9320ff..00e16201 100644
--- a/spec/erb_lint/linters/allowed_script_type_spec.rb
+++ b/spec/erb_lint/linters/allowed_script_type_spec.rb
@@ -25,9 +25,11 @@
let(:file) { '