rubocop-packaging 0.1.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/config/default.yml +31 -2
- data/lib/rubocop-packaging.rb +5 -5
- data/lib/rubocop/cop/packaging/bundler_setup_in_tests.rb +77 -0
- data/lib/rubocop/cop/packaging/gemspec_git.rb +29 -27
- data/lib/rubocop/cop/packaging/require_hardcoding_lib.rb +108 -0
- data/lib/rubocop/cop/packaging/require_relative_hardcoding_lib.rb +82 -0
- data/lib/rubocop/cop/packaging_cops.rb +4 -1
- data/lib/rubocop/packaging.rb +2 -2
- data/lib/rubocop/packaging/lib_helper_module.rb +41 -0
- data/lib/rubocop/packaging/version.rb +1 -1
- metadata +24 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 666f4f441549972df8c21db0c0a8c0029849da018dc71c9ca17d3c54ba532d4b
|
4
|
+
data.tar.gz: 0f2d7234dfd13bffdecdbd965998eabef9e38344c441dae94389289748258d98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 575ca964189b75c0d20fb0967139f56fa11720236f7c5708949f8264048450ea564ac5e501d71058da813ed569379cfdc23317d727aed7a5ab8ba488276e2556
|
7
|
+
data.tar.gz: 0afd0fe1a56716a5cb5d56f6bc3aeb02faff140e8229f759cea96e1133d65b31361a364f64d9262497d7253d06459ee438b0f58206d901eac038281ff41e33c8
|
data/README.md
CHANGED
@@ -5,9 +5,18 @@ which is a Ruby static code analyzer (a.k.a. linter) and code formatter.
|
|
5
5
|
|
6
6
|
It helps enforcing some of the guidelines that are expected of upstream
|
7
7
|
maintainers so that the downstream can build their packages in a clean
|
8
|
-
environment without any problems.
|
9
|
-
|
10
|
-
|
8
|
+
environment without any problems.
|
9
|
+
|
10
|
+
## Documentation
|
11
|
+
|
12
|
+
A detailed documentation, explaining what this extension is doing and the
|
13
|
+
reasoning behind it, can be found here: https://docs.rubocop.org/rubocop-packaging/
|
14
|
+
|
15
|
+
We also have a [packaging-style-guide](https://packaging.rubystyle.guide/),
|
16
|
+
listing some good and bad examples and the rationale behind these cops.
|
17
|
+
|
18
|
+
In case anything is not clear, please feel free to raise an issue, asking
|
19
|
+
for more explanation!
|
11
20
|
|
12
21
|
## Installation
|
13
22
|
|
data/config/default.yml
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
# This is the default configuration file.
|
2
2
|
|
3
|
+
Packaging/BundlerSetupInTests:
|
4
|
+
Description: >-
|
5
|
+
Using `bundler/setup` in tests is redundant. Consider
|
6
|
+
removing it.
|
7
|
+
Enabled: true
|
8
|
+
VersionAdded: '0.4'
|
9
|
+
VersionChanged: '0.5'
|
10
|
+
|
3
11
|
Packaging/GemspecGit:
|
4
|
-
Description:
|
12
|
+
Description: >-
|
13
|
+
Avoid using git to produce lists of files. Downstreams
|
14
|
+
often need to build your package in an environment
|
15
|
+
that does not have git (on purpose). Use some pure
|
16
|
+
Ruby alternative, like `Dir` or `Dir.glob`.
|
17
|
+
Enabled: true
|
18
|
+
VersionAdded: '0.1'
|
19
|
+
VersionChanged: '0.1'
|
20
|
+
|
21
|
+
Packaging/RequireHardcodingLib:
|
22
|
+
Description: >-
|
23
|
+
Avoid using `require` with relative path to lib. Use
|
24
|
+
`require` with absolute path instead.
|
25
|
+
Enabled: true
|
26
|
+
VersionAdded: '0.4'
|
27
|
+
VersionChanged: '0.5'
|
28
|
+
|
29
|
+
Packaging/RequireRelativeHardcodingLib:
|
30
|
+
Description: >-
|
31
|
+
Avoid using `require_relative` with relative path to
|
32
|
+
lib. Use `require` with absolute path instead.
|
5
33
|
Enabled: true
|
6
|
-
VersionAdded: '0.
|
34
|
+
VersionAdded: '0.2'
|
35
|
+
VersionChanged: '0.5'
|
data/lib/rubocop-packaging.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rubocop"
|
4
4
|
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
5
|
+
require_relative "rubocop/packaging"
|
6
|
+
require_relative "rubocop/packaging/version"
|
7
|
+
require_relative "rubocop/packaging/inject"
|
8
8
|
|
9
9
|
RuboCop::Packaging::Inject.defaults!
|
10
10
|
|
11
|
-
require_relative
|
11
|
+
require_relative "rubocop/cop/packaging_cops"
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop/packaging/lib_helper_module"
|
4
|
+
|
5
|
+
module RuboCop # :nodoc:
|
6
|
+
module Cop # :nodoc:
|
7
|
+
module Packaging # :nodoc:
|
8
|
+
# This cop flags the `require "bundler/setup"` calls if they're
|
9
|
+
# made from inside the tests directory.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# require "foo"
|
15
|
+
# require "bundler/setup"
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# require "foo"
|
19
|
+
#
|
20
|
+
class BundlerSetupInTests < Base
|
21
|
+
include RuboCop::Packaging::LibHelperModule
|
22
|
+
include RangeHelp
|
23
|
+
extend AutoCorrector
|
24
|
+
|
25
|
+
# This is the message that will be displayed when RuboCop::Packaging finds
|
26
|
+
# an offense of using `require "bundler/setup"` in the tests directory.
|
27
|
+
MSG = "Using `bundler/setup` in tests is redundant. Consider removing it."
|
28
|
+
|
29
|
+
def_node_matcher :bundler_setup?, <<~PATTERN
|
30
|
+
(send nil? :require
|
31
|
+
(str #bundler_setup_in_test_dir?))
|
32
|
+
PATTERN
|
33
|
+
|
34
|
+
# Extended from the Base class.
|
35
|
+
# More about the `#on_new_investigation` method can be found here:
|
36
|
+
# https://github.com/rubocop-hq/rubocop/blob/343f62e4555be0470326f47af219689e21c61a37/lib/rubocop/cop/base.rb
|
37
|
+
#
|
38
|
+
# Processing of the AST happens here.
|
39
|
+
def on_new_investigation
|
40
|
+
@file_path = processed_source.file_path
|
41
|
+
@file_directory = File.dirname(@file_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Extended from AST::Traversal.
|
45
|
+
# More about the `#on_send` method can be found here:
|
46
|
+
# https://github.com/rubocop-hq/rubocop-ast/blob/08d0f49a47af1e9a30a6d8f67533ba793c843d67/lib/rubocop/ast/traversal.rb#L112
|
47
|
+
def on_send(node)
|
48
|
+
return unless bundler_setup?(node)
|
49
|
+
|
50
|
+
add_offense(node) do |corrector|
|
51
|
+
autocorrect(corrector, node)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Called from on_send, this method helps to autocorrect
|
56
|
+
# the offenses flagged by this cop.
|
57
|
+
def autocorrect(corrector, node)
|
58
|
+
range = range_by_whole_lines(node.source_range, include_final_newline: true)
|
59
|
+
|
60
|
+
corrector.remove(range)
|
61
|
+
end
|
62
|
+
|
63
|
+
# This method is called from inside `#def_node_matcher`.
|
64
|
+
# It flags an offense if the `require "bundler/setup"`
|
65
|
+
# call is made from the tests directory.
|
66
|
+
def bundler_setup_in_test_dir?(str)
|
67
|
+
str.eql?("bundler/setup") && falls_in_test_dir?
|
68
|
+
end
|
69
|
+
|
70
|
+
# This method determines if the call is made *from* the tests directory.
|
71
|
+
def falls_in_test_dir?
|
72
|
+
%w[spec specs test tests].any? { |dir| File.expand_path(@file_directory).start_with?("#{root_dir}/#{dir}") }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -3,56 +3,59 @@
|
|
3
3
|
module RuboCop # :nodoc:
|
4
4
|
module Cop # :nodoc:
|
5
5
|
module Packaging # :nodoc:
|
6
|
-
# This cop
|
6
|
+
# This cop flags the usage of `git ls-files` in gemspec
|
7
7
|
# and suggests to use a plain Ruby alternative, like `Dir`,
|
8
|
-
# `Dir.glob
|
8
|
+
# `Dir.glob`, or `Rake::FileList` instead.
|
9
9
|
#
|
10
10
|
# @example
|
11
11
|
#
|
12
12
|
# # bad
|
13
13
|
# Gem::Specification.new do |spec|
|
14
|
-
# spec.files
|
14
|
+
# spec.files = `git ls-files`.split("\n")
|
15
|
+
# spec.test_files = `git ls-files -- spec`.split("\n")
|
15
16
|
# end
|
16
17
|
#
|
17
|
-
# #
|
18
|
+
# # good
|
18
19
|
# Gem::Specification.new do |spec|
|
19
|
-
# spec.files
|
20
|
-
#
|
21
|
-
# end
|
20
|
+
# spec.files = Dir["lib/**/*", "LICENSE", "README.md"]
|
21
|
+
# spec.test_files = Dir["spec/**/*"]
|
22
22
|
# end
|
23
23
|
#
|
24
24
|
# # bad
|
25
25
|
# Gem::Specification.new do |spec|
|
26
|
-
# spec.files
|
27
|
-
#
|
28
|
-
#
|
26
|
+
# spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
# `git ls-files -z`.split("\\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
|
+
# end
|
29
29
|
# end
|
30
30
|
#
|
31
31
|
# # good
|
32
|
+
# require "rake/file_list"
|
33
|
+
#
|
32
34
|
# Gem::Specification.new do |spec|
|
33
|
-
# spec.files =
|
34
|
-
# spec.test_files = Dir['spec/**/*']
|
35
|
+
# spec.files = Rake::FileList["**/*"].exclude(*File.read(".gitignore").split)
|
35
36
|
# end
|
36
37
|
#
|
37
|
-
# #
|
38
|
+
# # bad
|
38
39
|
# Gem::Specification.new do |spec|
|
39
|
-
# spec.files =
|
40
|
+
# spec.files = `git ls-files -- lib/`.split("\n")
|
41
|
+
# spec.test_files = `git ls-files -- test/{functional,unit}/*`.split("\n")
|
42
|
+
# spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
40
43
|
# end
|
41
44
|
#
|
42
45
|
# # good
|
43
46
|
# Gem::Specification.new do |spec|
|
44
|
-
# spec.files = Dir.glob(
|
45
|
-
# spec.test_files = Dir.glob(
|
46
|
-
# spec.executables = Dir.glob(
|
47
|
+
# spec.files = Dir.glob("lib/**/*")
|
48
|
+
# spec.test_files = Dir.glob("test/{functional,test}/*")
|
49
|
+
# spec.executables = Dir.glob("bin/*").map{ |f| File.basename(f) }
|
47
50
|
# end
|
48
51
|
#
|
49
|
-
class GemspecGit <
|
52
|
+
class GemspecGit < Base
|
50
53
|
# This is the message that will be displayed when RuboCop finds an
|
51
54
|
# offense of using `git ls-files`.
|
52
|
-
MSG =
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
MSG = "Avoid using git to produce lists of files. " \
|
56
|
+
"Downstreams often need to build your package in an environment " \
|
57
|
+
"that does not have git (on purpose). " \
|
58
|
+
"Use some pure Ruby alternative, like `Dir` or `Dir.glob`."
|
56
59
|
|
57
60
|
def_node_search :xstr, <<~PATTERN
|
58
61
|
(block
|
@@ -68,22 +71,21 @@ module RuboCop # :nodoc:
|
|
68
71
|
# https://github.com/rubocop-hq/rubocop/blob/59543c8e2b66bff249de131fa9105f3eb11e9edb/lib/rubocop/cop/cop.rb#L13-L25
|
69
72
|
#
|
70
73
|
# Processing of the AST happens here.
|
71
|
-
def
|
74
|
+
def on_new_investigation
|
72
75
|
return if processed_source.blank?
|
73
76
|
|
74
77
|
xstr(processed_source.ast).each do |node|
|
75
78
|
add_offense(
|
76
|
-
|
77
|
-
location: node.loc.expression,
|
79
|
+
node.loc.expression,
|
78
80
|
message: MSG
|
79
81
|
)
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
85
|
# This method is called from inside `#def_node_search`.
|
84
|
-
# It is used to find strings which start with
|
86
|
+
# It is used to find strings which start with "git".
|
85
87
|
def starts_with_git?(str)
|
86
|
-
str.start_with?(
|
88
|
+
str.start_with?("git")
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop/packaging/lib_helper_module"
|
4
|
+
|
5
|
+
module RuboCop # :nodoc:
|
6
|
+
module Cop # :nodoc:
|
7
|
+
module Packaging # :nodoc:
|
8
|
+
# This cop flags the `require` calls, from anywhere mapping to
|
9
|
+
# the "lib" directory, except originating from lib/.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# require "../lib/foo/bar"
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# require "foo/bar"
|
18
|
+
#
|
19
|
+
# # bad
|
20
|
+
# require File.expand_path("../../lib/foo", __FILE__)
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
# require "foo"
|
24
|
+
#
|
25
|
+
# # bad
|
26
|
+
# require File.expand_path("../../../lib/foo/bar/baz/qux", __dir__)
|
27
|
+
#
|
28
|
+
# # good
|
29
|
+
# require "foo/bar/baz/qux"
|
30
|
+
#
|
31
|
+
# # bad
|
32
|
+
# require File.dirname(__FILE__) + "/../../lib/baz/qux"
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
# require "baz/qux"
|
36
|
+
#
|
37
|
+
class RequireHardcodingLib < Base
|
38
|
+
include RuboCop::Packaging::LibHelperModule
|
39
|
+
extend AutoCorrector
|
40
|
+
|
41
|
+
# This is the message that will be displayed when RuboCop::Packaging
|
42
|
+
# finds an offense of using `require` with relative path to lib.
|
43
|
+
MSG = "Avoid using `require` with relative path to `lib/`. " \
|
44
|
+
"Use `require` with absolute path instead."
|
45
|
+
|
46
|
+
def_node_matcher :require?, <<~PATTERN
|
47
|
+
{(send nil? :require (str #falls_in_lib?))
|
48
|
+
(send nil? :require (send (const nil? :File) :expand_path (str #falls_in_lib?) (send nil? :__dir__)))
|
49
|
+
(send nil? :require (send (const nil? :File) :expand_path (str #falls_in_lib_using_file?) (str _)))
|
50
|
+
(send nil? :require (send (send (const nil? :File) :dirname {(str _) (send nil? _)}) :+ (str #falls_in_lib_with_file_dirname_plus_str?)))
|
51
|
+
(send nil? :require (dstr (begin (send (const nil? :File) :dirname {(str _) (send nil? _)})) (str #falls_in_lib_with_file_dirname_plus_str?)))}
|
52
|
+
PATTERN
|
53
|
+
|
54
|
+
# Extended from the Base class.
|
55
|
+
# More about the `#on_new_investigation` method can be found here:
|
56
|
+
# https://github.com/rubocop-hq/rubocop/blob/343f62e4555be0470326f47af219689e21c61a37/lib/rubocop/cop/base.rb
|
57
|
+
#
|
58
|
+
# Processing of the AST happens here.
|
59
|
+
def on_new_investigation
|
60
|
+
@file_path = processed_source.file_path
|
61
|
+
@file_directory = File.dirname(@file_path)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Extended from AST::Traversal.
|
65
|
+
# More about the `#on_send` method can be found here:
|
66
|
+
# https://github.com/rubocop-hq/rubocop-ast/blob/08d0f49a47af1e9a30a6d8f67533ba793c843d67/lib/rubocop/ast/traversal.rb#L112
|
67
|
+
def on_send(node)
|
68
|
+
return unless require?(node)
|
69
|
+
|
70
|
+
add_offense(node) do |corrector|
|
71
|
+
corrector.replace(node, good_require_call)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Called from on_send, this method helps to replace
|
76
|
+
# the "bad" require call with the "good" one.
|
77
|
+
def good_require_call
|
78
|
+
good_call = @str.sub(%r{^.*/lib/}, "")
|
79
|
+
%(require "#{good_call}")
|
80
|
+
end
|
81
|
+
|
82
|
+
# This method is called from inside `#def_node_matcher`.
|
83
|
+
# It flags an offense if the `require` call is made from
|
84
|
+
# anywhere except the "lib" directory.
|
85
|
+
def falls_in_lib?(str)
|
86
|
+
@str = str
|
87
|
+
target_falls_in_lib?(str) && inspected_file_is_not_in_lib_or_gemspec?
|
88
|
+
end
|
89
|
+
|
90
|
+
# This method is called from inside `#def_node_matcher`.
|
91
|
+
# It flags an offense if the `require` call (using the __FILE__
|
92
|
+
# arguement) is made from anywhere except the "lib" directory.
|
93
|
+
def falls_in_lib_using_file?(str)
|
94
|
+
@str = str
|
95
|
+
target_falls_in_lib_using_file?(str) && inspected_file_is_not_in_lib_or_gemspec?
|
96
|
+
end
|
97
|
+
|
98
|
+
# This method preprends a "." to the string that starts with "/".
|
99
|
+
# And then determines if that call is made to "lib/".
|
100
|
+
def falls_in_lib_with_file_dirname_plus_str?(str)
|
101
|
+
@str = str
|
102
|
+
str.prepend(".")
|
103
|
+
target_falls_in_lib?(str) && inspected_file_is_not_in_lib_or_gemspec?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rubocop/packaging/lib_helper_module"
|
4
|
+
|
5
|
+
module RuboCop # :nodoc:
|
6
|
+
module Cop # :nodoc:
|
7
|
+
module Packaging # :nodoc:
|
8
|
+
# This cop flags the `require_relative` calls, from anywhere
|
9
|
+
# mapping to the "lib" directory, except originating from lib/ or
|
10
|
+
# the gemspec file, and suggests to use `require` instead.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# # bad
|
15
|
+
# require_relative "lib/foo"
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# require "foo"
|
19
|
+
#
|
20
|
+
# # bad
|
21
|
+
# require_relative "../../lib/foo/bar"
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# require "foo/bar"
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# require_relative "foo/bar/bax"
|
28
|
+
# require_relative "baz/qux"
|
29
|
+
#
|
30
|
+
class RequireRelativeHardcodingLib < Base
|
31
|
+
include RuboCop::Packaging::LibHelperModule
|
32
|
+
extend AutoCorrector
|
33
|
+
|
34
|
+
# This is the message that will be displayed when RuboCop finds an
|
35
|
+
# offense of using `require_relative` with relative path to lib.
|
36
|
+
MSG = "Avoid using `require_relative` with relative path to lib. " \
|
37
|
+
"Use `require` with absolute path instead."
|
38
|
+
|
39
|
+
def_node_matcher :require_relative, <<~PATTERN
|
40
|
+
(send nil? :require_relative
|
41
|
+
(str #falls_in_lib?))
|
42
|
+
PATTERN
|
43
|
+
|
44
|
+
# Extended from the Base class.
|
45
|
+
# More about the `#on_new_investigation` method can be found here:
|
46
|
+
# https://github.com/rubocop-hq/rubocop/blob/343f62e4555be0470326f47af219689e21c61a37/lib/rubocop/cop/base.rb
|
47
|
+
#
|
48
|
+
# Processing of the AST happens here.
|
49
|
+
def on_new_investigation
|
50
|
+
@file_path = processed_source.file_path
|
51
|
+
@file_directory = File.dirname(@file_path)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Extended from AST::Traversal.
|
55
|
+
# More about the `#on_send` method can be found here:
|
56
|
+
# https://github.com/rubocop-hq/rubocop-ast/blob/08d0f49a47af1e9a30a6d8f67533ba793c843d67/lib/rubocop/ast/traversal.rb#L112
|
57
|
+
def on_send(node)
|
58
|
+
return unless require_relative(node)
|
59
|
+
|
60
|
+
add_offense(node) do |corrector|
|
61
|
+
corrector.replace(node, good_require_call)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Called from on_send, this method helps to replace the
|
66
|
+
# "bad" require_relative call with the "good" one.
|
67
|
+
def good_require_call
|
68
|
+
good_call = File.expand_path(@str, @file_directory).delete_prefix("#{root_dir}/lib/")
|
69
|
+
%(require "#{good_call}")
|
70
|
+
end
|
71
|
+
|
72
|
+
# This method is called from inside `#def_node_matcher`.
|
73
|
+
# It flags an offense if the `require_relative` call is made
|
74
|
+
# from anywhere except the "lib" directory.
|
75
|
+
def falls_in_lib?(str)
|
76
|
+
@str = str
|
77
|
+
target_falls_in_lib?(str) && inspected_file_is_not_in_lib_or_gemspec?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,3 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "packaging/bundler_setup_in_tests"
|
4
|
+
require_relative "packaging/gemspec_git"
|
5
|
+
require_relative "packaging/require_hardcoding_lib"
|
6
|
+
require_relative "packaging/require_relative_hardcoding_lib"
|
data/lib/rubocop/packaging.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "rubocop/packaging/version"
|
4
4
|
|
5
5
|
module RuboCop
|
6
6
|
# RuboCop Packaging project namespace
|
7
7
|
module Packaging
|
8
8
|
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
9
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join(
|
9
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
|
10
10
|
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
11
11
|
|
12
12
|
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop # :nodoc:
|
4
|
+
module Packaging # :nodoc:
|
5
|
+
# This helper module extracts the methods which can be used
|
6
|
+
# in other cop classes.
|
7
|
+
module LibHelperModule
|
8
|
+
# For determining the root directory of the project.
|
9
|
+
def root_dir
|
10
|
+
RuboCop::ConfigLoader.project_root
|
11
|
+
end
|
12
|
+
|
13
|
+
# This method determines if the calls are made to the "lib" directory.
|
14
|
+
def target_falls_in_lib?(str)
|
15
|
+
File.expand_path(str, @file_directory).start_with?("#{root_dir}/lib")
|
16
|
+
end
|
17
|
+
|
18
|
+
# This method determines if the calls (using the __FILE__ argument)
|
19
|
+
# are made to the "lib" directory.
|
20
|
+
def target_falls_in_lib_using_file?(str)
|
21
|
+
File.expand_path(str, @file_path).start_with?("#{root_dir}/lib")
|
22
|
+
end
|
23
|
+
|
24
|
+
# This method determines if that call is made *from* the "lib" directory.
|
25
|
+
def inspected_file_falls_in_lib?
|
26
|
+
@file_path.start_with?("#{root_dir}/lib")
|
27
|
+
end
|
28
|
+
|
29
|
+
# This method determines if that call is made *from* the "gemspec" file.
|
30
|
+
def inspected_file_is_gemspec?
|
31
|
+
@file_path.end_with?("gemspec")
|
32
|
+
end
|
33
|
+
|
34
|
+
# This method determines if the inspected file is not in lib/ or
|
35
|
+
# isn't a gemspec file.
|
36
|
+
def inspected_file_is_not_in_lib_or_gemspec?
|
37
|
+
!inspected_file_falls_in_lib? && !inspected_file_is_gemspec?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-packaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Utkarsh Gupta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8
|
19
|
+
version: '0.8'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8
|
26
|
+
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.13
|
33
|
+
version: '0.13'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.13
|
40
|
+
version: '0.13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,20 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.89'
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '2.0'
|
90
93
|
type: :runtime
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
97
|
- - ">="
|
95
98
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
99
|
+
version: '0.89'
|
100
|
+
- - "<"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
97
103
|
description: |
|
98
104
|
A collection of RuboCop cops to check for downstream compatability issues in the
|
99
105
|
Ruby code.
|
@@ -107,10 +113,14 @@ files:
|
|
107
113
|
- README.md
|
108
114
|
- config/default.yml
|
109
115
|
- lib/rubocop-packaging.rb
|
116
|
+
- lib/rubocop/cop/packaging/bundler_setup_in_tests.rb
|
110
117
|
- lib/rubocop/cop/packaging/gemspec_git.rb
|
118
|
+
- lib/rubocop/cop/packaging/require_hardcoding_lib.rb
|
119
|
+
- lib/rubocop/cop/packaging/require_relative_hardcoding_lib.rb
|
111
120
|
- lib/rubocop/cop/packaging_cops.rb
|
112
121
|
- lib/rubocop/packaging.rb
|
113
122
|
- lib/rubocop/packaging/inject.rb
|
123
|
+
- lib/rubocop/packaging/lib_helper_module.rb
|
114
124
|
- lib/rubocop/packaging/version.rb
|
115
125
|
homepage: https://github.com/utkarsh2102/rubocop-packaging
|
116
126
|
licenses:
|
@@ -126,14 +136,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
136
|
requirements:
|
127
137
|
- - ">="
|
128
138
|
- !ruby/object:Gem::Version
|
129
|
-
version: 2.
|
139
|
+
version: 2.4.0
|
130
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
141
|
requirements:
|
132
142
|
- - ">="
|
133
143
|
- !ruby/object:Gem::Version
|
134
144
|
version: '0'
|
135
145
|
requirements: []
|
136
|
-
rubygems_version: 3.1.
|
146
|
+
rubygems_version: 3.1.4
|
137
147
|
signing_key:
|
138
148
|
specification_version: 4
|
139
149
|
summary: Automatic downstream compatability checking tool for Ruby code
|