diff --git a/.rubocop.yml b/.rubocop.yml index a122808d..42968658 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -42,6 +42,10 @@ Style/ClassAndModuleChildren: Style/GuardClause: Enabled: false +Style/IndentHeredoc: + # TODO(glebm): Remove this when we update the minimum Ruby version to 2.3+. + Enabled: false + Style/MultilineBlockChain: Enabled: false diff --git a/Gemfile b/Gemfile index 800e5dc0..678503a2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in i18n-tasks.gemspec @@ -6,7 +7,7 @@ gemspec unless ENV['TRAVIS'] group :development do - gem 'byebug', platforms: [:mri, :mswin, :x64_mingw_21, :x64_mingw_22], require: false + gem 'byebug', platforms: %i(mri mswin x64_mingw_21 x64_mingw_22), require: false gem 'rubinius-debugger', platform: :rbx, require: false end end diff --git a/Rakefile b/Rakefile index fdd9c291..2ae6f0e8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:rspec) diff --git a/i18n-tasks.gemspec b/i18n-tasks.gemspec index 463768af..01ec3f88 100644 --- a/i18n-tasks.gemspec +++ b/i18n-tasks.gemspec @@ -1,4 +1,5 @@ # frozen_string_literal: true + lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'i18n/tasks/version' diff --git a/lib/i18n/tasks.rb b/lib/i18n/tasks.rb index 9452ecd1..4153a3c7 100644 --- a/lib/i18n/tasks.rb +++ b/lib/i18n/tasks.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # define all the modules to be able to use :: module I18n module Tasks diff --git a/lib/i18n/tasks/base_task.rb b/lib/i18n/tasks/base_task.rb index d798b541..6d9317c8 100644 --- a/lib/i18n/tasks/base_task.rb +++ b/lib/i18n/tasks/base_task.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command_error' require 'i18n/tasks/split_key' require 'i18n/tasks/key_pattern_matching' diff --git a/lib/i18n/tasks/cli.rb b/lib/i18n/tasks/cli.rb index be78de9a..487cad46 100644 --- a/lib/i18n/tasks/cli.rb +++ b/lib/i18n/tasks/cli.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks' require 'i18n/tasks/commands' require 'optparse' diff --git a/lib/i18n/tasks/command/collection.rb b/lib/i18n/tasks/command/collection.rb index 22607dfc..111b873f 100644 --- a/lib/i18n/tasks/command/collection.rb +++ b/lib/i18n/tasks/command/collection.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command/dsl' require 'i18n/tasks/command/options/common' require 'i18n/tasks/command/options/locales' diff --git a/lib/i18n/tasks/command/commander.rb b/lib/i18n/tasks/command/commander.rb index e0fa4f98..286a38bc 100644 --- a/lib/i18n/tasks/command/commander.rb +++ b/lib/i18n/tasks/command/commander.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/cli' require 'i18n/tasks/reports/terminal' require 'i18n/tasks/reports/spreadsheet' diff --git a/lib/i18n/tasks/command/commands/data.rb b/lib/i18n/tasks/command/commands/data.rb index fd8e1499..c8694161 100644 --- a/lib/i18n/tasks/command/commands/data.rb +++ b/lib/i18n/tasks/command/commands/data.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands @@ -13,7 +14,7 @@ module Data cmd :normalize, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.normalize'), - args: [:locales, :pattern_router] + args: %i(locales pattern_router) def normalize(opt = {}) i18n.normalize_store! opt[:locales], opt[:pattern_router] @@ -48,7 +49,7 @@ def rm(opt = {}) cmd :data, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.data'), - args: [:locales, :out_format] + args: %i(locales out_format) def data(opt = {}) print_forest i18n.data_forest(opt[:locales]), opt @@ -57,7 +58,7 @@ def data(opt = {}) cmd :data_merge, pos: '[tree ...]', desc: t('i18n_tasks.cmd.desc.data_merge'), - args: [:data_format, :nostdin] + args: %i(data_format nostdin) def data_merge(opt = {}) forest = merge_forests_stdin_and_pos!(opt) @@ -68,7 +69,7 @@ def data_merge(opt = {}) cmd :data_write, pos: '[tree]', desc: t('i18n_tasks.cmd.desc.data_write'), - args: [:data_format, :nostdin] + args: %i(data_format nostdin) def data_write(opt = {}) forest = forest_pos_or_stdin!(opt) @@ -79,7 +80,7 @@ def data_write(opt = {}) cmd :data_remove, pos: '[tree]', desc: t('i18n_tasks.cmd.desc.data_remove'), - args: [:data_format, :nostdin] + args: %i(data_format nostdin) def data_remove(opt = {}) removed = i18n.data.remove_by_key!(forest_pos_or_stdin!(opt)) diff --git a/lib/i18n/tasks/command/commands/eq_base.rb b/lib/i18n/tasks/command/commands/eq_base.rb index 3a622874..63a7f8d9 100644 --- a/lib/i18n/tasks/command/commands/eq_base.rb +++ b/lib/i18n/tasks/command/commands/eq_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands @@ -8,7 +9,7 @@ module EqBase cmd :eq_base, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.eq_base'), - args: [:locales, :out_format] + args: %i(locales out_format) def eq_base(opt = {}) print_forest i18n.eq_base_keys(opt), opt, :eq_base_keys diff --git a/lib/i18n/tasks/command/commands/health.rb b/lib/i18n/tasks/command/commands/health.rb index 78c90f5a..21851f51 100644 --- a/lib/i18n/tasks/command/commands/health.rb +++ b/lib/i18n/tasks/command/commands/health.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands @@ -8,7 +9,7 @@ module Health cmd :health, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.health'), - args: [:locales, :out_format] + args: %i(locales out_format) def health(opt = {}) forest = i18n.data_forest(opt[:locales]) diff --git a/lib/i18n/tasks/command/commands/meta.rb b/lib/i18n/tasks/command/commands/meta.rb index db2667c1..3b964f78 100644 --- a/lib/i18n/tasks/command/commands/meta.rb +++ b/lib/i18n/tasks/command/commands/meta.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands diff --git a/lib/i18n/tasks/command/commands/missing.rb b/lib/i18n/tasks/command/commands/missing.rb index 1380f407..0a517f39 100644 --- a/lib/i18n/tasks/command/commands/missing.rb +++ b/lib/i18n/tasks/command/commands/missing.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command/collection' module I18n::Tasks @@ -24,7 +25,7 @@ module Missing cmd :missing, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.missing'), - args: [:locales, :out_format, :missing_types] + args: %i(locales out_format missing_types) def missing(opt = {}) forest = i18n.missing_keys(opt.slice(:locales, :base_locale, :missing_types)) diff --git a/lib/i18n/tasks/command/commands/tree.rb b/lib/i18n/tasks/command/commands/tree.rb index 1e535bcb..1f64e90b 100644 --- a/lib/i18n/tasks/command/commands/tree.rb +++ b/lib/i18n/tasks/command/commands/tree.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands @@ -19,7 +20,7 @@ def tree_translate(opts = {}) cmd :tree_merge, pos: '[[tree] [tree] ... (or stdin)]', desc: t('i18n_tasks.cmd.desc.tree_merge'), - args: [:data_format, :nostdin] + args: %i(data_format nostdin) def tree_merge(opts = {}) print_forest merge_forests_stdin_and_pos!(opts), opts @@ -28,7 +29,7 @@ def tree_merge(opts = {}) cmd :tree_filter, pos: '[pattern] [tree (or stdin)]', desc: t('i18n_tasks.cmd.desc.tree_filter'), - args: [:data_format, :pattern] + args: %i(data_format pattern) def tree_filter(opts = {}) pattern = arg_or_pos! :pattern, opts @@ -74,7 +75,7 @@ def tree_mv(opt = {}) cmd :tree_subtract, pos: '[[tree] [tree] ... (or stdin)]', desc: t('i18n_tasks.cmd.desc.tree_subtract'), - args: [:data_format, :nostdin] + args: %i(data_format nostdin) def tree_subtract(opt = {}) forests = forests_stdin_and_pos! opt, 2 @@ -85,7 +86,7 @@ def tree_subtract(opt = {}) cmd :tree_set_value, pos: '[VALUE] [tree (or stdin)]', desc: t('i18n_tasks.cmd.desc.tree_set_value'), - args: [:value, :data_format, :nostdin, :pattern] + args: %i(value data_format nostdin pattern) def tree_set_value(opt = {}) value = arg_or_pos! :value, opt diff --git a/lib/i18n/tasks/command/commands/usages.rb b/lib/i18n/tasks/command/commands/usages.rb index c72dd218..307cef89 100644 --- a/lib/i18n/tasks/command/commands/usages.rb +++ b/lib/i18n/tasks/command/commands/usages.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands @@ -12,7 +13,7 @@ module Usages cmd :find, pos: '[pattern]', desc: t('i18n_tasks.cmd.desc.find'), - args: [:out_format, :pattern, :strict] + args: %i(out_format pattern strict) def find(opt = {}) opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first) @@ -23,7 +24,7 @@ def find(opt = {}) cmd :unused, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.unused'), - args: [:locales, :out_format, :strict] + args: %i(locales out_format strict) def unused(opt = {}) forest = i18n.unused_keys(opt.slice(:locales, :strict)) @@ -34,7 +35,7 @@ def unused(opt = {}) cmd :remove_unused, pos: '[locale ...]', desc: t('i18n_tasks.cmd.desc.remove_unused'), - args: [:locales, :out_format, :strict, :confirm] + args: %i(locales out_format strict confirm) def remove_unused(opt = {}) unused_keys = i18n.unused_keys(opt.slice(:locales, :strict)) diff --git a/lib/i18n/tasks/command/commands/xlsx.rb b/lib/i18n/tasks/command/commands/xlsx.rb index f2bc3611..596275ff 100644 --- a/lib/i18n/tasks/command/commands/xlsx.rb +++ b/lib/i18n/tasks/command/commands/xlsx.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module Commands diff --git a/lib/i18n/tasks/command/dsl.rb b/lib/i18n/tasks/command/dsl.rb index 44fcf16d..a9d8e0d8 100644 --- a/lib/i18n/tasks/command/dsl.rb +++ b/lib/i18n/tasks/command/dsl.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module DSL diff --git a/lib/i18n/tasks/command/option_parsers/enum.rb b/lib/i18n/tasks/command/option_parsers/enum.rb index 21bd4e6d..234aac08 100644 --- a/lib/i18n/tasks/command/option_parsers/enum.rb +++ b/lib/i18n/tasks/command/option_parsers/enum.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module OptionParsers diff --git a/lib/i18n/tasks/command/option_parsers/locale.rb b/lib/i18n/tasks/command/option_parsers/locale.rb index 1e13756e..e93286e4 100644 --- a/lib/i18n/tasks/command/option_parsers/locale.rb +++ b/lib/i18n/tasks/command/option_parsers/locale.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Command module OptionParsers @@ -39,7 +40,7 @@ def call(vals, context) if vals == %w(all) || vals.blank? context.locales else - move_base_locale_to_front! vals.map { |v| v == 'base' ? context.base_locale : v }, context.base_locale + move_base_locale_to_front!(vals.map { |v| v == 'base' ? context.base_locale : v }, context.base_locale) end.tap do |locales| locales.each { |locale| validate! locale } end diff --git a/lib/i18n/tasks/command/options/common.rb b/lib/i18n/tasks/command/options/common.rb index 8e06c2ba..341cbf05 100644 --- a/lib/i18n/tasks/command/options/common.rb +++ b/lib/i18n/tasks/command/options/common.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command/dsl' module I18n::Tasks diff --git a/lib/i18n/tasks/command/options/data.rb b/lib/i18n/tasks/command/options/data.rb index 29320e98..1a4e05a4 100644 --- a/lib/i18n/tasks/command/options/data.rb +++ b/lib/i18n/tasks/command/options/data.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command/option_parsers/enum' module I18n::Tasks diff --git a/lib/i18n/tasks/command/options/locales.rb b/lib/i18n/tasks/command/options/locales.rb index 6807e032..63c7a60e 100644 --- a/lib/i18n/tasks/command/options/locales.rb +++ b/lib/i18n/tasks/command/options/locales.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command/option_parsers/locale' module I18n::Tasks diff --git a/lib/i18n/tasks/command_error.rb b/lib/i18n/tasks/command_error.rb index cc1e30e8..80510166 100644 --- a/lib/i18n/tasks/command_error.rb +++ b/lib/i18n/tasks/command_error.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n module Tasks # When this type of error is caught: diff --git a/lib/i18n/tasks/commands.rb b/lib/i18n/tasks/commands.rb index 0c2b6936..c2f03c41 100644 --- a/lib/i18n/tasks/commands.rb +++ b/lib/i18n/tasks/commands.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/command/dsl' require 'i18n/tasks/command/collection' require 'i18n/tasks/command/commands/health' diff --git a/lib/i18n/tasks/configuration.rb b/lib/i18n/tasks/configuration.rb index 0b981386..e5155b51 100644 --- a/lib/i18n/tasks/configuration.rb +++ b/lib/i18n/tasks/configuration.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::Configuration # rubocop:disable Metrics/ModuleLength DEFAULTS = { base_locale: 'en', diff --git a/lib/i18n/tasks/console_context.rb b/lib/i18n/tasks/console_context.rb index 2e85eedd..abeb2183 100644 --- a/lib/i18n/tasks/console_context.rb +++ b/lib/i18n/tasks/console_context.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks class ConsoleContext < BaseTask def to_s diff --git a/lib/i18n/tasks/data.rb b/lib/i18n/tasks/data.rb index 0704aa93..1769a75b 100644 --- a/lib/i18n/tasks/data.rb +++ b/lib/i18n/tasks/data.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/data/file_system' module I18n::Tasks diff --git a/lib/i18n/tasks/data/adapter/json_adapter.rb b/lib/i18n/tasks/data/adapter/json_adapter.rb index 53ed7377..67f2bf4c 100644 --- a/lib/i18n/tasks/data/adapter/json_adapter.rb +++ b/lib/i18n/tasks/data/adapter/json_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'json' module I18n::Tasks diff --git a/lib/i18n/tasks/data/adapter/yaml_adapter.rb b/lib/i18n/tasks/data/adapter/yaml_adapter.rb index c8251def..98e3b6ae 100644 --- a/lib/i18n/tasks/data/adapter/yaml_adapter.rb +++ b/lib/i18n/tasks/data/adapter/yaml_adapter.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'yaml' module I18n::Tasks module Data diff --git a/lib/i18n/tasks/data/file_formats.rb b/lib/i18n/tasks/data/file_formats.rb index ad3dc73f..70b60694 100644 --- a/lib/i18n/tasks/data/file_formats.rb +++ b/lib/i18n/tasks/data/file_formats.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'fileutils' module I18n diff --git a/lib/i18n/tasks/data/file_system.rb b/lib/i18n/tasks/data/file_system.rb index 41e8ef1a..c2fb6eff 100644 --- a/lib/i18n/tasks/data/file_system.rb +++ b/lib/i18n/tasks/data/file_system.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/data/file_system_base' require 'i18n/tasks/data/adapter/json_adapter' require 'i18n/tasks/data/adapter/yaml_adapter' diff --git a/lib/i18n/tasks/data/file_system_base.rb b/lib/i18n/tasks/data/file_system_base.rb index e59aa204..611d7aab 100644 --- a/lib/i18n/tasks/data/file_system_base.rb +++ b/lib/i18n/tasks/data/file_system_base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/data/tree/node' require 'i18n/tasks/data/router/pattern_router' require 'i18n/tasks/data/router/conservative_router' diff --git a/lib/i18n/tasks/data/router/conservative_router.rb b/lib/i18n/tasks/data/router/conservative_router.rb index e881770f..8e79a0f1 100644 --- a/lib/i18n/tasks/data/router/conservative_router.rb +++ b/lib/i18n/tasks/data/router/conservative_router.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/data/router/pattern_router' module I18n::Tasks diff --git a/lib/i18n/tasks/data/router/pattern_router.rb b/lib/i18n/tasks/data/router/pattern_router.rb index 4228f69f..c3e6fb4b 100644 --- a/lib/i18n/tasks/data/router/pattern_router.rb +++ b/lib/i18n/tasks/data/router/pattern_router.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/key_pattern_matching' require 'i18n/tasks/data/tree/node' diff --git a/lib/i18n/tasks/data/tree/siblings.rb b/lib/i18n/tasks/data/tree/siblings.rb index e5e31e95..48f343cb 100644 --- a/lib/i18n/tasks/data/tree/siblings.rb +++ b/lib/i18n/tasks/data/tree/siblings.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'set' require 'i18n/tasks/split_key' require 'i18n/tasks/data/tree/nodes' diff --git a/lib/i18n/tasks/data/tree/traversal.rb b/lib/i18n/tasks/data/tree/traversal.rb index 02bd60e9..2b7e02db 100644 --- a/lib/i18n/tasks/data/tree/traversal.rb +++ b/lib/i18n/tasks/data/tree/traversal.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'set' module I18n::Tasks diff --git a/lib/i18n/tasks/google_translation.rb b/lib/i18n/tasks/google_translation.rb index 6e829c99..a10e9906 100644 --- a/lib/i18n/tasks/google_translation.rb +++ b/lib/i18n/tasks/google_translation.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'easy_translate' require 'i18n/tasks/html_keys' diff --git a/lib/i18n/tasks/html_keys.rb b/lib/i18n/tasks/html_keys.rb index 5fbe1d97..959829d3 100644 --- a/lib/i18n/tasks/html_keys.rb +++ b/lib/i18n/tasks/html_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module HtmlKeys HTML_KEY_PATTERN = /[.\-_]html\z/ diff --git a/lib/i18n/tasks/ignore_keys.rb b/lib/i18n/tasks/ignore_keys.rb index cc0f0f3e..aa627214 100644 --- a/lib/i18n/tasks/ignore_keys.rb +++ b/lib/i18n/tasks/ignore_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::IgnoreKeys # whether to ignore the key # will also apply global ignore rules diff --git a/lib/i18n/tasks/key_pattern_matching.rb b/lib/i18n/tasks/key_pattern_matching.rb index 90e0612d..3aa76f74 100644 --- a/lib/i18n/tasks/key_pattern_matching.rb +++ b/lib/i18n/tasks/key_pattern_matching.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'strscan' module I18n::Tasks::KeyPatternMatching diff --git a/lib/i18n/tasks/locale_list.rb b/lib/i18n/tasks/locale_list.rb index f7ef6699..347496b0 100644 --- a/lib/i18n/tasks/locale_list.rb +++ b/lib/i18n/tasks/locale_list.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module LocaleList module_function diff --git a/lib/i18n/tasks/locale_pathname.rb b/lib/i18n/tasks/locale_pathname.rb index 9c04fb26..d83fc208 100644 --- a/lib/i18n/tasks/locale_pathname.rb +++ b/lib/i18n/tasks/locale_pathname.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module LocalePathname class << self diff --git a/lib/i18n/tasks/logging.rb b/lib/i18n/tasks/logging.rb index 4e8d382f..56ebd388 100644 --- a/lib/i18n/tasks/logging.rb +++ b/lib/i18n/tasks/logging.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::Logging module_function @@ -10,9 +11,7 @@ def warn_deprecated(message) end def log_verbose(message = nil) - if ::I18n::Tasks.verbose? - log_stderr Rainbow(message || yield).blue.bright - end + log_stderr Rainbow(message || yield).blue.bright if ::I18n::Tasks.verbose? end def log_warn(message) diff --git a/lib/i18n/tasks/missing_keys.rb b/lib/i18n/tasks/missing_keys.rb index 6887f7e1..85d63639 100644 --- a/lib/i18n/tasks/missing_keys.rb +++ b/lib/i18n/tasks/missing_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'set' module I18n::Tasks module MissingKeys diff --git a/lib/i18n/tasks/plural_keys.rb b/lib/i18n/tasks/plural_keys.rb index 6112bf56..c4c26ca7 100644 --- a/lib/i18n/tasks/plural_keys.rb +++ b/lib/i18n/tasks/plural_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'set' module I18n::Tasks::PluralKeys PLURAL_KEY_SUFFIXES = Set.new %w(zero one two few many other) diff --git a/lib/i18n/tasks/rainbow_utils.rb b/lib/i18n/tasks/rainbow_utils.rb index 6aaf26e9..afc7a565 100644 --- a/lib/i18n/tasks/rainbow_utils.rb +++ b/lib/i18n/tasks/rainbow_utils.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module I18n module Tasks module RainbowUtils diff --git a/lib/i18n/tasks/references.rb b/lib/i18n/tasks/references.rb index 57be42d5..a02391f5 100644 --- a/lib/i18n/tasks/references.rb +++ b/lib/i18n/tasks/references.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module References # Given a raw usage tree and a tree of reference keys in the data, return 3 trees: diff --git a/lib/i18n/tasks/reports/base.rb b/lib/i18n/tasks/reports/base.rb index 33c24776..c758e7e4 100644 --- a/lib/i18n/tasks/reports/base.rb +++ b/lib/i18n/tasks/reports/base.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::Reports class Base include I18n::Tasks::Logging diff --git a/lib/i18n/tasks/reports/spreadsheet.rb b/lib/i18n/tasks/reports/spreadsheet.rb index 6bbb4bfa..9b1a0f51 100644 --- a/lib/i18n/tasks/reports/spreadsheet.rb +++ b/lib/i18n/tasks/reports/spreadsheet.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/reports/base' require 'fileutils' diff --git a/lib/i18n/tasks/reports/terminal.rb b/lib/i18n/tasks/reports/terminal.rb index 2b5f3b78..6dc9152b 100644 --- a/lib/i18n/tasks/reports/terminal.rb +++ b/lib/i18n/tasks/reports/terminal.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/reports/base' require 'i18n/tasks/rainbow_utils' require 'terminal-table' @@ -6,7 +7,7 @@ module I18n module Tasks module Reports class Terminal < Base # rubocop:disable Metrics/ClassLength - def missing_keys(forest = task.missing_keys) + def missing_keys(forest = task.missing_keys) # rubocop:disable Metrics/AbcSize forest = collapse_missing_tree! forest if forest.present? print_title missing_title(forest) @@ -105,7 +106,8 @@ def format_key(key, data) from, to = data[:ref_info] resolved = key[0...to.length] after = key[to.length..-1] - " #{Rainbow(from).yellow}#{Rainbow(after).cyan}\n#{Rainbow('⮕').yellow.bright} #{Rainbow(resolved).yellow.bright}" + " #{Rainbow(from).yellow}#{Rainbow(after).cyan}\n" \ + "#{Rainbow('⮕').yellow.bright} #{Rainbow(resolved).yellow.bright}" else Rainbow(key).cyan end @@ -152,7 +154,8 @@ def print_locale_key_value_data_table(locale_key_value_datas) end def print_title(title) - log_stderr "#{Rainbow(title.strip).bright} #{I18n::Tasks::RainbowUtils.faint_color('|')} #{"i18n-tasks v#{I18n::Tasks::VERSION}"}" + log_stderr "#{Rainbow(title.strip).bright} #{I18n::Tasks::RainbowUtils.faint_color('|')} " \ + "#{"i18n-tasks v#{I18n::Tasks::VERSION}"}" end def print_success(message) diff --git a/lib/i18n/tasks/scanners/file_scanner.rb b/lib/i18n/tasks/scanners/file_scanner.rb index 6c49e757..70ab8260 100644 --- a/lib/i18n/tasks/scanners/file_scanner.rb +++ b/lib/i18n/tasks/scanners/file_scanner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/scanner' module I18n::Tasks::Scanners diff --git a/lib/i18n/tasks/scanners/files/caching_file_finder.rb b/lib/i18n/tasks/scanners/files/caching_file_finder.rb index 11a8e09b..bc34e8e7 100644 --- a/lib/i18n/tasks/scanners/files/caching_file_finder.rb +++ b/lib/i18n/tasks/scanners/files/caching_file_finder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/files/file_finder' module I18n::Tasks::Scanners::Files # Finds the files in the specified search paths with support for exclusion / inclusion patterns. diff --git a/lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb b/lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb index 2e764c5f..a7981fdf 100644 --- a/lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb +++ b/lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/files/caching_file_finder' module I18n::Tasks::Scanners::Files diff --git a/lib/i18n/tasks/scanners/files/caching_file_reader.rb b/lib/i18n/tasks/scanners/files/caching_file_reader.rb index c6948479..1d230df4 100644 --- a/lib/i18n/tasks/scanners/files/caching_file_reader.rb +++ b/lib/i18n/tasks/scanners/files/caching_file_reader.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/files/file_reader' module I18n::Tasks::Scanners::Files # Reads the files in 'rb' mode and UTF-8 encoding. diff --git a/lib/i18n/tasks/scanners/files/file_finder.rb b/lib/i18n/tasks/scanners/files/file_finder.rb index 010afd0a..af1befbb 100644 --- a/lib/i18n/tasks/scanners/files/file_finder.rb +++ b/lib/i18n/tasks/scanners/files/file_finder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::Scanners::Files # Finds the files in the specified search paths with support for exclusion / inclusion patterns. # diff --git a/lib/i18n/tasks/scanners/files/file_reader.rb b/lib/i18n/tasks/scanners/files/file_reader.rb index adc8bf45..5d4c6ea4 100644 --- a/lib/i18n/tasks/scanners/files/file_reader.rb +++ b/lib/i18n/tasks/scanners/files/file_reader.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::Scanners::Files # Reads the files in 'rb' mode and UTF-8 encoding. # diff --git a/lib/i18n/tasks/scanners/occurrence_from_position.rb b/lib/i18n/tasks/scanners/occurrence_from_position.rb index 830ae9ef..5e2bd182 100644 --- a/lib/i18n/tasks/scanners/occurrence_from_position.rb +++ b/lib/i18n/tasks/scanners/occurrence_from_position.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n module Tasks module Scanners diff --git a/lib/i18n/tasks/scanners/pattern_mapper.rb b/lib/i18n/tasks/scanners/pattern_mapper.rb index 2b729c70..ed52946b 100644 --- a/lib/i18n/tasks/scanners/pattern_mapper.rb +++ b/lib/i18n/tasks/scanners/pattern_mapper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/file_scanner' require 'i18n/tasks/scanners/relative_keys' require 'i18n/tasks/scanners/occurrence_from_position' diff --git a/lib/i18n/tasks/scanners/pattern_scanner.rb b/lib/i18n/tasks/scanners/pattern_scanner.rb index d2fbdf3f..563ca38e 100644 --- a/lib/i18n/tasks/scanners/pattern_scanner.rb +++ b/lib/i18n/tasks/scanners/pattern_scanner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/file_scanner' require 'i18n/tasks/scanners/relative_keys' require 'i18n/tasks/scanners/occurrence_from_position' diff --git a/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb b/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb index 76fa50e6..1a47baa1 100644 --- a/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb +++ b/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/pattern_scanner' module I18n::Tasks::Scanners diff --git a/lib/i18n/tasks/scanners/relative_keys.rb b/lib/i18n/tasks/scanners/relative_keys.rb index 80538d47..7da5702a 100644 --- a/lib/i18n/tasks/scanners/relative_keys.rb +++ b/lib/i18n/tasks/scanners/relative_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n module Tasks module Scanners diff --git a/lib/i18n/tasks/scanners/results/key_occurrences.rb b/lib/i18n/tasks/scanners/results/key_occurrences.rb index 0703b934..66e17d65 100644 --- a/lib/i18n/tasks/scanners/results/key_occurrences.rb +++ b/lib/i18n/tasks/scanners/results/key_occurrences.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/results/occurrence' module I18n::Tasks::Scanners::Results diff --git a/lib/i18n/tasks/scanners/results/occurrence.rb b/lib/i18n/tasks/scanners/results/occurrence.rb index 8fc2e79a..c2a46fc5 100644 --- a/lib/i18n/tasks/scanners/results/occurrence.rb +++ b/lib/i18n/tasks/scanners/results/occurrence.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Scanners module Results diff --git a/lib/i18n/tasks/scanners/ruby_ast_call_finder.rb b/lib/i18n/tasks/scanners/ruby_ast_call_finder.rb index 9545d06c..864f5530 100644 --- a/lib/i18n/tasks/scanners/ruby_ast_call_finder.rb +++ b/lib/i18n/tasks/scanners/ruby_ast_call_finder.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'ast' require 'set' module I18n::Tasks::Scanners diff --git a/lib/i18n/tasks/scanners/ruby_ast_scanner.rb b/lib/i18n/tasks/scanners/ruby_ast_scanner.rb index ddfe4c46..8ba3cc55 100644 --- a/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +++ b/lib/i18n/tasks/scanners/ruby_ast_scanner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/file_scanner' require 'i18n/tasks/scanners/relative_keys' require 'i18n/tasks/scanners/ruby_ast_call_finder' @@ -40,7 +41,7 @@ def scan_file(path) # transform_values is only available in ActiveSupport 4.2+ h.each { |k, v| h[k] = v.first } end.invert - results + magic_comments.flat_map do |comment| + results + (magic_comments.flat_map do |comment| @parser.reset associated_node = comment_to_node[comment] @call_finder.collect_calls( @@ -49,7 +50,7 @@ def scan_file(path) # method_name is not available at this stage send_node_to_key_occurrence(send_node, nil, location: associated_node || comment.location) end - end + end) rescue Exception => e # rubocop:disable Lint/RescueException raise ::I18n::Tasks::CommandError.new(e, "Error scanning #{path}: #{e.message}") end diff --git a/lib/i18n/tasks/scanners/ruby_key_literals.rb b/lib/i18n/tasks/scanners/ruby_key_literals.rb index d1d562d8..0f02ba6a 100644 --- a/lib/i18n/tasks/scanners/ruby_key_literals.rb +++ b/lib/i18n/tasks/scanners/ruby_key_literals.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks::Scanners module RubyKeyLiterals LITERAL_RE = /:?".+?"|:?'.+?'|:\w+/ diff --git a/lib/i18n/tasks/scanners/scanner.rb b/lib/i18n/tasks/scanners/scanner.rb index 363d1c5b..11ea0932 100644 --- a/lib/i18n/tasks/scanners/scanner.rb +++ b/lib/i18n/tasks/scanners/scanner.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/results/key_occurrences' module I18n::Tasks::Scanners diff --git a/lib/i18n/tasks/scanners/scanner_multiplexer.rb b/lib/i18n/tasks/scanners/scanner_multiplexer.rb index 6921e21e..24b12e6e 100644 --- a/lib/i18n/tasks/scanners/scanner_multiplexer.rb +++ b/lib/i18n/tasks/scanners/scanner_multiplexer.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks/scanners/scanner' module I18n::Tasks::Scanners diff --git a/lib/i18n/tasks/split_key.rb b/lib/i18n/tasks/split_key.rb index d26ddc53..5cafd133 100644 --- a/lib/i18n/tasks/split_key.rb +++ b/lib/i18n/tasks/split_key.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n module Tasks module SplitKey diff --git a/lib/i18n/tasks/stats.rb b/lib/i18n/tasks/stats.rb index 0fd77b77..f8949af9 100644 --- a/lib/i18n/tasks/stats.rb +++ b/lib/i18n/tasks/stats.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module Stats def forest_stats(forest) diff --git a/lib/i18n/tasks/string_interpolation.rb b/lib/i18n/tasks/string_interpolation.rb index 4dbb5d69..79e5ce77 100644 --- a/lib/i18n/tasks/string_interpolation.rb +++ b/lib/i18n/tasks/string_interpolation.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n::Tasks module StringInterpolation module_function diff --git a/lib/i18n/tasks/unused_keys.rb b/lib/i18n/tasks/unused_keys.rb index 629ac6de..cb1f5e1b 100644 --- a/lib/i18n/tasks/unused_keys.rb +++ b/lib/i18n/tasks/unused_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'set' module I18n @@ -13,11 +14,11 @@ def unused_keys(locales: nil, strict: nil) # @param [Boolean] strict if true, do not match dynamic keys def unused_tree(locale: base_locale, strict: nil) used_key_names = used_tree(strict: true).key_names - collapse_plural_nodes! data[locale].select_keys { |key, _node| + collapse_plural_nodes!(data[locale].select_keys do |key, _node| !ignore_key?(key, :unused) && (strict || !used_in_expr?(key)) && !used_key_names.include?(depluralize_key(key, locale)) - } + end) end end end diff --git a/lib/i18n/tasks/used_keys.rb b/lib/i18n/tasks/used_keys.rb index f6264a54..253e52ee 100644 --- a/lib/i18n/tasks/used_keys.rb +++ b/lib/i18n/tasks/used_keys.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'find' require 'i18n/tasks/scanners/pattern_with_scope_scanner' require 'i18n/tasks/scanners/ruby_ast_scanner' @@ -56,7 +57,7 @@ def used_in_source_tree(key_filter: nil, strict: nil) scanner(strict: strict).keys.freeze) if key_filter key_filter_re = compile_key_pattern(key_filter) - keys = keys.reject { |k| k.key !~ key_filter_re } + keys = keys.select { |k| k.key =~ key_filter_re } end Data::Tree::Node.new( key: 'used', @@ -128,7 +129,7 @@ def caching_file_reader # @return [Boolean] whether the key is potentially used in a code expression such as `t("category.#{category_key}")` def used_in_expr?(key) - !!(key =~ expr_key_re) # rubocop:disable Style/DoubleNegation + !!(key =~ expr_key_re) # rubocop:disable Style/DoubleNegation,Style/InverseMethods end private diff --git a/lib/i18n/tasks/version.rb b/lib/i18n/tasks/version.rb index 10b4a691..5634defa 100644 --- a/lib/i18n/tasks/version.rb +++ b/lib/i18n/tasks/version.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module I18n module Tasks VERSION = '0.9.12' diff --git a/spec/bin_simplecov_helper.rb b/spec/bin_simplecov_helper.rb index bb999302..df58358d 100644 --- a/spec/bin_simplecov_helper.rb +++ b/spec/bin_simplecov_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + if ENV['COVERAGE'] && !%w(rbx jruby).include?(RUBY_ENGINE) ENV['SIMPLECOV_NO_DEFAULTS'] = '1' require 'simplecov' diff --git a/spec/commands/data_commands_spec.rb b/spec/commands/data_commands_spec.rb index 6b40d83d..f1bb7338 100644 --- a/spec/commands/data_commands_spec.rb +++ b/spec/commands/data_commands_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Data commands' do diff --git a/spec/commands/missing_commands_spec.rb b/spec/commands/missing_commands_spec.rb index f7266689..ea4a2838 100644 --- a/spec/commands/missing_commands_spec.rb +++ b/spec/commands/missing_commands_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Missing commands' do diff --git a/spec/commands/tree_commands_spec.rb b/spec/commands/tree_commands_spec.rb index ea315f0f..0a550702 100644 --- a/spec/commands/tree_commands_spec.rb +++ b/spec/commands/tree_commands_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Tree commands' do diff --git a/spec/conservative_router_spec.rb b/spec/conservative_router_spec.rb index 3f269cfa..76d9cf4a 100644 --- a/spec/conservative_router_spec.rb +++ b/spec/conservative_router_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Conservative router' do diff --git a/spec/file_system_data_spec.rb b/spec/file_system_data_spec.rb index 3c6d985a..dcfe88d6 100644 --- a/spec/file_system_data_spec.rb +++ b/spec/file_system_data_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'File system i18n' do diff --git a/spec/google_translate_spec.rb b/spec/google_translate_spec.rb index 941a39df..183ae11a 100644 --- a/spec/google_translate_spec.rb +++ b/spec/google_translate_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/commands' diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb index 31d69eac..6a3e5cb4 100644 --- a/spec/i18n_spec.rb +++ b/spec/i18n_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'I18n' do diff --git a/spec/i18n_tasks_spec.rb b/spec/i18n_tasks_spec.rb index fb66b10b..f7bd8e35 100644 --- a/spec/i18n_tasks_spec.rb +++ b/spec/i18n_tasks_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'fileutils' require 'open3' @@ -27,9 +28,9 @@ expect(status).to be_success expect(out).to be_empty expect(err.lines.first.chomp).to eq('Usage: i18n-tasks [command] [options]') - expect(err).to include('Available commands', 'add-missing') + expect(err).to a_string_including('Available commands', 'add-missing') # a task from a plugin - expect(err).to include('greet') + expect(err).to a_string_including('greet') end, proc do out, err, status = Open3.capture3(env, 'bundle exec ../../bin/i18n-tasks --version') @@ -93,11 +94,11 @@ end it 'detects missing' do es_keys = expected_missing_keys_diff.grep(/^es\./) + - expected_missing_keys_in_source.map { |k| k[0] != '⮕' ? "es.#{k}" : k } + (expected_missing_keys_in_source.map { |k| k[0] != '⮕' ? "es.#{k}" : k }) out, result = run_cmd_capture_stdout_and_result 'missing' expect(result).to eq :exit_1 expect(out).to be_i18n_keys(expected_missing_keys_diff + - expected_missing_keys_in_source.map { |k| k[0] != '⮕' ? "all.#{k}" : k }) + (expected_missing_keys_in_source.map { |k| k[0] != '⮕' ? "all.#{k}" : k })) expect(run_cmd('missing', '-les')).to be_i18n_keys es_keys expect(run_cmd('missing', 'es')).to be_i18n_keys es_keys end diff --git a/spec/key_pattern_matching_spec.rb b/spec/key_pattern_matching_spec.rb index 487ec0a7..47d1b925 100644 --- a/spec/key_pattern_matching_spec.rb +++ b/spec/key_pattern_matching_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Key pattern' do diff --git a/spec/locale_pathname_spec.rb b/spec/locale_pathname_spec.rb index 70d0d871..f4ddb797 100644 --- a/spec/locale_pathname_spec.rb +++ b/spec/locale_pathname_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'LocalePathname' do diff --git a/spec/locale_tree/siblings_spec.rb b/spec/locale_tree/siblings_spec.rb index 82ad7597..abe976a1 100644 --- a/spec/locale_tree/siblings_spec.rb +++ b/spec/locale_tree/siblings_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Tree siblings / forest' do diff --git a/spec/pattern_scanner_spec.rb b/spec/pattern_scanner_spec.rb index be1e044f..e5bffbd7 100644 --- a/spec/pattern_scanner_spec.rb +++ b/spec/pattern_scanner_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'PatternScanner' do diff --git a/spec/pattern_with_scope_scanner_spec.rb b/spec/pattern_with_scope_scanner_spec.rb index a591fc8d..a3a40fae 100644 --- a/spec/pattern_with_scope_scanner_spec.rb +++ b/spec/pattern_with_scope_scanner_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'PatternWithScopeScanner' do diff --git a/spec/plural_keys_spec.rb b/spec/plural_keys_spec.rb index 66eaef67..a419a4c2 100644 --- a/spec/plural_keys_spec.rb +++ b/spec/plural_keys_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Plural keys' do diff --git a/spec/references_spec.rb b/spec/references_spec.rb index 25c1e1f3..7547eee4 100644 --- a/spec/references_spec.rb +++ b/spec/references_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'Reference keys' do diff --git a/spec/relative_keys_spec.rb b/spec/relative_keys_spec.rb index bd566aa3..95555b2c 100644 --- a/spec/relative_keys_spec.rb +++ b/spec/relative_keys_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/relative_keys' diff --git a/spec/scanners/files/caching_file_finder_provider_spec.rb b/spec/scanners/files/caching_file_finder_provider_spec.rb index 6f85ef37..8404d4d5 100644 --- a/spec/scanners/files/caching_file_finder_provider_spec.rb +++ b/spec/scanners/files/caching_file_finder_provider_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/files/caching_file_finder_provider' diff --git a/spec/scanners/files/caching_file_finder_spec.rb b/spec/scanners/files/caching_file_finder_spec.rb index bb1347af..40002035 100644 --- a/spec/scanners/files/caching_file_finder_spec.rb +++ b/spec/scanners/files/caching_file_finder_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/files/caching_file_finder' @@ -12,9 +13,9 @@ TestCodebase.setup(test_files.each_with_object({}) { |f, h| h[f] = '' }) TestCodebase.in_test_app_dir do finder = I18n::Tasks::Scanners::Files::CachingFileFinder.new - expect(finder.find_files).to eq test_files.map { |f| File.join('.', f) } + expect(finder.find_files).to eq(test_files.map { |f| File.join('.', f) }) TestCodebase.teardown - expect(finder.find_files).to eq test_files.map { |f| File.join('.', f) } + expect(finder.find_files).to eq(test_files.map { |f| File.join('.', f) }) end ensure TestCodebase.teardown @@ -28,9 +29,9 @@ TestCodebase.setup(test_files.each_with_object({}) { |f, h| h[f] = '' }) TestCodebase.in_test_app_dir do finder = I18n::Tasks::Scanners::Files::CachingFileFinder.new - expect(finder.traverse_files { |f| f }).to eq test_files.map { |f| File.join('.', f) } + expect(finder.traverse_files { |f| f }).to eq(test_files.map { |f| File.join('.', f) }) TestCodebase.teardown - expect(finder.traverse_files { |f| f }).to eq test_files.map { |f| File.join('.', f) } + expect(finder.traverse_files { |f| f }).to eq(test_files.map { |f| File.join('.', f) }) end ensure TestCodebase.teardown diff --git a/spec/scanners/files/caching_file_reader_spec.rb b/spec/scanners/files/caching_file_reader_spec.rb index 4b676dd0..a2177880 100644 --- a/spec/scanners/files/caching_file_reader_spec.rb +++ b/spec/scanners/files/caching_file_reader_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/files/caching_file_reader' diff --git a/spec/scanners/files/file_finder_spec.rb b/spec/scanners/files/file_finder_spec.rb index cd4ea6ea..6f711d9b 100644 --- a/spec/scanners/files/file_finder_spec.rb +++ b/spec/scanners/files/file_finder_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/files/file_finder' @@ -15,26 +16,28 @@ describe '#find_files' do it 'finds all the files in the current directory with default options' do finder = I18n::Tasks::Scanners::Files::FileFinder.new - expect(finder.find_files).to eq test_files.map { |f| File.join('.', f) } + expect(finder.find_files).to eq(test_files.map { |f| File.join('.', f) }) end it 'finds only the files in paths' do finder = I18n::Tasks::Scanners::Files::FileFinder.new(paths: %w(a/a a/b/a.txt)) - expect(finder.find_files).to eq test_files.select { |f| f.start_with?('a/a/') || f == 'a/b/a.txt' } + expect(finder.find_files).to eq(test_files.select { |f| f.start_with?('a/a/') || f == 'a/b/a.txt' }) end it 'find only the files specified by the inclusion patterns' do finder = I18n::Tasks::Scanners::Files::FileFinder.new( paths: %w(a), only: %w(a/a/**) ) - expect(finder.find_files).to eq test_files.select { |f| f.start_with?('a/a/') } + expect(finder.find_files).to eq(test_files.select { |f| f.start_with?('a/a/') }) end it 'finds only the files not specified by the exclusion patterns' do finder = I18n::Tasks::Scanners::Files::FileFinder.new( exclude: %w(./a/a/**) ) - expect(finder.find_files).to eq test_files.select { |f| !f.start_with?('a/a/') }.map { |f| File.join('.', f) } + expect(finder.find_files).to( + eq(test_files.reject { |f| f.start_with?('a/a/') }.map { |f| File.join('.', f) }) + ) end end diff --git a/spec/scanners/files/file_reader_spec.rb b/spec/scanners/files/file_reader_spec.rb index 208d8e76..65068590 100644 --- a/spec/scanners/files/file_reader_spec.rb +++ b/spec/scanners/files/file_reader_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/files/file_reader' diff --git a/spec/scanners/pattern_mapper_spec.rb b/spec/scanners/pattern_mapper_spec.rb index afbe304b..eaf4d619 100644 --- a/spec/scanners/pattern_mapper_spec.rb +++ b/spec/scanners/pattern_mapper_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/pattern_mapper' diff --git a/spec/scanners/scanner_multiplexer_spec.rb b/spec/scanners/scanner_multiplexer_spec.rb index 7205c2a1..890d69d8 100644 --- a/spec/scanners/scanner_multiplexer_spec.rb +++ b/spec/scanners/scanner_multiplexer_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' require 'i18n/tasks/scanners/scanner_multiplexer' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 449ef123..7c9f88ac 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + if ENV['COVERAGE'] && !%w(rbx jruby).include?(RUBY_ENGINE) require 'simplecov' SimpleCov.command_name 'RSpec' diff --git a/spec/split_key_spec.rb b/spec/split_key_spec.rb index d07b5aa8..bf4331e5 100644 --- a/spec/split_key_spec.rb +++ b/spec/split_key_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'SplitKey' do diff --git a/spec/support/capture_std.rb b/spec/support/capture_std.rb index 93128a95..f8c01a63 100644 --- a/spec/support/capture_std.rb +++ b/spec/support/capture_std.rb @@ -19,22 +19,26 @@ module CaptureStd def capture_stderr return yield if ENV['NOSILENCE'] - err = $stderr - $stderr = StringIO.new - yield - $stderr.string - ensure - $stderr = err + begin + err = $stderr + $stderr = StringIO.new + yield + $stderr.string + ensure + $stderr = err + end end def capture_stdout return yield if ENV['NOSILENCE'] - out = $stdout - $stdout = StringIO.new - yield - $stdout.string - ensure - $stdout = out + begin + out = $stdout + $stdout = StringIO.new + yield + $stdout.string + ensure + $stdout = out + end end def silence_stderr(&block) diff --git a/spec/support/fixtures.rb b/spec/support/fixtures.rb index 0a911b4e..243336c9 100644 --- a/spec/support/fixtures.rb +++ b/spec/support/fixtures.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # quick'n'dirty fixture loader module FixturesSupport def fixtures_contents diff --git a/spec/support/i18n_tasks_output_matcher.rb b/spec/support/i18n_tasks_output_matcher.rb index 913c7bcf..a91b1385 100644 --- a/spec/support/i18n_tasks_output_matcher.rb +++ b/spec/support/i18n_tasks_output_matcher.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec::Matchers.define :be_i18n_keys do |expected| def locale_re /^\w{2}\b/ diff --git a/spec/support/key_pattern_matcher.rb b/spec/support/key_pattern_matcher.rb index b6394588..01311cfe 100644 --- a/spec/support/key_pattern_matcher.rb +++ b/spec/support/key_pattern_matcher.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + RSpec::Matchers.define :match_key do |key| include I18n::Tasks::KeyPatternMatching diff --git a/spec/support/keys_and_occurrences.rb b/spec/support/keys_and_occurrences.rb index 4526bb49..9f08b25b 100644 --- a/spec/support/keys_and_occurrences.rb +++ b/spec/support/keys_and_occurrences.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module KeysAndOccurrences # rubocop:disable Metrics/ParameterLists def make_occurrence(path: '', line: '', pos: 1, line_pos: 1, line_num: 1, raw_key: nil) diff --git a/spec/support/strip_ansi_escape.rb b/spec/support/strip_ansi_escape.rb index b4fcd58f..2dc2d939 100644 --- a/spec/support/strip_ansi_escape.rb +++ b/spec/support/strip_ansi_escape.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Stolen from https://github.com/sickill/rainbow/pull/54 def strip_ansi_escape(string) string.gsub(/\e\[[0-9;]*[a-zA-Z]/, '') diff --git a/spec/support/test_codebase.rb b/spec/support/test_codebase.rb index 2e6a2d40..3fda798a 100644 --- a/spec/support/test_codebase.rb +++ b/spec/support/test_codebase.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'fileutils' require 'yaml' require_relative 'capture_std' diff --git a/spec/support/trees.rb b/spec/support/trees.rb index 385d3a8a..dec772c9 100644 --- a/spec/support/trees.rb +++ b/spec/support/trees.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + module Trees def expect_node_key_data(node, key, data) expect(node.full_key(root: false)).to eq key diff --git a/spec/used_keys_spec.rb b/spec/used_keys_spec.rb index 07439d7d..195f7128 100644 --- a/spec/used_keys_spec.rb +++ b/spec/used_keys_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' RSpec.describe 'UsedKeys' do diff --git a/templates/rspec/i18n_spec.rb b/templates/rspec/i18n_spec.rb index b2b2e617..4090059c 100644 --- a/templates/rspec/i18n_spec.rb +++ b/templates/rspec/i18n_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'i18n/tasks' RSpec.describe 'I18n' do