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
|
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
|
## Contributing
|
||||||
|
|
||||||
1. Fork it ( https://github.com/veelenga/ameba/fork )
|
1. Fork it ( https://github.com/veelenga/ameba/fork )
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(files, formatter : Formatter)
|
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 = Reporter.new formatter
|
||||||
reporter.start sources
|
reporter.start sources
|
||||||
|
|
|
@ -13,6 +13,7 @@ module Ameba
|
||||||
|
|
||||||
def start(sources)
|
def start(sources)
|
||||||
puts formatter.before sources
|
puts formatter.before sources
|
||||||
|
puts "\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def report(source)
|
def report(source)
|
||||||
|
@ -20,7 +21,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
def finish(sources)
|
def finish(sources)
|
||||||
puts
|
puts "\n\n"
|
||||||
puts formatter.after sources
|
puts formatter.after sources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,7 +40,20 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
def after(sources)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
struct Ameba::Rule::LineLength
|
struct Ameba::Rule::LineLength
|
||||||
def test(source)
|
def test(source)
|
||||||
source.lines.each do |line|
|
source.lines.each_with_index do |line, index|
|
||||||
if line.size > 79
|
if line.size > 79
|
||||||
source.errors << "Line too long"
|
source.error self, index + 1, "Line too long [#{line.size}]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
module Ameba
|
module Ameba
|
||||||
class Source
|
class Source
|
||||||
getter lines : Array(String)
|
record Error,
|
||||||
getter errors = [] of String
|
rule : String,
|
||||||
|
pos : Int32,
|
||||||
|
message : String
|
||||||
|
|
||||||
def initialize(content : String)
|
getter lines : Array(String)
|
||||||
@lines = content.split "\n"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue