audit: Port classname and template comments audit rules from line_problems method to rubocop
This commit is contained in:
parent
f57a172cd2
commit
bc2bcef1ba
@ -809,28 +809,6 @@ class FormulaAuditor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def line_problems(line, _lineno)
|
def line_problems(line, _lineno)
|
||||||
if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/
|
|
||||||
problem "Use a space in class inheritance: class Foo < #{Regexp.last_match(1)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Commented-out cmake support from default template
|
|
||||||
problem "Commented cmake call found" if line.include?('# system "cmake')
|
|
||||||
|
|
||||||
# Comments from default template
|
|
||||||
[
|
|
||||||
"# PLEASE REMOVE",
|
|
||||||
"# Documentation:",
|
|
||||||
"# if this fails, try separate make/make install steps",
|
|
||||||
"# The URL of the archive",
|
|
||||||
"## Naming --",
|
|
||||||
"# if your formula requires any X11/XQuartz components",
|
|
||||||
"# if your formula fails when building in parallel",
|
|
||||||
"# Remove unrecognized options if warned by configure",
|
|
||||||
].each do |comment|
|
|
||||||
next unless line.include?(comment)
|
|
||||||
problem "Please remove default template comments"
|
|
||||||
end
|
|
||||||
|
|
||||||
# FileUtils is included in Formula
|
# FileUtils is included in Formula
|
||||||
# encfs modifies a file with this name, so check for some leading characters
|
# encfs modifies a file with this name, so check for some leading characters
|
||||||
if line =~ %r{[^'"/]FileUtils\.(\w+)}
|
if line =~ %r{[^'"/]FileUtils\.(\w+)}
|
||||||
@ -891,9 +869,6 @@ class FormulaAuditor
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Commented-out depends_on
|
|
||||||
problem "Commented-out dep #{Regexp.last_match(1)}" if line =~ /#\s*depends_on\s+(.+)\s*$/
|
|
||||||
|
|
||||||
if line =~ /if\s+ARGV\.include\?\s+'--(HEAD|devel)'/
|
if line =~ /if\s+ARGV\.include\?\s+'--(HEAD|devel)'/
|
||||||
problem "Use \"if build.#{Regexp.last_match(1).downcase}?\" instead"
|
problem "Use \"if build.#{Regexp.last_match(1).downcase}?\" instead"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -302,6 +302,15 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Yields to a block with comment text as parameter
|
||||||
|
def audit_comments
|
||||||
|
@processed_source.comments.each do |comment_node|
|
||||||
|
@offensive_node = comment_node
|
||||||
|
@offense_source_range = :expression
|
||||||
|
yield comment_node.text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the begin position of the node's line in source code
|
# Returns the begin position of the node's line in source code
|
||||||
def line_start_column(node)
|
def line_start_column(node)
|
||||||
node.source_range.source_buffer.line_range(node.loc.line).begin_pos
|
node.source_range.source_buffer.line_range(node.loc.line).begin_pos
|
||||||
@ -312,6 +321,11 @@ module RuboCop
|
|||||||
node.source_range.begin_pos
|
node.source_range.begin_pos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the ending position of the node in source code
|
||||||
|
def end_column(node)
|
||||||
|
node.source_range.end_pos
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the line number of the node
|
# Returns the line number of the node
|
||||||
def line_number(node)
|
def line_number(node)
|
||||||
node.loc.line
|
node.loc.line
|
||||||
|
|||||||
@ -15,6 +15,49 @@ module RuboCop
|
|||||||
problem ":tex is deprecated" if depends_on?(:tex)
|
problem ":tex is deprecated" if depends_on?(:tex)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class ClassInheritance < FormulaCop
|
||||||
|
def audit_formula(_node, class_node, parent_class_node, _body_node)
|
||||||
|
begin_pos = start_column(parent_class_node)
|
||||||
|
end_pos = end_column(class_node)
|
||||||
|
return unless begin_pos-end_pos != 3
|
||||||
|
problem "Use a space in class inheritance: class #{@formula_name} < #{class_name(parent_class_node)}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Comments < FormulaCop
|
||||||
|
def audit_formula(_node, _class_node, _parent_class_node, _body_node)
|
||||||
|
# Commented-out cmake support from default template
|
||||||
|
audit_comments do |comment|
|
||||||
|
next unless comment.include?('# system "cmake')
|
||||||
|
problem "Commented cmake call found"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Comments from default template
|
||||||
|
audit_comments do |comment|
|
||||||
|
[
|
||||||
|
"# PLEASE REMOVE",
|
||||||
|
"# Documentation:",
|
||||||
|
"# if this fails, try separate make/make install steps",
|
||||||
|
"# The URL of the archive",
|
||||||
|
"## Naming --",
|
||||||
|
"# if your formula requires any X11/XQuartz components",
|
||||||
|
"# if your formula fails when building in parallel",
|
||||||
|
"# Remove unrecognized options if warned by configure",
|
||||||
|
].each do |template_comment|
|
||||||
|
next unless comment.include?(template_comment)
|
||||||
|
problem "Please remove default template comments"
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
audit_comments do |comment|
|
||||||
|
# Commented-out depends_on
|
||||||
|
next unless comment =~ /#\s*depends_on\s+(.+)\s*$/
|
||||||
|
problem "Commented-out dep #{Regexp.last_match(1)}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user