From 414279d3e51dc0e2a664ae9645537b9d82fc0675 Mon Sep 17 00:00:00 2001 From: Vincent Garrigues Date: Fri, 10 Nov 2023 15:22:48 +0000 Subject: [PATCH] Add tests for inline_mode --- README.md | 3 ++- lib/swiftformat/plugin.rb | 7 ++++++- spec/swiftformat/plugin_spec.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5119488..d4ebf57 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,8 @@ certain directories or files such as `Pods`, you can use the `exclude` parameter swiftformat.exclude = %w(Pods/** Carthage/** Sources/Nope.swift **/*_autogenerated.swift) ``` -If you want the format results shows in the diff instead of a comment, you can use inline_mode option. Violations that are out of the diff, will be shown in danger's fail or warn section. +If you want the format results shows in the diff instead of a comment, you can use the `inline_mode` option. Violations that are out of the diff will be shown in danger's fail or warn section: + ```ruby swiftformat.inline_mode = true ``` diff --git a/lib/swiftformat/plugin.rb b/lib/swiftformat/plugin.rb index 750be05..377e7c7 100644 --- a/lib/swiftformat/plugin.rb +++ b/lib/swiftformat/plugin.rb @@ -34,13 +34,18 @@ class DangerSwiftformat < Plugin # @return [String] attr_accessor :swiftversion + # Show issues inline in the diff instead of in a comment. + # + # @return [Boolean] + attr_accessor :inline_mode + # Runs swiftformat # # @param [Boolean] fail_on_error # # @return [void] # - def check_format(fail_on_error: false, inline_mode: false) + def check_format(fail_on_error: false) # Check if SwiftFormat is installed raise "Could not find SwiftFormat executable" unless swiftformat.installed? diff --git a/spec/swiftformat/plugin_spec.rb b/spec/swiftformat/plugin_spec.rb index e9cba9a..bbf2820 100644 --- a/spec/swiftformat/plugin_spec.rb +++ b/spec/swiftformat/plugin_spec.rb @@ -211,6 +211,19 @@ module Danger status = @sut.status_report expect(status[:errors]).to be_empty expect(status[:markdowns]).to_not be_empty + expect(status[:warnings]).to be_empty + end + + it "should send inline comments when inline_mode is true" do + @sut.inline_mode = true + + @sut.check_format + + status = @sut.status_report + p status + expect(status[:errors]).to be_empty + expect(status[:markdowns]).to be_empty + expect(status[:warnings]).to_not be_empty end end end