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
b1c374b7
Commit
b1c374b7
authored
4 years ago
by
Rylan Polster
Browse files
Options
Downloads
Patches
Plain Diff
style: fix deprecation date check
parent
9bbd866f
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/deprecate.rb
+8
-6
8 additions, 6 deletions
Library/Homebrew/rubocops/deprecate.rb
Library/Homebrew/test/rubocops/deprecate_spec.rb
+54
-7
54 additions, 7 deletions
Library/Homebrew/test/rubocops/deprecate_spec.rb
with
62 additions
and
13 deletions
Library/Homebrew/rubocops/deprecate.rb
+
8
−
6
View file @
b1c374b7
...
...
@@ -5,16 +5,14 @@ require "rubocops/extend/formula"
module
RuboCop
module
Cop
module
FormulaAudit
# This cop audits deprecate!
class
Deprecate
<
FormulaCop
# This cop audits deprecate!
date
class
Deprecate
Date
<
FormulaCop
def
audit_formula
(
_node
,
_class_node
,
_parent_class_node
,
body_node
)
deprecate_node
=
find_node_method_by_name
(
body_node
,
:deprecate!
)
return
if
deprecate_node
.
nil?
||
deprecate_node
.
children
.
length
<
3
return
if
deprecate_node
.
nil?
date_node
=
find_strings
(
deprecate_node
).
first
begin
deprecate_date
(
deprecate_node
)
do
|
date_node
|
Date
.
iso8601
(
string_content
(
date_node
))
rescue
ArgumentError
fixed_date_string
=
Date
.
parse
(
string_content
(
date_node
)).
iso8601
...
...
@@ -29,6 +27,10 @@ module RuboCop
corrector
.
replace
(
node
.
source_range
,
"
\"
#{
fixed_fixed_date_string
}
\"
"
)
end
end
def_node_search
:deprecate_date
,
<<~
EOS
(pair (sym :date) $str)
EOS
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/rubocops/deprecate_spec.rb
+
54
−
7
View file @
b1c374b7
...
...
@@ -2,16 +2,26 @@
require
"rubocops/deprecate"
describe
RuboCop
::
Cop
::
FormulaAudit
::
Deprecate
do
describe
RuboCop
::
Cop
::
FormulaAudit
::
Deprecate
Date
do
subject
(
:cop
)
{
described_class
.
new
}
context
"When auditing formula for deprecate!"
do
context
"When auditing formula for deprecate!
date:
"
do
it
"deprecation date is not ISO 8601 compliant"
do
expect_offense
(
<<~
RUBY
)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! :date => "June 25, 2020"
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
deprecate! date: "June 25, 2020"
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
end
RUBY
end
it
"deprecation date is not ISO 8601 compliant with reason"
do
expect_offense
(
<<~
RUBY
)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken", date: "June 25, 2020"
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
end
RUBY
end
...
...
@@ -20,7 +30,16 @@ describe RuboCop::Cop::FormulaAudit::Deprecate do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! :date => "2020-06-25"
deprecate! date: "2020-06-25"
end
RUBY
end
it
"deprecation date is ISO 8601 compliant with reason"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken", date: "2020-06-25"
end
RUBY
end
...
...
@@ -34,18 +53,46 @@ describe RuboCop::Cop::FormulaAudit::Deprecate do
RUBY
end
it
"no deprecation date with reason"
do
expect_no_offenses
(
<<~
RUBY
)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken"
end
RUBY
end
it
"auto corrects to ISO 8601 format"
do
source
=
<<~
RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! :date => "June 25, 2020"
deprecate! date: "June 25, 2020"
end
RUBY
corrected_source
=
<<~
RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! date: "2020-06-25"
end
RUBY
new_source
=
autocorrect_source
(
source
)
expect
(
new_source
).
to
eq
(
corrected_source
)
end
it
"auto corrects to ISO 8601 format with reason"
do
source
=
<<~
RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken", date: "June 25, 2020"
end
RUBY
corrected_source
=
<<~
RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate!
:
date
=>
"2020-06-25"
deprecate!
because: "is broken",
date
:
"2020-06-25"
end
RUBY
...
...
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