From 0085f7392d8a1149ba44a56b961b3fd68a08d806 Mon Sep 17 00:00:00 2001 From: dcrosby Date: Tue, 23 Jan 2024 11:10:22 -0800 Subject: [PATCH] [rubocop] fix Style/StringLiterals Signed-off-by: David Crosby --- .../cop/chefstyle/ruby/gemspec_license.rb | 2 +- .../ruby/legacy_powershell_out_methods.rb | 2 +- .../cop/chefstyle/ruby/require_net_https.rb | 2 +- .../chefstyle/ruby/unless_defined_require.rb | 140 +++++++++--------- .../cop/chef/ruby/chefspec_license_spec.rb | 8 +- .../ruby/gemspec_require_rubygems_spec.rb | 6 +- .../legacy_powershell_out_methods_spec.rb | 6 +- .../cop/chef/ruby/require_net_https_spec.rb | 4 +- .../chef/ruby/unless_defined_require_spec.rb | 8 +- 9 files changed, 89 insertions(+), 89 deletions(-) diff --git a/lib/rubocop/cop/chefstyle/ruby/gemspec_license.rb b/lib/rubocop/cop/chefstyle/ruby/gemspec_license.rb index 2979d58c..2b998c04 100644 --- a/lib/rubocop/cop/chefstyle/ruby/gemspec_license.rb +++ b/lib/rubocop/cop/chefstyle/ruby/gemspec_license.rb @@ -30,7 +30,7 @@ module Ruby class GemspecLicense < Base include RangeHelp - MSG = "All gemspec files should define their license." + MSG = 'All gemspec files should define their license.' def_node_search :license, <<~PATTERN (send _ {:license= :licenses=} _) diff --git a/lib/rubocop/cop/chefstyle/ruby/legacy_powershell_out_methods.rb b/lib/rubocop/cop/chefstyle/ruby/legacy_powershell_out_methods.rb index f7132362..fc824796 100644 --- a/lib/rubocop/cop/chefstyle/ruby/legacy_powershell_out_methods.rb +++ b/lib/rubocop/cop/chefstyle/ruby/legacy_powershell_out_methods.rb @@ -23,7 +23,7 @@ module Ruby # Use powershell_exec!/powershell_exec instead of powershell_out!/powershell_out. The new # methods don't spawn 2 shells per shellout and instead use .NET bindings to call PS directly. class LegacyPowershellOutMethods < Base - MSG = "Use powershell_exec!/powershell_exec instead of the slower legacy powershell_out!/powershell_out methods." + MSG = 'Use powershell_exec!/powershell_exec instead of the slower legacy powershell_out!/powershell_out methods.' RESTRICT_ON_SEND = %i(powershell_out! powershell_out).freeze def on_send(node) diff --git a/lib/rubocop/cop/chefstyle/ruby/require_net_https.rb b/lib/rubocop/cop/chefstyle/ruby/require_net_https.rb index ba2a14a6..5d8a6155 100644 --- a/lib/rubocop/cop/chefstyle/ruby/require_net_https.rb +++ b/lib/rubocop/cop/chefstyle/ruby/require_net_https.rb @@ -34,7 +34,7 @@ module Ruby class RequireNetHttps < Base extend RuboCop::Cop::AutoCorrector - MSG = "net/https is deprecated and just includes net/http and openssl. We should include those directly instead." + MSG = 'net/https is deprecated and just includes net/http and openssl. We should include those directly instead.' def_node_matcher :require_net_https?, <<-PATTERN (send nil? :require (str "net/https")) diff --git a/lib/rubocop/cop/chefstyle/ruby/unless_defined_require.rb b/lib/rubocop/cop/chefstyle/ruby/unless_defined_require.rb index abd9bdb9..af3d8d64 100644 --- a/lib/rubocop/cop/chefstyle/ruby/unless_defined_require.rb +++ b/lib/rubocop/cop/chefstyle/ruby/unless_defined_require.rb @@ -29,76 +29,76 @@ class UnlessDefinedRequire < Base MSG = "Workaround rubygems slow requires by only running require if the class isn't already defined" REQUIRE_TO_CLASS = { - "addressable/uri" => "Addressable::URI", - "appscript" => "Appscript", - "base64" => "Base64", - "benchmark" => "Benchmark", - "cgi" => "CGI", - "chef-utils" => "ChefUtils::CANARY", - "chef-utils/dist" => "ChefUtils::Dist", - "csv" => "CSV", - "digest" => "Digest", - "digest/md5" => "Digest::MD5", - "digest/sha1" => "Digest::SHA1", - "digest/sha2" => "Digest::SHA2", - "droplet_kit" => "DropletKit", - "erb" => "Erb", - "erubis" => "Erubis", - "etc" => "Etc", - "excon" => "Excon", - "faraday" => "Faraday", - "ffi_yajl" => "FFI_Yajl", - "ffi" => "FFI", - "fileutils" => "FileUtils", - "find" => "Find.find", - "forwardable" => "Forwardable", - "ipaddr" => "IPAddr", - "json" => "JSON", - "mime/types" => "MIME::Types", - "mixlib/archive" => "Mixlib::Archive", - "mixlib/cli" => "Mixlib::CLI", - "mixlib/config" => "Mixlib::Config", - "mixlib/shellout" => "Mixlib::ShellOut", - "multi_json" => "MultiJson", - "net/http" => "Net::HTTP", - "net/ssh" => "Net::SSH", - "netaddr" => "NetAddr", - "nokogiri" => "Nokogiri", - "ohai" => "Ohai::System", - "open-uri" => "OpenURI", - "openssl" => "OpenSSL", - "optparse" => "OptionParser", - "ostruct" => "OpenStruct", - "pathname" => "Pathname", - "pp" => "PP", - "rack" => "Rack", - "rbconfig" => "RbConfig", - "retryable" => "Retryable", - "rexml/document" => "REXML::Document", - "rubygems" => "Gem", - "rubygems/package" => "Gem::Package", - "securerandom" => "SecureRandom", - "set" => "Set", - "shellwords" => "Shellwords", - "singleton" => "Singleton", - "socket" => "Socket", - "sslshake" => "SSLShake", - "stringio" => "StringIO", - "tempfile" => "Tempfile", - "thor" => "Thor", - "time" => "Time.zone_offset", - "timeout" => "Timeout", - "tmpdir" => "Dir.mktmpdir", - "tomlrb" => "Tomlrb", - "uri" => "URI", - "webrick" => "WEBrick", - "win32/registry" => "Win32::Registry", - "win32ole" => "WIN32OLE", - "winrm" => "WinRM::Connection", - "yard" => "YARD", - "zip" => "Zip", - "zlib" => "Zlib", - "pastel" => "Pastel", + 'addressable/uri' => 'Addressable::URI', + 'appscript' => 'Appscript', + 'base64' => 'Base64', + 'benchmark' => 'Benchmark', + 'cgi' => 'CGI', + 'chef-utils' => 'ChefUtils::CANARY', + 'chef-utils/dist' => 'ChefUtils::Dist', + 'csv' => 'CSV', + 'digest' => 'Digest', + 'digest/md5' => 'Digest::MD5', + 'digest/sha1' => 'Digest::SHA1', + 'digest/sha2' => 'Digest::SHA2', + 'droplet_kit' => 'DropletKit', + 'erb' => 'Erb', + 'erubis' => 'Erubis', + 'etc' => 'Etc', + 'excon' => 'Excon', + 'faraday' => 'Faraday', + 'ffi_yajl' => 'FFI_Yajl', + 'ffi' => 'FFI', + 'fileutils' => 'FileUtils', + 'find' => 'Find.find', + 'forwardable' => 'Forwardable', + 'ipaddr' => 'IPAddr', + 'json' => 'JSON', + 'mime/types' => 'MIME::Types', + 'mixlib/archive' => 'Mixlib::Archive', + 'mixlib/cli' => 'Mixlib::CLI', + 'mixlib/config' => 'Mixlib::Config', + 'mixlib/shellout' => 'Mixlib::ShellOut', + 'multi_json' => 'MultiJson', + 'net/http' => 'Net::HTTP', + 'net/ssh' => 'Net::SSH', + 'netaddr' => 'NetAddr', + 'nokogiri' => 'Nokogiri', + 'ohai' => 'Ohai::System', + 'open-uri' => 'OpenURI', + 'openssl' => 'OpenSSL', + 'optparse' => 'OptionParser', + 'ostruct' => 'OpenStruct', + 'pathname' => 'Pathname', + 'pp' => 'PP', + 'rack' => 'Rack', + 'rbconfig' => 'RbConfig', + 'retryable' => 'Retryable', + 'rexml/document' => 'REXML::Document', + 'rubygems' => 'Gem', + 'rubygems/package' => 'Gem::Package', + 'securerandom' => 'SecureRandom', + 'set' => 'Set', + 'shellwords' => 'Shellwords', + 'singleton' => 'Singleton', + 'socket' => 'Socket', + 'sslshake' => 'SSLShake', + 'stringio' => 'StringIO', + 'tempfile' => 'Tempfile', + 'thor' => 'Thor', + 'time' => 'Time.zone_offset', + 'timeout' => 'Timeout', + 'tmpdir' => 'Dir.mktmpdir', + 'tomlrb' => 'Tomlrb', + 'uri' => 'URI', + 'webrick' => 'WEBrick', + 'win32/registry' => 'Win32::Registry', + 'win32ole' => 'WIN32OLE', + 'winrm' => 'WinRM::Connection', + 'yard' => 'YARD', + 'zip' => 'Zip', + 'zlib' => 'Zlib', + 'pastel' => 'Pastel', }.freeze def_node_matcher :require?, <<-PATTERN diff --git a/spec/rubocop/cop/chef/ruby/chefspec_license_spec.rb b/spec/rubocop/cop/chef/ruby/chefspec_license_spec.rb index af1067fc..43f6e641 100644 --- a/spec/rubocop/cop/chef/ruby/chefspec_license_spec.rb +++ b/spec/rubocop/cop/chef/ruby/chefspec_license_spec.rb @@ -16,18 +16,18 @@ # limitations under the License. # -require "spec_helper" +require 'spec_helper' describe RuboCop::Cop::Chef::Ruby::GemspecLicense, :config do subject(:cop) { described_class.new(config) } before do allow(IO).to receive(:read).and_call_original - allow(IO).to receive(:read).with("/foo/bar/chef.gemspec").and_return("Gem::Specification.new do |spec|\n spec.name = 'chef'\nend") + allow(IO).to receive(:read).with('/foo/bar/chef.gemspec').and_return("Gem::Specification.new do |spec|\n spec.name = 'chef'\nend") end - it "registers an offense when the license method is missing" do - expect_offense(<<~RUBY, "/foo/bar/chef.gemspec") + it 'registers an offense when the license method is missing' do + expect_offense(<<~RUBY, '/foo/bar/chef.gemspec') Gem::Specification.new do |spec| ^ All gemspec files should define their license. spec.name = "chef" diff --git a/spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb b/spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb index 20244ab0..fb9a122a 100644 --- a/spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb +++ b/spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb @@ -16,12 +16,12 @@ # limitations under the License. # -require "spec_helper" +require 'spec_helper' describe RuboCop::Cop::Chef::Ruby::GemspecRequireRubygems, :config do subject(:cop) { described_class.new(config) } - it "registers an offense when requiring rubygems" do + it 'registers an offense when requiring rubygems' do expect_offense(<<~RUBY) require "rubygems" ^^^^^^^^^^^^^^^^^^ Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now. @@ -30,7 +30,7 @@ expect_correction("\n") end - it "registers an offense when requiring rubygems with a conditional" do + it 'registers an offense when requiring rubygems with a conditional' do expect_offense(<<~RUBY) require "rubygems" unless defined?(Gem) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now. diff --git a/spec/rubocop/cop/chef/ruby/legacy_powershell_out_methods_spec.rb b/spec/rubocop/cop/chef/ruby/legacy_powershell_out_methods_spec.rb index 09c72df5..7b7d0833 100644 --- a/spec/rubocop/cop/chef/ruby/legacy_powershell_out_methods_spec.rb +++ b/spec/rubocop/cop/chef/ruby/legacy_powershell_out_methods_spec.rb @@ -16,19 +16,19 @@ # limitations under the License. # -require "spec_helper" +require 'spec_helper' describe RuboCop::Cop::Chef::Ruby::LegacyPowershellOutMethods, :config do subject(:cop) { described_class.new(config) } - it "registers an offense when using powershell_out!" do + it 'registers an offense when using powershell_out!' do expect_offense(<<~RUBY) powershell_out!('foo') ^^^^^^^^^^^^^^^^^^^^^^ Use powershell_exec!/powershell_exec instead of the slower legacy powershell_out!/powershell_out methods. RUBY end - it "registers an offense when using powershell_out" do + it 'registers an offense when using powershell_out' do expect_offense(<<~RUBY) powershell_out('foo') ^^^^^^^^^^^^^^^^^^^^^ Use powershell_exec!/powershell_exec instead of the slower legacy powershell_out!/powershell_out methods. diff --git a/spec/rubocop/cop/chef/ruby/require_net_https_spec.rb b/spec/rubocop/cop/chef/ruby/require_net_https_spec.rb index e5af019b..74b969b0 100644 --- a/spec/rubocop/cop/chef/ruby/require_net_https_spec.rb +++ b/spec/rubocop/cop/chef/ruby/require_net_https_spec.rb @@ -16,12 +16,12 @@ # limitations under the License. # -require "spec_helper" +require 'spec_helper' describe RuboCop::Cop::Chef::Ruby::RequireNetHttps, :config do subject(:cop) { described_class.new(config) } - it "registers an offense when when requiring net/https" do + it 'registers an offense when when requiring net/https' do expect_offense(<<~RUBY) require 'net/https' ^^^^^^^^^^^^^^^^^^^ net/https is deprecated and just includes net/http and openssl. We should include those directly instead. diff --git a/spec/rubocop/cop/chef/ruby/unless_defined_require_spec.rb b/spec/rubocop/cop/chef/ruby/unless_defined_require_spec.rb index 200bf6f9..04de02ca 100644 --- a/spec/rubocop/cop/chef/ruby/unless_defined_require_spec.rb +++ b/spec/rubocop/cop/chef/ruby/unless_defined_require_spec.rb @@ -16,13 +16,13 @@ # limitations under the License. # -require "spec_helper" +require 'spec_helper' describe RuboCop::Cop::Chef::Ruby::UnlessDefinedRequire, :config do subject(:cop) { described_class.new(config) } - context "with a require known to the cop" do - it "registers an offense without an if defined? check" do + context 'with a require known to the cop' do + it 'registers an offense without an if defined? check' do expect_offense(<<~RUBY) require 'digest/md5' ^^^^^^^^^^^^^^^^^^^^ Workaround rubygems slow requires by only running require if the class isn't already defined @@ -40,7 +40,7 @@ end end - context "with a require unknown to the cop" do + context 'with a require unknown to the cop' do it "doesn't register an offense with an if defined? check" do expect_no_offenses("require 'foo/bar' unless defined?(Foo::Bar)") end