2017-11-07 21:50:25 +00:00
|
|
|
module Ameba::Rule
|
2017-11-01 12:42:58 +00:00
|
|
|
# A rule that disallows calls to debugger.
|
|
|
|
#
|
|
|
|
# This is because we don't want debugger breakpoints accidentally being
|
|
|
|
# committed into our codebase.
|
2017-11-01 17:30:08 +00:00
|
|
|
#
|
2017-11-14 07:24:36 +00:00
|
|
|
# YAML configuration example:
|
|
|
|
#
|
|
|
|
# ```
|
|
|
|
# DebuggerStatement:
|
|
|
|
# Enabled: true
|
|
|
|
# ```
|
|
|
|
#
|
2017-11-07 21:50:25 +00:00
|
|
|
struct DebuggerStatement < Base
|
2017-11-22 06:44:29 +00:00
|
|
|
properties do
|
2018-05-03 15:57:47 +00:00
|
|
|
description "Disallows calls to debugger"
|
2017-11-22 06:44:29 +00:00
|
|
|
end
|
|
|
|
|
2018-04-17 04:29:43 +00:00
|
|
|
MSG = "Possible forgotten debugger statement detected"
|
|
|
|
|
2017-11-01 12:42:58 +00:00
|
|
|
def test(source)
|
2018-05-03 15:57:47 +00:00
|
|
|
AST::NodeVisitor.new self, source
|
2017-11-01 12:42:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test(source, node : Crystal::Call)
|
|
|
|
return unless node.name == "debugger" &&
|
|
|
|
node.args.empty? &&
|
|
|
|
node.obj.nil?
|
|
|
|
|
2018-04-17 04:29:43 +00:00
|
|
|
source.error self, node.location, MSG
|
2017-11-01 12:42:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|