mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Rule dsl
This commit is contained in:
parent
7d3d0902e5
commit
c8dcddea22
3 changed files with 22 additions and 21 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
# 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
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue