rubocop-dependency 0.1.1 → 0.2.0

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: bbf1b624216ceee7dd7b2b25a407cace73538a8cbaf9be1eb1a38b6c59691893
4
+ data.tar.gz: d843b719eea3f148c8fee2f9fa484a21a2c904a982e008f666f9cf96dd0d3bcf
5
5
  SHA512:
6
- metadata.gz: 741d66c429a907657b24b3e7b8cd8efe71d55e8e9254caada358f449aef1d058970e255b7af824eda475631dee538a9ca2ac21dd6ca830aa946e3fbb4df9814a
7
- data.tar.gz: eb9a850a6a827336eb7d8b4c1dd25532044ec781fe162b9eb2132d18d34a22a1e5885fd841329816c53c5319dacc58e71c3167b2d9ba801b6fb17727c1cbf58d
6
+ metadata.gz: 7f34d8be696624921aab680434d1a180431577a083860823e352dd4179e4a0515134d40e09f6fd13cfb112f97a974be2b134e60c09ba394f713f0bd8412748f6
7
+ data.tar.gz: '056538df68f3fcf8603ecf041801686e0cb1065e656fa5f274223fc13d6947aa7c04dfef8ba26fb122b54fdcd4b289a5d835cd4aaf1d2d649a836f5d0f8349eb'
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
+ - BannedConstPatterns: Foo # Array<String> | String. This value is used as Regexp pattern.
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`.
@@ -7,7 +7,7 @@ module RuboCop
7
7
  #
8
8
  # @example
9
9
  # # Rules:
10
- # # - BannedConsts: Foo
10
+ # # - BannedConstPatterns: Foo
11
11
  # # FromNamespacePatterns:
12
12
  # # - \ABar(\W|\z)
13
13
  #
@@ -18,19 +18,27 @@ module RuboCop
18
18
  #
19
19
  class OverBoundary < Base
20
20
  def on_const(node)
21
+ return if node.parent&.const_type?
22
+
21
23
  const_name = node.const_name
22
- parent_module_name = node.parent_module_name
24
+ current_namespace =
25
+ node
26
+ .each_ancestor(:class, :module)
27
+ .map { |a| a.defined_module_name }
28
+ .reverse.join('::')
23
29
 
24
30
  if cop_config['Rules']
25
31
  .select { |rule|
26
- Array(rule['BannedConsts']).include?(const_name)
32
+ Array(rule['BannedConstPatterns']).any? { |banned_pattern|
33
+ Regexp.new(banned_pattern).match?(const_name)
34
+ }
27
35
  }
28
36
  .any? { |rule|
29
37
  Array(rule['FromNamespacePatterns']).any? { |from_pattern|
30
- Regexp.new(from_pattern).match?(parent_module_name)
38
+ Regexp.new(from_pattern).match?(current_namespace)
31
39
  }
32
40
  }
33
- add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{parent_module_name}`.")
41
+ add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{current_namespace}`.")
34
42
  end
35
43
  end
36
44
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Dependency
5
- VERSION = "0.1.1"
5
+ VERSION = "0.2.0"
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - KATO Kei
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-26 00:00:00.000000000 Z
11
+ date: 2025-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -118,7 +118,7 @@ metadata:
118
118
  homepage_uri: https://github.com/keik/rubocop-dependency
119
119
  source_code_uri: https://github.com/keik/rubocop-dependency
120
120
  changelog_uri: https://github.com/keik/rubocop-dependency/CHANGELOG.md
121
- post_install_message:
121
+ post_install_message:
122
122
  rdoc_options: []
123
123
  require_paths:
124
124
  - lib
@@ -133,8 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 3.0.3
137
- signing_key:
136
+ rubygems_version: 3.4.19
137
+ signing_key:
138
138
  specification_version: 4
139
139
  summary: Code style checking for dependencies control.
140
140
  test_files: []