From 911e249d72248ca8f8a945dd345aadf9f58aeea5 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 21 Sep 2022 22:55:50 +0530 Subject: [PATCH] Bump RuboCop to `1.36.x` (#9125) Merge pull request 9125 --- .rubocop.yml | 67 ++++++++++++++++++- Gemfile | 2 +- lib/jekyll/commands/build.rb | 4 +- lib/jekyll/commands/clean.rb | 3 +- lib/jekyll/commands/doctor.rb | 24 +++---- lib/jekyll/commands/new.rb | 12 ++-- lib/jekyll/commands/new_theme.rb | 7 +- lib/jekyll/commands/serve.rb | 30 ++++----- .../commands/serve/live_reload_reactor.rb | 2 +- lib/jekyll/commands/serve/servlet.rb | 2 +- lib/jekyll/configuration.rb | 4 +- .../converters/markdown/kramdown_parser.rb | 2 +- lib/jekyll/excerpt.rb | 4 +- lib/jekyll/filters.rb | 2 +- lib/jekyll/hooks.rb | 4 +- lib/jekyll/plugin_manager.rb | 7 +- lib/jekyll/renderer.rb | 4 +- lib/jekyll/site.rb | 14 ++-- lib/jekyll/tags/highlight.rb | 4 +- lib/jekyll/tags/include.rb | 4 +- lib/jekyll/tags/post_url.rb | 10 +-- lib/jekyll/theme.rb | 4 +- lib/jekyll/url.rb | 2 +- lib/jekyll/utils/ansi.rb | 2 +- test/helper.rb | 5 +- test/test_commands_serve.rb | 4 +- test/test_doctor_command.rb | 8 ++- test/test_excerpt.rb | 9 ++- test/test_page_without_a_file.rb | 4 +- test/test_regenerator.rb | 4 +- test/test_site.rb | 4 +- test/test_tags.rb | 14 ++-- test/test_theme_assets_reader.rb | 9 ++- 33 files changed, 167 insertions(+), 114 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 69c279c9..8e311450 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,6 +27,9 @@ AllCops: Gemspec/DeprecatedAttributeAssignment: Enabled: true +Gemspec/RequireMFA: + Enabled: false + Layout/BeginEndAlignment: Enabled: true Layout/EmptyComment: @@ -43,6 +46,12 @@ Layout/HashAlignment: EnforcedHashRocketStyle: table Layout/IndentationWidth: Severity: error +Layout/LineContinuationLeadingSpace: + Enabled: true +Layout/LineContinuationSpacing: + Enabled: true +Layout/LineEndStringConcatenationIndentation: + Enabled: true Layout/LineLength: Exclude: - !ruby/regexp /features\/.*.rb/ @@ -66,12 +75,18 @@ Layout/SpaceInsideHashLiteralBraces: Lint/AmbiguousAssignment: Enabled: true +Lint/AmbiguousOperatorPrecedence: + Enabled: true +Lint/AmbiguousRange: + Enabled: true Lint/BinaryOperatorWithIdenticalOperands: Enabled: true Lint/ConstantDefinitionInBlock: Enabled: true Exclude: - test/**/*.rb +Lint/ConstantOverwrittenInRescue: + Enabled: true Lint/DeprecatedConstants: Enabled: true Lint/DeprecatedOpenSSLConstant: @@ -123,6 +138,10 @@ Lint/RedundantDirGlobSort: Enabled: true Lint/RedundantSafeNavigation: Enabled: true +Lint/RequireRangeParentheses: + Enabled: true +Lint/RequireRelativeSelfPath: + Enabled: true Lint/SelfAssignment: Enabled: true Lint/StructNewOverride: @@ -187,6 +206,8 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 13 +Minitest/AssertEmptyLiteral: + Enabled: false Minitest/AssertInDelta: Enabled: true Minitest/AssertionInLifecycleHook: @@ -199,6 +220,8 @@ Minitest/AssertPathExists: Enabled: true Minitest/AssertSilent: Enabled: true +Minitest/AssertWithExpectedArgument: + Enabled: true Minitest/LiteralAsActualArgument: Enabled: true Minitest/TestMethodName: @@ -211,10 +234,10 @@ Minitest/RefuteKindOf: Enabled: true Minitest/RefutePathExists: Enabled: true +Minitest/UnreachableAssertion: + Enabled: true Minitest/UnspecifiedException: Enabled: true -Minitest/AssertEmptyLiteral: - Enabled: false Naming/FileName: Enabled: false @@ -242,10 +265,16 @@ Performance/CollectionLiteralInLoop: Enabled: true Performance/ConstantRegexp: Enabled: true +Performance/MapCompact: + Enabled: true Performance/MethodObjectAsBlock: Enabled: true +Performance/RedundantEqualityComparisonBlock: + Enabled: false Performance/RedundantSortBlock: Enabled: true +Performance/RedundantSplitRegexpArgument: + Enabled: true Performance/RedundantStringChars: Enabled: true Performance/ReverseFirst: @@ -254,6 +283,8 @@ Performance/SortReverse: Enabled: false Performance/Squeeze: Enabled: true +Performance/StringIdentifierArgument: + Enabled: true Performance/StringInclude: Enabled: true Exclude: @@ -261,6 +292,10 @@ Performance/StringInclude: Performance/Sum: Enabled: true +Security/CompoundHash: + Enabled: true +Security/IoMethods: + Enabled: true Security/MarshalLoad: Exclude: - !ruby/regexp /test\/.*.rb$/ @@ -303,12 +338,20 @@ Style/Documentation: Enabled: false Style/DoubleNegation: Enabled: false +Style/EmptyHeredoc: + Enabled: true Style/EndlessMethod: Enabled: true Style/ExplicitBlockArgument: Enabled: false Style/ExponentialNotation: Enabled: true +Style/EnvHome: + Enabled: true +Style/FetchEnvVar: + Enabled: false +Style/FileRead: + Enabled: false Style/FormatStringToken: Exclude: - lib/jekyll/utils/ansi.rb @@ -316,6 +359,8 @@ Style/FormatStringToken: - lib/jekyll/profiler.rb Style/FrozenStringLiteralComment: EnforcedStyle: always +Style/FileWrite: + Enabled: true Style/GlobalStdStream: Enabled: true Style/GuardClause: @@ -341,6 +386,12 @@ Style/IfWithBooleanLiteralBranches: Enabled: true Style/KeywordParametersOrder: Enabled: true +Style/MagicCommentFormat: + Enabled: true +Style/MapCompactWithConditionalBlock: + Enabled: true +Style/MapToHash: + Enabled: true Style/MixinUsage: Exclude: - test/helper.rb @@ -350,10 +401,14 @@ Style/MultilineTernaryOperator: Severity: error Style/NegatedIfElseCondition: Enabled: true +Style/NestedFileDirname: + Enabled: true Style/NilLambda: Enabled: true Style/OptionalBooleanParameter: Enabled: true + Exclude: + - lib/jekyll/log_adapter.rb Style/PercentLiteralDelimiters: PreferredDelimiters: "%Q": "{}" @@ -363,6 +418,8 @@ Style/PercentLiteralDelimiters: "%s": () "%w": () "%x": () +Style/QuotedSymbols: + Enabled: true Style/RedundantArgument: Enabled: true Style/RedundantAssignment: @@ -371,12 +428,18 @@ Style/RedundantFetchBlock: Enabled: false Style/RedundantFileExtensionInRequire: Enabled: true +Style/RedundantInitialize: + Enabled: true + Exclude: + - lib/jekyll/plugin.rb Style/RedundantRegexpCharacterClass: Enabled: true Style/RedundantRegexpEscape: Enabled: true Style/RedundantSelfAssignment: Enabled: true +Style/RedundantSelfAssignmentBranch: + Enabled: true Style/RegexpLiteral: EnforcedStyle: percent_r Style/RescueModifier: diff --git a/Gemfile b/Gemfile index 3053fcba..66575a7e 100644 --- a/Gemfile +++ b/Gemfile @@ -23,7 +23,7 @@ group :test do gem "nokogiri", "~> 1.7" gem "rspec" gem "rspec-mocks" - gem "rubocop", "~> 1.32.0" + gem "rubocop", "~> 1.36.0" gem "rubocop-minitest" gem "rubocop-performance" gem "rubocop-rake" diff --git a/lib/jekyll/commands/build.rb b/lib/jekyll/commands/build.rb index 7fc6dfa7..204b2a12 100644 --- a/lib/jekyll/commands/build.rb +++ b/lib/jekyll/commands/build.rb @@ -30,8 +30,8 @@ module Jekyll site = Jekyll::Site.new(options) if options.fetch("skip_initial_build", false) - Jekyll.logger.warn "Build Warning:", "Skipping the initial build." \ - " This may result in an out-of-date site." + Jekyll.logger.warn "Build Warning:", + "Skipping the initial build. This may result in an out-of-date site." else build(site, options) end diff --git a/lib/jekyll/commands/clean.rb b/lib/jekyll/commands/clean.rb index 9bebd517..9b657a49 100644 --- a/lib/jekyll/commands/clean.rb +++ b/lib/jekyll/commands/clean.rb @@ -7,8 +7,7 @@ module Jekyll def init_with_program(prog) prog.command(:clean) do |c| c.syntax "clean [subcommand]" - c.description "Clean the site " \ - "(removes site output and metadata file) without building." + c.description "Clean the site (removes site output and metadata file) without building." add_build_options(c) diff --git a/lib/jekyll/commands/doctor.rb b/lib/jekyll/commands/doctor.rb index 480dd9bd..7e012936 100644 --- a/lib/jekyll/commands/doctor.rb +++ b/lib/jekyll/commands/doctor.rb @@ -53,14 +53,14 @@ module Jekyll "Detected '_posts' directory outside custom `collections_dir`!" Jekyll.logger.warn "", "Please move '#{posts_at_root}' into the custom directory at " \ - "'#{site.in_source_dir(site.config["collections_dir"])}'" + "'#{site.in_source_dir(site.config["collections_dir"])}'" false end def deprecated_relative_permalinks(site) if site.config["relative_permalinks"] - Jekyll::Deprecator.deprecation_message "Your site still uses relative permalinks," \ - " which was removed in Jekyll v3.0.0." + Jekyll::Deprecator.deprecation_message "Your site still uses relative permalinks, " \ + "which was removed in Jekyll v3.0.0." true end end @@ -105,9 +105,9 @@ module Jekyll next unless real_urls.uniq.size > 1 urls_only_differ_by_case = true - Jekyll.logger.warn "Warning:", "The following URLs only differ" \ - " by case. On a case-insensitive file system one of the URLs" \ - " will be overwritten by the other: #{real_urls.join(", ")}" + Jekyll.logger.warn "Warning:", "The following URLs only differ by case. On a " \ + "case-insensitive file system one of the URLs will be " \ + "overwritten by the other: #{real_urls.join(", ")}" end urls_only_differ_by_case end @@ -148,8 +148,8 @@ module Jekyll def url_exists?(url) return true unless url.nil? || url.empty? - Jekyll.logger.warn "Warning:", "You didn't set an URL in the config file, "\ - "you may encounter problems with some plugins." + Jekyll.logger.warn "Warning:", "You didn't set an URL in the config file, you may " \ + "encounter problems with some plugins." false end @@ -159,16 +159,16 @@ module Jekyll # Addressable::URI#parse only raises a TypeError # https://github.com/sporkmonger/addressable/blob/0a0e96acb17225f9b1c9cab0bad332b448934c9a/lib/addressable/uri.rb#L103 rescue TypeError - Jekyll.logger.warn "Warning:", "The site URL does not seem to be valid, "\ - "check the value of `url` in your config file." + Jekyll.logger.warn "Warning:", "The site URL does not seem to be valid, " \ + "check the value of `url` in your config file." false end def url_absolute(url) return true if url.is_a?(String) && Addressable::URI.parse(url).absolute? - Jekyll.logger.warn "Warning:", "Your site URL does not seem to be absolute, "\ - "check the value of `url` in your config file." + Jekyll.logger.warn "Warning:", "Your site URL does not seem to be absolute, " \ + "check the value of `url` in your config file." false end end diff --git a/lib/jekyll/commands/new.rb b/lib/jekyll/commands/new.rb index f85026ba..0a00f263 100644 --- a/lib/jekyll/commands/new.rb +++ b/lib/jekyll/commands/new.rb @@ -28,8 +28,8 @@ module Jekyll FileUtils.mkdir_p new_blog_path if preserve_source_location?(new_blog_path, options) Jekyll.logger.error "Conflict:", "#{new_blog_path} exists and is not empty." - Jekyll.logger.abort_with "", "Ensure #{new_blog_path} is empty or else " \ - "try again with `--force` to proceed and overwrite any files." + Jekyll.logger.abort_with "", "Ensure #{new_blog_path} is empty or else try again " \ + "with `--force` to proceed and overwrite any files." end if options["blank"] @@ -108,13 +108,9 @@ module Jekyll def create_site(new_blog_path) create_sample_files new_blog_path - File.open(File.expand_path(initialized_post_name, new_blog_path), "w") do |f| - f.write(scaffold_post_content) - end + File.write(File.expand_path(initialized_post_name, new_blog_path), scaffold_post_content) - File.open(File.expand_path("Gemfile", new_blog_path), "w") do |f| - f.write(gemfile_contents) - end + File.write(File.expand_path("Gemfile", new_blog_path), gemfile_contents) end def preserve_source_location?(path, options) diff --git a/lib/jekyll/commands/new_theme.rb b/lib/jekyll/commands/new_theme.rb index f4251470..3419d175 100644 --- a/lib/jekyll/commands/new_theme.rb +++ b/lib/jekyll/commands/new_theme.rb @@ -10,8 +10,7 @@ module Jekyll prog.command(:"new-theme") do |c| c.syntax "new-theme NAME" c.description "Creates a new Jekyll theme scaffold" - c.option "code_of_conduct", \ - "-c", "--code-of-conduct", \ + c.option "code_of_conduct", "-c", "--code-of-conduct", "Include a Code of Conduct. (defaults to false)" c.action do |args, opts| @@ -30,8 +29,8 @@ module Jekyll Jekyll.logger.abort_with "Conflict:", "#{theme.path} already exists." if theme.path.exist? theme.create! - Jekyll.logger.info "Your new Jekyll theme, #{theme.name.cyan}," \ - " is ready for you in #{theme.path.to_s.cyan}!" + Jekyll.logger.info "Your new Jekyll theme, #{theme.name.cyan}, " \ + "is ready for you in #{theme.path.to_s.cyan}!" Jekyll.logger.info "For help getting started, read #{theme.path}/README.md." end end diff --git a/lib/jekyll/commands/serve.rb b/lib/jekyll/commands/serve.rb index 2bb9c8c1..4600130f 100644 --- a/lib/jekyll/commands/serve.rb +++ b/lib/jekyll/commands/serve.rb @@ -21,11 +21,11 @@ module Jekyll "ssl_key" => ["--ssl-key [KEY]", "X.509 (SSL) Private Key."], "port" => ["-P", "--port [PORT]", "Port to listen on"], "show_dir_listing" => ["--show-dir-listing", - "Show a directory listing instead of loading" \ - " your index file.",], + "Show a directory listing instead of loading " \ + "your index file.",], "skip_initial_build" => ["skip_initial_build", "--skip-initial-build", - "Skips the initial site build which occurs before" \ - " the server is started.",], + "Skips the initial site build which occurs before " \ + "the server is started.",], "livereload" => ["-l", "--livereload", "Use LiveReload to automatically refresh browsers",], "livereload_ignore" => ["--livereload-ignore ignore GLOB1[,GLOB2[,...]]", @@ -113,8 +113,8 @@ module Jekyll def validate_options(opts) if opts["livereload"] if opts["detach"] - Jekyll.logger.warn "Warning:", "--detach and --livereload are mutually exclusive." \ - " Choosing --livereload" + Jekyll.logger.warn "Warning:", "--detach and --livereload are mutually exclusive. " \ + "Choosing --livereload" opts["detach"] = false end if opts["ssl_cert"] || opts["ssl_key"] @@ -132,9 +132,9 @@ module Jekyll livereload_max_delay livereload_ignore livereload_port).any? { |o| opts[o] } - Jekyll.logger.abort_with "--livereload-min-delay, "\ - "--livereload-max-delay, --livereload-ignore, and "\ - "--livereload-port require the --livereload option." + Jekyll.logger.abort_with "--livereload-min-delay, --livereload-max-delay, " \ + "--livereload-ignore, and --livereload-port require " \ + "the --livereload option." end end @@ -174,7 +174,8 @@ module Jekyll # Do a base pre-setup of WEBRick so that everything is in place # when we get ready to party, checking for an setting up an error page # and making sure our destination exists. - + # + # rubocop:disable Security/IoMethods def setup(destination) require_relative "serve/servlet" @@ -188,6 +189,7 @@ module Jekyll end end end + # rubocop:enable Security/IoMethods def webrick_opts(opts) opts = { @@ -263,8 +265,7 @@ module Jekyll return system "xdg-open", address if Utils::Platforms.linux? return system "open", address if Utils::Platforms.osx? - Jekyll.logger.error "Refusing to launch browser; " \ - "Platform launcher unknown." + Jekyll.logger.error "Refusing to launch browser. Platform launcher unknown." end # Keep in our area with a thread or detach the server as requested @@ -277,9 +278,8 @@ module Jekyll end Process.detach(pid) - Jekyll.logger.info "Server detached with pid '#{pid}'.", \ - "Run `pkill -f jekyll' or `kill -9 #{pid}'" \ - " to stop the server." + Jekyll.logger.info "Server detached with pid '#{pid}'.", + "Run `pkill -f jekyll' or `kill -9 #{pid}' to stop the server." else t = Thread.new { server.start } trap("INT") { server.shutdown } diff --git a/lib/jekyll/commands/serve/live_reload_reactor.rb b/lib/jekyll/commands/serve/live_reload_reactor.rb index e79a876a..78f9408f 100644 --- a/lib/jekyll/commands/serve/live_reload_reactor.rb +++ b/lib/jekyll/commands/serve/live_reload_reactor.rb @@ -110,7 +110,7 @@ module Jekyll def log_error(error) Jekyll.logger.error "LiveReload experienced an error. " \ - "Run with --trace for more information." + "Run with --trace for more information." raise error end end diff --git a/lib/jekyll/commands/serve/servlet.rb b/lib/jekyll/commands/serve/servlet.rb index d91f871f..c8895e57 100644 --- a/lib/jekyll/commands/serve/servlet.rb +++ b/lib/jekyll/commands/serve/servlet.rb @@ -128,7 +128,7 @@ module Jekyll class Servlet < WEBrick::HTTPServlet::FileHandler DEFAULTS = { "Cache-Control" => "private, max-age=0, proxy-revalidate, " \ - "no-store, no-cache, must-revalidate", + "no-store, no-cache, must-revalidate", }.freeze def initialize(server, root, callbacks) diff --git a/lib/jekyll/configuration.rb b/lib/jekyll/configuration.rb index c7acb383..9b2fbffc 100644 --- a/lib/jekyll/configuration.rb +++ b/lib/jekyll/configuration.rb @@ -304,8 +304,8 @@ module Jekyll return if config["plugins"].is_a?(Array) Jekyll.logger.error "'plugins' should be set as an array of gem-names, but was: " \ - "#{config["plugins"].inspect}. Use 'plugins_dir' instead to set the directory " \ - "for your non-gemified Ruby plugins." + "#{config["plugins"].inspect}. Use 'plugins_dir' instead to set " \ + "the directory for your non-gemified Ruby plugins." raise Jekyll::Errors::InvalidConfigurationError, "'plugins' should be set as an array, but was: #{config["plugins"].inspect}." end diff --git a/lib/jekyll/converters/markdown/kramdown_parser.rb b/lib/jekyll/converters/markdown/kramdown_parser.rb index 67514807..1e6a1ded 100644 --- a/lib/jekyll/converters/markdown/kramdown_parser.rb +++ b/lib/jekyll/converters/markdown/kramdown_parser.rb @@ -1,4 +1,4 @@ -# Frozen-string-literal: true +# frozen_string_literal: true module Kramdown # A Kramdown::Document subclass meant to optimize memory usage from initializing diff --git a/lib/jekyll/excerpt.rb b/lib/jekyll/excerpt.rb index a406951e..63185203 100644 --- a/lib/jekyll/excerpt.rb +++ b/lib/jekyll/excerpt.rb @@ -190,8 +190,8 @@ module Jekyll def print_build_warning Jekyll.logger.warn "Warning:", "Excerpt modified in #{doc.relative_path}!" - Jekyll.logger.warn "", "Found a Liquid block containing the excerpt separator" \ - " #{doc.excerpt_separator.inspect}. " + Jekyll.logger.warn "", "Found a Liquid block containing the excerpt separator " \ + "#{doc.excerpt_separator.inspect}." Jekyll.logger.warn "", "The block has been modified with the appropriate closing tag." Jekyll.logger.warn "", "Feel free to define a custom excerpt or excerpt_separator in the" Jekyll.logger.warn "", "document's Front Matter if the generated excerpt is unsatisfactory." diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb index 7042c0c6..5422d52a 100644 --- a/lib/jekyll/filters.rb +++ b/lib/jekyll/filters.rb @@ -311,7 +311,7 @@ module Jekyll order = + 1 else raise ArgumentError, "Invalid nils order: " \ - "'#{nils}' is not a valid nils order. It must be 'first' or 'last'." + "'#{nils}' is not a valid nils order. It must be 'first' or 'last'." end sort_input(input, property, order) diff --git a/lib/jekyll/hooks.rb b/lib/jekyll/hooks.rb index efb85269..482d8026 100644 --- a/lib/jekyll/hooks.rb +++ b/lib/jekyll/hooks.rb @@ -78,8 +78,8 @@ module Jekyll } unless @registry[owner][event] - raise NotAvailable, "Invalid hook. #{owner} supports only the " \ - "following hooks #{@registry[owner].keys.inspect}" + raise NotAvailable, "Invalid hook. #{owner} supports only the following hooks " \ + "#{@registry[owner].keys.inspect}" end raise Uncallable, "Hooks must respond to :call" unless block.respond_to? :call diff --git a/lib/jekyll/plugin_manager.rb b/lib/jekyll/plugin_manager.rb index fe2e43f9..84c555ab 100644 --- a/lib/jekyll/plugin_manager.rb +++ b/lib/jekyll/plugin_manager.rb @@ -113,9 +113,10 @@ module Jekyll pagination_included = (site.config["plugins"] || []).include?("jekyll-paginate") || defined?(Jekyll::Paginate) if site.config["paginate"] && !pagination_included - Jekyll::Deprecator.deprecation_message "You appear to have pagination " \ - "turned on, but you haven't included the `jekyll-paginate` gem. " \ - "Ensure you have `plugins: [jekyll-paginate]` in your configuration file." + Jekyll::Deprecator.deprecation_message <<~MSG + You appear to have pagination turned on, but you haven't included the `jekyll-paginate` + gem. Ensure you have `plugins: [jekyll-paginate]` in your configuration file. + MSG end end end diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index ddf078fd..c365a0d7 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -105,7 +105,7 @@ module Jekyll converter.convert output rescue StandardError => e Jekyll.logger.error "Conversion error:", - "#{converter.class} encountered an error while "\ + "#{converter.class} encountered an error while " \ "converting '#{document.relative_path}':" Jekyll.logger.error("", e.to_s) raise e @@ -179,7 +179,7 @@ module Jekyll return unless invalid_layout?(layout) Jekyll.logger.warn "Build Warning:", "Layout '#{document.data["layout"]}' requested " \ - "in #{document.relative_path} does not exist." + "in #{document.relative_path} does not exist." end # Render layout content into document.output diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index abd75883..2fad097b 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -328,11 +328,11 @@ module Jekyll # Returns def relative_permalinks_are_deprecated if config["relative_permalinks"] - Jekyll.logger.abort_with "Since v3.0, permalinks for pages" \ - " in subfolders must be relative to the" \ - " site source directory, not the parent" \ - " directory. Check https://jekyllrb.com/docs/upgrading/"\ - " for more info." + Jekyll.logger.abort_with "Since v3.0, permalinks for pages " \ + "in subfolders must be relative to the " \ + "site source directory, not the parent " \ + "directory. Check https://jekyllrb.com/docs/upgrading/ " \ + "for more info." end end @@ -536,8 +536,8 @@ module Jekyll if config["theme"].is_a?(String) Jekyll::Theme.new(config["theme"]) else - Jekyll.logger.warn "Theme:", "value of 'theme' in config should be " \ - "String to use gem-based themes, but got #{config["theme"].class}" + Jekyll.logger.warn "Theme:", "value of 'theme' in config should be String to use " \ + "gem-based themes, but got #{config["theme"].class}" nil end end diff --git a/lib/jekyll/tags/highlight.rb b/lib/jekyll/tags/highlight.rb index 7b7f3d2e..806665e3 100644 --- a/lib/jekyll/tags/highlight.rb +++ b/lib/jekyll/tags/highlight.rb @@ -104,8 +104,8 @@ module Jekyll "class=\"language-#{@lang.to_s.tr("+", "-")}\"", "data-lang=\"#{@lang}\"", ].join(" ") - "
"\
-        "#{code.chomp}
" + "
" \
+          "#{code.chomp}
" end end end diff --git a/lib/jekyll/tags/include.rb b/lib/jekyll/tags/include.rb index 058d8280..6960952e 100644 --- a/lib/jekyll/tags/include.rb +++ b/lib/jekyll/tags/include.rb @@ -179,8 +179,8 @@ module Jekyll private def could_not_locate_message(file, includes_dirs, safe) - message = "Could not locate the included file '#{file}' in any of "\ - "#{includes_dirs}. Ensure it exists in one of those directories and" + message = "Could not locate the included file '#{file}' in any of #{includes_dirs}. " \ + "Ensure it exists in one of those directories and" message + if safe " is not a symlink as those are not allowed in safe mode." else diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 874dd643..7774d377 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -86,11 +86,11 @@ module Jekyll site.posts.docs.each do |document| next unless @post.deprecated_equality document - Jekyll::Deprecator.deprecation_message "A call to "\ - "'{% post_url #{@post.name} %}' did not match " \ - "a post using the new matching method of checking name " \ - "(path-date-slug) equality. Please make sure that you " \ - "change this tag to match the post's name exactly." + Jekyll::Deprecator.deprecation_message( + "A call to '{% post_url #{@post.name} %}' did not match a post using the new " \ + "matching method of checking name (path-date-slug) equality. Please make sure " \ + "that you change this tag to match the post's name exactly." + ) return relative_url(document) end diff --git a/lib/jekyll/theme.rb b/lib/jekyll/theme.rb index 6505c048..a3f2a94d 100644 --- a/lib/jekyll/theme.rb +++ b/lib/jekyll/theme.rb @@ -18,8 +18,8 @@ module Jekyll # Otherwise, Jekyll.sanitized path with prepend the unresolved root @root ||= File.realpath(gemspec.full_gem_path) rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP - raise "Path #{gemspec.full_gem_path} does not exist, is not accessible "\ - "or includes a symbolic link loop" + raise "Path #{gemspec.full_gem_path} does not exist, is not accessible or includes " \ + "a symbolic link loop" end # The name of theme directory diff --git a/lib/jekyll/url.rb b/lib/jekyll/url.rb index 3c4a0091..aeb2ac0d 100644 --- a/lib/jekyll/url.rb +++ b/lib/jekyll/url.rb @@ -100,7 +100,7 @@ module Jekyll winner = pool.find { |key| @placeholders.key?(key) } if winner.nil? raise NoMethodError, - "The URL template doesn't have #{pool.join(" or ")} keys. "\ + "The URL template doesn't have #{pool.join(" or ")} keys. " \ "Check your permalink template!" end diff --git a/lib/jekyll/utils/ansi.rb b/lib/jekyll/utils/ansi.rb index 35c5ffbc..00d1b1db 100644 --- a/lib/jekyll/utils/ansi.rb +++ b/lib/jekyll/utils/ansi.rb @@ -1,4 +1,4 @@ -# Frozen-string-literal: true +# frozen_string_literal: true module Jekyll module Utils diff --git a/test/helper.rb b/test/helper.rb index c40adcba..7b1a2b4b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -105,8 +105,7 @@ class JekyllUnitTest < Minitest::Test end def mocks_expect(*args) - RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect)\ - .bind(self).call(*args) + RSpec::Mocks::ExampleMethods::ExpectHost.instance_method(:expect).bind(self).call(*args) end def before_setup @@ -166,7 +165,7 @@ class JekyllUnitTest < Minitest::Test def directory_with_contents(path) FileUtils.rm_rf(path) FileUtils.mkdir(path) - File.open("#{path}/index.html", "w") { |f| f.write("I was previously generated.") } + File.write("#{path}/index.html", "I was previously generated.") end def with_env(key, value) diff --git a/test/test_commands_serve.rb b/test/test_commands_serve.rb index 8e5005b8..fe9d972c 100644 --- a/test/test_commands_serve.rb +++ b/test/test_commands_serve.rb @@ -75,9 +75,7 @@ class TestCommandsServe < JekyllUnitTest HTML - File.open(File.join(@destination, "hello.html"), "w") do |f| - f.write(simple_page) - end + File.write(File.join(@destination, "hello.html"), simple_page) allow(Jekyll::Site).to receive(:new).and_return(site) end diff --git a/test/test_doctor_command.rb b/test/test_doctor_command.rb index 00984a82..9a1e4173 100644 --- a/test/test_doctor_command.rb +++ b/test/test_doctor_command.rb @@ -22,6 +22,7 @@ class TestDoctorCommand < JekyllUnitTest assert_equal "", output end + # rubocop:disable Layout/LineLength should "return warning for pages only differing by case" do @site = Site.new(Jekyll.configuration( "source" => File.join(source_dir, "/_urls_differ_by_case_invalid"), @@ -32,9 +33,10 @@ class TestDoctorCommand < JekyllUnitTest ret = Jekyll::Commands::Doctor.urls_only_differ_by_case(@site) assert ret end - assert_includes output, "Warning: The following URLs only differ by case. "\ - "On a case-insensitive file system one of the URLs will be overwritten by the "\ - "other: #{dest_dir}/about/index.html, #{dest_dir}/About/index.html" + assert_includes output, "Warning: The following URLs only differ by case. On a case-" \ + "insensitive file system one of the URLs will be overwritten by the " \ + "other: #{dest_dir}/about/index.html, #{dest_dir}/About/index.html" end + # rubocop:enable Layout/LineLength end end diff --git a/test/test_excerpt.rb b/test/test_excerpt.rb index 195ac98e..5a4ce0a7 100644 --- a/test/test_excerpt.rb +++ b/test/test_excerpt.rb @@ -111,8 +111,7 @@ class TestExcerpt < JekyllUnitTest context "#content" do context "before render" do should "be the first paragraph of the page" do - expected = "First paragraph with [link ref][link].\n\n[link]: "\ - "https://jekyllrb.com/" + expected = "First paragraph with [link ref][link].\n\n[link]: https://jekyllrb.com/" assert_equal expected, @excerpt.content end @@ -129,7 +128,7 @@ class TestExcerpt < JekyllUnitTest end should "be the first paragraph of the page" do - expected = "

First paragraph with link "\ + expected = "

First paragraph with link " \ "ref.

\n\n" assert_equal expected, @extracted_excerpt.output end @@ -146,7 +145,7 @@ class TestExcerpt < JekyllUnitTest end should "contain all refs at the bottom of the page" do - (0..3).each do |i| + 4.times do |i| assert_match "[link_#{i}]: www.example.com/#{i}", @excerpt.content end end @@ -159,7 +158,7 @@ class TestExcerpt < JekyllUnitTest @rendered_post = @post.dup do_render(@rendered_post) output = @rendered_post.data["excerpt"].output - (0..3).each do |i| + 4.times do |i| assert_includes output, "" end end diff --git a/test/test_page_without_a_file.rb b/test/test_page_without_a_file.rb index c6302e75..e9202132 100644 --- a/test/test_page_without_a_file.rb +++ b/test/test_page_without_a_file.rb @@ -164,8 +164,8 @@ class TestPageWithoutAFile < JekyllUnitTest refute_path_exists(dest_dir("virtual-about", "index.html")) end - should "be processed and written to destination when passed as "\ - "an entry in 'site.pages' array" do + should "be processed and written to destination when passed as an entry in " \ + "'site.pages' array" do @page.content = "{{ site.title }}" @page.data["permalink"] = "/virtual-about/" diff --git a/test/test_regenerator.rb b/test/test_regenerator.rb index 1c78b6fa..3a3b16b8 100644 --- a/test/test_regenerator.rb +++ b/test/test_regenerator.rb @@ -174,9 +174,7 @@ class TestRegenerator < JekyllUnitTest metadata_file = source_dir(".jekyll-metadata") @regenerator = Regenerator.new(@site) - File.open(metadata_file, "w") do |f| - f.write(@regenerator.metadata.to_yaml) - end + File.write(metadata_file, @regenerator.metadata.to_yaml) @regenerator = Regenerator.new(@site) assert_equal File.mtime(@path), @regenerator.metadata[@path]["mtime"] diff --git a/test/test_site.rb b/test/test_site.rb index 56419a73..246f813e 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -621,8 +621,8 @@ class TestSite < JekyllUnitTest site = fixture_site("theme" => {}) assert_nil site.theme end - expected_msg = "Theme: value of 'theme' in config should be String " \ - "to use gem-based themes, but got Hash\n" + expected_msg = "Theme: value of 'theme' in config should be String to use " \ + "gem-based themes, but got Hash\n" assert_includes output, expected_msg end diff --git a/test/test_tags.rb b/test/test_tags.rb index 305baf0d..a82a6f2e 100644 --- a/test/test_tags.rb +++ b/test/test_tags.rb @@ -450,10 +450,10 @@ class TestTags < JekyllUnitTest end should "throw a deprecation warning" do - deprecation_warning = " Deprecation: A call to "\ - "'{% post_url 2008-11-21-nested %}' did not match a post using the new matching "\ - "method of checking name (path-date-slug) equality. Please make sure that you "\ - "change this tag to match the post's name exactly." + deprecation_warning = " Deprecation: A call to '{% post_url 2008-11-21-nested %}' " \ + "did not match a post using the new matching method of checking " \ + "name (path-date-slug) equality. Please make sure that you change " \ + "this tag to match the post's name exactly." assert_includes Jekyll.logger.messages, deprecation_warning end end @@ -693,7 +693,7 @@ class TestTags < JekyllUnitTest context "include tag with parameters" do context "with symlink'd include" do should "not allow symlink includes" do - File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") } + File.write("tmp/pages-test", "SYMLINK TEST") assert_raises IOError do content = <<~CONTENT --- @@ -1142,7 +1142,7 @@ class TestTags < JekyllUnitTest context "with symlink'd include" do should "not allow symlink includes" do - File.open("tmp/pages-test", "w") { |file| file.write("SYMLINK TEST") } + File.write("tmp/pages-test", "SYMLINK TEST") assert_raises IOError do content = <<~CONTENT --- @@ -1181,7 +1181,7 @@ class TestTags < JekyllUnitTest "safe" => true) end assert_match( - "Ensure it exists in one of those directories and is not a symlink "\ + "Ensure it exists in one of those directories and is not a symlink " \ "as those are not allowed in safe mode.", ex.message ) diff --git a/test/test_theme_assets_reader.rb b/test/test_theme_assets_reader.rb index 02ce004f..f45503e7 100644 --- a/test/test_theme_assets_reader.rb +++ b/test/test_theme_assets_reader.rb @@ -14,15 +14,14 @@ class TestThemeAssetsReader < JekyllUnitTest def assert_file_with_relative_path(haystack, relative_path) assert haystack.any? { |f| f.relative_path == relative_path - }, "Site should read in the #{relative_path} file, " \ - "but it was not found in #{haystack.inspect}" + }, "Site should read in the #{relative_path} file, but it was not found in #{haystack.inspect}" end def refute_file_with_relative_path(haystack, relative_path) refute haystack.any? { |f| f.relative_path == relative_path - }, "Site should not have read in the #{relative_path} file, " \ - "but it was found in #{haystack.inspect}" + }, "Site should not have read in the #{relative_path} file, but it was found in " \ + "#{haystack.inspect}" end context "with a valid theme" do @@ -82,7 +81,7 @@ class TestThemeAssetsReader < JekyllUnitTest begin tmp_dir = Dir.mktmpdir("jekyll-theme-test") - File.open(File.join(tmp_dir, "test.txt"), "wb") { |f| f.write "content" } + File.binwrite(File.join(tmp_dir, "test.txt"), "content") theme_dir = File.join(__dir__, "fixtures", "test-theme-symlink") File.symlink(tmp_dir, File.join(theme_dir, "assets"))