mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add DisabledFormatter to trace disabled lines
This commit is contained in:
parent
9f85b16e09
commit
69cff77970
5 changed files with 63 additions and 4 deletions
41
spec/ameba/formatter/disabled_formatter_spec.cr
Normal file
41
spec/ameba/formatter/disabled_formatter_spec.cr
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
require "../../spec_helper"
|
||||||
|
|
||||||
|
module Ameba::Formatter
|
||||||
|
describe DisabledFormatter do
|
||||||
|
output = IO::Memory.new
|
||||||
|
subject = DisabledFormatter.new output
|
||||||
|
|
||||||
|
describe "#finished" do
|
||||||
|
it "writes a final message" do
|
||||||
|
subject.finished [Source.new ""]
|
||||||
|
output.to_s.should contain "Disabled rules using inline directives:"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "writes disabled rules if any" do
|
||||||
|
Colorize.enabled = false
|
||||||
|
|
||||||
|
path = "source.cr"
|
||||||
|
s = Source.new("", path).tap do |s|
|
||||||
|
s.error(ErrorRule.new, 1, 2, "ErrorRule", :disabled)
|
||||||
|
s.error(NamedRule.new, 2, 2, "NamedRule", :disabled)
|
||||||
|
end
|
||||||
|
subject.finished [s]
|
||||||
|
log = output.to_s
|
||||||
|
log.should contain "#{path}:1 #{ErrorRule.name}"
|
||||||
|
log.should contain "#{path}:2 #{NamedRule.name}"
|
||||||
|
ensure
|
||||||
|
output.clear
|
||||||
|
Colorize.enabled = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not write not-disabled rules" do
|
||||||
|
s = Source.new("", "source.cr").tap do |s|
|
||||||
|
s.error(ErrorRule.new, 1, 2, "ErrorRule")
|
||||||
|
s.error(NamedRule.new, 2, 2, "NamedRule", :disabled)
|
||||||
|
end
|
||||||
|
subject.finished [s]
|
||||||
|
output.to_s.should_not contain ErrorRule.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -17,6 +17,7 @@ class Ameba::Config
|
||||||
todo: Formatter::TODOFormatter,
|
todo: Formatter::TODOFormatter,
|
||||||
flycheck: Formatter::FlycheckFormatter,
|
flycheck: Formatter::FlycheckFormatter,
|
||||||
silent: Formatter::BaseFormatter,
|
silent: Formatter::BaseFormatter,
|
||||||
|
disabled: Formatter::DisabledFormatter,
|
||||||
}
|
}
|
||||||
|
|
||||||
PATH = ".ameba.yml"
|
PATH = ".ameba.yml"
|
||||||
|
|
17
src/ameba/formatter/disabled_formatter.cr
Normal file
17
src/ameba/formatter/disabled_formatter.cr
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Ameba::Formatter
|
||||||
|
# A formatter that shows all disabled line using inline directives.
|
||||||
|
class DisabledFormatter < BaseFormatter
|
||||||
|
def finished(sources)
|
||||||
|
output << "Disabled rules using inline directives: \n\n"
|
||||||
|
|
||||||
|
sources.each do |source|
|
||||||
|
source.errors.select(&.disabled?).each do |e|
|
||||||
|
if loc = e.location
|
||||||
|
output << "#{source.path}:#{loc.line_number}".colorize(:cyan)
|
||||||
|
output << " #{e.rule.name}\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@ module Ameba
|
||||||
# 1. The line of the location ends with a comment directive.
|
# 1. The line of the location ends with a comment directive.
|
||||||
# 2. The line above the location is a comment directive.
|
# 2. The line above the location is a comment directive.
|
||||||
#
|
#
|
||||||
# For example, here is two examples of disabled location:
|
# For example, here are two examples of disabled location:
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# # ameba:disable LargeNumbers
|
# # ameba:disable LargeNumbers
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Ameba
|
||||||
# Represents an error caught by Ameba.
|
# Represents an error caught by Ameba.
|
||||||
#
|
#
|
||||||
# Each error has the rule that created this error,
|
# Each error has the rule that created this error,
|
||||||
# location of the issue and a message.
|
# location of the issue, message and status.
|
||||||
record Error,
|
record Error,
|
||||||
rule : Rule::Base,
|
rule : Rule::Base,
|
||||||
location : Crystal::Location?,
|
location : Crystal::Location?,
|
||||||
|
@ -43,7 +43,7 @@ module Ameba
|
||||||
def initialize(@code : String, @path = "")
|
def initialize(@code : String, @path = "")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds new error to the list of errors.
|
# Adds a new error to the list of errors.
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# source.error rule, location, "Line too long"
|
# source.error rule, location, "Line too long"
|
||||||
|
@ -54,7 +54,7 @@ module Ameba
|
||||||
errors << Error.new rule, location, message, status
|
errors << Error.new rule, location, message, status
|
||||||
end
|
end
|
||||||
|
|
||||||
# Adds new error to the list of errors using line and column number.
|
# Adds a new error to the list of errors using line and column number.
|
||||||
#
|
#
|
||||||
# ```
|
# ```
|
||||||
# source.error rule, line_number, column_number, "Bad code"
|
# source.error rule, line_number, column_number, "Bad code"
|
||||||
|
|
Loading…
Reference in a new issue