Skip to content

Commit

Permalink
Fix rubocop warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Jan 16, 2018
1 parent b509482 commit bd46109
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 35 deletions.
4 changes: 1 addition & 3 deletions bin/i18n-tasks
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

if ENV['I18N_TASKS_BIN_SIMPLECOV_COVERAGE']
require_relative '../spec/bin_simplecov_helper'
end
require_relative '../spec/bin_simplecov_helper' if ENV['I18N_TASKS_BIN_SIMPLECOV_COVERAGE']

# prevent i18n gem warning
require 'i18n'
Expand Down
6 changes: 3 additions & 3 deletions i18n-tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
TEXT
s.homepage = 'https://github.com/glebm/i18n-tasks'
if s.respond_to?(:metadata=)
s.metadata = { 'issue_tracker' => 'https://github.com/glebm/i18n-tasks' }
end
s.metadata = { 'issue_tracker' => 'https://github.com/glebm/i18n-tasks' } if s.respond_to?(:metadata=)
# rubocop:disable Gemspec/RequiredRubyVersion
s.required_ruby_version = '~> 2.1' if s.respond_to?(:required_ruby_version=)
# rubocop:enable Gemspec/RequiredRubyVersion

s.files = `git ls-files`.split($/)
s.files -= s.files.grep(%r{^(doc/|\.|spec/)}) + %w[CHANGES.md config/i18n-tasks.yml Gemfile]
Expand Down
4 changes: 1 addition & 3 deletions lib/i18n/tasks/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def optparse_no_command!(argv)

def allow_help_arg_first!(argv)
# allow `i18n-tasks --help command` in addition to `i18n-tasks command --help`
if %w[-h --help].include?(argv[0]) && argv[1] && !argv[1].start_with?('-')
argv[0], argv[1] = argv[1], argv[0]
end
argv[0], argv[1] = argv[1], argv[0] if %w[-h --help].include?(argv[0]) && argv[1] && !argv[1].start_with?('-')
end

def parse_command!(argv)
Expand Down
4 changes: 1 addition & 3 deletions lib/i18n/tasks/command/commands/health.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ module Health
def health(opt = {})
forest = i18n.data_forest(opt[:locales])
stats = i18n.forest_stats(forest)
if stats[:key_count].zero?
fail CommandError, t('i18n_tasks.health.no_keys_detected')
end
fail CommandError, t('i18n_tasks.health.no_keys_detected') if stats[:key_count].zero?
terminal_report.forest_stats forest, stats
[missing(opt), unused(opt), check_normalized(opt)].detect { |result| result == :exit_1 }
end
Expand Down
4 changes: 1 addition & 3 deletions lib/i18n/tasks/command/options/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def merge_forests_stdin_and_pos!(opt)

# @return [I18n::Tasks::Data::Tree::Siblings]
def parse_forest(src, format)
unless src
fail CommandError, I18n.t('i18n_tasks.cmd.errors.pass_forest')
end
fail CommandError, I18n.t('i18n_tasks.cmd.errors.pass_forest') unless src
if format == 'keys'
::I18n::Tasks::Data::Tree::Siblings.from_key_names parse_keys(src)
else
Expand Down
8 changes: 2 additions & 6 deletions lib/i18n/tasks/data/tree/siblings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,8 @@ def from_flat_pairs(pairs)
private

def parse_parent_opt!(opts)
if opts[:parent_key]
opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(key: opts[:parent_key])
end
if opts[:parent_attr]
opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(opts[:parent_attr])
end
opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(key: opts[:parent_key]) if opts[:parent_key]
opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(opts[:parent_attr]) if opts[:parent_attr]
if opts[:parent_locale]
opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(
key: opts[:parent_locale], data: { locale: opts[:parent_locale] }
Expand Down
4 changes: 1 addition & 3 deletions lib/i18n/tasks/data/tree/traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ def set_each_value!(val_pattern, key_pattern = nil, &value_proc)
value_or_default_or_human_key: node_value.presence || default || human_key
)
end
if key_pattern.present?
pattern_re = I18n::Tasks::KeyPatternMatching.compile_key_pattern(key_pattern)
end
pattern_re = I18n::Tasks::KeyPatternMatching.compile_key_pattern(key_pattern) if key_pattern.present?
keys.each do |key, node| # rubocop:disable Performance/HashEachMethods
next if pattern_re && key !~ pattern_re
node.value = value_proc.call(node)
Expand Down
8 changes: 2 additions & 6 deletions lib/i18n/tasks/google_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ def google_translate_list(list, opts) # rubocop:disable Metrics/AbcSize
# @return [Array<[String, Object]>] translated list
def fetch_google_translations(list, opts)
from_values(list, EasyTranslate.translate(to_values(list), opts)).tap do |result|
if result.blank?
fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_results')
end
fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_results') if result.blank?
end
end

private

def validate_google_translate_api_key!(key)
if key.blank?
fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_api_key')
end
fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_api_key') if key.blank?
end

# @param [Array<[String, Object]>] list of key-value pairs
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/reports/terminal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module I18n
module Tasks
module Reports
class Terminal < Base # rubocop:disable Metrics/ClassLength
def missing_keys(forest = task.missing_keys) # rubocop:disable Metrics/AbcSize
def missing_keys(forest = task.missing_keys)
forest = collapse_missing_tree! forest
if forest.present?
print_title missing_title(forest)
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/tasks/scanners/results/occurrence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def initialize(path:, pos:, line_num:, line_pos:, line:, raw_key: nil, default_a
@raw_key = raw_key
@default_arg = default_arg
end
# rubocop:enable Metrics/ParameterLists

def inspect
"Occurrence(#{@path}:#{@line_num}:#{@line_pos}:#{@pos}:#{@raw_key}:#{@default_arg})"
Expand Down
4 changes: 1 addition & 3 deletions lib/i18n/tasks/scanners/ruby_ast_call_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def on_send(send_node)
message = send_node.children[1]
valid_receivers = @message_receivers[message]
# use `any?` because `include?` checks type equality, but the receiver is a Parser::AST::Node != AST::Node.
if valid_receivers && valid_receivers.any? { |r| r == receiver }
@callback.call(send_node, @method_name)
end
@callback.call(send_node, @method_name) if valid_receivers && valid_receivers.any? { |r| r == receiver }
# always invoke handler_missing to get nested translations in children
handler_missing send_node
nil
Expand Down
1 change: 0 additions & 1 deletion lib/i18n/tasks/used_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def scanner(strict: nil)
if args && args[:strict]
fail CommandError, 'the strict option is global and cannot be applied on the scanner level'
end

ActiveSupport::Inflector.constantize(class_name).new(
config: merge_scanner_configs(shared_options, args || {}),
file_finder_provider: caching_file_finder_provider,
Expand Down
1 change: 1 addition & 0 deletions spec/support/keys_and_occurrences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def make_occurrence(path: '', line: '', pos: 1, line_pos: 1, line_num: 1, raw_ke
path: path, line: line, pos: pos, line_pos: line_pos, line_num: line_num, raw_key: raw_key
)
end
# rubocop:enable Metrics/ParameterLists

def make_occurrences(occurrences)
occurrences.map { |attr| make_occurrence(attr) }
Expand Down

0 comments on commit bd46109

Please sign in to comment.