rubocop-dependency 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f0316c1f3ef845942c446d2eb9f332406088df236203770d0bc49609805f373
4
+ data.tar.gz: 8814b0ce0eee121c597f408276e4c81707d283e54f0981f807fbdad2232dd5aa
5
+ SHA512:
6
+ metadata.gz: 741d66c429a907657b24b3e7b8cd8efe71d55e8e9254caada358f449aef1d058970e255b7af824eda475631dee538a9ca2ac21dd6ca830aa946e3fbb4df9814a
7
+ data.tar.gz: eb9a850a6a827336eb7d8b4c1dd25532044ec781fe162b9eb2132d18d34a22a1e5885fd841329816c53c5319dacc58e71c3167b2d9ba801b6fb17727c1cbf58d
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Rubocop::Dependency
2
+
3
+ [![Coverage Status](https://coveralls.io/repos/github/keik/rubocop-dependency/badge.svg?branch=circleci)](https://coveralls.io/github/keik/rubocop-dependency?branch=circleci)
4
+
5
+ Code style checking for dependencies control, as an extension to [RuboCop](https://github.com/rubocop/rubocop).
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rubocop-dependency', require: false
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Put this into your .rubocop.yml.
20
+
21
+ ```
22
+ require: rubocop-dependency
23
+ ```
24
+
25
+ ## Cops
26
+
27
+ Dependency/OverBoundary
28
+
29
+ Check not to refer constants over dependency boundaries which given from `Rules` config.
30
+
31
+ When the following `Rules` is given,
32
+
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
37
+ - \ABar(\W|\z)
38
+ ```
39
+
40
+ The following code is considered problems.
41
+
42
+ ```
43
+ class Bar
44
+ Foo
45
+ ^^^ Const `Foo` cannot use from namespace `Bar`.
46
+ end
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/keik/rubocop-dependency.
@@ -0,0 +1,4 @@
1
+ Dependency/OverBoundary:
2
+ Description: 'Rectrict which constants can be referred in a given namespace.'
3
+ Enabled: false
4
+ Rules: []
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Dependency
6
+ # Check not to refer constants over dependency boundaries which given from `Rules` config.
7
+ #
8
+ # @example
9
+ # # Rules:
10
+ # # - BannedConsts: Foo
11
+ # # FromNamespacePatterns:
12
+ # # - \ABar(\W|\z)
13
+ #
14
+ # class Bar
15
+ # # Bad. Cannot refer Foo from Bar namespace
16
+ # Foo
17
+ # end
18
+ #
19
+ class OverBoundary < Base
20
+ def on_const(node)
21
+ const_name = node.const_name
22
+ parent_module_name = node.parent_module_name
23
+
24
+ if cop_config['Rules']
25
+ .select { |rule|
26
+ Array(rule['BannedConsts']).include?(const_name)
27
+ }
28
+ .any? { |rule|
29
+ Array(rule['FromNamespacePatterns']).any? { |from_pattern|
30
+ Regexp.new(from_pattern).match?(parent_module_name)
31
+ }
32
+ }
33
+ add_offense(node, message: "Const `#{const_name}` cannot use from namespace `#{parent_module_name}`.")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'dependency/over_boundary'
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Dependency
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Dependency
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "dependency/version"
4
+
5
+ module RuboCop
6
+ module Dependency
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
10
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
11
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
12
+
13
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/dependency'
6
+ require_relative 'rubocop/dependency/version'
7
+ require_relative 'rubocop/dependency/inject'
8
+
9
+ RuboCop::Dependency::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/dependency_cops'
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-dependency
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - KATO Kei
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-lcov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |2
98
+ Code style checking for dependencies control.
99
+ A plugin for the RuboCop code style enforcing & linting tool.
100
+ email:
101
+ - k4t0.kei@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - README.md
107
+ - config/default.yml
108
+ - lib/rubocop-dependency.rb
109
+ - lib/rubocop/cop/dependency/over_boundary.rb
110
+ - lib/rubocop/cop/dependency_cops.rb
111
+ - lib/rubocop/dependency.rb
112
+ - lib/rubocop/dependency/inject.rb
113
+ - lib/rubocop/dependency/version.rb
114
+ homepage: https://github.com/keik/rubocop-dependency
115
+ licenses:
116
+ - MIT
117
+ metadata:
118
+ homepage_uri: https://github.com/keik/rubocop-dependency
119
+ source_code_uri: https://github.com/keik/rubocop-dependency
120
+ changelog_uri: https://github.com/keik/rubocop-dependency/CHANGELOG.md
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.5.0
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.0.3
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Code style checking for dependencies control.
140
+ test_files: []