Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
f648dd03
Commit
f648dd03
authored
7 years ago
by
Gautham Goli
Browse files
Options
Downloads
Patches
Plain Diff
lines_cop: Update regex patterns to prevent false positives
parent
7caca570
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/rubocops/lines_cop.rb
+18
-18
18 additions, 18 deletions
Library/Homebrew/rubocops/lines_cop.rb
Library/Homebrew/test/rubocops/lines_cop_spec.rb
+2
-2
2 additions, 2 deletions
Library/Homebrew/test/rubocops/lines_cop_spec.rb
with
20 additions
and
20 deletions
Library/Homebrew/rubocops/lines_cop.rb
+
18
−
18
View file @
f648dd03
...
...
@@ -105,25 +105,25 @@ module RuboCop
find_instance_method_call
(
body_node
,
:build
,
:without?
)
do
|
method
|
arg
=
parameters
(
method
).
first
next
unless
match
=
regex_match_group
(
arg
,
/-?-?without-(.*)/
)
next
unless
match
=
regex_match_group
(
arg
,
/
^
-?-?without-(.*)/
)
problem
"Don't duplicate 'without': Use `build.without?
\"
#{
match
[
1
]
}
\"
` to check for
\"
--without-
#{
match
[
1
]
}
\"
"
end
find_instance_method_call
(
body_node
,
:build
,
:with?
)
do
|
method
|
arg
=
parameters
(
method
).
first
next
unless
match
=
regex_match_group
(
arg
,
/-?-?with-(.*)/
)
next
unless
match
=
regex_match_group
(
arg
,
/
^
-?-?with-(.*)/
)
problem
"Don't duplicate 'with': Use `build.with?
\"
#{
match
[
1
]
}
\"
` to check for
\"
--with-
#{
match
[
1
]
}
\"
"
end
find_instance_method_call
(
body_node
,
:build
,
:include?
)
do
|
method
|
arg
=
parameters
(
method
).
first
next
unless
match
=
regex_match_group
(
arg
,
/with(out)?-(.*)/
)
next
unless
match
=
regex_match_group
(
arg
,
/
^
with(out)?-(.*)/
)
problem
"Use build.with
#{
match
[
1
]
}
?
\"
#{
match
[
2
]
}
\"
instead of build.include? 'with
#{
match
[
1
]
}
-
#{
match
[
2
]
}
'"
end
find_instance_method_call
(
body_node
,
:build
,
:include?
)
do
|
method
|
arg
=
parameters
(
method
).
first
next
unless
match
=
regex_match_group
(
arg
,
/\-\-(.*)/
)
next
unless
match
=
regex_match_group
(
arg
,
/
^
\-\-(.*)
$
/
)
problem
"Reference '
#{
match
[
1
]
}
' without dashes"
end
end
...
...
@@ -145,7 +145,7 @@ module RuboCop
# Check for long inreplace block vars
find_all_blocks
(
body_node
,
:inreplace
)
do
|
node
|
block_arg
=
node
.
arguments
.
children
.
first
next
unless
block_arg
.
source
.
size
>
1
next
unless
block_arg
.
source
.
size
>
1
problem
"
\"
inreplace <filenames> do |s|
\"
is preferred over
\"
|
#{
block_arg
.
source
}
|
\"
."
end
...
...
@@ -169,7 +169,7 @@ module RuboCop
end
find_instance_method_call
(
body_node
,
:man
,
:
+
)
do
|
method
|
next
unless
match
=
regex_match_group
(
parameters
(
method
).
first
,
/man[1-8]/
)
next
unless
match
=
regex_match_group
(
parameters
(
method
).
first
,
/
^
man[1-8]
$
/
)
problem
"
\"
#{
method
.
source
}
\"
should be
\"
#{
match
[
0
]
}
\"
"
end
...
...
@@ -194,18 +194,18 @@ module RuboCop
# Prefer formula path shortcuts in strings
formula_path_strings
(
body_node
,
:share
)
do
|
p
|
next
unless
match
=
regex_match_group
(
p
,
%r{(/(man))/?}
)
next
unless
match
=
regex_match_group
(
p
,
%r{
^
(/(man))/?}
)
problem
"
\"\#
{share}
#{
match
[
1
]
}
\"
should be
\"\#
{
#{
match
[
2
]
}
}
\"
"
end
formula_path_strings
(
body_node
,
:prefix
)
do
|
p
|
if
match
=
regex_match_group
(
p
,
%r{(/share/(info|man))$}
)
if
match
=
regex_match_group
(
p
,
%r{
^
(/share/(info|man))$}
)
problem
"
\"\#\{
prefix}
#{
match
[
1
]
}
\"
should be
\"\#
{
#{
match
[
2
]
}
}
\"
"
end
if
match
=
regex_match_group
(
p
,
%r{((/share/man/)(man[1-8]))}
)
if
match
=
regex_match_group
(
p
,
%r{
^
((/share/man/)(man[1-8]))}
)
problem
"
\"\#\{
prefix}
#{
match
[
1
]
}
\"
should be
\"\#
{
#{
match
[
3
]
}
}
\"
"
end
if
match
=
regex_match_group
(
p
,
%r{(/(bin|include|libexec|lib|sbin|share|Frameworks))}i
)
if
match
=
regex_match_group
(
p
,
%r{
^
(/(bin|include|libexec|lib|sbin|share|Frameworks))}i
)
problem
"
\"\#\{
prefix}
#{
match
[
1
]
}
\"
should be
\"\#
{
#{
match
[
2
].
downcase
}
}
\"
"
end
end
...
...
@@ -213,12 +213,12 @@ module RuboCop
find_every_method_call_by_name
(
body_node
,
:depends_on
).
each
do
|
method
|
key
,
value
=
destructure_hash
(
parameters
(
method
).
first
)
next
if
key
.
nil?
||
value
.
nil?
next
unless
match
=
regex_match_group
(
value
,
/(lua|perl|python|ruby)(\d*)/
)
next
unless
match
=
regex_match_group
(
value
,
/
^
(lua|perl|python|ruby)(\d*)/
)
problem
"
#{
match
[
1
]
}
modules should be vendored rather than use deprecated
#{
method
.
source
}
`"
end
find_every_method_call_by_name
(
body_node
,
:system
).
each
do
|
method
|
next
unless
match
=
regex_match_group
(
parameters
(
method
).
first
,
/(env|export)(\s+)?/
)
next
unless
match
=
regex_match_group
(
parameters
(
method
).
first
,
/
^
(env|export)(\s+)?/
)
problem
"Use ENV instead of invoking '
#{
match
[
1
]
}
' to modify the environment"
end
...
...
@@ -243,7 +243,7 @@ module RuboCop
find_instance_method_call
(
body_node
,
"ARGV"
,
:include?
)
do
|
method
|
param
=
parameters
(
method
).
first
next
unless
match
=
regex_match_group
(
param
,
/--(HEAD|devel)/
)
next
unless
match
=
regex_match_group
(
param
,
/
^
--(HEAD|devel)/
)
problem
"Use
\"
if build.
#{
match
[
1
].
downcase
}
?
\"
instead"
end
...
...
@@ -258,14 +258,14 @@ module RuboCop
conditional_dependencies
(
body_node
)
do
|
node
,
method
,
param
,
dep_node
|
dep
=
string_content
(
dep_node
)
if
node
.
if?
if
(
method
==
:include?
&&
regex_match_group
(
param
,
/with-
#{
dep
}
$/
))
||
(
method
==
:with?
&&
regex_match_group
(
param
,
/
#{
dep
}
$/
))
if
(
method
==
:include?
&&
regex_match_group
(
param
,
/
^
with-
#{
dep
}
$/
))
||
(
method
==
:with?
&&
regex_match_group
(
param
,
/
^
#{
dep
}
$/
))
offending_node
(
dep_node
.
parent
)
problem
"Replace
#{
node
.
source
}
with
#{
dep_node
.
parent
.
source
}
=> :optional"
end
elsif
node
.
unless?
if
(
method
==
:include?
&&
regex_match_group
(
param
,
/without-
#{
dep
}
$/
))
||
(
method
==
:without?
&&
regex_match_group
(
param
,
/
#{
dep
}
$/
))
if
(
method
==
:include?
&&
regex_match_group
(
param
,
/
^
without-
#{
dep
}
$/
))
||
(
method
==
:without?
&&
regex_match_group
(
param
,
/
^
#{
dep
}
$/
))
offending_node
(
dep_node
.
parent
)
problem
"Replace
#{
node
.
source
}
with
#{
dep_node
.
parent
.
source
}
=> :recommended"
end
...
...
@@ -276,7 +276,7 @@ module RuboCop
problem
"'fails_with :llvm' is now a no-op so should be removed"
end
find_method_with_args
(
body_node
,
:system
,
/(otool|install_name_tool|lipo)/
)
do
find_method_with_args
(
body_node
,
:system
,
/
^
(otool|install_name_tool|lipo)/
)
do
next
if
@formula_name
==
"cctools"
problem
"Use ruby-macho instead of calling
#{
@offensive_node
.
source
}
"
end
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/rubocops/lines_cop_spec.rb
+
2
−
2
View file @
f648dd03
...
...
@@ -762,8 +762,8 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
depends_on "foo" if build.with? "
with-
foo"
^^^^^^^^^^^^^^^^ Replace depends_on "foo" if build.with? "
with-
foo" with depends_on "foo" => :optional
depends_on "foo" if build.with? "foo"
^^^^^^^^^^^^^^^^ Replace depends_on "foo" if build.with? "foo" with depends_on "foo" => :optional
end
RUBY
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment