rubocop-asjer 0.2.0 → 0.3.1
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 +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +14 -0
- data/lib/rubocop/asjer/version.rb +1 -1
- data/lib/rubocop/cop/asjer/no_default_translation.rb +40 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a228c899c0ddc18cd12cc18f5d43dced28ade2a8e230b61db7d2b4eff348671b
|
|
4
|
+
data.tar.gz: 3bee7420da10095a5d2c2eb4cbbde60f3fbb787f46bf73875288da5a07eb4372
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c63346eb316976ed2c79a48d52354f55b533d2c45aff4b9ebecb1989a5f023b2456a9078bc7ce92fd29f774960bb616da32841f9280c48424fc81005c66bf9ca
|
|
7
|
+
data.tar.gz: 9dd4c7226b6f413d716a5cb4687d6233f301284d21fb1c9c9e67850a92ed5f394b685fbe2518712573d261ece51fb7e3517ffa7dbfc9327030efa1923cf50787
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.1](https://github.com/asjer/rubocop-asjer/compare/v0.3.0...v0.3.1) (2026-01-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* enable autocorrect for all `default:` option cases in `NoDefaultTranslation` ([fbd359e](https://github.com/asjer/rubocop-asjer/commit/fbd359e6f252188880535c87b3f5abbbd8bac571))
|
|
9
|
+
|
|
10
|
+
## [0.3.0](https://github.com/asjer/rubocop-asjer/compare/v0.2.0...v0.3.0) (2026-01-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* enhance `Asjer/NoDefaultTranslation` cop with autocorrection for default option usage ([2773334](https://github.com/asjer/rubocop-asjer/commit/27733346af4884edad9d495d4ef9d566d36d4584))
|
|
16
|
+
|
|
3
17
|
## [0.2.0](https://github.com/asjer/rubocop-asjer/compare/v0.1.0...v0.2.0) (2025-12-31)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -19,6 +19,9 @@ module RuboCop
|
|
|
19
19
|
# I18n.t('some.key')
|
|
20
20
|
#
|
|
21
21
|
class NoDefaultTranslation < Base
|
|
22
|
+
extend AutoCorrector
|
|
23
|
+
include RangeHelp
|
|
24
|
+
|
|
22
25
|
MSG = 'Define translations in locale files instead of using `default:`.'
|
|
23
26
|
|
|
24
27
|
RESTRICT_ON_SEND = %i[t translate].freeze
|
|
@@ -30,9 +33,45 @@ module RuboCop
|
|
|
30
33
|
|
|
31
34
|
def on_send(node)
|
|
32
35
|
translation_with_default?(node) do |default_pair|
|
|
33
|
-
add_offense(default_pair)
|
|
36
|
+
add_offense(default_pair) do |corrector|
|
|
37
|
+
corrector.remove(removal_range(default_pair))
|
|
38
|
+
end
|
|
34
39
|
end
|
|
35
40
|
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def removal_range(node)
|
|
45
|
+
hash_node = node.parent
|
|
46
|
+
pairs = hash_node.pairs
|
|
47
|
+
|
|
48
|
+
return hash_with_comma_range(hash_node) if pairs.size == 1
|
|
49
|
+
|
|
50
|
+
pair_removal_range(node, pairs)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def hash_with_comma_range(hash_node)
|
|
54
|
+
with_space = range_with_surrounding_space(range: hash_node.source_range, side: :left)
|
|
55
|
+
range_with_surrounding_comma(with_space, :left)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def pair_removal_range(node, pairs)
|
|
59
|
+
index = pairs.index(node)
|
|
60
|
+
|
|
61
|
+
last_pair?(index, pairs) ? leading_range(node, pairs[index - 1]) : trailing_range(node, pairs[index + 1])
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def last_pair?(index, pairs)
|
|
65
|
+
index == pairs.size - 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def leading_range(node, prev_pair)
|
|
69
|
+
range_between(prev_pair.source_range.end_pos, node.source_range.end_pos)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def trailing_range(node, next_pair)
|
|
73
|
+
range_between(node.source_range.begin_pos, next_pair.source_range.begin_pos)
|
|
74
|
+
end
|
|
36
75
|
end
|
|
37
76
|
end
|
|
38
77
|
end
|