Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to RuboCop 1.0 #46

Merged
merged 6 commits into from Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 40 additions & 34 deletions .rubocop_todo.yml
@@ -1,44 +1,50 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-06-12 15:16:26 -0700 using RuboCop version 0.57.2.
# on 2020-10-25 09:49:30 UTC using RuboCop version 1.0.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
# Offense count: 1
# Configuration parameters: Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'rubocop-i18n.gemspec'

# Offense count: 1
# Cop supports --auto-correct.
Lint/InterpolationCheck:
Exclude:
- 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb'

# Offense count: 4
# Offense count: 2
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 29

# Offense count: 6
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Enabled: false
Max: 61

# Offense count: 1
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Enabled: false
Max: 106
Max: 108

# Offense count: 3
# Offense count: 5
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 7
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
Metrics/MethodLength:
Max: 25

# Offense count: 2
Metrics/PerceivedComplexity:
Max: 8
# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'lib/rubocop-i18n.rb'

# Offense count: 2
Style/Documentation:
Expand All @@ -49,37 +55,37 @@ Style/Documentation:
- 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'

# Offense count: 12
# Configuration parameters: EnforcedStyle.
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
Exclude:
- 'spec/rubocop/cop/i18n/gettext/decorate_function_message_spec.rb'
- 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation_spec.rb'
- 'spec/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation_spec.rb'
- 'spec/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent_spec.rb'
- 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb'
EnforcedStyle: template

# Offense count: 3
# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
- 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'

# Offense count: 10
# Offense count: 6
# Cop supports --auto-correct.
Style/IfUnlessModifier:
Exclude:
- 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
- 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
- 'lib/rubocop/rspec/cop_helper.rb'

# Offense count: 93
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Offense count: 5
# Configuration parameters: AllowModifier.
Style/SoleNestedConditional:
Exclude:
- 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
- 'lib/rubocop/cop/i18n/gettext/decorate_string.rb'
- 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
- 'lib/rubocop/cop/i18n/rails_i18n/decorate_string.rb'

# Offense count: 50
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Layout/LineLength:
Max: 174

Naming/FileName:
Exclude:
- 'lib/rubocop-i18n.rb'
40 changes: 20 additions & 20 deletions README.md
Expand Up @@ -34,33 +34,33 @@ require:
...
# You *must* choose GetText or Rails-i18n style checking
# If you want GetText-style checking
GetText:
I18n/GetText:
Enabled: true
RailsI18n:
I18n/RailsI18n:
Enabled: false
# If you want rails-i18n-style checking
RailsI18n:
I18n/RailsI18n:
Enabled: true
GetText:
I18n/GetText:
Enabled: false
# If you want custom control of all the cops
GetText/DecorateString:
I18n/GetText/DecorateString:
Enabled: false
# Disable the autocorrect
AutoCorrect: false
GetText/DecorateFunctionMessage:
I18n/GetText/DecorateFunctionMessage:
Enabled: false
GetText/DecorateStringFormattingUsingInterpolation:
I18n/GetText/DecorateStringFormattingUsingInterpolation:
Enabled: false
GetText/DecorateStringFormattingUsingPercent:
I18n/GetText/DecorateStringFormattingUsingPercent:
Enabled: false
RailsI18n/DecorateString:
I18n/RailsI18n/DecorateString:
Enabled: false
```

## Cops

### GetText/DecorateString
### I18n/GetText/DecorateString

This cop is looks for strings that appear to be sentences but are not decorated.
Sentences are determined by the STRING_REGEXP.
Expand Down Expand Up @@ -90,7 +90,7 @@ _("Result is good.")
"a string that doesn't start with a capital letter."
```

### GetText/DecorateFunctionMessage
### I18n/GetText/DecorateFunctionMessage

