Skip to content

Commit

Permalink
Reformat Ruby files for line length of 120
Browse files Browse the repository at this point in the history
The rubocop community has decided to standardize on 120 characters for
default line length.

rubocop/rubocop#7952

Update rubocop config and reformat ruby files to embrace this
convention.
  • Loading branch information
mattbrictson committed May 24, 2020
1 parent e6e67d7 commit 55dcfcc
Show file tree
Hide file tree
Showing 62 changed files with 117 additions and 406 deletions.
3 changes: 1 addition & 2 deletions .rubocop.yml
Expand Up @@ -21,8 +21,7 @@ Layout/HashAlignment:
- key

Layout/LineLength:
Exclude:
- "*.gemspec"
Max: 120

Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space
Expand Down
16 changes: 5 additions & 11 deletions Rakefile
Expand Up @@ -11,8 +11,7 @@ RuboCop::RakeTask.new
Rake::TestTask.new("test:unit") do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"] -
FileList["test/**/*_e2e_test.rb"]
t.test_files = FileList["test/**/*_test.rb"] - FileList["test/**/*_e2e_test.rb"]
end

Rake::TestTask.new("test:e2e") do |t|
Expand Down Expand Up @@ -44,12 +43,9 @@ namespace :bump do

replace_in_file "tomo.gemspec", /ruby_version = ">= (.*)"/ => lowest
replace_in_file ".rubocop.yml", /TargetRubyVersion: (.*)/ => lowest_minor
replace_in_file ".circleci/config.yml",
%r{circleci/ruby:([\d\.]+)} => latest
replace_in_file ".circleci/Dockerfile",
%r{circleci/ruby:([\d\.]+)} => latest
replace_in_file "docs/comparisons.md",
/ruby version\s*\|\s*([\d\.]+)/i => lowest_minor
replace_in_file ".circleci/config.yml", %r{circleci/ruby:([\d\.]+)} => latest
replace_in_file ".circleci/Dockerfile", %r{circleci/ruby:([\d\.]+)} => latest
replace_in_file "docs/comparisons.md", /ruby version\s*\|\s*([\d\.]+)/i => lowest_minor

travis = YAML.safe_load(open(".travis.yml"))
travis["rvm"] = RubyVersions.latest_supported_patches + ["ruby-head"]
Expand Down Expand Up @@ -100,9 +96,7 @@ module RubyVersions

def versions
@_versions ||= begin
yaml = URI.open(
"https://raw.githubusercontent.com/ruby/www.ruby-lang.org/master/_data/downloads.yml"
)
yaml = URI.open("https://raw.githubusercontent.com/ruby/www.ruby-lang.org/master/_data/downloads.yml")
YAML.safe_load(yaml, symbolize_names: true)
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/tomo/cli.rb
Expand Up @@ -55,8 +55,7 @@ def prepare_completions(argv)
argv << "" if argv.shift == "--complete"
end

# rubocop:disable Metrics/CyclomaticComplexity
def lookup_command(argv)
def lookup_command(argv) # rubocop:disable Metrics/CyclomaticComplexity
command_name = argv.first unless Completions.active? && argv.length == 1
command_name = Abbrev.abbrev(COMMANDS.keys)[command_name]
argv.shift if command_name
Expand All @@ -65,7 +64,6 @@ def lookup_command(argv)
command = COMMANDS[command_name] || Tomo::Commands::Default
[command, command_name]
end
# rubocop:enable Metrics/CyclomaticComplexity

