From cad03d2fad931e684e255eeed44411ce64386eca Mon Sep 17 00:00:00 2001 From: Dana Sherson Date: Sun, 3 Dec 2023 13:16:35 +1300 Subject: [PATCH] Rubocop --- .rubocop.yml | 5 +- .spellr_wordlists/english.txt | 1 + Brewfile | 77 ++++++++++---------- Gemfile | 8 ++- spec/bash_support_spec.rb | 54 +++++++------- spec/git_helper_spec.rb | 28 ++++---- spec/git_spec.rb | 90 +++++++++++++++-------- spec/spec_helper.rb | 2 +- spec/speckly.rb | 51 ++++++------- spec/speckly/api.rb | 3 +- spec/speckly/command.rb | 17 ++--- spec/speckly/concat_io.rb | 2 + spec/speckly/eventually.rb | 6 +- spec/speckly/io.rb | 12 ++-- spec/speckly/rspec.rb | 2 + spec/speckly/rspec/have_exitstatus.rb | 30 +++++--- spec/speckly/rspec/have_output.rb | 100 +++++++++++++++++++------- spec/speckly/rspec_matchers.rb | 4 +- spec/speckly/session.rb | 4 +- spec/support/git_helpers.rb | 25 ++++--- 20 files changed, 314 insertions(+), 207 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 54cd86d..2e90217 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,7 @@ AllCops: - .bundle/**/* - tmp/**/* - vendor/**/* + - github-cctray/**/* DisplayCopNames: true DisplayStyleGuide: true @@ -59,14 +60,14 @@ Metrics: CountComments: false Metrics/BlockLength: - ExcludedMethods: + AllowedMethods: - configure - describe - context - it Layout/LineLength: - Max: 80 + Max: 120 IgnoreCopDirectives: true Metrics/MethodLength: diff --git a/.spellr_wordlists/english.txt b/.spellr_wordlists/english.txt index 052e7e3..b7664fe 100644 --- a/.spellr_wordlists/english.txt +++ b/.spellr_wordlists/english.txt @@ -48,6 +48,7 @@ coreaudiod cppflags cruisecontrol cwd +cyclomatic dest diffable diffr diff --git a/Brewfile b/Brewfile index 51fc99e..7adbe17 100644 --- a/Brewfile +++ b/Brewfile @@ -1,39 +1,40 @@ -tap "heroku/brew" -tap "homebrew/bundle" -tap "homebrew/cask" -tap "homebrew/cask-fonts" -tap "homebrew/core" -tap "homebrew/services" -brew "fnm" -brew "rust" -brew "pcre" -brew "bash" -brew "chruby" -brew "ruby-install" -brew "exercism" -brew "diffr" -brew "git" -brew "git-lfs" -brew "gnupg" -brew "jq" -brew "pinentry-mac" -brew "pkg-config" -brew "rbspy" -brew "shellcheck" -brew "wget" -brew "yq" -cask "finicky" -cask "textmate" -cask "1password" -cask "docker" -cask "dropbox" -cask "firefox" -cask "font-inconsolata" -cask "google-chrome" -cask "istat-menus" -cask "visual-studio-code" -cask "ccmenu" -cask "slack" -cask "spotify" -cask "textmate" +# frozen_string_literal: true +tap 'heroku/brew' +tap 'homebrew/bundle' +tap 'homebrew/cask' +tap 'homebrew/cask-fonts' +tap 'homebrew/core' +tap 'homebrew/services' +brew 'fnm' +brew 'rust' +brew 'pcre' +brew 'bash' +brew 'chruby' +brew 'ruby-install' +brew 'exercism' +brew 'diffr' +brew 'git' +brew 'git-lfs' +brew 'gnupg' +brew 'jq' +brew 'pinentry-mac' +brew 'pkg-config' +brew 'rbspy' +brew 'shellcheck' +brew 'wget' +brew 'yq' +cask 'finicky' +cask 'textmate' +cask '1password' +cask 'docker' +cask 'dropbox' +cask 'firefox' +cask 'font-inconsolata' +cask 'google-chrome' +cask 'istat-menus' +cask 'visual-studio-code' +cask 'ccmenu' +cask 'slack' +cask 'spotify' +cask 'textmate' diff --git a/Gemfile b/Gemfile index 70cf73b..f6ffcb3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,10 @@ +# frozen_string_literal: true + source 'https://rubygems.org' -gem 'spellr' -gem 'rspec' -gem 'tty_string' gem 'pry' +gem 'rspec' gem 'rubocop' gem 'rubocop-rspec' +gem 'spellr' +gem 'tty_string' diff --git a/spec/bash_support_spec.rb b/spec/bash_support_spec.rb index 6f158c6..132ca84 100644 --- a/spec/bash_support_spec.rb +++ b/spec/bash_support_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + COLOR_RED = ENV.fetch('COLOR_RED') COLOR_GREEN = ENV.fetch('COLOR_GREEN') COLOR_YELLOW = ENV.fetch('COLOR_YELLOW') @@ -11,14 +13,14 @@ RSpec.describe 'bash_support' do it 'returns current ruby version' do copy_file '.ruby-version' - expect(run 'ruby -v').to have_output( + expect(run('ruby -v')).to have_output( "ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin22]\n" ) end describe 'echoerr' do it 'returns red text for echoerr' do - expect(run 'echoerr No', expect_exit: 1).to have_output( + expect(run('echoerr No', expect_exit: 1)).to have_output( stderr: "#{COLOR_RED}error: No#{COLOR_RESET}\n", stdout: nil ) @@ -27,156 +29,156 @@ describe 'echodo' do it 'returns grey text for echodo to stderr and does the thing to stdout' do - expect(run "echodo echo 1").to have_output( + expect(run('echodo echo 1')).to have_output( stderr: "#{COLOR_GREY}echo 1#{COLOR_RESET}\n", stdout: "1\n" ) end it 'removes unnecessary single quotes' do - expect(run "echodo echo '1'").to have_output( + expect(run("echodo echo '1'")).to have_output( stderr: "#{COLOR_GREY}echo 1#{COLOR_RESET}\n", stdout: "1\n" ) end it 'removes unnecessary double quotes' do - expect(run 'echodo echo "1"').to have_output( + expect(run('echodo echo "1"')).to have_output( stderr: "#{COLOR_GREY}echo 1#{COLOR_RESET}\n", stdout: "1\n" ) end it 'retains quoted empty double quoted strings' do - expect(run 'echodo echo ""').to have_output( + expect(run('echodo echo ""')).to have_output( stderr: "#{COLOR_GREY}echo ''#{COLOR_RESET}\n", stdout: "\n" ) end it 'retains quoted empty single quoted strings' do - expect(run "echodo echo ''").to have_output( + expect(run("echodo echo ''")).to have_output( stderr: "#{COLOR_GREY}echo ''#{COLOR_RESET}\n", stdout: "\n" ) end it 'uses single quotes to escape spaces when given a single quoted string' do - expect(run "echodo echo '1 and 2'").to have_output( + expect(run("echodo echo '1 and 2'")).to have_output( stderr: "#{COLOR_GREY}echo '1 and 2'#{COLOR_RESET}\n", stdout: "1 and 2\n" ) end it 'uses single quotes to escape spaces when given a double quoted string' do - expect(run 'echodo echo "1 and 2"').to have_output( + expect(run('echodo echo "1 and 2"')).to have_output( stderr: "#{COLOR_GREY}echo '1 and 2'#{COLOR_RESET}\n", stdout: "1 and 2\n" ) end it 'uses single quotes to escape spaces when given a backslash escaped string' do - expect(run "echodo echo 1\\ and\\ 2").to have_output( + expect(run('echodo echo 1\\ and\\ 2')).to have_output( stderr: "#{COLOR_GREY}echo '1 and 2'#{COLOR_RESET}\n", stdout: "1 and 2\n" ) end it 'uses single quotes to escape \\(whatever\\)' do - expect(run "echodo echo \\(whatever\\)").to have_output( + expect(run('echodo echo \\(whatever\\)')).to have_output( stderr: "#{COLOR_GREY}echo '(whatever)'#{COLOR_RESET}\n", stdout: "(whatever)\n" ) end it "uses single quotes to escape '(whatever)'" do - expect(run "echodo echo '(whatever)'").to have_output( + expect(run("echodo echo '(whatever)'")).to have_output( stderr: "#{COLOR_GREY}echo '(whatever)'#{COLOR_RESET}\n", stdout: "(whatever)\n" ) end it "uses single quotes to escape '[whatever]" do - expect(run "echodo echo '[whatever]'").to have_output( + expect(run("echodo echo '[whatever]'")).to have_output( stderr: "#{COLOR_GREY}echo '[whatever]'#{COLOR_RESET}\n", stdout: "[whatever]\n" ) end it "uses single quotes to escape 'what)ever]'" do - expect(run "echodo echo 'what)ever]'").to have_output( + expect(run("echodo echo 'what)ever]'")).to have_output( stderr: "#{COLOR_GREY}echo 'what)ever]'#{COLOR_RESET}\n", stdout: "what)ever]\n" ) end it "uses single quotes to escape 'what) ever]'" do - expect(run "echodo echo 'what) ever]'").to have_output( + expect(run("echodo echo 'what) ever]'")).to have_output( stderr: "#{COLOR_GREY}echo 'what) ever]'#{COLOR_RESET}\n", stdout: "what) ever]\n" ) end it "uses single quotes to escape 'what)ever'" do - expect(run "echodo echo 'what)ever'").to have_output( + expect(run("echodo echo 'what)ever'")).to have_output( stderr: "#{COLOR_GREY}echo 'what)ever'#{COLOR_RESET}\n", stdout: "what)ever\n" ) end it "uses single quotes to escape 'what>ever'" do - expect(run "echodo echo 'what>ever'").to have_output( + expect(run("echodo echo 'what>ever'")).to have_output( stderr: "#{COLOR_GREY}echo 'what>ever'#{COLOR_RESET}\n", stdout: "what>ever\n" ) end it "uses single quotes to escape 'what(s) { TTYString.parse(s.to_s, clear_style: clear_style).split(split) } + ->(s) { TTYString.parse(s.to_s, clear_style:).split(split) } elsif rendered - ->(s) { TTYString.parse(s.to_s, clear_style: clear_style) } + ->(s) { TTYString.parse(s.to_s, clear_style:) } elsif split ->(s) { s.to_s.split(split) } else @@ -60,7 +104,7 @@ def prepare_value_transformer(rendered, split) end end - def prepare_result_for_diff + def prepare_result_for_diff # rubocop:disable Metrics/MethodLength @expected, @actual = if @expected_merged [@expected_merged, @actual_merged] elsif @expected_stdout && @expected_stderr @@ -74,11 +118,13 @@ def prepare_result_for_diff false end - def prepare_matchers(command, merged, stdout, stderr) + def prepare_matchers(command, merged, stdout, stderr) # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity, Metrics/AbcSize if command.merged? && (stdout != NO_ARG || stderr != NO_ARG) - raise ArgumentError, "command was run with `merged_output: true` so can't match stdout and stderr separately" + raise ArgumentError, 'command was run with `merged_output: true` ' \ + "so can't match stdout and stderr separately" elsif merged != NO_ARG && (stdout != NO_ARG || stderr != NO_ARG) - raise ArgumentError, "can't use a merged matcher and single stream matchers together" + raise ArgumentError, "can't use a merged matcher and single stream " \ + 'matchers together' elsif merged == NO_ARG && stdout == NO_ARG && stderr == NO_ARG @expected_merged = be_present elsif stdout == NO_ARG && stderr == NO_ARG @@ -91,11 +137,11 @@ def prepare_matchers(command, merged, stdout, stderr) elsif stderr != NO_ARG @expected_stderr = io_matcher(stderr) else - raise ArgumentError, "Unexpected argument combination" + raise ArgumentError, 'Unexpected argument combination' end end - def io_matcher(arg) + def io_matcher(arg) # rubocop:disable Metrics/MethodLength if arg == NO_ARG || arg == true be_present elsif arg diff --git a/spec/speckly/rspec_matchers.rb b/spec/speckly/rspec_matchers.rb index 3a5c2c7..7906eac 100644 --- a/spec/speckly/rspec_matchers.rb +++ b/spec/speckly/rspec_matchers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'shellwords' module Speckly @@ -7,5 +9,3 @@ module Speckly require_relative 'rspec/have_exitstatus' require_relative 'rspec/have_output' - - diff --git a/spec/speckly/session.rb b/spec/speckly/session.rb index 913c620..ec5cb86 100644 --- a/spec/speckly/session.rb +++ b/spec/speckly/session.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'tmpdir' module Speckly @@ -19,7 +21,7 @@ def dir attr_reader :commands - def chdir(dir, return_if: :block_given?) + def chdir(dir, return_if: :block_given?) # rubocop:disable Metrics/MethodLength return_if = block_given? if return_if == :block_given? return_to = ::Dir.pwd if return_if dir = mktmpdir if dir == :temp diff --git a/spec/support/git_helpers.rb b/spec/support/git_helpers.rb index 5b9c669..9702286 100644 --- a/spec/support/git_helpers.rb +++ b/spec/support/git_helpers.rb @@ -1,26 +1,31 @@ +# frozen_string_literal: true + module CLIHelper - def git(args = nil, **kwargs) - run("git #{args}", **kwargs) + def git(args = nil, **) + run("git #{args}", **) end - def git_add(args, **kwargs) - git("add #{args}", **kwargs) + def git_add(args, **) + git("add #{args}", **) end - def git_checkout(args, **kwargs) - git("checkout #{args}", **kwargs) + def git_checkout(args, **) + git("checkout #{args}", **) end - def git_commit(args = nil, **kwargs) - git("commit --no-gpg-sign #{args}", **kwargs) + def git_commit(args = nil, **) + git("commit --no-gpg-sign #{args}", **) end def expect_clean_git_status - expect(git("status --long")).to have_output("On branch main\nnothing to commit, working tree clean\n") + expect(git('status --long')).to have_output(<<~MESSAGE) + On branch main + nothing to commit, working tree clean + MESSAGE end def expect_empty_stash - expect(git("stash list")).to_not have_output + expect(git('stash list')).not_to have_output end def git_log