rubocop-rake 0.3.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +44 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +17 -2
- data/CHANGELOG.md +33 -7
- data/Gemfile +1 -0
- data/README.md +6 -3
- data/config/default.yml +16 -6
- data/lib/rubocop-rake.rb +3 -0
- data/lib/rubocop/cop/rake/class_definition_in_task.rb +2 -6
- data/lib/rubocop/cop/rake/desc.rb +19 -28
- data/lib/rubocop/cop/rake/duplicate_namespace.rb +84 -0
- data/lib/rubocop/cop/rake/duplicate_task.rb +83 -0
- data/lib/rubocop/cop/rake/helper/on_namespace.rb +23 -0
- data/lib/rubocop/cop/rake/helper/on_task.rb +23 -0
- data/lib/rubocop/cop/rake/helper/task_name.rb +30 -0
- data/lib/rubocop/cop/rake/method_definition_in_task.rb +1 -1
- data/lib/rubocop/cop/rake_cops.rb +2 -0
- data/lib/rubocop/rake/inject.rb +2 -2
- data/lib/rubocop/rake/version.rb +1 -1
- data/rubocop-rake.gemspec +4 -4
- metadata +21 -16
- data/.travis.yml +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a878d5ccc2eec701b39d7d2ee54cbee2eeafc822d0fdd9ebb1bd24174f62eb6e
|
4
|
+
data.tar.gz: 137d23f7a93f25c027872cff22cca183e87b3c57a34b63a970a6687101a2ea69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67ef6e06e7704cac677af3256d2a14c15729b521a2873d971bf0339eed83bdb04019ea7302cc35b8a461469c52c77382da35d2fca1e7d022cd471a10a832bfa4
|
7
|
+
data.tar.gz: 111a3788568c30c1588e4aa4108cce2c5d8a4eae21d9f11d897f19fa44495486933edbd8ca0945d63b8daefcc1551e74e69197a02c7006c1f1bf0f57da79f9fa
|
@@ -0,0 +1,44 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
steps: &steps
|
4
|
+
steps:
|
5
|
+
- checkout
|
6
|
+
- run: bundle install
|
7
|
+
- run: bundle exec rake
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
|
11
|
+
ruby-2.5:
|
12
|
+
docker:
|
13
|
+
- image: circleci/ruby:2.5
|
14
|
+
<<: *steps
|
15
|
+
|
16
|
+
ruby-2.6:
|
17
|
+
docker:
|
18
|
+
- image: circleci/ruby:2.6
|
19
|
+
<<: *steps
|
20
|
+
|
21
|
+
ruby-2.7:
|
22
|
+
docker:
|
23
|
+
- image: circleci/ruby:2.7
|
24
|
+
<<: *steps
|
25
|
+
|
26
|
+
ruby-3.0:
|
27
|
+
docker:
|
28
|
+
- image: circleci/ruby:3.0
|
29
|
+
<<: *steps
|
30
|
+
|
31
|
+
ruby-head:
|
32
|
+
docker:
|
33
|
+
- image: rubocophq/circleci-ruby-snapshot:latest
|
34
|
+
<<: *steps
|
35
|
+
|
36
|
+
workflows:
|
37
|
+
version: 2
|
38
|
+
build:
|
39
|
+
jobs:
|
40
|
+
- ruby-2.5
|
41
|
+
- ruby-2.6
|
42
|
+
- ruby-2.7
|
43
|
+
- ruby-3.0
|
44
|
+
- ruby-head
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
|
3
3
|
require:
|
4
|
+
- rubocop/cop/internal_affairs
|
4
5
|
- rubocop-rake
|
5
6
|
- rubocop-rspec
|
6
7
|
|
7
8
|
AllCops:
|
8
|
-
TargetRubyVersion: 2.
|
9
|
+
TargetRubyVersion: 2.5
|
10
|
+
|
11
|
+
InternalAffairs/NodeMatcherDirective:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Enabled: false
|
9
16
|
|
10
17
|
Metrics:
|
11
18
|
Enabled: false
|
@@ -19,7 +26,7 @@ Style/AccessModifierDeclarations:
|
|
19
26
|
Style/NumericPredicate:
|
20
27
|
Enabled: false
|
21
28
|
|
22
|
-
Style/
|
29
|
+
Style/RedundantPercentQ:
|
23
30
|
Exclude:
|
24
31
|
- '*.gemspec'
|
25
32
|
|
@@ -33,9 +40,17 @@ Style/PercentLiteralDelimiters:
|
|
33
40
|
Exclude:
|
34
41
|
- '*.gemspec'
|
35
42
|
|
43
|
+
Style/TrailingCommaInArguments:
|
44
|
+
EnforcedStyleForMultiline: comma
|
45
|
+
|
36
46
|
RSpec/ExampleLength:
|
37
47
|
Enabled: false
|
38
48
|
|
39
49
|
Naming/FileName:
|
40
50
|
Exclude:
|
41
51
|
- 'lib/rubocop-rake.rb'
|
52
|
+
|
53
|
+
# This disabling is a workaround for https://github.com/rubocop-hq/rubocop-rspec/issues/1068.
|
54
|
+
# The cop has been disabled because FactoryBot is not used in this repository.
|
55
|
+
RSpec/FactoryBot/CreateList:
|
56
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -2,31 +2,54 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
-
|
5
|
+
## 0.6.0 (2021-06-29)
|
6
6
|
|
7
|
-
###
|
7
|
+
### Changes
|
8
|
+
|
9
|
+
* [#33](https://github.com/rubocop/rubocop-rake/pull/33): Drop support for Ruby 2.3. ([@koic][])
|
10
|
+
* [#34](https://github.com/rubocop/rubocop-rake/pull/34): Require RuboCop 1.0 or higher. ([@koic][])
|
11
|
+
* [#38](https://github.com/rubocop/rubocop-rake/pull/37): Drop support for Ruby 2.4. ([@tejasbubane])
|
12
|
+
* [#36](https://github.com/rubocop/rubocop-rake/issues/36): Fix `Rake/Desc` to not generate offense for prerequisite declarations. ([@tejasbubane][])
|
13
|
+
|
14
|
+
## 0.5.1 (2020-02-14)
|
8
15
|
|
9
16
|
### Bug fixes
|
10
17
|
|
11
|
-
|
18
|
+
* [#28](https://github.com/rubocop/rubocop-rake/issues/28): Fix `Rake/Desc` to avoid an error when `task` is not a task definition. ([@pocke][])
|
19
|
+
|
20
|
+
## 0.5.0 (2019-10-31)
|
21
|
+
|
22
|
+
### New features
|
23
|
+
|
24
|
+
* [#14](https://github.com/rubocop/rubocop-rake/issues/14): Add Rake/DuplicateNamespace cop. ([@jaruuuu][])
|
25
|
+
|
26
|
+
## 0.4.0 (2019-10-13)
|
27
|
+
|
28
|
+
### New features
|
29
|
+
|
30
|
+
* [#13](https://github.com/rubocop/rubocop-rake/issues/13): Add Rake/DuplicateTask cop. ([@pocke][])
|
31
|
+
|
32
|
+
## 0.3.1 (2019-10-06)
|
33
|
+
|
34
|
+
### Bug fixes
|
12
35
|
|
13
|
-
|
36
|
+
* [#17](https://github.com/rubocop/rubocop-rake/pull/17): Filter target files for Rake/ClassDefinitionInTask cop. ([@pocke][])
|
14
37
|
|
15
38
|
## 0.3.0 (2019-09-25)
|
16
39
|
|
17
40
|
### New features
|
18
41
|
|
19
|
-
* [#6](https://github.com/rubocop
|
42
|
+
* [#6](https://github.com/rubocop/rubocop-rake/issues/6): Add `Rake/ClassDefinitionInTask` cop. ([@pocke][])
|
20
43
|
|
21
44
|
### Bug fixes
|
22
45
|
|
23
|
-
* [#8](https://github.com/rubocop
|
46
|
+
* [#8](https://github.com/rubocop/rubocop-rake/issues/8): Make Rake/Desc to not require description for the default task. ([@pocke][])
|
24
47
|
|
25
48
|
## 0.2.0 (2019-09-17)
|
26
49
|
|
27
50
|
### New features
|
28
51
|
|
29
|
-
* [#5](https://github.com/rubocop
|
52
|
+
* [#5](https://github.com/rubocop/rubocop-rake/pull/5): Add `Rake/MethodDefinitionInTask`. ([@pocke][])
|
30
53
|
|
31
54
|
## 0.1.0 (2019-09-04)
|
32
55
|
|
@@ -36,3 +59,6 @@
|
|
36
59
|
* Add `Rake/Desc`. ([@pocke][])
|
37
60
|
|
38
61
|
[@pocke]: https://github.com/pocke
|
62
|
+
[@jaruuuu]: https://github.com/jaruuuu
|
63
|
+
[@koic]: https://github.com/koic
|
64
|
+
[@tejasbubane]: https://github.com/tejasbubane
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/rubocop-rake.svg)](https://rubygems.org/gems/rubocop-rake)
|
2
|
+
[![CircleCI](https://circleci.com/gh/rubocop/rubocop-rake.svg?style=svg)](https://circleci.com/gh/rubocop/rubocop-rake)
|
3
|
+
|
1
4
|
# RuboCop Rake
|
2
5
|
|
3
|
-
A [RuboCop](https://github.com/rubocop
|
6
|
+
A [RuboCop](https://github.com/rubocop/rubocop) plugin for Rake.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
8
11
|
|
9
12
|
```ruby
|
10
|
-
gem 'rubocop-rake'
|
13
|
+
gem 'rubocop-rake', require: false
|
11
14
|
```
|
12
15
|
|
13
16
|
And then execute:
|
@@ -34,5 +37,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
37
|
|
35
38
|
## Contributing
|
36
39
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop/rubocop-rake.
|
38
41
|
|
data/config/default.yml
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Rake:
|
2
|
+
Enabled: true
|
3
|
+
Include:
|
4
|
+
- 'Rakefile'
|
5
|
+
- '**/*.rake'
|
6
|
+
|
1
7
|
Rake/ClassDefinitionInTask:
|
2
8
|
Description: 'Do not define a class or module in rake task, because it will be defined to the top level.'
|
3
9
|
Enabled: true
|
@@ -7,14 +13,18 @@ Rake/Desc:
|
|
7
13
|
Description: 'Describe the task with `desc` method.'
|
8
14
|
Enabled: true
|
9
15
|
VersionAdded: '0.1.0'
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
|
17
|
+
Rake/DuplicateNamespace:
|
18
|
+
Description: 'Do not define namespace with the same name'
|
19
|
+
Enabled: true
|
20
|
+
VersionAdded: '0.5.0'
|
21
|
+
|
22
|
+
Rake/DuplicateTask:
|
23
|
+
Description: 'Do not define tasks with the same name'
|
24
|
+
Enabled: true
|
25
|
+
VersionAdded: '0.4.0'
|
13
26
|
|
14
27
|
Rake/MethodDefinitionInTask:
|
15
28
|
Description: 'Do not define a method in rake task, because it will be defined to the top level.'
|
16
29
|
Enabled: true
|
17
30
|
VersionAdded: '0.2.0'
|
18
|
-
Include:
|
19
|
-
- 'Rakefile'
|
20
|
-
- '**/*.rake'
|
data/lib/rubocop-rake.rb
CHANGED
@@ -9,5 +9,8 @@ require_relative 'rubocop/rake/inject'
|
|
9
9
|
RuboCop::Rake::Inject.defaults!
|
10
10
|
|
11
11
|
require_relative 'rubocop/cop/rake/helper/class_definition'
|
12
|
+
require_relative 'rubocop/cop/rake/helper/on_task'
|
12
13
|
require_relative 'rubocop/cop/rake/helper/task_definition'
|
14
|
+
require_relative 'rubocop/cop/rake/helper/task_name'
|
15
|
+
require_relative 'rubocop/cop/rake/helper/on_namespace'
|
13
16
|
require_relative 'rubocop/cop/rake_cops'
|
@@ -28,18 +28,14 @@ module RuboCop
|
|
28
28
|
# task :foo do
|
29
29
|
# end
|
30
30
|
#
|
31
|
-
class ClassDefinitionInTask <
|
31
|
+
class ClassDefinitionInTask < Base
|
32
32
|
MSG = 'Do not define a %<type>s in rake task, because it will be defined to the top level.'
|
33
33
|
|
34
34
|
def on_class(node)
|
35
35
|
return if Helper::ClassDefinition.in_class_definition?(node)
|
36
36
|
return unless Helper::TaskDefinition.in_task_or_namespace?(node)
|
37
37
|
|
38
|
-
add_offense(node)
|
39
|
-
end
|
40
|
-
|
41
|
-
def message(node)
|
42
|
-
format(MSG, type: node.type)
|
38
|
+
add_offense(node, message: format(MSG, type: node.type))
|
43
39
|
end
|
44
40
|
|
45
41
|
alias on_module on_class
|
@@ -27,17 +27,22 @@ module RuboCop
|
|
27
27
|
# task :do_something do
|
28
28
|
# end
|
29
29
|
#
|
30
|
-
class Desc <
|
30
|
+
class Desc < Base
|
31
|
+
include Helper::OnTask
|
32
|
+
extend AutoCorrector
|
33
|
+
|
31
34
|
MSG = 'Describe the task with `desc` method.'
|
32
35
|
|
33
|
-
def_node_matcher :
|
34
|
-
(send nil? :task
|
36
|
+
def_node_matcher :prerequisites, <<~PATTERN
|
37
|
+
(send nil? :task (hash (pair _ $_)))
|
35
38
|
PATTERN
|
36
39
|
|
37
|
-
def
|
38
|
-
return unless task?(node)
|
40
|
+
def on_task(node)
|
39
41
|
return if task_with_desc?(node)
|
40
|
-
return if task_name(node) == :default
|
42
|
+
return if Helper::TaskName.task_name(node) == :default
|
43
|
+
|
44
|
+
requirements = prerequisites(node)
|
45
|
+
return if requirements&.array_type?
|
41
46
|
|
42
47
|
add_offense(node)
|
43
48
|
end
|
@@ -45,29 +50,13 @@ module RuboCop
|
|
45
50
|
private def task_with_desc?(node)
|
46
51
|
parent, task = parent_and_task(node)
|
47
52
|
return false unless parent
|
53
|
+
return true unless can_insert_desc_to?(parent)
|
48
54
|
|
49
55
|
idx = parent.children.find_index(task) - 1
|
50
56
|
desc_candidate = parent.children[idx]
|
51
57
|
return false unless desc_candidate
|
52
58
|
|
53
|
-
desc_candidate.send_type? && desc_candidate.
|
54
|
-
end
|
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
|
59
|
+
desc_candidate.send_type? && desc_candidate.method?(:desc)
|
71
60
|
end
|
72
61
|
|
73
62
|
private def parent_and_task(task_node)
|
@@ -75,15 +64,17 @@ module RuboCop
|
|
75
64
|
return nil, task_node unless parent
|
76
65
|
return parent, task_node unless parent.block_type?
|
77
66
|
|
78
|
-
# rubocop:disable Style/GuardClause
|
79
67
|
if parent.children.find_index(task_node) == 0
|
80
68
|
# when task {}
|
81
|
-
|
69
|
+
[parent.parent, parent]
|
82
70
|
else
|
83
71
|
# when something { task }
|
84
|
-
|
72
|
+
[parent, task_node]
|
85
73
|
end
|
86
|
-
|
74
|
+
end
|
75
|
+
|
76
|
+
private def can_insert_desc_to?(parent)
|
77
|
+
parent.begin_type? || parent.block_type? || parent.kwbegin_type?
|
87
78
|
end
|
88
79
|
end
|
89
80
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
# If namespaces are defined with the same name, Rake executes the both namespaces
|
7
|
+
# in definition order.
|
8
|
+
# It is redundant. You should squash them into one definition.
|
9
|
+
# This cop detects it.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# namespace :foo do
|
14
|
+
# task :bar do
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# namespace :foo do
|
18
|
+
# task :hoge do
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
# namespace :foo do
|
24
|
+
# task :bar do
|
25
|
+
# end
|
26
|
+
# task :hoge do
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
class DuplicateNamespace < Base
|
31
|
+
include Helper::OnNamespace
|
32
|
+
|
33
|
+
MSG = 'Namespace `%<namespace>s` is defined at both %<previous>s and %<current>s.'
|
34
|
+
|
35
|
+
def initialize(*)
|
36
|
+
super
|
37
|
+
@namespaces = {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_namespace(node)
|
41
|
+
namespaces = namespaces(node)
|
42
|
+
return if namespaces.include?(nil)
|
43
|
+
|
44
|
+
full_name = namespaces.reverse.join(':')
|
45
|
+
if (previous = @namespaces[full_name])
|
46
|
+
message = message_for_dup(previous: previous, current: node, namespace: full_name)
|
47
|
+
add_offense(node, message: message)
|
48
|
+
else
|
49
|
+
@namespaces[full_name] = node
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def namespaces(node)
|
54
|
+
ns = []
|
55
|
+
|
56
|
+
node.each_ancestor(:block) do |block_node|
|
57
|
+
send_node = block_node.send_node
|
58
|
+
next unless send_node.method?(:namespace)
|
59
|
+
|
60
|
+
name = Helper::TaskName.task_name(send_node)
|
61
|
+
ns << name
|
62
|
+
end
|
63
|
+
|
64
|
+
ns
|
65
|
+
end
|
66
|
+
|
67
|
+
def message_for_dup(previous:, current:, namespace:)
|
68
|
+
format(
|
69
|
+
MSG,
|
70
|
+
namespace: namespace,
|
71
|
+
previous: source_location(previous),
|
72
|
+
current: source_location(current),
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def source_location(node)
|
77
|
+
range = node.location.expression
|
78
|
+
path = smart_path(range.source_buffer.name)
|
79
|
+
"#{path}:#{range.line}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
# If tasks are defined with the same name, Rake executes the both tasks
|
7
|
+
# in definition order.
|
8
|
+
# It is misleading sometimes. You should squash them into one definition.
|
9
|
+
# This cop detects it.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
# task :foo do
|
14
|
+
# p 'foo 1'
|
15
|
+
# end
|
16
|
+
# task :foo do
|
17
|
+
# p 'foo 2'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# task :foo do
|
22
|
+
# p 'foo 1'
|
23
|
+
# p 'foo 2'
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
class DuplicateTask < Base
|
27
|
+
include Helper::OnTask
|
28
|
+
|
29
|
+
MSG = 'Task `%<task>s` is defined at both %<previous>s and %<current>s.'
|
30
|
+
|
31
|
+
def initialize(*)
|
32
|
+
super
|
33
|
+
@tasks = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_task(node)
|
37
|
+
namespaces = namespaces(node)
|
38
|
+
return if namespaces.include?(nil)
|
39
|
+
|
40
|
+
task_name = Helper::TaskName.task_name(node)
|
41
|
+
return unless task_name
|
42
|
+
|
43
|
+
full_name = [*namespaces.reverse, task_name].join(':')
|
44
|
+
if (previous = @tasks[full_name])
|
45
|
+
message = message_for_dup(previous: previous, current: node, task_name: full_name)
|
46
|
+
add_offense(node, message: message)
|
47
|
+
else
|
48
|
+
@tasks[full_name] = node
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def namespaces(node)
|
53
|
+
ns = []
|
54
|
+
|
55
|
+
node.each_ancestor(:block) do |block_node|
|
56
|
+
send_node = block_node.send_node
|
57
|
+
next unless send_node.method?(:namespace)
|
58
|
+
|
59
|
+
name = Helper::TaskName.task_name(send_node)
|
60
|
+
ns << name
|
61
|
+
end
|
62
|
+
|
63
|
+
ns
|
64
|
+
end
|
65
|
+
|
66
|
+
def message_for_dup(previous:, current:, task_name:)
|
67
|
+
format(
|
68
|
+
MSG,
|
69
|
+
task: task_name,
|
70
|
+
previous: source_location(previous),
|
71
|
+
current: source_location(current),
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
def source_location(node)
|
76
|
+
range = node.location.expression
|
77
|
+
path = smart_path(range.source_buffer.name)
|
78
|
+
"#{path}:#{range.line}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
module Helper
|
7
|
+
module OnNamespace
|
8
|
+
extend NodePattern::Macros
|
9
|
+
|
10
|
+
def_node_matcher :namespace?, <<~PATTERN
|
11
|
+
(send nil? :namespace ...)
|
12
|
+
PATTERN
|
13
|
+
|
14
|
+
def on_send(node)
|
15
|
+
return unless namespace?(node)
|
16
|
+
|
17
|
+
on_namespace(node)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
module Helper
|
7
|
+
module OnTask
|
8
|
+
extend NodePattern::Macros
|
9
|
+
|
10
|
+
def_node_matcher :task?, <<~PATTERN
|
11
|
+
(send nil? :task ...)
|
12
|
+
PATTERN
|
13
|
+
|
14
|
+
def on_send(node)
|
15
|
+
return unless task?(node)
|
16
|
+
|
17
|
+
on_task(node)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Rake
|
6
|
+
module Helper
|
7
|
+
module TaskName
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def task_name(node)
|
11
|
+
first_arg = node.arguments[0]
|
12
|
+
case first_arg&.type
|
13
|
+
when :sym, :str
|
14
|
+
first_arg.value.to_sym
|
15
|
+
when :hash
|
16
|
+
return nil if first_arg.children.size != 1
|
17
|
+
|
18
|
+
pair = first_arg.children.first
|
19
|
+
key = pair.children.first
|
20
|
+
case key.type
|
21
|
+
when :sym, :str
|
22
|
+
key.value.to_sym
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rubocop/rake/inject.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# The original code is from https://github.com/rubocop
|
4
|
-
# See https://github.com/rubocop
|
3
|
+
# The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
|
4
|
+
# See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
|
5
5
|
module RuboCop
|
6
6
|
module Rake
|
7
7
|
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
data/lib/rubocop/rake/version.rb
CHANGED
data/rubocop-rake.gemspec
CHANGED
@@ -10,15 +10,15 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = %q{A RuboCop plugin for Rake}
|
12
12
|
spec.description = %q{A RuboCop plugin for Rake}
|
13
|
-
spec.homepage = "https://github.com/rubocop
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
13
|
+
spec.homepage = "https://github.com/rubocop/rubocop-rake"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
15
|
spec.licenses = ['MIT']
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
18
|
|
19
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
20
20
|
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
-
spec.metadata["changelog_uri"] = "https://github.com/rubocop
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/rubocop/rubocop-rake/blob/master/CHANGELOG.md"
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
-
spec.add_runtime_dependency 'rubocop'
|
32
|
+
spec.add_runtime_dependency 'rubocop', '~> 1.0'
|
33
33
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '1.0'
|
27
27
|
description: A RuboCop plugin for Rake
|
28
28
|
email:
|
29
29
|
- kuwabara@pocke.me
|
@@ -31,11 +31,11 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".circleci/config.yml"
|
34
35
|
- ".gitignore"
|
35
36
|
- ".rspec"
|
36
37
|
- ".rubocop.yml"
|
37
38
|
- ".rubocop_todo.yml"
|
38
|
-
- ".travis.yml"
|
39
39
|
- CHANGELOG.md
|
40
40
|
- Gemfile
|
41
41
|
- LICENSE
|
@@ -47,23 +47,28 @@ files:
|
|
47
47
|
- lib/rubocop-rake.rb
|
48
48
|
- lib/rubocop/cop/rake/class_definition_in_task.rb
|
49
49
|
- lib/rubocop/cop/rake/desc.rb
|
50
|
+
- lib/rubocop/cop/rake/duplicate_namespace.rb
|
51
|
+
- lib/rubocop/cop/rake/duplicate_task.rb
|
50
52
|
- lib/rubocop/cop/rake/helper/class_definition.rb
|
53
|
+
- lib/rubocop/cop/rake/helper/on_namespace.rb
|
54
|
+
- lib/rubocop/cop/rake/helper/on_task.rb
|
51
55
|
- lib/rubocop/cop/rake/helper/task_definition.rb
|
56
|
+
- lib/rubocop/cop/rake/helper/task_name.rb
|
52
57
|
- lib/rubocop/cop/rake/method_definition_in_task.rb
|
53
58
|
- lib/rubocop/cop/rake_cops.rb
|
54
59
|
- lib/rubocop/rake.rb
|
55
60
|
- lib/rubocop/rake/inject.rb
|
56
61
|
- lib/rubocop/rake/version.rb
|
57
62
|
- rubocop-rake.gemspec
|
58
|
-
homepage: https://github.com/rubocop
|
63
|
+
homepage: https://github.com/rubocop/rubocop-rake
|
59
64
|
licenses:
|
60
65
|
- MIT
|
61
66
|
metadata:
|
62
67
|
allowed_push_host: https://rubygems.org
|
63
|
-
homepage_uri: https://github.com/rubocop
|
64
|
-
source_code_uri: https://github.com/rubocop
|
65
|
-
changelog_uri: https://github.com/rubocop
|
66
|
-
post_install_message:
|
68
|
+
homepage_uri: https://github.com/rubocop/rubocop-rake
|
69
|
+
source_code_uri: https://github.com/rubocop/rubocop-rake
|
70
|
+
changelog_uri: https://github.com/rubocop/rubocop-rake/blob/master/CHANGELOG.md
|
71
|
+
post_install_message:
|
67
72
|
rdoc_options: []
|
68
73
|
require_paths:
|
69
74
|
- lib
|
@@ -71,15 +76,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
76
|
requirements:
|
72
77
|
- - ">="
|
73
78
|
- !ruby/object:Gem::Version
|
74
|
-
version: 2.
|
79
|
+
version: 2.5.0
|
75
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
81
|
requirements:
|
77
82
|
- - ">="
|
78
83
|
- !ruby/object:Gem::Version
|
79
84
|
version: '0'
|
80
85
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
82
|
-
signing_key:
|
86
|
+
rubygems_version: 3.2.13
|
87
|
+
signing_key:
|
83
88
|
specification_version: 4
|
84
89
|
summary: A RuboCop plugin for Rake
|
85
90
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
rvm:
|
4
|
-
- 2.4.7
|
5
|
-
- 2.5.6
|
6
|
-
- 2.6.4
|
7
|
-
- ruby-head
|
8
|
-
|
9
|
-
cache: bundler
|
10
|
-
bundler_args: --jobs=4 --retry=3
|
11
|
-
sudo: false
|
12
|
-
|
13
|
-
|
14
|
-
before_install: 'gem update --system'
|
15
|
-
|
16
|
-
script:
|
17
|
-
- bundle exec rake
|
18
|
-
|
19
|
-
matrix:
|
20
|
-
allow_failures:
|
21
|
-
- rvm: ruby-head
|
22
|
-
fast_finish: true
|