mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Make TODOFormatter
's configuration file path configurable
Fixes the case where formatter specs were deleting project's `.ameba.yml` file
This commit is contained in:
parent
23c61e04c0
commit
1b342e8257
2 changed files with 7 additions and 5 deletions
|
@ -1,10 +1,12 @@
|
||||||
require "../../spec_helper"
|
require "../../spec_helper"
|
||||||
require "file_utils"
|
require "file_utils"
|
||||||
|
|
||||||
|
CONFIG_PATH = Path[Dir.tempdir] / Ameba::Config::FILENAME
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
private def with_formatter(&)
|
private def with_formatter(&)
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
formatter = Formatter::TODOFormatter.new(io)
|
formatter = Formatter::TODOFormatter.new(io, CONFIG_PATH)
|
||||||
|
|
||||||
yield formatter, io
|
yield formatter, io
|
||||||
end
|
end
|
||||||
|
@ -20,7 +22,7 @@ module Ameba
|
||||||
|
|
||||||
describe Formatter::TODOFormatter do
|
describe Formatter::TODOFormatter do
|
||||||
::Spec.after_each do
|
::Spec.after_each do
|
||||||
FileUtils.rm_rf(Ameba::Config::DEFAULT_PATH)
|
FileUtils.rm_rf(CONFIG_PATH)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "problems not found" do
|
context "problems not found" do
|
||||||
|
@ -45,7 +47,7 @@ module Ameba
|
||||||
s = Source.new "a = 1", "source.cr"
|
s = Source.new "a = 1", "source.cr"
|
||||||
s.add_issue DummyRule.new, {1, 2}, "message"
|
s.add_issue DummyRule.new, {1, 2}, "message"
|
||||||
formatter.finished([s])
|
formatter.finished([s])
|
||||||
io.to_s.should contain "Created #{Config::DEFAULT_PATH}"
|
io.to_s.should contain "Created #{CONFIG_PATH}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Ameba::Formatter
|
||||||
# Basically, it takes all issues reported and disables corresponding rules
|
# Basically, it takes all issues reported and disables corresponding rules
|
||||||
# or excludes failed sources from these rules.
|
# or excludes failed sources from these rules.
|
||||||
class TODOFormatter < DotFormatter
|
class TODOFormatter < DotFormatter
|
||||||
def initialize(@output = STDOUT)
|
def initialize(@output = STDOUT, @config_path : Path = Config::DEFAULT_PATH)
|
||||||
end
|
end
|
||||||
|
|
||||||
def finished(sources)
|
def finished(sources)
|
||||||
|
@ -26,7 +26,7 @@ module Ameba::Formatter
|
||||||
end
|
end
|
||||||
|
|
||||||
private def generate_todo_config(issues)
|
private def generate_todo_config(issues)
|
||||||
file = File.new(Config::DEFAULT_PATH, mode: "w")
|
file = File.new(@config_path, mode: "w")
|
||||||
file << header
|
file << header
|
||||||
rule_issues_map(issues).each do |rule, rule_issues|
|
rule_issues_map(issues).each do |rule, rule_issues|
|
||||||
file << "\n# Problems found: #{rule_issues.size}"
|
file << "\n# Problems found: #{rule_issues.size}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue