From e044bd43beab6029211689a9dd041721a651064e Mon Sep 17 00:00:00 2001 From: Frieder Bluemle Date: Tue, 24 Oct 2017 14:01:35 +0800 Subject: [PATCH] Update templates This fixes several rubocop and linter warnings, such as prefer usage of single-quoted strings when string interpolation is no needed, and lines that are too long. --- lib/bundler/templates/Executable | 14 ++++----- lib/bundler/templates/Executable.bundler | 28 ++++++++--------- lib/bundler/templates/Executable.standalone | 10 +++---- lib/bundler/templates/Gemfile | 4 +-- lib/bundler/templates/gems.rb | 4 +-- .../templates/newgem/CODE_OF_CONDUCT.md.tt | 6 ++-- lib/bundler/templates/newgem/Gemfile.tt | 2 +- lib/bundler/templates/newgem/README.md.tt | 30 +++++++++++++++---- lib/bundler/templates/newgem/bin/console.tt | 8 ++--- lib/bundler/templates/newgem/exe/newgem.tt | 2 +- .../templates/newgem/ext/newgem/extconf.rb.tt | 2 +- lib/bundler/templates/newgem/lib/newgem.rb.tt | 4 +-- .../templates/newgem/newgem.gemspec.tt | 29 +++++++++--------- .../templates/newgem/spec/newgem_spec.rb.tt | 4 +-- .../templates/newgem/spec/spec_helper.rb.tt | 6 ++-- .../templates/newgem/test/newgem_test.rb.tt | 2 +- .../templates/newgem/test/test_helper.rb.tt | 6 ++-- 17 files changed, 90 insertions(+), 71 deletions(-) diff --git a/lib/bundler/templates/Executable b/lib/bundler/templates/Executable index 9289debc262..124889d7013 100755 --- a/lib/bundler/templates/Executable +++ b/lib/bundler/templates/Executable @@ -1,4 +1,4 @@ -#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG["ruby_install_name"] %> +#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %> # frozen_string_literal: true # @@ -8,14 +8,14 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('../bundle', __FILE__) load(bundle_binstub) if File.file?(bundle_binstub) -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../<%= relative_gemfile_path %>", +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../<%= relative_gemfile_path %>', Pathname.new(__FILE__).realpath) -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("<%= spec.name %>", "<%= executable %>") +load Gem.bin_path('<%= spec.name %>', '<%= executable %>') diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler index eeda90b584b..de204d7c5e1 100644 --- a/lib/bundler/templates/Executable.bundler +++ b/lib/bundler/templates/Executable.bundler @@ -1,4 +1,4 @@ -#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG["ruby_install_name"] %> +#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %> # frozen_string_literal: true # @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -require "rubygems" +require 'rubygems' m = Module.new do module_function @@ -18,12 +18,12 @@ m = Module.new do end def env_var_version - ENV["BUNDLER_VERSION"] + ENV['BUNDLER_VERSION'] end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| @@ -31,23 +31,23 @@ m = Module.new do bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 || ">= 0.a" + bundler_version = $1 || '>= 0.a' update_index = i end bundler_version end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV['BUNDLE_GEMFILE'] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../<%= relative_gemfile_path %>", __FILE__) + File.expand_path('../<%= relative_gemfile_path %>', __FILE__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile) else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -68,22 +68,22 @@ m = Module.new do end def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile + ENV['BUNDLE_GEMFILE'] ||= gemfile # must dup string for RG < 1.8 compatibility activate_bundler(bundler_version.dup) end def activate_bundler(bundler_version) - if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") - bundler_version = "< 2" + if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0') + bundler_version = '< 2' end gem_error = activation_error_handling do - gem "bundler", bundler_version + gem 'bundler', bundler_version end return if gem_error.nil? require_error = activation_error_handling do - require "bundler/version" + require 'bundler/version' end return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" @@ -101,5 +101,5 @@ end m.load_bundler! if m.invoked_as_script? - load Gem.bin_path("<%= spec.name %>", "<%= executable %>") + load Gem.bin_path('<%= spec.name %>', '<%= executable %>') end diff --git a/lib/bundler/templates/Executable.standalone b/lib/bundler/templates/Executable.standalone index 4bf0753f44d..c114afe3376 100644 --- a/lib/bundler/templates/Executable.standalone +++ b/lib/bundler/templates/Executable.standalone @@ -1,4 +1,4 @@ -#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG["ruby_install_name"] %> +#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %> # # This file was generated by Bundler. # @@ -6,9 +6,9 @@ # this file is here to facilitate running it. # -require "pathname" +require 'pathname' path = Pathname.new(__FILE__) -$:.unshift File.expand_path "../<%= standalone_path %>", path.realpath +$:.unshift File.expand_path '../<%= standalone_path %>', path.realpath -require "bundler/setup" -load File.expand_path "../<%= executable_path %>", path.realpath +require 'bundler/setup' +load File.expand_path '../<%= executable_path %>', path.realpath diff --git a/lib/bundler/templates/Gemfile b/lib/bundler/templates/Gemfile index 1afd2cce673..3e72af11862 100644 --- a/lib/bundler/templates/Gemfile +++ b/lib/bundler/templates/Gemfile @@ -1,7 +1,7 @@ # frozen_string_literal: true -source "https://rubygems.org" +source 'https://rubygems.org' git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } -# gem "rails" +# gem 'rails' diff --git a/lib/bundler/templates/gems.rb b/lib/bundler/templates/gems.rb index 547cd6e8d9b..3fe6725b83d 100644 --- a/lib/bundler/templates/gems.rb +++ b/lib/bundler/templates/gems.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true # A sample gems.rb -source "https://rubygems.org" +source 'https://rubygems.org' git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } -# gem "rails" +# gem 'rails' diff --git a/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt b/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt index a3833d29d78..b87c1ae7676 100644 --- a/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +++ b/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt @@ -23,7 +23,7 @@ include: Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or -advances + advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic @@ -67,8 +67,8 @@ members of the project's leadership. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ diff --git a/lib/bundler/templates/newgem/Gemfile.tt b/lib/bundler/templates/newgem/Gemfile.tt index c114bd66659..df90355fba6 100644 --- a/lib/bundler/templates/newgem/Gemfile.tt +++ b/lib/bundler/templates/newgem/Gemfile.tt @@ -1,4 +1,4 @@ -source "https://rubygems.org" +source 'https://rubygems.org' git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } diff --git a/lib/bundler/templates/newgem/README.md.tt b/lib/bundler/templates/newgem/README.md.tt index 22ddeaa91a6..9661d9dfb33 100644 --- a/lib/bundler/templates/newgem/README.md.tt +++ b/lib/bundler/templates/newgem/README.md.tt @@ -1,6 +1,9 @@ # <%= config[:constant_name] %> -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/<%= config[:namespaced_path] %>`. To experiment with that code, run `bin/console` for an interactive prompt. +Welcome to your new gem! In this directory, you'll find the files you need to be +able to package up your Ruby library into a gem. Put your Ruby code in the file +`lib/<%= config[:namespaced_path] %>`. +To experiment with that code, run `bin/console` for an interactive prompt. TODO: Delete this and the text above, and describe your gem @@ -26,22 +29,37 @@ TODO: Write usage instructions here ## Development -After checking out the repo, run `bin/setup` to install dependencies.<% if config[:test] %> Then, run `rake <%= config[:test].sub('mini', '').sub('rspec', 'spec') %>` to run the tests.<% end %> You can also run `bin/console` for an interactive prompt that will allow you to experiment.<% if config[:bin] %> Run `bundle exec <%= config[:name] %>` to use the gem in this directory, ignoring other installed copies of this gem.<% end %> +After checking out the repo, run `bin/setup` to install dependencies. +<% if config[:test] %>Then, run `rake <%= config[:test].sub('mini', '').sub('rspec', 'spec') %>` to run the tests.<% end %> +You can also run `bin/console` for an interactive prompt that will allow you to +experiment. +<% if config[:bin] %>Run `bundle exec <%= config[:name] %>` to use the gem in this directory, ignoring other installed copies of this gem.<% end %> -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install this gem onto your local machine, run `bundle exec rake install`. To +release a new version, update the version number in `version.rb`, and then run +`bundle exec rake release`, which will create a Git tag for the version, push +Git commits and tags, and push the `.gem` file to +[rubygems.org](https://rubygems.org). ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/<%= config[:github_username] %>/<%= config[:name] %>.<% if config[:coc] %> This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.<% end %> +Bug reports and pull requests are welcome on GitHub at +https://github.com/<%= config[:github_username] %>/<%= config[:name] %>.<% if config[:coc] %> +This project is intended to be a safe, welcoming space for collaboration, and +contributors are expected to adhere to the +[Contributor Covenant](http://contributor-covenant.org) code of conduct.<% end %> <% if config[:mit] -%> ## License -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). +The gem is available as open source under the terms of the +[MIT License](https://opensource.org/licenses/MIT). <% end -%> <% if config[:coc] -%> ## Code of Conduct -Everyone interacting in the <%= config[:constant_name] %> project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/<%= config[:github_username] %>/<%= config[:name] %>/blob/master/CODE_OF_CONDUCT.md). +Everyone interacting in the <%= config[:constant_name] %> project’s +codebases, issue trackers, chat rooms and mailing lists is expected to follow +the [code of conduct](https://github.com/<%= config[:github_username] %>/<%= config[:name] %>/blob/master/CODE_OF_CONDUCT.md). <% end -%> diff --git a/lib/bundler/templates/newgem/bin/console.tt b/lib/bundler/templates/newgem/bin/console.tt index a27f82430f9..c5c2545cb14 100644 --- a/lib/bundler/templates/newgem/bin/console.tt +++ b/lib/bundler/templates/newgem/bin/console.tt @@ -1,14 +1,14 @@ #!/usr/bin/env ruby -require "bundler/setup" -require "<%= config[:namespaced_path] %>" +require 'bundler/setup' +require '<%= config[:namespaced_path] %>' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) -# require "pry" +# require 'pry' # Pry.start -require "irb" +require 'irb' IRB.start(__FILE__) diff --git a/lib/bundler/templates/newgem/exe/newgem.tt b/lib/bundler/templates/newgem/exe/newgem.tt index a8339bb79f5..a0052988155 100644 --- a/lib/bundler/templates/newgem/exe/newgem.tt +++ b/lib/bundler/templates/newgem/exe/newgem.tt @@ -1,3 +1,3 @@ #!/usr/bin/env ruby -require "<%= config[:namespaced_path] %>" +require '<%= config[:namespaced_path] %>' diff --git a/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt b/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt index 8cfc828f94f..c25ffaa6863 100644 --- a/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +++ b/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt @@ -1,3 +1,3 @@ -require "mkmf" +require 'mkmf' create_makefile(<%= config[:makefile_path].inspect %>) diff --git a/lib/bundler/templates/newgem/lib/newgem.rb.tt b/lib/bundler/templates/newgem/lib/newgem.rb.tt index 7d8ad90ab0c..d5cf23c9e03 100644 --- a/lib/bundler/templates/newgem/lib/newgem.rb.tt +++ b/lib/bundler/templates/newgem/lib/newgem.rb.tt @@ -1,6 +1,6 @@ -require "<%= config[:namespaced_path] %>/version" +require '<%= config[:namespaced_path] %>/version' <%- if config[:ext] -%> -require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>" +require '<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>' <%- end -%> <%- config[:constant_array].each_with_index do |c, i| -%> diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt index 97da2b14d81..2786db664f1 100644 --- a/lib/bundler/templates/newgem/newgem.gemspec.tt +++ b/lib/bundler/templates/newgem/newgem.gemspec.tt @@ -2,9 +2,9 @@ # coding: utf-8 <%- end -%> -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "<%= config[:namespaced_path] %>/version" +require '<%= config[:namespaced_path] %>/version' Gem::Specification.new do |spec| spec.name = <%= config[:name].inspect %> @@ -14,36 +14,37 @@ Gem::Specification.new do |spec| spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.} spec.description = %q{TODO: Write a longer description or delete this line.} - spec.homepage = "TODO: Put your gem's website or public repo URL here." + spec.homepage = 'TODO: Insert website or public repo URL of your gem.' <%- if config[:mit] -%> - spec.license = "MIT" + spec.license = 'MIT' <%- end -%> - # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' - # to allow pushing to a single host or delete this section to allow pushing to any host. + # Prevent pushing this gem to RubyGems.org. To allow pushes either set the + # 'allowed_push_host' to allow pushing to a single host or delete this section + # to allow pushing to any host. if spec.respond_to?(:metadata) spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" else - raise "RubyGems 2.0 or newer is required to protect against " \ - "public gem pushes." + raise 'RubyGems 2.0 or newer is required to protect against ' \ + 'public gem pushes.' end spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] <%- if config[:ext] -%> spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"] <%- end -%> - spec.add_development_dependency "bundler", "~> <%= config[:bundler_version] %>" - spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency 'bundler', '~> <%= config[:bundler_version] %>' + spec.add_development_dependency 'rake', '~> 10.0' <%- if config[:ext] -%> - spec.add_development_dependency "rake-compiler" + spec.add_development_dependency 'rake-compiler' <%- end -%> <%- if config[:test] -%> - spec.add_development_dependency "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>" + spec.add_development_dependency '<%= config[:test] %>', '~> <%= config[:test_framework_version] %>' <%- end -%> end diff --git a/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt b/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt index c63b4878306..61118067587 100644 --- a/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +++ b/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt @@ -1,9 +1,9 @@ RSpec.describe <%= config[:constant_name] %> do - it "has a version number" do + it 'has a version number' do expect(<%= config[:constant_name] %>::VERSION).not_to be nil end - it "does something useful" do + it 'does something useful' do expect(false).to eq(true) end end diff --git a/lib/bundler/templates/newgem/spec/spec_helper.rb.tt b/lib/bundler/templates/newgem/spec/spec_helper.rb.tt index 805cf57e011..8377cd3ffb1 100644 --- a/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +++ b/lib/bundler/templates/newgem/spec/spec_helper.rb.tt @@ -1,9 +1,9 @@ -require "bundler/setup" -require "<%= config[:namespaced_path] %>" +require 'bundler/setup' +require '<%= config[:namespaced_path] %>' RSpec.configure do |config| # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = ".rspec_status" + config.example_status_persistence_file_path = '.rspec_status' # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_patching! diff --git a/lib/bundler/templates/newgem/test/newgem_test.rb.tt b/lib/bundler/templates/newgem/test/newgem_test.rb.tt index f2af9f90e0b..95e33a34ea0 100644 --- a/lib/bundler/templates/newgem/test/newgem_test.rb.tt +++ b/lib/bundler/templates/newgem/test/newgem_test.rb.tt @@ -1,4 +1,4 @@ -require "test_helper" +require 'test_helper' class <%= config[:constant_name] %>Test < Minitest::Test def test_that_it_has_a_version_number diff --git a/lib/bundler/templates/newgem/test/test_helper.rb.tt b/lib/bundler/templates/newgem/test/test_helper.rb.tt index 725e3e46473..49a56c18000 100644 --- a/lib/bundler/templates/newgem/test/test_helper.rb.tt +++ b/lib/bundler/templates/newgem/test/test_helper.rb.tt @@ -1,4 +1,4 @@ -$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) -require "<%= config[:namespaced_path] %>" +$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +require '<%= config[:namespaced_path] %>' -require "minitest/autorun" +require 'minitest/autorun'