rubocop-packaging 0.1.0 → 0.5.0
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 +32 -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 +31 -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 +19 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e096b94cc72a619f1accaa3fda9021424a1954ddd3364d34df4c36e66cb8926
|
4
|
+
data.tar.gz: d96b87bbb45fd4448665e6578039f3c167818a78894066953cd4a87a0af3e2de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5f7400a946fc39f6de1907f01445d13e3935299058db606edef6e1527dae2efeb944921bee5e7bce5dfddc73d8e4fd39c1cc3a16105b0e1dcdb550a8962e71
|
7
|
+
data.tar.gz: f122820131b25c3fe87ce4c4abe5cce1f9fa22bed5e0bbf60e5fe68273ca4f8a089a7479ca9bf11a85d34227cae8878fd6875c0b7a3216e0bb7377aee73b27ac
|
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,36 @@
|
|
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
|
+
Using `bundler/setup` in tests is redundant. Consider
|
14
|
+
Avoid using git to produce lists of files. Downstreams
|
15
|
+
often need to build your package in an environment
|
16
|
+
that does not have git (on purpose). Use some pure
|
17
|
+
Ruby alternative, like `Dir` or `Dir.glob`.
|
18
|
+
Enabled: true
|
19
|
+
VersionAdded: '0.1'
|
20
|
+
VersionChanged: '0.1'
|
21
|
+
|
22
|
+
Packaging/RequireHardcodingLib:
|
23
|
+
Description: >-
|
24
|
+
Avoid using `require` with relative path to lib. Use
|
25
|
+
`require` with absolute path instead.
|
26
|
+
Enabled: true
|
27
|
+
VersionAdded: '0.4'
|
28
|
+
VersionChanged: '0.5'
|
29
|
+
|
30
|
+
Packaging/RequireRelativeHardcodingLib:
|
31
|
+
Description: >-
|
32
|
+
Avoid using `require_relative` with relative path to
|
33
|
+
lib. Use `require` with absolute path instead.
|
5
34
|
Enabled: true
|
6
|
-
VersionAdded: '0.
|
35
|
+
VersionAdded: '0.2'
|
36
|
+
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,20 +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
|
75
|
+
return if processed_source.blank?
|
76
|
+
|
72
77
|
xstr(processed_source.ast).each do |node|
|
73
78
|
add_offense(
|
74
|
-
|
75
|
-
location: node.loc.expression,
|
79
|
+
node.loc.expression,
|
76
80
|
message: MSG
|
77
81
|
)
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
81
85
|
# This method is called from inside `#def_node_search`.
|
82
|
-
# It is used to find strings which start with
|
86
|
+
# It is used to find strings which start with "git".
|
83
87
|
def starts_with_git?(str)
|
84
|
-
str.start_with?(
|
88
|
+
str.start_with?("git")
|
85
89
|
end
|
86
90
|
end
|
87
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.rb"
|
16
|
+
#
|
17
|
+
# # good
|
18
|
+
# require "foo.rb"
|
19
|
+
#
|
20
|
+
# # bad
|
21
|
+
# require_relative "../../lib/foo/bar"
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
# require "foo/bar"
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
# require_relative "spec_helper"
|
28
|
+
# require_relative "spec/foo/bar"
|
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.0
|
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-09-19 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
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: '0.89'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: '0.89'
|
97
97
|
description: |
|
98
98
|
A collection of RuboCop cops to check for downstream compatability issues in the
|
99
99
|
Ruby code.
|
@@ -107,10 +107,14 @@ files:
|
|
107
107
|
- README.md
|
108
108
|
- config/default.yml
|
109
109
|
- lib/rubocop-packaging.rb
|
110
|
+
- lib/rubocop/cop/packaging/bundler_setup_in_tests.rb
|
110
111
|
- lib/rubocop/cop/packaging/gemspec_git.rb
|
112
|
+
- lib/rubocop/cop/packaging/require_hardcoding_lib.rb
|
113
|
+
- lib/rubocop/cop/packaging/require_relative_hardcoding_lib.rb
|
111
114
|
- lib/rubocop/cop/packaging_cops.rb
|
112
115
|
- lib/rubocop/packaging.rb
|
113
116
|
- lib/rubocop/packaging/inject.rb
|
117
|
+
- lib/rubocop/packaging/lib_helper_module.rb
|
114
118
|
- lib/rubocop/packaging/version.rb
|
115
119
|
homepage: https://github.com/utkarsh2102/rubocop-packaging
|
116
120
|
licenses:
|
@@ -126,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
130
|
requirements:
|
127
131
|
- - ">="
|
128
132
|
- !ruby/object:Gem::Version
|
129
|
-
version: 2.
|
133
|
+
version: 2.4.0
|
130
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
135
|
requirements:
|
132
136
|
- - ">="
|