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
c84b5f98
Commit
c84b5f98
authored
4 years ago
by
Rylan Polster
Browse files
Options
Downloads
Patches
Plain Diff
style: require `tag` and `revision` for git urls
parent
7af967de
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/urls.rb
+20
-0
20 additions, 0 deletions
Library/Homebrew/rubocops/urls.rb
Library/Homebrew/test/rubocops/urls_spec.rb
+120
-0
120 additions, 0 deletions
Library/Homebrew/test/rubocops/urls_spec.rb
with
140 additions
and
0 deletions
Library/Homebrew/rubocops/urls.rb
+
20
−
0
View file @
c84b5f98
...
...
@@ -315,6 +315,26 @@ module RuboCop
"https://pypi.org/project/
#{
package_name
}
/#files"
end
end
# This cop makes sure that git urls have both a `tag` and `revision`.
#
# @api private
class
GitUrls
<
FormulaCop
def
audit_formula
(
_node
,
_class_node
,
_parent_class_node
,
body_node
)
find_method_calls_by_name
(
body_node
,
:url
).
each
do
|
url
|
next
unless
string_content
(
parameters
(
url
).
first
).
match?
(
/\.git$/
)
next
if
url_has_tag_and_revision?
(
parameters
(
url
).
last
)
offending_node
(
url
)
problem
"Specify a `tag` and `revision` for git urls"
end
end
def_node_matcher
:url_has_tag_and_revision?
,
<<~
EOS
(hash <(pair (sym :tag) str) (pair (sym :revision) str) ...>)
EOS
end
end
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/rubocops/urls_spec.rb
+
120
−
0
View file @
c84b5f98
...
...
@@ -276,3 +276,123 @@ describe RuboCop::Cop::FormulaAudit::PyPiUrls do
end
end
end
describe
RuboCop
::
Cop
::
FormulaAudit
::
GitUrls
do
subject
(
:cop
)
{
described_class
.
new
}
context
"when a git URL is used"
do
it
"reports no offenses with a non-git url"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://foo.com"
end
RUBY
end
it
"reports no offenses with both a tag and a revision"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
tag: "v1.0.0",
revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
end
RUBY
end
it
"reports no offenses with both a tag, revision and `shallow` before"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
shallow: false,
tag: "v1.0.0",
revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
end
RUBY
end
it
"reports no offenses with both a tag, revision and `shallow` after"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
tag: "v1.0.0",
revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
shallow: false
end
RUBY
end
it
"reports an offense with no `revision`"
do
expect_offense
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specify a `tag` and `revision` for git urls
tag: "v1.0.0"
end
RUBY
end
it
"reports an offense with no `revision` and `shallow`"
do
expect_offense
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specify a `tag` and `revision` for git urls
shallow: false,
tag: "v1.0.0"
end
RUBY
end
it
"reports an offense with no `tag`"
do
expect_offense
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specify a `tag` and `revision` for git urls
revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
end
RUBY
end
it
"reports an offense with no `tag` and `shallow`"
do
expect_offense
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://github.com/foo/bar.git",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specify a `tag` and `revision` for git urls
revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
shallow: false
end
RUBY
end
it
"reports no offenses with missing arguments in `head`"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://foo.com"
head do
url "https://github.com/foo/bar.git"
end
end
RUBY
end
it
"reports no offenses with missing arguments in `devel`"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
desc "foo"
url "https://foo.com"
devel do
url "https://github.com/foo/bar.git"
end
end
RUBY
end
end
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