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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/rubocop/cop/ipepe/alphabetical_hash_keys.rb +16 -10
- data/lib/rubocop/ipepe/version.rb +1 -1
- data/rubocop-ipepe.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de4eaca3e90e2d725150dfd73f2ac1f7fe2ded6cd6e74fbc655bda32271aff06
|
4
|
+
data.tar.gz: ed69c79e05e846fcb7ba3dbcbad84fd79a166038a1a62dfd51ed7510a16f1865
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70334cad11275adc26a93458415d56bc61782bd12ba25055d62dec895c2dd4cc37d6bec273e2ddd596d4b794ed30a9dd5d1c736980a66f721b31e2434ad78d8e
|
7
|
+
data.tar.gz: 401005de826accbc78ddeb851d09202a67d22b073760178f31128977c280f32496b0e74419f2416989f34d21b77695d364594c3e673ec599d15bef75d1180bb4
|
data/Gemfile.lock
CHANGED
@@ -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
|
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.
|
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
|
data/rubocop-ipepe.gemspec
CHANGED
@@ -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", "
|
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.
|
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:
|
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.
|
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.
|
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
|