audit: detect more 'pkgshare' candidates (#328)

The new check also allows the `+` operator instead of our (still heavily
preferred) `/` operator for path concatenation and also triggers if the
operator is surrounded by whitespace.

Also recognizes single-quoted strings and uses a back reference to
match the closing quote for a slightly lower chance of false positives.

Closes #322.
This commit is contained in:
Martin Afanasjew 2016-06-07 17:46:40 +02:00
parent 2cd81e5051
commit af42deca4a

View File

@ -919,8 +919,8 @@ class FormulaAuditor
problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}"
end
if line =~ %r{share/"#{Regexp.escape(formula.name)}[/'"]}
problem "Use pkgshare instead of (share/\"#{formula.name}\")"
if line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)}
problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")"
end
end
end