File tree 4 files changed +35
-9
lines changed
4 files changed +35
-9
lines changed Original file line number Diff line number Diff line change 1
1
# This configuration was generated by
2
2
# `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.
4
4
# The point is for the user to remove these configuration records
5
5
# one by one as the offenses are removed from the code base.
6
6
# Note that changes in the inspected code, or installation of new
7
7
# 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'
Original file line number Diff line number Diff line change 2
2
3
3
## master (unreleased)
4
4
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
+
5
9
<!--
6
10
7
11
### New features
16
20
17
21
### New features
18
22
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 ] [ ] )
20
24
21
25
## 0.1.0 (2019-09-04)
22
26
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ module Rake
7
7
# It is useful as a documentation of task. And Rake does not display
8
8
# task that does not have `desc` by `rake -T`.
9
9
#
10
+ # Note: This cop does not require description for the default task,
11
+ # because the default task is executed with `rake` without command.
12
+ #
10
13
# @example
11
14
# # bad
12
15
# task :do_something
@@ -34,6 +37,7 @@ class Desc < Cop
34
37
def on_send ( node )
35
38
return unless task? ( node )
36
39
return if task_with_desc? ( node )
40
+ return if task_name ( node ) == :default
37
41
38
42
add_offense ( node )
39
43
end
@@ -49,6 +53,23 @@ def on_send(node)
49
53
desc_candidate . send_type? && desc_candidate . method_name == :desc
50
54
end
51
55
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
+
52
73
private def parent_and_task ( task_node )
53
74
parent = task_node . parent
54
75
return nil , task_node unless parent
Original file line number Diff line number Diff line change 44
44
task :bar
45
45
RUBY
46
46
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
47
55
end
You can’t perform that action at this time.
0 commit comments