This commit is contained in:
Vitalii Elenhaupt 2017-10-30 23:26:47 +02:00
parent 7d3d0902e5
commit c8dcddea22
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
3 changed files with 22 additions and 21 deletions

View file

@ -4,6 +4,16 @@ module Ameba
Rules::TrailingWhitespace, Rules::TrailingWhitespace,
] ]
macro rule(name, &block)
module Ameba::Rules
struct {{name.id}} < Rule
def test(source)
{{block.body}}
end
end
end
end
abstract struct Rule abstract struct Rule
abstract def test(source : Source) abstract def test(source : Source)

View file

@ -1,14 +1,8 @@
module Ameba::Rules # A rule that disallows lines longer than 79 symbols.
# A rule that checks the size of lines in sources.
# Ameba.rule LineLength do |source|
# This rule will report an error if there is at least source.lines.each_with_index do |line, index|
# one line longer than 79 symbols. next unless line.size > 79
struct LineLength < Rule source.error self, index + 1, "Line too long (#{line.size} symbols)"
def test(source)
source.lines.each_with_index do |line, index|
next unless line.size > 79
source.error self, index + 1, "Line too long (#{line.size} symbols)"
end
end
end end
end end

View file

@ -1,11 +1,8 @@
module Ameba::Rules # A rule that disallows trailing whitespace at the end of a line.
# A rule that disallows trailing whitespace at the end of a line.
struct TrailingWhitespace < Rule Ameba.rule TrailingWhitespace do |source|
def test(source) source.lines.each_with_index do |line, index|
source.lines.each_with_index do |line, index| next unless line =~ /\s$/
next unless line =~ /\s$/ source.error self, index + 1, "Trailing whitespace detected"
source.error self, index + 1, "Trailing whitespace detected"
end
end
end end
end end