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,
]
macro rule(name, &block)
module Ameba::Rules
struct {{name.id}} < Rule
def test(source)
{{block.body}}
end
end
end
end
abstract struct Rule
abstract def test(source : Source)

View File

@ -1,14 +1,8 @@
module Ameba::Rules
# A rule that checks the size of lines in sources.
#
# This rule will report an error if there is at least
# one line longer than 79 symbols.
struct LineLength < Rule
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
# A rule that disallows lines longer than 79 symbols.
Ameba.rule LineLength do |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

View File

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