diff --git a/.generated_files_rubocop.yml b/.generated_files_rubocop.yml new file mode 100644 index 0000000000..cabd0719fa --- /dev/null +++ b/.generated_files_rubocop.yml @@ -0,0 +1,12 @@ +# This rubocop configuration is ONLY for the generated files (listed in Rakefile). It is not meant to be used for RDoc's +# source code. +# The purpose of this file is to ensure the generated files don't have trailing whitespace or empty lines, which could +# be a problem for ruby/ruby's CI +AllCops: + TargetRubyVersion: 3.3 + DisabledByDefault: true + +Layout/TrailingWhitespace: + Enabled: true +Layout/TrailingEmptyLines: + Enabled: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37f8b4889c..72fa2b42bf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -45,5 +45,17 @@ jobs: RUBYOPT: --enable-frozen_string_literal - if: ${{ matrix.ruby == 'head' && startsWith(matrix.os, 'ubuntu') }} run: bundle exec rake rdoc - - if: ${{ matrix.ruby == 'head' && startsWith(matrix.os, 'ubuntu') }} - run: bundle exec rake rubocop + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + bundler-cache: true + - name: Run rubocop + run: bundle exec rubocop + # Just to make sure the format_generated_files task is working + - name: Sanity check for the format_generated_files task + run: bundle exec rake generate format_generated_files diff --git a/.rubocop.yml b/.rubocop.yml index c6b29b030c..63f03e02e3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,19 @@ AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.0 DisabledByDefault: true - Exclude: - - rdoc.gemspec + SuggestExtensions: false Layout/TrailingWhitespace: Enabled: true + Layout/TrailingEmptyLines: Enabled: true + +Layout/SpaceAroundKeyword: + Enabled: true + +Layout/SpaceBeforeComma: + Enabled: true + +Layout/SpaceAfterComma: + Enabled: true diff --git a/Rakefile b/Rakefile index 2cd29bdd84..6f1e3d1b4e 100644 --- a/Rakefile +++ b/Rakefile @@ -105,8 +105,8 @@ begin require 'rubocop/rake_task' rescue LoadError else - RuboCop::RakeTask.new(:rubocop) do |t| - t.options = [*parsed_files] + RuboCop::RakeTask.new(:format_generated_files) do |t| + t.options = parsed_files + ["--config=.generated_files_rubocop.yml"] end - task :build => [:generate, "rubocop:autocorrect"] + task :build => [:generate, "format_generated_files:autocorrect"] end diff --git a/lib/rdoc/code_object/alias.rb b/lib/rdoc/code_object/alias.rb index 446cf9ccb4..92df7e448f 100644 --- a/lib/rdoc/code_object/alias.rb +++ b/lib/rdoc/code_object/alias.rb @@ -70,7 +70,7 @@ def full_old_name # HTML id-friendly version of +#new_name+. def html_name - CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '') + CGI.escape(@new_name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '') end def inspect # :nodoc: diff --git a/lib/rdoc/code_object/method_attr.rb b/lib/rdoc/code_object/method_attr.rb index 61ddb32f46..27e6599bc1 100644 --- a/lib/rdoc/code_object/method_attr.rb +++ b/lib/rdoc/code_object/method_attr.rb @@ -268,8 +268,8 @@ def block_params=(value) when 'const_get' then 'const' when 'new' then $1.split('::').last. # ClassName => class_name - gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). - gsub(/([a-z\d])([A-Z])/,'\1_\2'). + gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). + gsub(/([a-z\d])([A-Z])/, '\1_\2'). downcase else $2 @@ -291,7 +291,7 @@ def block_params=(value) def html_name require 'cgi/util' - CGI.escape(@name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '') + CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '') end ## diff --git a/lib/rdoc/code_object/top_level.rb b/lib/rdoc/code_object/top_level.rb index 3864f66431..b93e3802fc 100644 --- a/lib/rdoc/code_object/top_level.rb +++ b/lib/rdoc/code_object/top_level.rb @@ -183,8 +183,8 @@ def inspect # :nodoc: "#<%s:0x%x %p modules: %p classes: %p>" % [ self.class, object_id, base_name, - @modules.map { |n,m| m }, - @classes.map { |n,c| c } + @modules.map { |n, m| m }, + @classes.map { |n, c| c } ] end @@ -254,8 +254,8 @@ def pretty_print q # :nodoc: q.text "base name: #{base_name.inspect}" q.breakable - items = @modules.map { |n,m| m } - items.concat @modules.map { |n,c| c } + items = @modules.map { |n, m| m } + items.concat @modules.map { |n, c| c } q.seplist items do |mod| q.pp mod end end end diff --git a/lib/rdoc/generator/pot/message_extractor.rb b/lib/rdoc/generator/pot/message_extractor.rb index 313dfd2dc7..4938858bdc 100644 --- a/lib/rdoc/generator/pot/message_extractor.rb +++ b/lib/rdoc/generator/pot/message_extractor.rb @@ -29,7 +29,7 @@ def extract_from_klass klass extract_text(klass.comment_location, klass.full_name) klass.each_section do |section, constants, attributes| - extract_text(section.title ,"#{klass.full_name}: section title") + extract_text(section.title, "#{klass.full_name}: section title") section.comments.each do |comment| extract_text(comment, "#{klass.full_name}: #{section.title}") end diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb index f6eb06da95..ed014f255b 100644 --- a/lib/rdoc/markup/attribute_manager.rb +++ b/lib/rdoc/markup/attribute_manager.rb @@ -260,7 +260,7 @@ def unmask_protected_sequences def add_word_pair(start, stop, name, exclusive = false) raise ArgumentError, "Word flags may not start with '<'" if - start[0,1] == '<' + start[0, 1] == '<' bitmap = @attributes.bitmap_for name @@ -271,7 +271,7 @@ def add_word_pair(start, stop, name, exclusive = false) @word_pair_map[pattern] = bitmap end - @protectable << start[0,1] + @protectable << start[0, 1] @protectable.uniq! @exclusive_bitmap |= bitmap if exclusive diff --git a/lib/rdoc/markup/to_bs.rb b/lib/rdoc/markup/to_bs.rb index afd9d6e981..b7b73e73f7 100644 --- a/lib/rdoc/markup/to_bs.rb +++ b/lib/rdoc/markup/to_bs.rb @@ -24,7 +24,7 @@ def initialize markup = nil def init_tags add_tag :BOLD, '+b', '-b' add_tag :EM, '+_', '-_' - add_tag :TT, '' , '' # we need in_tt information maintained + add_tag :TT, '', '' # we need in_tt information maintained end ## diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 7518e6cc54..c8fca4a262 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -683,7 +683,7 @@ def parse argv EOF - parsers = Hash.new { |h,parser| h[parser] = [] } + parsers = Hash.new { |h, parser| h[parser] = [] } RDoc::Parser.parsers.each do |regexp, parser| parsers[parser.name.sub('RDoc::Parser::', '')] << regexp.source diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index f8f238fd74..4050d7aa49 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -440,7 +440,7 @@ def do_constants # Scans #content for rb_include_module def do_includes - @content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m| + @content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c, m| next unless cls = @classes[c] m = @known_classes[m] || m diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index 4014c6eb1c..12a50f8d0e 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -193,7 +193,7 @@ class << self; prepend Git; end entries << [entry_name, entry_body] if entry_name - entries.reject! do |(entry,_)| + entries.reject! do |(entry, _)| entry == nil end