rubocop-packaging 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a302f7a6e19e06fa73adecfaa4be36d8db647d2aef3571554d4246b222306c6
|
4
|
+
data.tar.gz: af9c1d6e9435f94adbdaaf8a256291e3546fe3dfc024f36abf462c1e1b707046
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11fc92be8299fb440ed62524b58d9d0684e520ad30879c86c2a79d16a6880248090f595a50ace1bc8569f551ad0b5e56ae5773398a6b2f4c91232b1e31009612
|
7
|
+
data.tar.gz: b50af49a31c46beb60f283604bb2877b0bd461bcd702adacf39f635d48603484782f52ef923b9fe960f035c0ce9bda3fe7d0fa1be17bf0076864445ab7571183
|
data/config/default.yml
CHANGED
@@ -3,4 +3,10 @@
|
|
3
3
|
Packaging/GemspecGit:
|
4
4
|
Description: 'Use pure Ruby alternative instead of `git ls-files`.'
|
5
5
|
Enabled: true
|
6
|
-
VersionAdded: '0.
|
6
|
+
VersionAdded: '0.1'
|
7
|
+
VersionChanged: '0.1'
|
8
|
+
|
9
|
+
Packaging/RelativeRequireToLib:
|
10
|
+
Description: 'Avoid using `require_relative` with relative path to lib.'
|
11
|
+
Enabled: true
|
12
|
+
VersionAdded: '0.2'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop # :nodoc:
|
4
|
+
module Cop # :nodoc:
|
5
|
+
module Packaging # :nodoc:
|
6
|
+
# This cop is used to identify the `require_relative` calls,
|
7
|
+
# mapping to the "lib" directory and suggests to use `require`
|
8
|
+
# instead.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# require_relative 'lib/foo.rb'
|
14
|
+
#
|
15
|
+
# # bad
|
16
|
+
# require_relative '../../lib/foo/bar'
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# require 'foo.rb'
|
20
|
+
#
|
21
|
+
# # good
|
22
|
+
# require 'foo/bar'
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# require_relative 'spec_helper'
|
26
|
+
# require_relative 'foo/bar'
|
27
|
+
#
|
28
|
+
class RelativeRequireToLib < Base
|
29
|
+
# This is the message that will be displayed when RuboCop finds an
|
30
|
+
# offense of using `require_relative` with relative path to lib.
|
31
|
+
MSG = 'Avoid using `require_relative` with relative path to lib. ' \
|
32
|
+
'Use `require` instead.'
|
33
|
+
|
34
|
+
def_node_matcher :require_relative, <<~PATTERN
|
35
|
+
(send nil? :require_relative
|
36
|
+
(str #target_falls_in_lib?))
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
# Extended from the Base class.
|
40
|
+
# More about the `#on_new_investigation` method can be found here:
|
41
|
+
# https://github.com/rubocop-hq/rubocop/blob/343f62e4555be0470326f47af219689e21c61a37/lib/rubocop/cop/base.rb
|
42
|
+
#
|
43
|
+
# Processing of the AST happens here.
|
44
|
+
def on_new_investigation
|
45
|
+
@file_path = processed_source.file_path
|
46
|
+
@file_directory = File.dirname(@file_path)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Extended from AST::Traversal.
|
50
|
+
# More about the `#on_send` method can be found here:
|
51
|
+
# https://github.com/rubocop-hq/rubocop-ast/blob/08d0f49a47af1e9a30a6d8f67533ba793c843d67/lib/rubocop/ast/traversal.rb#L112
|
52
|
+
def on_send(node)
|
53
|
+
return unless require_relative(node)
|
54
|
+
|
55
|
+
add_offense(node)
|
56
|
+
end
|
57
|
+
|
58
|
+
# This method is called from inside `#def_node_matcher`.
|
59
|
+
# It is used to find paths which starts with "lib".
|
60
|
+
def target_falls_in_lib?(str)
|
61
|
+
root_dir = RuboCop::ConfigLoader.project_root
|
62
|
+
File.expand_path(str, @file_directory).start_with?(root_dir + '/lib')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
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.2.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-07-
|
11
|
+
date: 2020-07-24 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.88'
|
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.88'
|
97
97
|
description: |
|
98
98
|
A collection of RuboCop cops to check for downstream compatability issues in the
|
99
99
|
Ruby code.
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- config/default.yml
|
109
109
|
- lib/rubocop-packaging.rb
|
110
110
|
- lib/rubocop/cop/packaging/gemspec_git.rb
|
111
|
+
- lib/rubocop/cop/packaging/relative_require_to_lib.rb
|
111
112
|
- lib/rubocop/cop/packaging_cops.rb
|
112
113
|
- lib/rubocop/packaging.rb
|
113
114
|
- lib/rubocop/packaging/inject.rb
|