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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14304d50b67b9946c5962a7d4a120f924b1fa12f0236e51dab8b58d106b4a81c
4
- data.tar.gz: d827d6b122b63d7ce6e012551d389f9e3ee34597d99e9d7b6739e533243d8fe7
3
+ metadata.gz: 2b6574fbdd64dbe9c5df47c71132c17feb7b0399491902c8e01480e333a361ec
4
+ data.tar.gz: d24998e7452dbd98f07f29b63db9fc7a10392f6d91244b8eec333afdb3484ef8
5
5
  SHA512:
6
- metadata.gz: 1079f85fad77e44350769a85a5d925d4ca46c249952d3903f6b0e4804ed22b8435a4e27f0a717296bf024389413852ee89f45ae36cad44c4106560914fe97f1e
7
- data.tar.gz: f32b18ca6c6db87e80b6ee71bb754717aab1750fc4596949a6e4b2d001034319a5843d5b9771171e332ec9b9ff2e86a7af2ddbbfded90e6c35659d7ef5d7f078
6
+ metadata.gz: 0d56524f419e37ee6d62469f3cc7a1b940d62793673bfd51fa8b86f991adf6adfeed20dcb7d0f17297defe1eb334bbe2fa6654dfcfeba0828740caf19755aafc
7
+ data.tar.gz: b331328c525c4c441277e96f2eec388360c2648469da9cbe86ce1b1adb6ab814f20425002288c5c378906d1d15a37b7db3b37eabedd861177da55ed12826c3e8
@@ -19,7 +19,7 @@ Style/AccessModifierDeclarations:
19
19
  Style/NumericPredicate:
20
20
  Enabled: false
21
21
 
22
- Style/UnneededPercentQ:
22
+ Style/RedundantPercentQ:
23
23
  Exclude:
24
24
  - '*.gemspec'
25
25
 
@@ -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
@@ -7,4 +7,5 @@ gemspec
7
7
 
8
8
  gem "rake", "~> 12.0"
9
9
  gem 'rspec'
10
+ gem 'rubocop', '>= 0.76'
10
11
  gem 'rubocop-rspec'
@@ -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
@@ -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
@@ -3,4 +3,5 @@
3
3
  require_relative 'rake/class_definition_in_task'
4
4
  require_relative 'rake/desc'
5
5
  require_relative 'rake/duplicate_task'
6
+ require_relative 'rake/duplicate_namespace'
6
7
  require_relative 'rake/method_definition_in_task'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Rake
5
- VERSION = "0.4.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
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.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-13 00:00:00.000000000 Z
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