mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
It works
This commit is contained in:
parent
ffd44dc77b
commit
5e10113055
5 changed files with 48 additions and 9 deletions
15
README.md
15
README.md
|
@ -33,6 +33,21 @@ require "ameba"
|
|||
Ameba.run
|
||||
```
|
||||
|
||||
```sh
|
||||
Inspecting 7 files.
|
||||
|
||||
|
||||
..F...F
|
||||
|
||||
7 inspected, 2 failures.
|
||||
|
||||
src/ameba/formatter.cr:47
|
||||
Ameba::Rule::LineLength: Line too long [122]
|
||||
|
||||
src/ameba.cr:18
|
||||
Ameba::Rule::LineLength: Line too long [81]
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it ( https://github.com/veelenga/ameba/fork )
|
||||
|
|
|
@ -13,7 +13,7 @@ module Ameba
|
|||
end
|
||||
|
||||
def run(files, formatter : Formatter)
|
||||
sources = files.map { |path| Source.new(File.read path) }
|
||||
sources = files.map { |path| Source.new(path) }
|
||||
|
||||
reporter = Reporter.new formatter
|
||||
reporter.start sources
|
||||
|
|
|
@ -13,6 +13,7 @@ module Ameba
|
|||
|
||||
def start(sources)
|
||||
puts formatter.before sources
|
||||
puts "\n\n"
|
||||
end
|
||||
|
||||
def report(source)
|
||||
|
@ -20,7 +21,7 @@ module Ameba
|
|||
end
|
||||
|
||||
def finish(sources)
|
||||
puts
|
||||
puts "\n\n"
|
||||
puts formatter.after sources
|
||||
end
|
||||
end
|
||||
|
@ -39,7 +40,20 @@ module Ameba
|
|||
end
|
||||
|
||||
def after(sources)
|
||||
"Done!"
|
||||
String.build do |mes|
|
||||
failures = sources.select { |s| s.errors.any? }
|
||||
l = failures.map { |f| f.errors.size }.sum
|
||||
|
||||
mes << "#{sources.size} inspected, #{l} failure#{"s" if l != 1}.\n\n"
|
||||
|
||||
failures.each do |failure|
|
||||
failure.errors.each do |error|
|
||||
mes << "#{failure.path}:#{error.pos}"
|
||||
mes << "\n"
|
||||
mes << "#{error.rule}: #{error.message}\n\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
struct Ameba::Rule::LineLength
|
||||
def test(source)
|
||||
source.lines.each do |line|
|
||||
source.lines.each_with_index do |line, index|
|
||||
if line.size > 79
|
||||
source.errors << "Line too long"
|
||||
source.error self, index + 1, "Line too long [#{line.size}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
module Ameba
|
||||
class Source
|
||||
getter lines : Array(String)
|
||||
getter errors = [] of String
|
||||
record Error,
|
||||
rule : String,
|
||||
pos : Int32,
|
||||
message : String
|
||||
|
||||
def initialize(content : String)
|
||||
@lines = content.split "\n"
|
||||
getter lines : Array(String)
|
||||
getter errors = [] of Error
|
||||
getter path : String
|
||||
|
||||
def initialize(@path : String)
|
||||
@lines = File.read_lines(@path)
|
||||
end
|
||||
|
||||
def error(rule, line_number : Int32, message : String)
|
||||
errors << Error.new rule.class.name, line_number, message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue