Skip to content

Commit

Permalink
[rubocop] fix Style/StringLiterals
Browse files Browse the repository at this point in the history
Signed-off-by: David Crosby <dcrosby@fb.com>
  • Loading branch information
dafyddcrosby committed Jan 23, 2024
1 parent b96656f commit 0085f73
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/chefstyle/ruby/gemspec_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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=} _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/chefstyle/ruby/require_net_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
140 changes: 70 additions & 70 deletions lib/rubocop/cop/chefstyle/ruby/unless_defined_require.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/chef/ruby/chefspec_license_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check failure on line 26 in spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb

View workflow job for this annotation

GitHub Actions / cookstyle

[Correctable] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
^^^^^^^^^^^^^^^^^^ Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now.
Expand All @@ -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)

Check failure on line 35 in spec/rubocop/cop/chef/ruby/gemspec_require_rubygems_spec.rb

View workflow job for this annotation

GitHub Actions / cookstyle

[Correctable] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rubygems does not need to be required in a Gemspec. It's already loaded out of the box in Ruby now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Check failure on line 26 in spec/rubocop/cop/chef/ruby/legacy_powershell_out_methods_spec.rb

View workflow job for this annotation

GitHub Actions / cookstyle

[Correctable] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
^^^^^^^^^^^^^^^^^^^^^^ 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')

Check failure on line 33 in spec/rubocop/cop/chef/ruby/legacy_powershell_out_methods_spec.rb

View workflow job for this annotation

GitHub Actions / cookstyle

[Correctable] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
^^^^^^^^^^^^^^^^^^^^^ Use powershell_exec!/powershell_exec instead of the slower legacy powershell_out!/powershell_out methods.
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/chef/ruby/require_net_https_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 26 in spec/rubocop/cop/chef/ruby/require_net_https_spec.rb

View workflow job for this annotation

GitHub Actions / cookstyle

[Correctable] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
^^^^^^^^^^^^^^^^^^^ net/https is deprecated and just includes net/http and openssl. We should include those directly instead.
Expand Down
8 changes: 4 additions & 4 deletions spec/rubocop/cop/chef/ruby/unless_defined_require_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check failure on line 27 in spec/rubocop/cop/chef/ruby/unless_defined_require_spec.rb

View workflow job for this annotation

GitHub Actions / cookstyle

[Correctable] Layout/HeredocIndentation: Use 2 spaces for indentation in a heredoc. (https://rubystyle.guide#squiggly-heredocs)
^^^^^^^^^^^^^^^^^^^^ Workaround rubygems slow requires by only running require if the class isn't already defined
Expand All @@ -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
Expand Down

0 comments on commit 0085f73

Please sign in to comment.