sevencop 0.9.0 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/default.yml +6 -0
- data/lib/rubocop/cop/sevencop/hash_literal_order.rb +24 -8
- data/lib/rubocop/cop/sevencop/inferred_spec_type.rb +1 -1
- data/lib/sevencop/config_loader.rb +48 -0
- data/lib/sevencop/rubocop_extension.rb +10 -0
- data/lib/sevencop/version.rb +1 -1
- data/lib/sevencop.rb +1 -13
- metadata +4 -3
- data/lib/sevencop/inject.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d3ab099568a85aea228ce2fcf282f4e0bc7a2e2c6f3315191c2e9e14367a173
|
4
|
+
data.tar.gz: aeba9572d3eeb74d5d4da5473b30b62d291b0e01d8f5644f041ca41ecd43994f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 643b778e5c44256e590b1a7344825f46c1057a18d3e424076583b522a21f957ca1acf37e2ba6f59d58b72a66e929e2aada551c627cf039d065dbea2646d4e485
|
7
|
+
data.tar.gz: 723e43f5d54dab22c1be3d02bb1074d6899783aec74c64c1fa6ead9294b01ffde02d5aae1b1792e483082d5d297f784de393a20285d34a303e892febc2522ae6
|
data/Gemfile.lock
CHANGED
data/config/default.yml
CHANGED
@@ -11,6 +11,12 @@ Sevencop/HashLiteralOrder:
|
|
11
11
|
Enabled: false
|
12
12
|
VersionAdded: '0.6'
|
13
13
|
|
14
|
+
Sevencop/InferredSpecType:
|
15
|
+
Description: |
|
16
|
+
Identifies redundant spec type.
|
17
|
+
Enabled: false
|
18
|
+
VersionAdded: '0.9'
|
19
|
+
|
14
20
|
Sevencop/OrderField:
|
15
21
|
Description: |
|
16
22
|
Wrap safe SQL String by `Arel.sql`.
|
@@ -55,13 +55,13 @@ module RuboCop
|
|
55
55
|
# @param [RuboCop::AST::HashNode] node
|
56
56
|
# @return [String]
|
57
57
|
def autocorrect(node)
|
58
|
-
[
|
59
|
-
'{',
|
58
|
+
parts = [
|
60
59
|
whitespace_leading(node),
|
61
60
|
sort(node.pairs).map(&:source).join(",#{whitespace_between(node)}"),
|
62
|
-
whitespace_trailing(node)
|
63
|
-
|
64
|
-
].
|
61
|
+
whitespace_trailing(node)
|
62
|
+
]
|
63
|
+
parts = ['{', *parts, '}'] if node.braces?
|
64
|
+
parts.join
|
65
65
|
end
|
66
66
|
|
67
67
|
# @param [Array<RuboCop::AST::PairNode>] pairs
|
@@ -84,7 +84,9 @@ module RuboCop
|
|
84
84
|
# ^^^
|
85
85
|
def whitespace_between(node)
|
86
86
|
if node.pairs.length >= 2
|
87
|
-
|
87
|
+
processed_source.raw_source[
|
88
|
+
node.pairs[0].location.expression.end_pos + 1...node.pairs[1].location.expression.begin_pos
|
89
|
+
]
|
88
90
|
else
|
89
91
|
' '
|
90
92
|
end
|
@@ -95,7 +97,9 @@ module RuboCop
|
|
95
97
|
# { a: 1, b: 1 }
|
96
98
|
# ^^
|
97
99
|
def whitespace_trailing(node)
|
98
|
-
|
100
|
+
processed_source.raw_source[
|
101
|
+
node.pairs[-1].location.expression.end_pos...node.location.expression.end.begin_pos - offset_for(node)
|
102
|
+
]
|
99
103
|
end
|
100
104
|
|
101
105
|
# @param [RuboCop::AST::HashNode] node
|
@@ -103,7 +107,19 @@ module RuboCop
|
|
103
107
|
# { a: 1, b: 1 }
|
104
108
|
# ^^^^
|
105
109
|
def whitespace_leading(node)
|
106
|
-
|
110
|
+
processed_source.raw_source[
|
111
|
+
node.location.expression.begin.end_pos + offset_for(node)...node.pairs[0].location.expression.begin_pos
|
112
|
+
]
|
113
|
+
end
|
114
|
+
|
115
|
+
# @param [RuboCop::AST::HashNode] node
|
116
|
+
# @return [Integer]
|
117
|
+
def offset_for(node)
|
118
|
+
if node.braces?
|
119
|
+
1
|
120
|
+
else
|
121
|
+
0
|
122
|
+
end
|
107
123
|
end
|
108
124
|
end
|
109
125
|
end
|
@@ -113,7 +113,7 @@ module RuboCop
|
|
113
113
|
# @return [Symbol, nil]
|
114
114
|
def inferred_type_from_file_path
|
115
115
|
INFERENCES.find do |inference|
|
116
|
-
break inference[:type] if file_path.
|
116
|
+
break inference[:type] if file_path.include?(inference[:prefix])
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
module Sevencop
|
6
|
+
# Merge default RuboCop config with plugin config.
|
7
|
+
class ConfigLoader
|
8
|
+
PLUGIN_CONFIG_PATH = ::File.expand_path(
|
9
|
+
'../../config/default.yml',
|
10
|
+
__dir__
|
11
|
+
)
|
12
|
+
|
13
|
+
class << self
|
14
|
+
# @return [RuboCop::Config]
|
15
|
+
def call
|
16
|
+
new.call
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [RuboCop::Config]
|
21
|
+
def call
|
22
|
+
::RuboCop::ConfigLoader.merge_with_default(
|
23
|
+
plugin_config,
|
24
|
+
PLUGIN_CONFIG_PATH
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# @return [RuboCop::Config]
|
31
|
+
def plugin_config
|
32
|
+
config = ::RuboCop::Config.new(
|
33
|
+
plugin_config_hash,
|
34
|
+
PLUGIN_CONFIG_PATH
|
35
|
+
)
|
36
|
+
config.make_excludes_absolute
|
37
|
+
config
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Hash]
|
41
|
+
def plugin_config_hash
|
42
|
+
::RuboCop::ConfigLoader.send(
|
43
|
+
:load_yaml_configuration,
|
44
|
+
PLUGIN_CONFIG_PATH
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sevencop/version.rb
CHANGED
data/lib/sevencop.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'pathname'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
-
require_relative 'sevencop/
|
6
|
+
require_relative 'sevencop/rubocop_extension'
|
7
7
|
require_relative 'sevencop/version'
|
8
8
|
|
9
9
|
require_relative 'rubocop/cop/sevencop/belongs_to_optional'
|
@@ -14,15 +14,3 @@ require_relative 'rubocop/cop/sevencop/redundant_existence_check'
|
|
14
14
|
require_relative 'rubocop/cop/sevencop/to_s_with_argument'
|
15
15
|
require_relative 'rubocop/cop/sevencop/uniqueness_validator_explicit_case_sensitivity'
|
16
16
|
require_relative 'rubocop/cop/sevencop/where_not'
|
17
|
-
|
18
|
-
module Sevencop
|
19
|
-
PROJECT_ROOT = ::Pathname.new(__dir__).parent.expand_path.freeze
|
20
|
-
|
21
|
-
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
22
|
-
|
23
|
-
CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
24
|
-
|
25
|
-
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
26
|
-
end
|
27
|
-
|
28
|
-
Sevencop::Inject.defaults!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevencop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -50,7 +50,8 @@ files:
|
|
50
50
|
- lib/rubocop/cop/sevencop/uniqueness_validator_explicit_case_sensitivity.rb
|
51
51
|
- lib/rubocop/cop/sevencop/where_not.rb
|
52
52
|
- lib/sevencop.rb
|
53
|
-
- lib/sevencop/
|
53
|
+
- lib/sevencop/config_loader.rb
|
54
|
+
- lib/sevencop/rubocop_extension.rb
|
54
55
|
- lib/sevencop/version.rb
|
55
56
|
- sevencop.gemspec
|
56
57
|
homepage: https://github.com/r7kamura/sevencop
|
data/lib/sevencop/inject.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rubocop'
|
4
|
-
|
5
|
-
# The original code is from https://github.com/rubocop/rubocop-rspec/blob/main/lib/rubocop/rspec/inject.rb
|
6
|
-
# See https://github.com/rubocop/rubocop-rspec/blob/main/MIT-LICENSE.md
|
7
|
-
module Sevencop
|
8
|
-
module Inject
|
9
|
-
def self.defaults!
|
10
|
-
path = CONFIG_DEFAULT.to_s
|
11
|
-
hash = ::RuboCop::ConfigLoader.send(:load_yaml_configuration, path)
|
12
|
-
config = ::RuboCop::Config.new(hash, path).tap(&:make_excludes_absolute)
|
13
|
-
puts "configuration from #{path}" if ::RuboCop::ConfigLoader.debug?
|
14
|
-
config = ::RuboCop::ConfigLoader.merge_with_default(config, path)
|
15
|
-
::RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|