rubocop-dependency 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f0316c1f3ef845942c446d2eb9f332406088df236203770d0bc49609805f373
4
- data.tar.gz: 8814b0ce0eee121c597f408276e4c81707d283e54f0981f807fbdad2232dd5aa
3
+ metadata.gz: 7bdeb2c962a35bae787df85079409fb708f9dca68f4e04710df43d30565649a7
4
+ data.tar.gz: 6e9f3bfd975008e1ff78b4b1913e4ef440053dcbcd652e3acb426e1d6f048c77
5
5
  SHA512:
6
- metadata.gz: 741d66c429a907657b24b3e7b8cd8efe71d55e8e9254caada358f449aef1d058970e255b7af824eda475631dee538a9ca2ac21dd6ca830aa946e3fbb4df9814a
7
- data.tar.gz: eb9a850a6a827336eb7d8b4c1dd25532044ec781fe162b9eb2132d18d34a22a1e5885fd841329816c53c5319dacc58e71c3167b2d9ba801b6fb17727c1cbf58d
6
+ metadata.gz: cba1ae758b36e3dee42c4168b4d46caa7e724400cf91c8a41fba5c57e9988d5593438b744406af215f2afb94bf2e8af27b711ba6b2c9bcb6bd4ec0afe34cb903
7
+ data.tar.gz: 425d513994495296dcfa23d6d44731a05793b77afea6972fb801a83ab5f11cb334d734af097cc9acfaa10f8bcce78b6db599b98970e98ccb242d011b0fa79127
data/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  Code style checking for dependencies control, as an extension to [RuboCop](https://github.com/rubocop/rubocop).
6
6
 
7
- TODO: Delete this and the text above, and describe your gem
8
-
9
7
  ## Installation
10
8
 
11
9
  Add this line to your application's Gemfile:
@@ -18,28 +16,28 @@ gem 'rubocop-dependency', require: false
18
16
 
19
17
  Put this into your .rubocop.yml.
20
18
 
21
- ```
19
+ ```yaml
22
20
  require: rubocop-dependency
23
21
  ```
24
22
 
25
23
  ## Cops
26
24
 
27
- Dependency/OverBoundary
25
+ ### Dependency/OverBoundary
28
26
 
29
27
  Check not to refer constants over dependency boundaries which given from `Rules` config.
30
28
 
31
29
  When the following `Rules` is given,
32
30
 
33
- ```
34
- Rules: // Array of each rules
35
- - BannedConsts: Foo // Array<String> | String. Ba
36
- FromNamespacePatterns: // Array<String> | String. This value is used as Regexp pattern
31
+ ```yaml
32
+ Rules: # Array of each rules
33
+ - BannedConsts: Foo # Array<String> | String.
34
+ FromNamespacePatterns: # Array<String> | String. This value is used as Regexp pattern.
37
35
  - \ABar(\W|\z)
38
36
  ```
39
37
 
40
38
  The following code is considered problems.
41
39
 
42
- ```
40
+ ```ruby
43
41
  class Bar
44
42
  Foo
45
43
  ^^^ Const `Foo` cannot use from namespace `Bar`.
@@ -19,7 +19,11 @@ module RuboCop
19
19
  class OverBoundary < Base
20
20
  def on_const(node)
21
21
  const_name = node.const_name
22
- parent_module_name = node.parent_module_name
22
+ current_namespace =
23
+ node
24
+ .each_ancestor(:class, :module)
25
+ .map { |a| a.defined_module_name }
26
+ .reverse.join('::')
23
27
 
24
28
  if cop_config['Rules']
25
29
  .select { |rule|
@@ -27,10 +31,10 @@ module RuboCop
27
31
  }
28
32
  .any? { |rule|
29
33
  Array(rule['FromNamespacePatterns']).any? { |from_pattern|
30
- Regexp.new(from_pattern).match?(parent_module_name)
34
+ Regexp.new(from_pattern).match?(current_namespace)
31
35
  }
32
36
  }
33
- add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{parent_module_name}`.")
37
+ add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{current_namespace}`.")
34
38
  end
35
39
  end
36
40
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Dependency
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-dependency
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - KATO Kei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-26 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop