Skip to content

Commit

Permalink
Skip files with no offenses in the markdown formatter (#10616)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickselby committed May 13, 2022
1 parent 133ffce commit c225149
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 2 deletions.
@@ -0,0 +1 @@
* [#10616](https://github.com/rubocop/rubocop/pull/10616): Markdown formatter: skip files with no offenses. ([@rickselby][])
2 changes: 2 additions & 0 deletions lib/rubocop/formatter/markdown_formatter.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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.
Expand Down
1 change: 0 additions & 1 deletion spec/fixtures/markdown_formatter/project

This file was deleted.

@@ -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
@@ -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
6 changes: 6 additions & 0 deletions 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>(.*)<\/p>\Z/m).match(full_document)[1] rescue full_document
end
end
10 changes: 10 additions & 0 deletions 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<p>(.*)</p>\Z}m).match(full_document)[1]
rescue StandardError
full_document
end
end

0 comments on commit c225149

Please sign in to comment.