This cop looks for any raise or fail functions and checks that the user visible message is using gettext decoration with the _() function.
This cop makes sure the message is decorated, as well as checking that the formatting of the message is compliant according to the follow rules.
Expand Down Expand Up @@ -206,7 +206,7 @@ raise(someOtherFuntioncall(foo, "bar"))
In this raise or fail function, the message does not contain any decoration at all and the message is not a simple string. It may make sense to convert the message to a simple string. eg [Simple decoration of a message](#Simple-decoration-of-a-message).
Or ignore this raise or fail function following this [How to ignore rules in code](#How-to-ignore-rules-in-code) section.

### GetText/DecorateStringFormattingUsingInterpolation
### I18n/GetText/DecorateStringFormattingUsingInterpolation

This cop looks for decorated gettext methods _() and checks that all strings contained
within do not use string interpolation '#{}'
Expand All @@ -233,7 +233,7 @@ puts _("a message with a #{'interpolation'}")
puts _("a message that is %{type}") % { type: 'translatable' }
```

### GetText/DecorateStringFormattingUsingPercent
### I18n/GetText/DecorateStringFormattingUsingPercent

This cop looks for decorated gettext methods _() and checks that all strings contained
within do not use sprintf formatting '%s' etc
Expand All @@ -256,7 +256,7 @@ raise(_("Warning is %s") % ['bad'])
raise(_("Warning is %{value}") % { value: 'bad' })
```

### RailsI18n/DecorateString
### I18n/RailsI18n/DecorateString

This cop looks for decorated rails-i18n methods.

Expand All @@ -280,7 +280,7 @@ raise(translate("Warning is %{value}") % { value: 'good' })
raise(I18n.t("Warning is %{value}") % { value: 'good' })
```

### RailsI18n/DecorateStringFormattingUsingInterpolation
### I18n/RailsI18n/DecorateStringFormattingUsingInterpolation

This cop looks for decorated rails-i18n methods like `t()` and `translate()` and checks that all strings contained
within do not use string interpolation '#{}'
Expand Down Expand Up @@ -311,11 +311,11 @@ puts t("path.to.key.with.interpolation")

It may be necessary to ignore a cop for a particular piece of code. We follow standard rubocop idioms.
``` ruby
raise("We don't want this translated.") # rubocop:disable GetText/DecorateString
raise("We don't want this translated.") # rubocop:disable RailsI18n/DecorateString
raise("We don't want this translated") # rubocop:disable GetText/DecorateFunctionMessage
raise(_("We don't want this translated #{crazy}") # rubocop:disable GetText/DecorateStringFormattingUsingInterpolation)
raise(_("We don't want this translated %s") % ['crazy'] # rubocop:disable GetText/DecorateStringFormattingUsingPercent)
raise("We don't want this translated.") # rubocop:disable I18n/GetText/DecorateString
raise("We don't want this translated.") # rubocop:disable I18n/RailsI18n/DecorateString
raise("We don't want this translated") # rubocop:disable I18n/GetText/DecorateFunctionMessage
raise(_("We don't want this translated #{crazy}") # rubocop:disable I18n/GetText/DecorateStringFormattingUsingInterpolation)
raise(_("We don't want this translated %s") % ['crazy'] # rubocop:disable I18n/GetText/DecorateStringFormattingUsingPercent)
```

## Known Issues
Expand Down
4 changes: 1 addition & 3 deletions rubocop-i18n.gemspec
Expand Up @@ -2,7 +2,6 @@

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
rubocop_version = '~> 0.51'

Gem::Specification.new do |spec|
spec.name = 'rubocop-i18n'
Expand All @@ -27,6 +26,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '>= 12.3.3'
spec.add_development_dependency 'rb-readline', '~> 0.5.5'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop', rubocop_version
spec.add_runtime_dependency 'rubocop', rubocop_version
spec.add_runtime_dependency 'rubocop', '~> 1.0'
end
6 changes: 3 additions & 3 deletions spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb
Expand Up @@ -110,7 +110,7 @@

context 'when ignoring raised exceptions' do
let(:config) do
RuboCop::Config.new('RailsI18n/DecorateString' => { 'IgnoreExceptions' => true })
RuboCop::Config.new('I18n/RailsI18n/DecorateString' => { 'IgnoreExceptions' => true })
end

%w[fail raise].each do |type|
Expand All @@ -122,7 +122,7 @@

context 'when configuring a different regex' do
let(:config) do
RuboCop::Config.new('RailsI18n/DecorateString' => { 'Regexp' => '^test-test-test$' })
RuboCop::Config.new('I18n/RailsI18n/DecorateString' => { 'Regexp' => '^test-test-test$' })
end

it_behaves_like 'a_no_cop_required', "not_t('A sentence.')"
Expand All @@ -131,7 +131,7 @@

context 'when string type' do
let(:config) do
RuboCop::Config.new('RailsI18n/DecorateString' => { 'EnforcedSentenceType' => type })
RuboCop::Config.new('I18n/RailsI18n/DecorateString' => { 'EnforcedSentenceType' => type })
end

context 'is sentence' do
Expand Down
5 changes: 2 additions & 3 deletions spec/spec_helper.rb
@@ -1,10 +1,9 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'shared_functions'
require 'shared_examples'
require 'rubocop/cop/i18n'
require 'rubocop/rspec/cop_helper'
require 'shared_examples'
require 'shared_functions'

RSpec.configure do |config|
# These two settings work together to allow you to limit a spec run
Expand Down