rubocop-asjer 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d3baa4746687feba0e12f1d08c584524c9bd9305b83fed096327a4cf2634ce03
4
+ data.tar.gz: '085b3e1bedd28616edaf83348311646fed5d37e1def1424935d7b416dab4d6f2'
5
+ SHA512:
6
+ metadata.gz: fd93f923f955d81e3100ed7e727602b94f428a33fe08493138aa4b0b581f142271a71c3bd56e40e0b6981ffbefd2db659a0d5ed096dd68ff13114410ea39431b
7
+ data.tar.gz: 776b58fbb2a39b57e1d0167f32cb2bfb83f0d5c383d752a16f1999eb585673a2f17cee5368ce4dced75b6d33124afb1d43b1eba97b504df8c1c485e886bfe51d
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.1.0"
3
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2025-12-31)
4
+
5
+
6
+ ### Features
7
+
8
+ * add `Asjer/NoDefaultTranslation` cop to prevent use of `default:` option in translation calls ([0420fab](https://github.com/asjer/rubocop-asjer/commit/0420fabe0a3d3ca18eef1fb3475934825a2c4d7c))
9
+
10
+ ## Changelog
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Asjer Querido
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # RuboCop Asjer
2
+
3
+ Custom RuboCop cops: enforce i18n best practices and code quality standards.
4
+
5
+ ## Installation
6
+
7
+ Add to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubocop-asjer', require: false
11
+ ```
12
+
13
+ Then run:
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Add to your `.rubocop.yml`:
22
+
23
+ ```yaml
24
+ require:
25
+ - rubocop-asjer
26
+ ```
27
+
28
+ ## Available Cops
29
+
30
+ ### Asjer/NoDefaultTranslation
31
+
32
+ Checks for translation calls that use the `default:` option. Using `default:` bypasses the locale system and can lead to inconsistencies.
33
+
34
+ ```ruby
35
+ # bad
36
+ t('some.key', default: 'fallback text')
37
+ I18n.t('some.key', default: 'fallback')
38
+ I18n.translate('some.key', default: t('other.key'))
39
+
40
+ # good
41
+ t('some.key')
42
+ I18n.t('some.key')
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests.
48
+
49
+ To install this gem onto your local machine, run `bundle exec rake install`.
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/asjer/rubocop-asjer.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,4 @@
1
+ Asjer/NoDefaultTranslation:
2
+ Description: Checks for use of the `default:` option in translation calls.
3
+ Enabled: true
4
+ VersionAdded: "0.1.0"
data/greptile.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "triggerOnUpdates": true
3
+ }
data/lefthook.yml ADDED
@@ -0,0 +1,5 @@
1
+ remotes:
2
+ - git_url: https://github.com/asjer/lefthook-configs
3
+ refetch_frequency: 24h
4
+ configs:
5
+ lefthook-gem.yml
@@ -0,0 +1,20 @@
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!
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Asjer
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'asjer/version'
6
+ require_relative 'asjer/inject'
7
+ require_relative 'cop/asjer/no_default_translation'
8
+
9
+ module RuboCop
10
+ module Asjer
11
+ class Error < StandardError; end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Asjer
6
+ # Checks for translation calls that use the `default:` option.
7
+ #
8
+ # Using `default:` bypasses the locale system and can lead to
9
+ # inconsistencies. Define all translations in the locale files instead.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # t('some.key', default: 'fallback text')
14
+ # I18n.t('some.key', default: 'fallback')
15
+ # I18n.translate('some.key', default: t('other.key'))
16
+ #
17
+ # # good
18
+ # t('some.key')
19
+ # I18n.t('some.key')
20
+ #
21
+ class NoDefaultTranslation < Base
22
+ MSG = 'Define translations in locale files instead of using `default:`.'
23
+
24
+ RESTRICT_ON_SEND = %i[t translate].freeze
25
+
26
+ # @!method translation_with_default?(node)
27
+ def_node_matcher :translation_with_default?, <<~PATTERN
28
+ (send {nil? (const {nil? cbase} :I18n)} {:t :translate} ... (hash <$(pair (sym :default) _) ...>))
29
+ PATTERN
30
+
31
+ def on_send(node)
32
+ translation_with_default?(node) do |default_pair|
33
+ add_offense(default_pair)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ {
2
+ "include-component-in-tag": false,
3
+ "packages": {
4
+ ".": {
5
+ "release-type": "ruby",
6
+ "package-name": "rubocop-asjer",
7
+ "version-file": "lib/rubocop/asjer/version.rb",
8
+ "changelog-path": "CHANGELOG.md"
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ module Rubocop
2
+ module I18n
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-asjer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Asjer Querido
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rubocop
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ description: A collection of custom RuboCop cops for personal use, including i18n
27
+ best practices.
28
+ email:
29
+ - mail@asjer.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".release-please-manifest.json"
35
+ - CHANGELOG.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - config/default.yml
40
+ - greptile.json
41
+ - lefthook.yml
42
+ - lib/rubocop/asjer.rb
43
+ - lib/rubocop/asjer/inject.rb
44
+ - lib/rubocop/asjer/version.rb
45
+ - lib/rubocop/cop/asjer/no_default_translation.rb
46
+ - release-please-config.json
47
+ - sig/rubocop/i18n.rbs
48
+ homepage: https://github.com/asjer/rubocop-asjer
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/asjer/rubocop-asjer
53
+ source_code_uri: https://github.com/asjer/rubocop-asjer
54
+ changelog_uri: https://github.com/asjer/rubocop-asjer/blob/main/CHANGELOG.md
55
+ rubygems_mfa_required: 'true'
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.2.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: Custom RuboCop cops by Asjer
73
+ test_files: []