rubocop-rake 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -0
- data/config/default.yml +6 -0
- data/lib/rubocop-rake.rb +1 -0
- data/lib/rubocop/cop/rake/duplicate_namespace.rb +84 -0
- data/lib/rubocop/cop/rake/helper/on_namespace.rb +23 -0
- data/lib/rubocop/cop/rake_cops.rb +1 -0
- data/lib/rubocop/rake/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b6574fbdd64dbe9c5df47c71132c17feb7b0399491902c8e01480e333a361ec
|
4
|
+
data.tar.gz: d24998e7452dbd98f07f29b63db9fc7a10392f6d91244b8eec333afdb3484ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d56524f419e37ee6d62469f3cc7a1b940d62793673bfd51fa8b86f991adf6adfeed20dcb7d0f17297defe1eb334bbe2fa6654dfcfeba0828740caf19755aafc
|
7
|
+
data.tar.gz: b331328c525c4c441277e96f2eec388360c2648469da9cbe86ce1b1adb6ab814f20425002288c5c378906d1d15a37b7db3b37eabedd861177da55ed12826c3e8
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -12,6 +12,12 @@
|
|
12
12
|
|
13
13
|
-->
|
14
14
|
|
15
|
+
## 0.5.0 (2019-10-31)
|
16
|
+
|
17
|
+
### New features
|
18
|
+
|
19
|
+
* [#14](https://github.com/rubocop-hq/rubocop-rake/issues/14): Add Rake/DuplicateNamespace cop. ([@jaruuuu][])
|
20
|
+
|
15
21
|
## 0.4.0 (2019-10-13)
|
16
22
|
|
17
23
|
### New features
|
@@ -48,3 +54,4 @@
|
|
48
54
|
* Add `Rake/Desc`. ([@pocke][])
|
49
55
|
|
50
56
|
[@pocke]: https://github.com/pocke
|
57
|
+
[@jaruuuu]: https://github.com/jaruuuu
|
data/Gemfile
CHANGED
data/config/default.yml
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
Rake:
|
2
|
+
Enabled: true
|
2
3
|
Include:
|
3
4
|
- 'Rakefile'
|
4
5
|
- '**/*.rake'
|
@@ -13,6 +14,11 @@ Rake/Desc:
|
|
13
14
|
Enabled: true
|
14
15
|
VersionAdded: '0.1.0'
|
15
16
|
|
17
|
+
Rake/DuplicateNamespace:
|
18
|
+
Description: 'Do not define namespace with the same name'
|
19
|
+
Enabled: true
|
20
|
+
VersionAdded: '0.5.0'
|
21
|
+
|
16
22
|
Rake/DuplicateTask:
|
17
23
|
Description: 'Do not define tasks with the same name'
|
18
24
|
Enabled: true
|
data/lib/rubocop-rake.rb
CHANGED
@@ -12,4 +12,5 @@ require_relative 'rubocop/cop/rake/helper/class_definition'
|
|
12
12
|
require_relative 'rubocop/cop/rake/helper/on_task'
|
13
13
|
require_relative 'rubocop/cop/rake/helper/task_definition'
|
14
14
|
require_relative 'rubocop/cop/rake/helper/task_name'
|
15
|
+
require_relative 'rubocop/cop/rake/helper/on_namespace'
|
15
16
|
require_relative 'rubocop/cop/rake_cops'
|
@@ -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 < Cop
|
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_name == :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,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
|
data/lib/rubocop/rake/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-rake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Pocke Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -47,8 +47,10 @@ 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
|
50
51
|
- lib/rubocop/cop/rake/duplicate_task.rb
|
51
52
|
- lib/rubocop/cop/rake/helper/class_definition.rb
|
53
|
+
- lib/rubocop/cop/rake/helper/on_namespace.rb
|
52
54
|
- lib/rubocop/cop/rake/helper/on_task.rb
|
53
55
|
- lib/rubocop/cop/rake/helper/task_definition.rb
|
54
56
|
- lib/rubocop/cop/rake/helper/task_name.rb
|