rubocop-ipepe 0.2.0 → 0.2.5

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: 88e1adbe08b2ef30c8afacb029a5240dcb26fb73cb7462951a5e48b42a2c011e
4
- data.tar.gz: f09e9d131d92b567b163af95a17399ea251d0c04cb73de37bacf763b5762c305
3
+ metadata.gz: de4eaca3e90e2d725150dfd73f2ac1f7fe2ded6cd6e74fbc655bda32271aff06
4
+ data.tar.gz: ed69c79e05e846fcb7ba3dbcbad84fd79a166038a1a62dfd51ed7510a16f1865
5
5
  SHA512:
6
- metadata.gz: b43f6237752ad1a9f250c9645c1fbdcbb547c2b5c2f76ed12246d8c3bdc83a8df660f6980ba0b59caa69dd87be9b61c5d56e3fc47f8c85b721eb618231c57863
7
- data.tar.gz: f4ea5b113609baa4371c244272c00daa21d912436fb4d474c51ef1a1977370a9935222b62e534c1d306153ff01bd571e4459761e6e2143ce617cb3df67103568
6
+ metadata.gz: 70334cad11275adc26a93458415d56bc61782bd12ba25055d62dec895c2dd4cc37d6bec273e2ddd596d4b794ed30a9dd5d1c736980a66f721b31e2434ad78d8e
7
+ data.tar.gz: 401005de826accbc78ddeb851d09202a67d22b073760178f31128977c280f32496b0e74419f2416989f34d21b77695d364594c3e673ec599d15bef75d1180bb4
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-ipepe (0.2.0)
5
- rubocop (~> 1.41)
4
+ rubocop-ipepe (0.2.5)
5
+ rubocop (>= 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -5,9 +5,15 @@ module RuboCop
5
5
  extend AutoCorrector
6
6
  MSG = "Ensure that keys in hash are in alphabetical order".freeze
7
7
 
8
- def on_hash(node)
8
+ def on_hash(node) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
9
9
  keys = node.children.select(&:pair_type?).map(&:key)
10
- sorted_keys = keys.sort_by(&:value)
10
+ sorted_keys = keys.sort_by do |k|
11
+ if k.respond_to?(:value)
12
+ k.value.to_s
13
+ elsif k.respond_to?(:const_name)
14
+ k.const_name.to_s
15
+ end
16
+ end
11
17
  return if cop_not_applicable?(keys, sorted_keys)
12
18
 
13
19
  add_offense(node) do |corrector|
@@ -17,30 +23,30 @@ module RuboCop
17
23
  corrector.replace(
18
24
  node,
19
25
  [
20
- "{",
26
+ ("{" if node.source.start_with?("{")),
21
27
  sorted_keypairs(node, sorted_keys).join(",#{join_keys_with}"),
22
- "}"
23
- ].join(join_keys_with)
28
+ ("}" if node.source.end_with?("}"))
29
+ ].compact.join(join_keys_with)
24
30
  )
25
31
  end
26
32
  end
27
33
 
28
34
  private
29
35
 
30
- def cop_not_applicable?(keys, sorted_keys)
36
+ def cop_not_applicable?(keys, sorted_keys) # rubocop:disable Metrics/PerceivedComplexity
31
37
  keys.empty? ||
32
38
  keys.one? ||
33
- (keys.none?(&:str_type?) && keys.none?(&:sym_type?)) ||
39
+ (keys.none?(&:str_type?) && keys.none?(&:sym_type?) && keys.none?(&:const_type?)) ||
34
40
  keys == sorted_keys
35
41
  end
36
42
 
37
43
  def sorted_keypairs(node, sorted_keys)
38
44
  sorted_keys.map do |k|
39
45
  keypair = node.children.find { |n| n.key == k }
40
- if keypair.key.str_type?
41
- "#{keypair.key.source} => #{keypair.value.source}"
42
- elsif keypair.key.sym_type?
46
+ if keypair.key.sym_type?
43
47
  "#{keypair.key.source}: #{keypair.value.source}"
48
+ else
49
+ "#{keypair.key.source} => #{keypair.value.source}"
44
50
  end
45
51
  end
46
52
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module Ipepe
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "0.2.5".freeze
4
4
  end
5
5
  end
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_runtime_dependency "rubocop", "~> 1.41"
30
+ spec.add_runtime_dependency "rubocop", ">= 1.0"
31
31
  spec.metadata["rubygems_mfa_required"] = "true"
32
32
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-ipepe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patryk Ptasinski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-21 00:00:00.000000000 Z
11
+ date: 2024-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.41'
19
+ version: '1.0'
20
20
  type: :runtime
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: '1.41'
26
+ version: '1.0'
27
27
  description: This gem is a collection of RuboCop cops used by ipepe.
28
28
  email:
29
29
  - patryk@ipepe.pl