Skip to content

Commit

Permalink
Drop MRI < 2.3 support and test against the latest rubies (#298)
Browse files Browse the repository at this point in the history
* Test against the latest ruby
* Test against all major supported MRI's
* Drop support for EOL'd rubies
* Test major supported jrubies as well: 9.1 as MRI 2.3-compatible and 9.2 as MRI 2.5-compatible.
* Fix rubocop TODO's that can now be fixed
  • Loading branch information
deivid-rodriguez authored and glebm committed Sep 13, 2018
1 parent 1c9160c commit 3582b9a
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 111 deletions.
12 changes: 0 additions & 12 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,9 @@ Style/FormatStringToken:
Style/GuardClause:
Enabled: false

Layout/IndentHeredoc:
# TODO(glebm): Remove this when we update the minimum Ruby version to 2.3+.
Enabled: false

Style/MultilineBlockChain:
Enabled: false

Style/NumericPredicate:
# TODO(glebm): Remove this when we update the minimum Ruby version to 2.3+.
Enabled: false

Style/SafeNavigation:
# TODO(glebm): Remove this when we update the minimum Ruby version to 2.3+.
Enabled: false

Style/StderrPuts:
# This is intentional, i18n-tasks stderr output is mostly anything but warnings.
Enabled: false
Expand Down
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ sudo: false
dist: trusty
language: ruby
rvm:
- 2.2.3
- jruby
- 2.5.1
- 2.4.4
- 2.3.7
- jruby-9.1.17.0
- jruby-9.2.0.0
- rbx-3
cache: bundler
bundler_args: --without debug
Expand Down
22 changes: 10 additions & 12 deletions i18n-tasks.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
s.email = ['[email protected]']
s.license = 'MIT'
s.summary = 'Manage localization and translation with the awesome power of static analysis'
s.description = <<-TEXT
i18n-tasks helps you find and manage missing and unused translations.
s.description = <<~TEXT
i18n-tasks helps you find and manage missing and unused translations.
It analyses code statically for key usages, such as `I18n.t('some.key')`, in order to report keys that are missing or unused,
pre-fill missing keys (optionally from Google Translate), and remove unused keys.
It analyses code statically for key usages, such as `I18n.t('some.key')`, in order to report keys that are missing or unused,
pre-fill missing keys (optionally from Google Translate), and remove unused keys.
TEXT
s.post_install_message = <<-TEXT
# Install default configuration:
cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
# Add an RSpec for missing and unused keys:
cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
s.post_install_message = <<~TEXT
# Install default configuration:
cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
# Add an RSpec for missing and unused keys:
cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
TEXT
s.homepage = 'https://github.com/glebm/i18n-tasks'
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.required_ruby_version = '~> 2.3' if s.respond_to?(:required_ruby_version=)

s.files = `git ls-files`.split($/)
s.files -= s.files.grep(%r{^(doc/|\.|spec/)}) + %w[CHANGES.md config/i18n-tasks.yml Gemfile]
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/command/option_parsers/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def call(vals, context)
end

def move_base_locale_to_front!(locales, base_locale)
if (pos = locales.index(base_locale)) && pos > 0
if (pos = locales.index(base_locale)) && pos.positive?
locales[pos], locales[0] = locales[0], locales[pos]
end
locales
Expand Down
60 changes: 30 additions & 30 deletions lib/i18n/tasks/console_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ def banner
end

def guide
Rainbow('i18n-tasks IRB Quick Start guide').green.bright + "\n" + <<-TEXT
#{Rainbow('Data as trees').yellow}
tree(locale)
used_tree(key_filter: nil, strict: nil)
unused_tree(locale: base_locale, strict: nil)
build_tree('es' => {'hello' => 'Hola'})
Rainbow('i18n-tasks IRB Quick Start guide').green.bright + "\n" + <<~TEXT
#{Rainbow('Data as trees').yellow}
tree(locale)
used_tree(key_filter: nil, strict: nil)
unused_tree(locale: base_locale, strict: nil)
build_tree('es' => {'hello' => 'Hola'})
#{Rainbow('Traversal').yellow}
tree = missing_diff_tree('es')
tree.nodes { |node| }
tree.nodes.to_a
tree.leaves { |node| }
tree.each { |root_node| }
# also levels, depth_first, and breadth_first
#{Rainbow('Traversal').yellow}
tree = missing_diff_tree('es')
tree.nodes { |node| }
tree.nodes.to_a
tree.leaves { |node| }
tree.each { |root_node| }
# also levels, depth_first, and breadth_first
#{Rainbow('Select nodes').yellow}
tree.select_nodes { |node| } # new tree with only selected nodes
#{Rainbow('Select nodes').yellow}
tree.select_nodes { |node| } # new tree with only selected nodes
#{Rainbow('Match by full key').yellow}
tree.select_keys { |key, leaf| } # new tree with only selected keys
tree.grep_keys(/hello/) # grep, using ===
tree.keys { |key, leaf| } # enumerate over [full_key, leaf_node]
# Pass {root: true} to include root node in full_key (usually locale)
#{Rainbow('Match by full key').yellow}
tree.select_keys { |key, leaf| } # new tree with only selected keys
tree.grep_keys(/hello/) # grep, using ===
tree.keys { |key, leaf| } # enumerate over [full_key, leaf_node]
# Pass {root: true} to include root node in full_key (usually locale)
#{Rainbow('Nodes').yellow}
node = node(key, locale)
node.key # only the part after the last dot
node.full_key # full key. Includes root key, pass {root: false} to override.
# also: value, value_or_children_hash, data, walk_to_root, walk_from_root
Tree::Node.new(key: 'en')
#{Rainbow('Nodes').yellow}
node = node(key, locale)
node.key # only the part after the last dot
node.full_key # full key. Includes root key, pass {root: false} to override.
# also: value, value_or_children_hash, data, walk_to_root, walk_from_root
Tree::Node.new(key: 'en')
#{Rainbow('Keys').yellow}
t(key, locale)
key_value?(key, locale)
depluralize_key(key, locale) # convert 'hat.one' to 'hat'
#{Rainbow('Keys').yellow}
t(key, locale)
key_value?(key, locale)
depluralize_key(key, locale) # convert 'hat.one' to 'hat'
TEXT
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/i18n/tasks/data/file_system_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def external(locale)
# @param [::I18n::Tasks::Data::Siblings] tree
def set(locale, tree)
locale = locale.to_s
@trees.delete(locale) if @trees
@trees&.delete(locale)
paths_before = Set.new(get(locale)[locale].leaves.map { |node| node.data[:path] })
paths_after = Set.new([])
router.route locale, tree do |path, tree_slice|
Expand All @@ -66,7 +66,7 @@ def set(locale, tree)
(paths_before - paths_after).each do |path|
FileUtils.remove_file(path) if File.exist?(path)
end
@trees.delete(locale) if @trees
@trees&.delete(locale)
@available_locales = nil
end

Expand Down Expand Up @@ -180,14 +180,14 @@ def filter_nil_keys!(path, data, suffix = [])
data.each do |key, value|
if key.nil?
data.delete(key)
log_warn <<-TEXT
Skipping a nil key found in #{path.inspect}:
key: #{suffix.join('.')}.`nil`
value: #{value.inspect}
Nil keys are not supported by i18n.
The following unquoted YAML keys result in a nil key:
#{%w[null Null NULL ~].join(', ')}
See http://yaml.org/type/null.html
log_warn <<~TEXT
Skipping a nil key found in #{path.inspect}:
key: #{suffix.join('.')}.`nil`
value: #{value.inspect}
Nil keys are not supported by i18n.
The following unquoted YAML keys result in a nil key:
#{%w[null Null NULL ~].join(', ')}
See http://yaml.org/type/null.html
TEXT
elsif value.is_a?(Hash)
filter_nil_keys! path, value, suffix + [key]
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/data/tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def to_nodes
end

def to_siblings
parent && parent.children || Siblings.new(nodes: [self])
parent&.children || Siblings.new(nodes: [self])
end

def to_hash(sort = false)
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/data/tree/traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def select_nodes!(&block)
to_remove = []
each do |node|
if block.yield(node)
node.children.select_nodes!(&block) if node.children
node.children&.select_nodes!(&block)
else
# removing during each is unsafe
to_remove << node
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/locale_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module I18n::Tasks
module LocalePathname
class << self
def replace_locale(path, from, to)
path && path.gsub(path_locale_re(from), to)
path&.gsub(path_locale_re(from), to)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/reports/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def eq_base_title(key_values, locale = base_locale)
def used_title(keys_nodes, filter)
used_n = keys_nodes.map { |_k, node| node.data[:occurrences].size }.reduce(:+).to_i
"#{keys_nodes.size} key#{'s' if keys_nodes.size != 1}#{" matching '#{filter}'" if filter}"\
"#{" (#{used_n} usage#{'s' if used_n != 1})" if used_n > 0}"
"#{" (#{used_n} usage#{'s' if used_n != 1})" if used_n.positive?}"
end

# Sort keys by their attributes in order
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/scanners/relative_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def path_root(path, roots)
def prefix(normalized_path, calling_method: nil)
file_key = normalized_path.gsub(%r{(\.[^/]+)*$}, '').tr(File::SEPARATOR, DOT)
calling_method = calling_method.call if calling_method.respond_to?(:call)
if calling_method && calling_method.present?
if calling_method&.present?
# Relative keys in mailers have a `_mailer` infix, but relative keys in controllers do not have one:
"#{file_key.sub(/_controller$/, '')}.#{calling_method}"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/scanners/ruby_ast_call_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +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.
@callback.call(send_node, @method_name) if valid_receivers && valid_receivers.any? { |r| r == receiver }
@callback.call(send_node, @method_name) if valid_receivers&.any? { |r| r == receiver }
# always invoke handler_missing to get nested translations in children
handler_missing send_node
nil
Expand Down
10 changes: 5 additions & 5 deletions lib/i18n/tasks/translators/base_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def restore_interpolations(untranslated, translated)
end

def raise_interpolation_error(untranslated, translated, e)
fail CommandError.new(e, <<-TEXT.strip)
Error when restoring interpolations:
original: "#{untranslated}"
response: "#{translated}"
error: #{e.message} (#{e.class.name})
fail CommandError.new(e, <<~TEXT.strip)
Error when restoring interpolations:
original: "#{untranslated}"
response: "#{translated}"
error: #{e.message} (#{e.class.name})
TEXT
end

Expand Down
38 changes: 19 additions & 19 deletions spec/i18n_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,30 +308,30 @@
describe 'find' do
it 'prints usages' do
result = strip_ansi_escape(run_cmd('find', 'used.*'))
expect(result).to eq(<<-TXT)
used.a 2
app/views/usages.html.slim:1 p = t 'used.a'
app/views/usages.html.slim:2 b = t 'used.a'
expect(result).to eq(<<~TXT)
used.a 2
app/views/usages.html.slim:1 p = t 'used.a'
app/views/usages.html.slim:2 b = t 'used.a'
TXT
end

it 'finds references' do
result = strip_ansi_escape(run_cmd('find', 'reference*'))
expect(result).to eq(<<-TXT)
missing_target.a (resolved ref)
app/views/index.html.slim:36 = t 'reference-missing-target.a'
reference-missing-target (ref key)
app/views/index.html.slim:36 = t 'reference-missing-target.a'
reference-missing-target.a (ref)
app/views/index.html.slim:36 = t 'reference-missing-target.a'
reference-ok-nested (ref key)
app/views/index.html.slim:35 = t 'reference-ok-nested.a'
reference-ok-nested.a (ref)
app/views/index.html.slim:35 = t 'reference-ok-nested.a'
reference-ok-plain (ref key)
app/views/index.html.slim:34 = t 'reference-ok-plain'
resolved_reference_target.a (resolved ref)
app/views/index.html.slim:35 = t 'reference-ok-nested.a'
expect(result).to eq(<<~TXT)
missing_target.a (resolved ref)
app/views/index.html.slim:36 = t 'reference-missing-target.a'
reference-missing-target (ref key)
app/views/index.html.slim:36 = t 'reference-missing-target.a'
reference-missing-target.a (ref)
app/views/index.html.slim:36 = t 'reference-missing-target.a'
reference-ok-nested (ref key)
app/views/index.html.slim:35 = t 'reference-ok-nested.a'
reference-ok-nested.a (ref)
app/views/index.html.slim:35 = t 'reference-ok-nested.a'
reference-ok-plain (ref key)
app/views/index.html.slim:34 = t 'reference-ok-plain'
resolved_reference_target.a (resolved ref)
app/views/index.html.slim:35 = t 'reference-ok-nested.a'
TXT
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/support/i18n_tasks_output_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def extract_keys(actual)
e = expected.sort
a = extract_keys(actual).sort

<<-MSG.strip
Expected #{e}, but had #{a}. Diff:
<<~MSG.strip
Expected #{e}, but had #{a}. Diff:
missing: #{e - a}
extra: #{a - e}
missing: #{e - a}
extra: #{a - e}
MSG
end
end
20 changes: 10 additions & 10 deletions spec/used_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
let!(:task) { I18n::Tasks::BaseTask.new }
let(:file_name) { 'a.html.slim' }
let(:file_content) do
<<-SLIM
div = t 'a'
p = t 'a'
h1 = t 'b'
h2 = t 'c.layer'
h3 = t 'c.layer.underneath_c'
<<~SLIM
div = t 'a'
p = t 'a'
h1 = t 'b'
h2 = t 'c.layer'
h3 = t 'c.layer.underneath_c'
SLIM
end

Expand Down Expand Up @@ -63,10 +63,10 @@
describe 'when input is haml' do
let(:file_name) { 'a.html.haml' }
let(:file_content) do
<<-HAML
#first{ title: t('a') }
.second{ title: t('a') }
- # t('a') in a comment is ignored
<<~HAML
#first{ title: t('a') }
.second{ title: t('a') }
- # t('a') in a comment is ignored
HAML
end

Expand Down

0 comments on commit 3582b9a

Please sign in to comment.