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 +4 -4
- data/README.md +7 -9
- data/lib/rubocop/cop/dependency/over_boundary.rb +7 -3
- data/lib/rubocop/dependency/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bdeb2c962a35bae787df85079409fb708f9dca68f4e04710df43d30565649a7
|
4
|
+
data.tar.gz: 6e9f3bfd975008e1ff78b4b1913e4ef440053dcbcd652e3acb426e1d6f048c77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
35
|
-
- BannedConsts: Foo
|
36
|
-
FromNamespacePatterns:
|
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
|
-
|
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?(
|
34
|
+
Regexp.new(from_pattern).match?(current_namespace)
|
31
35
|
}
|
32
36
|
}
|
33
|
-
add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{
|
37
|
+
add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{current_namespace}`.")
|
34
38
|
end
|
35
39
|
end
|
36
40
|
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.
|
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-
|
11
|
+
date: 2021-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|