sevencop 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2be2d44c67e1057b48a80a65e3bcdaaf1663d00b4cfd40a780e5524279be89e8
4
- data.tar.gz: 577fe7a5e296a27b002814584a2716b6a445b6013d8759233a8ca1bb31183a32
3
+ metadata.gz: 3d3ab099568a85aea228ce2fcf282f4e0bc7a2e2c6f3315191c2e9e14367a173
4
+ data.tar.gz: aeba9572d3eeb74d5d4da5473b30b62d291b0e01d8f5644f041ca41ecd43994f
5
5
  SHA512:
6
- metadata.gz: c0acba59ece08f76e4c937542c5579e2352582d32dffd6e07f584466f8d386cfe863af58c6b480c0e9db675584b4a6a977c9babb18b7c83676b5f8112c63a885
7
- data.tar.gz: 5bb840ce34348e557cc9512b9f4ffcb6f8da0cf680e35cb77f11a2858aa68fc2a51b4229e8feadafda21507f699d5977d5ec9906e109652d29d9333ba0522adc
6
+ metadata.gz: 643b778e5c44256e590b1a7344825f46c1057a18d3e424076583b522a21f957ca1acf37e2ba6f59d58b72a66e929e2aada551c627cf039d065dbea2646d4e485
7
+ data.tar.gz: 723e43f5d54dab22c1be3d02bb1074d6899783aec74c64c1fa6ead9294b01ffde02d5aae1b1792e483082d5d297f784de393a20285d34a303e892febc2522ae6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sevencop (0.9.2)
4
+ sevencop (0.9.3)
5
5
  rubocop
6
6
 
7
7
  GEM
@@ -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
- ].join
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
- node.source[node.pairs[0].location.expression.end_pos + 1...node.pairs[1].location.expression.begin_pos]
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
- node.source[node.pairs[-1].location.expression.end_pos...node.location.end.begin_pos]
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
- node.source[node.location.begin.end_pos...node.pairs[0].location.expression.begin_pos]
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
@@ -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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'config_loader'
6
+
7
+ RuboCop::ConfigLoader.instance_variable_set(
8
+ :@default_configuration,
9
+ Sevencop::ConfigLoader.call
10
+ )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sevencop
4
- VERSION = '0.9.2'
4
+ VERSION = '0.9.3'
5
5
  end
data/lib/sevencop.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'pathname'
4
4
  require 'yaml'
5
5
 
6
- require_relative 'sevencop/inject'
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.2
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-19 00:00:00.000000000 Z
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/inject.rb
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
@@ -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