diff --git a/changelog/change_markdown_formatter_to_skip_files_with_no_offenses.md b/changelog/change_markdown_formatter_to_skip_files_with_no_offenses.md new file mode 100644 index 00000000000..f2d2d9591ae --- /dev/null +++ b/changelog/change_markdown_formatter_to_skip_files_with_no_offenses.md @@ -0,0 +1 @@ +* [#10616](https://github.com/rubocop/rubocop/pull/10616): Markdown formatter: skip files with no offenses. ([@rickselby][]) diff --git a/lib/rubocop/formatter/markdown_formatter.rb b/lib/rubocop/formatter/markdown_formatter.rb index 7051c2c0e84..aba51aa7d24 100644 --- a/lib/rubocop/formatter/markdown_formatter.rb +++ b/lib/rubocop/formatter/markdown_formatter.rb @@ -41,6 +41,8 @@ def render_markdown def write_file_messages files.each do |file| + next if file.offenses.empty? + write_heading(file) file.offenses.each do |offense| write_context(offense) diff --git a/spec/fixtures/markdown_formatter/expected.md b/spec/fixtures/markdown_formatter/expected.md index a9c9785d995..2814d310dc7 100644 --- a/spec/fixtures/markdown_formatter/expected.md +++ b/spec/fixtures/markdown_formatter/expected.md @@ -1,6 +1,6 @@ # RuboCop Inspection Report -3 files inspected, 22 offenses detected: +4 files inspected, 22 offenses detected: ### app/controllers/application_controller.rb - (1 offense) * **Line # 1 - convention:** Style/FrozenStringLiteralComment: Missing frozen string literal comment. diff --git a/spec/fixtures/markdown_formatter/project b/spec/fixtures/markdown_formatter/project deleted file mode 120000 index e705edc617b..00000000000 --- a/spec/fixtures/markdown_formatter/project +++ /dev/null @@ -1 +0,0 @@ -../html_formatter/project \ No newline at end of file diff --git a/spec/fixtures/markdown_formatter/project/app/controllers/application_controller.rb b/spec/fixtures/markdown_formatter/project/app/controllers/application_controller.rb new file mode 100644 index 00000000000..ab168ef12a1 --- /dev/null +++ b/spec/fixtures/markdown_formatter/project/app/controllers/application_controller.rb @@ -0,0 +1,7 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception + + # “Test encoding issues by using curly quotes” +end diff --git a/spec/fixtures/markdown_formatter/project/app/controllers/books_controller.rb b/spec/fixtures/markdown_formatter/project/app/controllers/books_controller.rb new file mode 100644 index 00000000000..114e4f9babc --- /dev/null +++ b/spec/fixtures/markdown_formatter/project/app/controllers/books_controller.rb @@ -0,0 +1,74 @@ +class BooksController < ApplicationController + before_action :set_book, only: [:show, :edit, :update, :destroy] + + # GET /books + # GET /books.json + def index + @books = Book.all + end + + # GET /books/1 + # GET /books/1.json + def show + end + + # GET /books/new + def new + @book = Book.new + end + + # GET /books/1/edit + def edit + end + + # POST /books + # POST /books.json + def create + @book = Book.new(book_params) + + respond_to do |format| + if @book.save + format.html { redirect_to @book, notice: 'Book was successfully created.' } # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + format.json { render :show, status: :created, location: @book } + else + format.html { render :new } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /books/1 + # PATCH/PUT /books/1.json + def update + respond_to do |format| + if @book.update(book_params) + format.html { redirect_to @book, notice: 'Book was successfully updated.' } # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + format.json { render :show, status: :ok, location: @book } + else + format.html { render :edit } + format.json { render json: @book.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /books/1 + # DELETE /books/1.json + def destroy + @book.destroy + respond_to do |format| + format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' } # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_book + @book = Book.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the allow list through. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + def book_params + params.require(:book).permit(:name) + end +end diff --git a/spec/fixtures/markdown_formatter/project/app/models/book.rb b/spec/fixtures/markdown_formatter/project/app/models/book.rb new file mode 100644 index 00000000000..2f59496c789 --- /dev/null +++ b/spec/fixtures/markdown_formatter/project/app/models/book.rb @@ -0,0 +1,6 @@ +class Book < ActiveRecord::Base + def someMethod + foo = bar = baz + Regexp.new(/\A

(.*)<\/p>\Z/m).match(full_document)[1] rescue full_document + end +end diff --git a/spec/fixtures/markdown_formatter/project/app/models/shelf.rb b/spec/fixtures/markdown_formatter/project/app/models/shelf.rb new file mode 100644 index 00000000000..219d6e50d22 --- /dev/null +++ b/spec/fixtures/markdown_formatter/project/app/models/shelf.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Book class comment +class Book < ActiveRecord::Base + def some_method + Regexp.new(%r{\A

(.*)

\Z}m).match(full_document)[1] + rescue StandardError + full_document + end +end