Skip to content

Commit 0a4f009

Browse files
authored
Merge pull request #11 from pocke/desc-for-default-task
Make Rake/Desc to not require description for the default task
2 parents 3ac66ce + 7b4c71e commit 0a4f009

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

.rubocop_todo.yml

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-09-17 22:35:51 +0900 using RuboCop version 0.74.0.
3+
# on 2019-09-18 21:43:54 +0900 using RuboCop version 0.74.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
8-
9-
# Offense count: 1
10-
# Configuration parameters: Include.
11-
# Include: Rakefile, **/*.rake
12-
Rake/Desc:
13-
Exclude:
14-
- 'Rakefile'

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Bug fixes
6+
7+
* [#8](https://github.com/pocke/rubocop-rake/issues/8): Make Rake/Desc to not require description for the default task. ([@pocke][])
8+
59
<!--
610
711
### New features
@@ -16,7 +20,7 @@
1620

1721
### New features
1822

19-
* [#5](https://github.com/pocke/rubocop-rake): Add `Rake/MethodDefinitionInTask`. ([@pocke][])
23+
* [#5](https://github.com/pocke/rubocop-rake/pull/5): Add `Rake/MethodDefinitionInTask`. ([@pocke][])
2024

2125
## 0.1.0 (2019-09-04)
2226

lib/rubocop/cop/rake/desc.rb

+21
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Rake
77
# It is useful as a documentation of task. And Rake does not display
88
# task that does not have `desc` by `rake -T`.
99
#
10+
# Note: This cop does not require description for the default task,
11+
# because the default task is executed with `rake` without command.
12+
#
1013
# @example
1114
# # bad
1215
# task :do_something
@@ -34,6 +37,7 @@ class Desc < Cop
3437
def on_send(node)
3538
return unless task?(node)
3639
return if task_with_desc?(node)
40+
return if task_name(node) == :default
3741

3842
add_offense(node)
3943
end
@@ -49,6 +53,23 @@ def on_send(node)
4953
desc_candidate.send_type? && desc_candidate.method_name == :desc
5054
end
5155

56+
private def task_name(node)
57+
first_arg = node.arguments[0]
58+
case first_arg&.type
59+
when :sym, :str
60+
return first_arg.value.to_sym
61+
when :hash
62+
return nil if first_arg.children.size != 1
63+
64+
pair = first_arg.children.first
65+
key = pair.children.first
66+
case key.type
67+
when :sym, :str
68+
key.value.to_sym
69+
end
70+
end
71+
end
72+
5273
private def parent_and_task(task_node)
5374
parent = task_node.parent
5475
return nil, task_node unless parent

spec/rubocop/cop/rake/desc_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@
4444
task :bar
4545
RUBY
4646
end
47+
48+
it 'do not register an offense for the default task' do
49+
expect_no_offenses(<<~RUBY)
50+
task default: :spec
51+
52+
task default: [:spec, :rubocop]
53+
RUBY
54+
end
4755
end

0 commit comments

Comments
 (0)