def task_format?(arg)
arg.to_s.match?(/\A\S+:\S*\z/)
Expand Down
16 changes: 4 additions & 12 deletions lib/tomo/cli/common_options.rb
@@ -1,22 +1,15 @@
module Tomo
class CLI
module CommonOptions
# rubocop:disable Metrics/MethodLength
def self.included(mod)
def self.included(mod) # rubocop:disable Metrics/MethodLength
mod.class_eval do
option :color,
"--[no-]color",
"Enable/disable color output" do |color|
option :color, "--[no-]color", "Enable/disable color output" do |color|
Colors.enabled = color
end
option :debug,
"--[no-]debug",
"Enable/disable verbose debug logging" do |debug|
option :debug, "--[no-]debug", "Enable/disable verbose debug logging" do |debug|
Tomo.debug = debug
end
option :trace,
"--[no-]trace",
"Display full backtrace on error" do |trace|
option :trace, "--[no-]trace", "Display full backtrace on error" do |trace|
CLI.show_backtrace = trace
end
option :help, "-h, --help", "Print this documentation" do |_help|
Expand All @@ -27,7 +20,6 @@ def self.included(mod)
after_parse :dump_runtime_info
end
end
# rubocop:enable Metrics/MethodLength

private

Expand Down
9 changes: 2 additions & 7 deletions lib/tomo/cli/deploy_options.rb
@@ -1,8 +1,7 @@
module Tomo
class CLI
module DeployOptions
# rubocop:disable Metrics/MethodLength
def self.included(mod)
def self.included(mod) # rubocop:disable Metrics/MethodLength
mod.class_eval do
option :environment,
"-e, --environment ENVIRONMENT",
Expand All @@ -23,7 +22,6 @@ def self.included(mod)
after_parse :prompt_for_environment
end
end
# rubocop:enable Metrics/MethodLength

private

Expand All @@ -49,10 +47,7 @@ def prompt_for_environment(*args, options)
return if envs.empty?
return unless Console.interactive?

options[:environment] = Console.menu(
"Choose an environment:",
choices: envs
)
options[:environment] = Console.menu("Choose an environment:", choices: envs)
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions lib/tomo/cli/parser.rb
Expand Up @@ -46,12 +46,7 @@ def parse(argv)
attr_reader :rules, :usage, :after_parse_methods

def evaluate(argv, state, literal:)
RulesEvaluator.evaluate(
rules: rules.to_a,
argv: argv,
state: state,
literal: literal
)
RulesEvaluator.evaluate(rules: rules.to_a, argv: argv, state: state, literal: literal)
end

def check_required_rules(state)
Expand Down
4 changes: 1 addition & 3 deletions lib/tomo/cli/project_options.rb
Expand Up @@ -3,9 +3,7 @@ class CLI
module ProjectOptions
def self.included(mod)
mod.class_eval do
option :project,
"-c, --config PATH",
"Location of project config (default: #{DEFAULT_CONFIG_PATH})"
option :project, "-c, --config PATH", "Location of project config (default: #{DEFAULT_CONFIG_PATH})"
end
end

Expand Down
26 changes: 4 additions & 22 deletions lib/tomo/cli/rules.rb
Expand Up @@ -51,32 +51,19 @@ def to_a
attr_reader :rules

def optional_arg_rule(spec, values_proc)
Rules::Argument.new(
spec,
values_proc: values_proc,
required: false,
multiple: false
)
Rules::Argument.new(spec, values_proc: values_proc, required: false, multiple: false)
end

def required_arg_rule(spec, values_proc)
Rules::Argument.new(
spec,
values_proc: values_proc,
required: true,
multiple: false
)
Rules::Argument.new(spec, values_proc: values_proc, required: true, multiple: false)
end

def mutiple_optional_args_rule(spec, values_proc)
Rules::Argument.new(spec, multiple: true, values_proc: values_proc)
end

def on_off_switch_rule(key, name, _values_proc, callback_proc)
Rules::Switch.new(key,
"--#{name}",
"--no-#{name}",
callback_proc: callback_proc) do |arg|
Rules::Switch.new(key, "--#{name}", "--no-#{name}", callback_proc: callback_proc) do |arg|
arg == "--#{name}"
end
end
Expand All @@ -86,12 +73,7 @@ def basic_switch_rule(key, *switches, _values_proc, callback_proc)
end

