rubocop-asjer 0.1.0 → 0.3.0
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/README.md +3 -1
- data/lib/rubocop/asjer/plugin.rb +31 -0
- data/lib/rubocop/asjer/version.rb +1 -1
- data/lib/rubocop/asjer.rb +1 -1
- data/lib/rubocop/cop/asjer/no_default_translation.rb +30 -1
- metadata +19 -4
- data/lib/rubocop/asjer/inject.rb +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 421e0eeba6d681b0ee11e88059773f9278c24aa02c30f509e2bd23713ca321e8
|
|
4
|
+
data.tar.gz: fc1298e689e874814629eab4120349f7658fc848719fff602608f92feb81bb0c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e9d9d5a7d0169b30cafb338aa14c61dacfceca1f423d66892791f51fca3d4f3be8a400cc14a834360cdd3ab5e52153658ff1725922a293bf7bca70d81854c31
|
|
7
|
+
data.tar.gz: 9186614b1209094a659de0a9ec93bc3c5ab7d581db77528977f6ecf4f188350bc9ec32348c356dcb8d1b38e78f82aeb7b4a9f03323eefc5c1c788b5ce6e47ee7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.3.0](https://github.com/asjer/rubocop-asjer/compare/v0.2.0...v0.3.0) (2026-01-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* enhance `Asjer/NoDefaultTranslation` cop with autocorrection for default option usage ([2773334](https://github.com/asjer/rubocop-asjer/commit/27733346af4884edad9d495d4ef9d566d36d4584))
|
|
9
|
+
|
|
10
|
+
## [0.2.0](https://github.com/asjer/rubocop-asjer/compare/v0.1.0...v0.2.0) (2025-12-31)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* integrate `lint_roller` and refactor as a plugin ([476e97a](https://github.com/asjer/rubocop-asjer/commit/476e97ab7635770a7fc6d9f163c8dd833bc3714f))
|
|
16
|
+
|
|
3
17
|
## 0.1.0 (2025-12-31)
|
|
4
18
|
|
|
5
19
|
|
data/README.md
CHANGED
|
@@ -21,10 +21,12 @@ bundle install
|
|
|
21
21
|
Add to your `.rubocop.yml`:
|
|
22
22
|
|
|
23
23
|
```yaml
|
|
24
|
-
|
|
24
|
+
plugins:
|
|
25
25
|
- rubocop-asjer
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
> **Note:** The `plugins` directive requires RuboCop 1.72+. For older versions, use `require: rubocop-asjer` instead.
|
|
29
|
+
|
|
28
30
|
## Available Cops
|
|
29
31
|
|
|
30
32
|
### Asjer/NoDefaultTranslation
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'lint_roller'
|
|
4
|
+
|
|
5
|
+
module RuboCop
|
|
6
|
+
module Asjer
|
|
7
|
+
# A plugin that integrates RuboCop Asjer with RuboCop's plugin system.
|
|
8
|
+
class Plugin < LintRoller::Plugin
|
|
9
|
+
def about
|
|
10
|
+
LintRoller::About.new(
|
|
11
|
+
name: 'rubocop-asjer',
|
|
12
|
+
version: VERSION,
|
|
13
|
+
homepage: 'https://github.com/asjer/rubocop-asjer',
|
|
14
|
+
description: 'A collection of custom RuboCop cops for personal use, including i18n best practices.'
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def supported?(context)
|
|
19
|
+
context.engine == :rubocop
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def rules(_context)
|
|
23
|
+
LintRoller::Rules.new(
|
|
24
|
+
type: :path,
|
|
25
|
+
config_format: :rubocop,
|
|
26
|
+
value: Pathname.new(__dir__).join('../../../config/default.yml')
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
data/lib/rubocop/asjer.rb
CHANGED
|
@@ -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,35 @@ 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
|
+
# Skip autocorrection if default: is the only hash option
|
|
38
|
+
next if default_pair.parent.pairs.size == 1
|
|
39
|
+
|
|
40
|
+
corrector.remove(removal_range(default_pair))
|
|
41
|
+
end
|
|
34
42
|
end
|
|
35
43
|
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def removal_range(node)
|
|
48
|
+
pairs = node.parent.pairs
|
|
49
|
+
index = pairs.index(node)
|
|
50
|
+
|
|
51
|
+
last_pair?(index, pairs) ? leading_range(node, pairs[index - 1]) : trailing_range(node, pairs[index + 1])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def last_pair?(index, pairs)
|
|
55
|
+
index == pairs.size - 1
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def leading_range(node, prev_pair)
|
|
59
|
+
range_between(prev_pair.source_range.end_pos, node.source_range.end_pos)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def trailing_range(node, next_pair)
|
|
63
|
+
range_between(node.source_range.begin_pos, next_pair.source_range.begin_pos)
|
|
64
|
+
end
|
|
36
65
|
end
|
|
37
66
|
end
|
|
38
67
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-asjer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Asjer Querido
|
|
@@ -9,20 +9,34 @@ bindir: exe
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: lint_roller
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.1'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: rubocop
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
15
29
|
requirements:
|
|
16
30
|
- - ">="
|
|
17
31
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
32
|
+
version: 1.72.0
|
|
19
33
|
type: :runtime
|
|
20
34
|
prerelease: false
|
|
21
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
36
|
requirements:
|
|
23
37
|
- - ">="
|
|
24
38
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
39
|
+
version: 1.72.0
|
|
26
40
|
description: A collection of custom RuboCop cops for personal use, including i18n
|
|
27
41
|
best practices.
|
|
28
42
|
email:
|
|
@@ -40,7 +54,7 @@ files:
|
|
|
40
54
|
- greptile.json
|
|
41
55
|
- lefthook.yml
|
|
42
56
|
- lib/rubocop/asjer.rb
|
|
43
|
-
- lib/rubocop/asjer/
|
|
57
|
+
- lib/rubocop/asjer/plugin.rb
|
|
44
58
|
- lib/rubocop/asjer/version.rb
|
|
45
59
|
- lib/rubocop/cop/asjer/no_default_translation.rb
|
|
46
60
|
- release-please-config.json
|
|
@@ -53,6 +67,7 @@ metadata:
|
|
|
53
67
|
source_code_uri: https://github.com/asjer/rubocop-asjer
|
|
54
68
|
changelog_uri: https://github.com/asjer/rubocop-asjer/blob/main/CHANGELOG.md
|
|
55
69
|
rubygems_mfa_required: 'true'
|
|
70
|
+
default_lint_roller_plugin: RuboCop::Asjer::Plugin
|
|
56
71
|
rdoc_options: []
|
|
57
72
|
require_paths:
|
|
58
73
|
- lib
|
data/lib/rubocop/asjer/inject.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'yaml'
|
|
4
|
-
|
|
5
|
-
module RuboCop
|
|
6
|
-
module Asjer
|
|
7
|
-
# Injects the default configuration into RuboCop
|
|
8
|
-
class Inject
|
|
9
|
-
def self.defaults!
|
|
10
|
-
path = File.expand_path('../../../config/default.yml', __dir__)
|
|
11
|
-
hash = YAML.safe_load_file(path)
|
|
12
|
-
config = RuboCop::Config.new(hash, path)
|
|
13
|
-
config = RuboCop::ConfigLoader.merge_with_default(config, path)
|
|
14
|
-
RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
RuboCop::Asjer::Inject.defaults!
|