Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Rake/Desc to not require description for the default task #11

Merged
merged 3 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-09-17 22:35:51 +0900 using RuboCop version 0.74.0.
# on 2019-09-18 21:43:54 +0900 using RuboCop version 0.74.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Configuration parameters: Include.
# Include: Rakefile, **/*.rake
Rake/Desc:
Exclude:
- 'Rakefile'
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#8](https://github.com/pocke/rubocop-rake/issues/8): Make Rake/Desc to not require description for the default task. ([@pocke][])

<!--

### New features
Expand All @@ -16,7 +20,7 @@

### New features

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

## 0.1.0 (2019-09-04)

Expand Down
21 changes: 21 additions & 0 deletions lib/rubocop/cop/rake/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Rake
# It is useful as a documentation of task. And Rake does not display
# task that does not have `desc` by `rake -T`.
#
# Note: This cop does not require description for the default task,
# because the default task is executed with `rake` without command.
#
# @example
# # bad
# task :do_something
Expand Down Expand Up @@ -34,6 +37,7 @@ class Desc < Cop
def on_send(node)
return unless task?(node)
return if task_with_desc?(node)
return if task_name(node) == :default

add_offense(node)
end
Expand All @@ -49,6 +53,23 @@ def on_send(node)
desc_candidate.send_type? && desc_candidate.method_name == :desc
end

private def task_name(node)
first_arg = node.arguments[0]
case first_arg&.type
when :sym, :str
return first_arg.value.to_sym
when :hash
return nil if first_arg.children.size != 1

pair = first_arg.children.first
key = pair.children.first
case key.type
when :sym, :str
key.value.to_sym
end
end
end

private def parent_and_task(task_node)
parent = task_node.parent
return nil, task_node unless parent
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rake/desc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@
task :bar
RUBY
end

it 'do not register an offense for the default task' do
expect_no_offenses(<<~RUBY)
task default: :spec

task default: [:spec, :rubocop]
RUBY
end
end