def value_switch_rule(key, *switches, values_proc, callback_proc)
Rules::ValueSwitch.new(
key,
*switches,
values_proc: values_proc,
callback_proc: callback_proc
)
Rules::ValueSwitch.new(key, *switches, values_proc: values_proc, callback_proc: callback_proc)
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions lib/tomo/cli/rules/switch.rb
@@ -1,10 +1,6 @@
class Tomo::CLI::Rules
class Switch
def initialize(key,
*switches,
required: false,
callback_proc:,
&convert_proc)
def initialize(key, *switches, required: false, callback_proc:, &convert_proc)
@key = key
@switches = switches
@callback_proc = callback_proc
Expand Down
3 changes: 1 addition & 2 deletions lib/tomo/cli/rules/value_switch.rb
Expand Up @@ -51,8 +51,7 @@ def values(state)
end

def raise_missing_value(switch)
raise Tomo::CLI::Error,
"Please specify a value for the #{yellow(switch)} option."
raise Tomo::CLI::Error, "Please specify a value for the #{yellow(switch)} option."
end
end
end
16 changes: 3 additions & 13 deletions lib/tomo/cli/rules_evaluator.rb
Expand Up @@ -41,11 +41,7 @@ def match_next_rule
def complete_if_needed(matched_rules, *matched_args)
return unless Completions.active?

completions.print_completions_and_exit(
matched_rules,
*matched_args,
state: state
)
completions.print_completions_and_exit(matched_rules, *matched_args, state: state)
end

def remaining_rules
Expand All @@ -56,15 +52,9 @@ def remaining_rules

def raise_unrecognized_args
problem_arg = argv.first
type = if literal || !problem_arg.start_with?("-")
"arg"
else
"option"
end
type = literal || !problem_arg.start_with?("-") ? "arg" : "option"

raise CLI::Error,
"#{Colors.yellow(problem_arg)} is not a recognized #{type} "\
"for this tomo command."
raise CLI::Error, "#{Colors.yellow(problem_arg)} is not a recognized #{type} for this tomo command."
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions lib/tomo/cli/usage.rb
Expand Up @@ -18,9 +18,7 @@ def banner=(banner)
end

def to_s
indent([
"", banner_proc.call, "Options:", "", indent(options_help), "\n"
].join("\n"))
indent(["", banner_proc.call, "Options:", "", indent(options_help), "\n"].join("\n"))
end

private
Expand Down
4 changes: 1 addition & 3 deletions lib/tomo/commands/default.rb
Expand Up @@ -42,9 +42,7 @@ def call(*args, options)
# do anything, so if we got this far, something has gone wrong.

if options.any?
raise CLI::Error,
"Options must be specified after the command: " +
yellow("tomo #{args.first} [options]")
raise CLI::Error, "Options must be specified after the command: " + yellow("tomo #{args.first} [options]")
end

raise_unrecognized_command(args.first)
Expand Down
4 changes: 1 addition & 3 deletions lib/tomo/commands/run.rb
Expand Up @@ -3,9 +3,7 @@ module Commands
class Run < CLI::Command
include CLI::DeployOptions

option :privileged,
"--[no-]privileged",
"Run the task using a privileged user (e.g. root)"
option :privileged, "--[no-]privileged", "Run the task using a privileged user (e.g. root)"

include CLI::ProjectOptions
include CLI::CommonOptions
Expand Down
16 changes: 5 additions & 11 deletions lib/tomo/configuration.rb
Expand Up @@ -3,16 +3,13 @@ class Configuration
autoload :DSL, "tomo/configuration/dsl"
autoload :Environment, "tomo/configuration/environment"
autoload :Glob, "tomo/configuration/glob"
autoload :PluginFileNotFoundError,
"tomo/configuration/plugin_file_not_found_error"
autoload :PluginFileNotFoundError, "tomo/configuration/plugin_file_not_found_error"
autoload :PluginsRegistry, "tomo/configuration/plugins_registry"
autoload :ProjectNotFoundError, "tomo/configuration/project_not_found_error"
autoload :RoleBasedTaskFilter, "tomo/configuration/role_based_task_filter"
autoload :UnknownEnvironmentError,
"tomo/configuration/unknown_environment_error"
autoload :UnknownEnvironmentError, "tomo/configuration/unknown_environment_error"
autoload :UnknownPluginError, "tomo/configuration/unknown_plugin_error"
autoload :UnspecifiedEnvironmentError,
"tomo/configuration/unspecified_environment_error"
autoload :UnspecifiedEnvironmentError, "tomo/configuration/unspecified_environment_error"

def self.from_config_rb(path=DEFAULT_CONFIG_PATH)
ProjectNotFoundError.raise_with(path: path) unless File.file?(path)
Expand All @@ -27,8 +24,7 @@ def self.from_config_rb(path=DEFAULT_CONFIG_PATH)
raise DSL::ErrorFormatter.decorate(e, path, config_rb&.lines)
end

attr_accessor :environments, :deploy_tasks, :setup_tasks, :hosts, :plugins,
:settings, :task_filter, :path
attr_accessor :environments, :deploy_tasks, :setup_tasks, :hosts, :plugins, :settings, :task_filter, :path

def initialize
@environments = {}
Expand Down Expand Up @@ -116,9 +112,7 @@ def raise_no_environment_specified
end

def raise_unknown_environment(environ)
UnknownEnvironmentError.raise_with(
name: environ, known_environments: environments.keys
)
UnknownEnvironmentError.raise_with(name: environ, known_environments: environments.keys)
end
end
end
3 changes: 1 addition & 2 deletions lib/tomo/configuration/dsl/hosts_and_settings.rb
Expand Up @@ -7,8 +7,7 @@ def set(settings)
self
end

def host(address, port: 22, roles: [],
log_prefix: nil, privileged_user: "root")
def host(address, port: 22, roles: [], log_prefix: nil, privileged_user: "root")
@config.hosts << Host.parse(
address,
privileged_user: privileged_user,
Expand Down
3 changes: 1 addition & 2 deletions lib/tomo/configuration/plugins_registry.rb
@@ -1,8 +1,7 @@
module Tomo
class Configuration
class PluginsRegistry
autoload :FileResolver,
"tomo/configuration/plugins_registry/file_resolver"
autoload :FileResolver, "tomo/configuration/plugins_registry/file_resolver"
autoload :GemResolver, "tomo/configuration/plugins_registry/gem_resolver"

attr_reader :helper_modules, :settings
Expand Down
5 changes: 1 addition & 4 deletions lib/tomo/configuration/unknown_environment_error.rb
Expand Up @@ -36,10 +36,7 @@ def wrong_envs
end

def suggestions
@_suggestions ||= Error::Suggestions.new(
dictionary: known_environments,
word: name
)
@_suggestions ||= Error::Suggestions.new(dictionary: known_environments, word: name)
end
end
end
Expand Down
10 changes: 2 additions & 8 deletions lib/tomo/console.rb
Expand Up @@ -18,10 +18,7 @@ def initialize(env=ENV, input=$stdin)
end

def interactive?
input.respond_to?(:raw) &&
input.respond_to?(:tty?) &&
input.tty? &&
!ci?
input.respond_to?(:raw) && input.respond_to?(:tty?) && input.tty? && !ci?
end

def prompt(question)
Expand Down Expand Up @@ -66,10 +63,7 @@ def assert_interactive
end

def raise_non_interactive
NonInteractiveError.raise_with(
task: Runtime::Current.task,
ci_var: (env.keys & CI_VARS).first
)
NonInteractiveError.raise_with(task: Runtime::Current.task, ci_var: (env.keys & CI_VARS).first)
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/tomo/console/menu.rb
Expand Up @@ -12,8 +12,7 @@ class Menu
extend Forwardable
include Colors

def initialize(question, options, key_reader: KeyReader.new,
output: $stdout)
def initialize(question, options, key_reader: KeyReader.new, output: $stdout)
@question = question
@options = options
@position = 0
Expand Down

0 comments on commit 55dcfcc

Please sign in to comment.