From 30f4c419369c53b2975f4b768e459a12e41811db Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Wed, 9 Aug 2017 19:28:43 +0200 Subject: [PATCH 01/11] Add more file file extensions - The plugin now also checks files with extensions .hpp, .hh, .cxx, .cc, .cpp - The error message is more informative. It first lists the offending files, then suggests appropriate actions and eventually prints the patches to apply. --- lib/code_style_validation/plugin.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/code_style_validation/plugin.rb b/lib/code_style_validation/plugin.rb index 8f424a5..cb52e09 100755 --- a/lib/code_style_validation/plugin.rb +++ b/lib/code_style_validation/plugin.rb @@ -3,7 +3,8 @@ module Danger # added lines on the current MR / PR, # and offers inline patches. # - # It uses 'clang-format' and only checks ".h", ".m" and ".mm" files + # It uses 'clang-format' and only checks ".h", ".m", ".mm", ".hpp", ".hh", + # ".cxx", ".cc" and ".cpp" files # # @example Ensure that added lines does not violate code style # @@ -43,7 +44,7 @@ def check(config = {}) return if message.empty? fail VIOLATION_ERROR_MESSAGE - markdown '### Code Style Check (`.h`, `.m` and `.mm`)' + markdown '### Code Style Check' markdown '---' markdown message end @@ -69,7 +70,7 @@ def get_changes(diff_str, ignore_file_patterns) file_name = filename_line.split('+++ b/').last.chomp - unless file_name.end_with?('.m', '.h', '.mm') + unless file_name.end_with?('.m', '.h', '.mm', '.hpp', '.hh', '.cxx', '.cc', '.cpp') next end @@ -130,7 +131,14 @@ def generate_markdown(title, content) def resolve_changes(changes) # Parse all patches from diff string - markup_message = '' + markup_message = 'Code style violations detected in the following files:' + "\n" + changes.each do |file_name, changed_lines| + markup_message += '* `' + file_name + "`\n\n" + end + + markup_message += 'Execute one of the following actions and commit again:' + "\n" + markup_message += '1. Run `clang-format` on the offending files' + "\n" + markup_message += '2. Apply the suggested patches with `git apply patch`.' + "\n" # patches.each do |patch| changes.each do |file_name, changed_lines| From 5ca556ea567ee0d95d3a3a0ec43de6fcaa06bcd5 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 12:42:19 +0200 Subject: [PATCH 02/11] Fix tests, refactor message generation --- lib/code_style_validation/plugin.rb | 43 +++++++++++++++++------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/code_style_validation/plugin.rb b/lib/code_style_validation/plugin.rb index cb52e09..717e9aa 100755 --- a/lib/code_style_validation/plugin.rb +++ b/lib/code_style_validation/plugin.rb @@ -40,7 +40,19 @@ def check(config = {}) end changes = get_changes(diff, ignore_file_patterns) - message = resolve_changes(changes) + offending_files, patches = resolve_changes(changes) + + message = '' + unless offending_files.empty? + message = 'Code style violations detected in the following files:' + "\n" + offending_files.each do |file_name| + message += '* `' + file_name + "`\n\n" + end + message += 'Execute one of the following actions and commit again:' + "\n" + message += '1. Run `clang-format` on the offending files' + "\n" + message += '2. Apply the suggested patches with `git apply patch`.' + "\n\n" + message += patches.join(' ') + end return if message.empty? fail VIOLATION_ERROR_MESSAGE @@ -122,24 +134,17 @@ def parse_diff(diff) patches end - def generate_markdown(title, content) - markup_message = '#### ' + title + "\n" - markup_message += "```diff \n" + content + "\n``` \n" - markup_message + def generate_patch(title, content) + markup_patch = '#### ' + title + "\n" + markup_patch += "```diff \n" + content + "\n``` \n" + markup_patch end def resolve_changes(changes) # Parse all patches from diff string - markup_message = 'Code style violations detected in the following files:' + "\n" - changes.each do |file_name, changed_lines| - markup_message += '* `' + file_name + "`\n\n" - end - - markup_message += 'Execute one of the following actions and commit again:' + "\n" - markup_message += '1. Run `clang-format` on the offending files' + "\n" - markup_message += '2. Apply the suggested patches with `git apply patch`.' + "\n" - + offending_files = [] + patches = [] # patches.each do |patch| changes.each do |file_name, changed_lines| changed_lines_command_array = [] @@ -165,14 +170,16 @@ def resolve_changes(changes) formatted_temp_file.close formatted_temp_file.unlink - # generate Markup message of patch suggestions - # to prevent code-style violations + # generate arrays with: + # 1. Name of offending files + # 2. Suggested patches, in Markdown format unless diff.empty? - markup_message += generate_markdown(file_name, diff) + offending_files = [file_name] + patches = [generate_patch(file_name, diff)] end end - markup_message + return offending_files, patches end end end From 69305565a498705509835df630083b06463527e2 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 14:54:58 +0200 Subject: [PATCH 03/11] Generate offending_files and patches arrays properly --- lib/code_style_validation/plugin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/code_style_validation/plugin.rb b/lib/code_style_validation/plugin.rb index 717e9aa..7c722f4 100755 --- a/lib/code_style_validation/plugin.rb +++ b/lib/code_style_validation/plugin.rb @@ -174,8 +174,8 @@ def resolve_changes(changes) # 1. Name of offending files # 2. Suggested patches, in Markdown format unless diff.empty? - offending_files = [file_name] - patches = [generate_patch(file_name, diff)] + offending_files.push(file_name) + patches.push(generate_patch(file_name, diff)) end end From af2b349f994bc7c391d22dc53bbef3fcfdf175b4 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Thu, 10 Aug 2017 16:00:21 +0200 Subject: [PATCH 04/11] Allow user to specify file extensions to check --- README.md | 13 ++++++++++--- lib/code_style_validation/plugin.rb | 27 ++++++++++++++++----------- spec/code_style_validation_spec.rb | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fb1fc9b..b943660 100755 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ [![Build Status](https://travis-ci.org/flix-tech/danger-code_style_validation.svg?branch=master)](https://travis-ci.org/flix-tech/danger-code_style_validation) -This plugin looks for code style violations for added lines and suggests patches. - -It uses 'clang-format' and only checks `.h`, `.m` and `.mm` files +This plugin uses 'clang-format' to look for code style violations in added +lines on the current MR / PR, and offers inline patches. +By default only Objective-C files, with extensions `.h`, `.m`, `.mm` and +`.C`, are checked. ![Example](/doc/images/example.png) @@ -24,6 +25,12 @@ Inside your `Dangerfile` : code_style_validation.check ``` +To check files with extensions other than the default ones: + +```ruby +code_style_validation.check file_extensions: ['.hpp', '.cpp'] +``` + To ignore specific paths, use `ignore_file_patterns` : ```ruby diff --git a/lib/code_style_validation/plugin.rb b/lib/code_style_validation/plugin.rb index 7c722f4..e6e91ee 100755 --- a/lib/code_style_validation/plugin.rb +++ b/lib/code_style_validation/plugin.rb @@ -1,16 +1,18 @@ module Danger - # This plugin looks for code style violations for - # added lines on the current MR / PR, - # and offers inline patches. + # This plugin uses 'clang-format' to look for code style violations in added + # lines on the current MR / PR, and offers inline patches. + # By default only Objective-C files, with extensions ".h", ".m", ".mm" and + # ".C", are checked. + # + # @example Ensure that changes do not violate code style in Objective-C files # - # It uses 'clang-format' and only checks ".h", ".m", ".mm", ".hpp", ".hh", - # ".cxx", ".cc" and ".cpp" files + # code_style_validation.check # - # @example Ensure that added lines does not violate code style + # @example Ensure that changes do not violate code style in files with given extensions # - # code_style_validation.check + # code_style_validation.check file_extensions: ['.hpp', '.cpp'] # - # @example Ensure that changes don't violate code style, ignoring Pods directory + # @example Ensure that changes do not violate code style, ignoring Pods directory # # code_style_validation.check ignore_file_patterns: [/^Pods\//] # @@ -25,6 +27,9 @@ class DangerCodeStyleValidation < Plugin # # @return [void] def check(config = {}) + defaults = {file_extensions: ['.h', '.m', '.mm', '.C'], ignore_file_patterns: []} + config = defaults.merge(config) + file_extensions = [*config[:file_extensions]] ignore_file_patterns = [*config[:ignore_file_patterns]] diff = '' @@ -39,7 +44,7 @@ def check(config = {}) raise 'Unknown SCM Provider' end - changes = get_changes(diff, ignore_file_patterns) + changes = get_changes(diff, file_extensions, ignore_file_patterns) offending_files, patches = resolve_changes(changes) message = '' @@ -63,7 +68,7 @@ def check(config = {}) private - def get_changes(diff_str, ignore_file_patterns) + def get_changes(diff_str, file_extensions, ignore_file_patterns) changes = {} line_cursor = 0 @@ -82,7 +87,7 @@ def get_changes(diff_str, ignore_file_patterns) file_name = filename_line.split('+++ b/').last.chomp - unless file_name.end_with?('.m', '.h', '.mm', '.hpp', '.hh', '.cxx', '.cc', '.cpp') + unless file_name.end_with?(*file_extensions) next end diff --git a/spec/code_style_validation_spec.rb b/spec/code_style_validation_spec.rb index 8c627d1..50f8116 100755 --- a/spec/code_style_validation_spec.rb +++ b/spec/code_style_validation_spec.rb @@ -16,7 +16,7 @@ module Danger diff = File.read('spec/fixtures/violated_diff.diff') @my_plugin.github.stub(:pr_diff).and_return diff - @my_plugin.check + @my_plugin.check file_extensions: ['.h', '.m', '.mm', '.C', '.cpp'] expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE]) end From e2218566f419a1f9a0aa95aa88a0e7fc85860fc6 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 11 Aug 2017 14:47:41 +0200 Subject: [PATCH 05/11] Adds some tests for file extension configuration --- spec/code_style_validation_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/spec/code_style_validation_spec.rb b/spec/code_style_validation_spec.rb index 50f8116..6cd954c 100755 --- a/spec/code_style_validation_spec.rb +++ b/spec/code_style_validation_spec.rb @@ -21,6 +21,15 @@ module Danger expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE]) end + it 'Does not report error when extension is excluded' do + diff = File.read('spec/fixtures/violated_diff.diff') + + @my_plugin.github.stub(:pr_diff).and_return diff + @my_plugin.check file_extensions: ['.h', '.c'] + + expect(@dangerfile.status_report[:errors]).to eq([]) + end + it 'Does not report error when code not violated' do diff = File.read('spec/fixtures/innocent_diff.diff') @@ -52,7 +61,8 @@ module Danger diff = File.read('spec/fixtures/violated_diff.diff') @my_plugin.github.stub(:pr_diff).and_return diff - @my_plugin.check ignore_file_patterns: [%r{^spec/}] + @my_plugin.check file_extensions: ['.h', '.m'], + ignore_file_patterns: [%r{^spec/}] expect(@dangerfile.status_report[:errors]).to eq([]) end @@ -65,6 +75,15 @@ module Danger expect(@dangerfile.status_report[:errors]).to eq([]) end + + it 'Allows single file extension instead of array' do + diff = File.read('spec/fixtures/violated_diff.diff') + + @my_plugin.github.stub(:pr_diff).and_return diff + @my_plugin.check file_extensions: '.m' + + expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE]) + end end end end From 3ae72a44e956a8af295839023ab23b32b247ad87 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 11 Aug 2017 15:17:59 +0200 Subject: [PATCH 06/11] Adds code style violation message verification --- spec/code_style_validation_spec.rb | 2 ++ spec/fixtures/violated_diff_message.md | 30 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 spec/fixtures/violated_diff_message.md diff --git a/spec/code_style_validation_spec.rb b/spec/code_style_validation_spec.rb index 6cd954c..6a93d27 100755 --- a/spec/code_style_validation_spec.rb +++ b/spec/code_style_validation_spec.rb @@ -14,11 +14,13 @@ module Danger it 'Reports code style violation as error' do diff = File.read('spec/fixtures/violated_diff.diff') + expected_message = File.read('spec/fixtures/violated_diff_message.md') @my_plugin.github.stub(:pr_diff).and_return diff @my_plugin.check file_extensions: ['.h', '.m', '.mm', '.C', '.cpp'] expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE]) + expect(@dangerfile.status_report[:markdowns].map(&:message).join("\n")).to eq(expected_message) end it 'Does not report error when extension is excluded' do diff --git a/spec/fixtures/violated_diff_message.md b/spec/fixtures/violated_diff_message.md new file mode 100644 index 0000000..d3d60a6 --- /dev/null +++ b/spec/fixtures/violated_diff_message.md @@ -0,0 +1,30 @@ +### Code Style Check +--- +Code style violations detected in the following files: +* `spec/fixtures/BadViewController.m` + +Execute one of the following actions and commit again: +1. Run `clang-format` on the offending files +2. Apply the suggested patches with `git apply patch`. + +#### spec/fixtures/BadViewController.m +```diff +--- spec/fixtures/BadViewController.m ++++ spec/fixtures/BadViewController.m +@@ -1,9 +1,11 @@ +-@interface ViewController ( ) @end ++@interface ViewController () ++@end + + @implementation ViewController +--(void ) viewDidLoad { ++- (void)viewDidLoad ++{ + [super viewDidLoad]; +- NSLog( @"perfect change!") ; ++ NSLog(@"perfect change!"); + } + + @end + +``` From b9537b1850b712ebfb9d9f622886a3c71b36ed0f Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 11 Aug 2017 16:58:15 +0200 Subject: [PATCH 07/11] Adds .clang-format to make diffs produced in tests deterministic --- .clang-format | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..358887d --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +BasedOnStyle: LLVM +AlignAfterOpenBracket: false +AllowShortFunctionsOnASingleLine: None +AlwaysBreakBeforeMultilineStrings: false +BreakBeforeBinaryOperators: All +BreakBeforeBraces: Linux +ColumnLimit: 0 +ExperimentalAutoDetectBinPacking: true +IndentCaseLabels: true +IndentWidth: 4 +MaxEmptyLinesToKeep: 2 +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: false +SpaceAfterCStyleCast: true +TabWidth: 4 From 157179307b4cd52903bd1bf4bc83ed5c28632a6e Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 11 Aug 2017 17:08:07 +0200 Subject: [PATCH 08/11] Simplifies .clang-format & updates expected Markdown text --- .clang-format | 15 --------------- spec/fixtures/violated_diff_message.md | 10 +++++----- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/.clang-format b/.clang-format index 358887d..9b3aa8b 100644 --- a/.clang-format +++ b/.clang-format @@ -1,16 +1 @@ BasedOnStyle: LLVM -AlignAfterOpenBracket: false -AllowShortFunctionsOnASingleLine: None -AlwaysBreakBeforeMultilineStrings: false -BreakBeforeBinaryOperators: All -BreakBeforeBraces: Linux -ColumnLimit: 0 -ExperimentalAutoDetectBinPacking: true -IndentCaseLabels: true -IndentWidth: 4 -MaxEmptyLinesToKeep: 2 -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: false -SpaceAfterCStyleCast: true -TabWidth: 4 diff --git a/spec/fixtures/violated_diff_message.md b/spec/fixtures/violated_diff_message.md index d3d60a6..42a6ff0 100644 --- a/spec/fixtures/violated_diff_message.md +++ b/spec/fixtures/violated_diff_message.md @@ -11,18 +11,18 @@ Execute one of the following actions and commit again: ```diff --- spec/fixtures/BadViewController.m +++ spec/fixtures/BadViewController.m -@@ -1,9 +1,11 @@ +@@ -1,9 +1,10 @@ -@interface ViewController ( ) @end +@interface ViewController () +@end @implementation ViewController --(void ) viewDidLoad { -+- (void)viewDidLoad -+{ - [super viewDidLoad]; +- [super viewDidLoad]; - NSLog( @"perfect change!") ; -+ NSLog(@"perfect change!"); ++- (void)viewDidLoad { ++ [super viewDidLoad]; ++ NSLog(@"perfect change!"); } @end From eb1ca60cbe7ec8046fc47cae5a50f91640434d85 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Mon, 14 Aug 2017 18:43:36 +0200 Subject: [PATCH 09/11] Address @nikolaykasyanov review, fix #9 --- README.md | 4 ++-- lib/code_style_validation/plugin.rb | 30 ++++++++++++++--------------- spec/code_style_validation_spec.rb | 18 ++++++++--------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b943660..8db71ef 100755 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ This plugin uses 'clang-format' to look for code style violations in added lines on the current MR / PR, and offers inline patches. -By default only Objective-C files, with extensions `.h`, `.m`, `.mm` and -`.C`, are checked. +By default only Objective-C files, with extensions `.h`, `.m`, and `.mm` are +checked. ![Example](/doc/images/example.png) diff --git a/lib/code_style_validation/plugin.rb b/lib/code_style_validation/plugin.rb index e6e91ee..c3c5a4e 100755 --- a/lib/code_style_validation/plugin.rb +++ b/lib/code_style_validation/plugin.rb @@ -1,9 +1,9 @@ module Danger # This plugin uses 'clang-format' to look for code style violations in added # lines on the current MR / PR, and offers inline patches. - # By default only Objective-C files, with extensions ".h", ".m", ".mm" and - # ".C", are checked. - # + # By default only Objective-C files, with extensions ".h", ".m", and ".mm" + # are checked. + # # @example Ensure that changes do not violate code style in Objective-C files # # code_style_validation.check @@ -21,13 +21,13 @@ module Danger # class DangerCodeStyleValidation < Plugin VIOLATION_ERROR_MESSAGE = 'Code style violations detected.'.freeze - + # Validates the code style of changed & added files using clang-format. # Generates Markdown message with respective patches. # # @return [void] def check(config = {}) - defaults = {file_extensions: ['.h', '.m', '.mm', '.C'], ignore_file_patterns: []} + defaults = {file_extensions: ['.h', '.m', '.mm'], ignore_file_patterns: []} config = defaults.merge(config) file_extensions = [*config[:file_extensions]] ignore_file_patterns = [*config[:ignore_file_patterns]] @@ -49,15 +49,15 @@ def check(config = {}) message = '' unless offending_files.empty? - message = 'Code style violations detected in the following files:' + "\n" - offending_files.each do |file_name| - message += '* `' + file_name + "`\n\n" - end + message = 'Code style violations detected in the following files:' + "\n" + offending_files.each do |file_name| + message += '* `' + file_name + "`\n\n" + end message += 'Execute one of the following actions and commit again:' + "\n" message += '1. Run `clang-format` on the offending files' + "\n" message += '2. Apply the suggested patches with `git apply patch`.' + "\n\n" message += patches.join(' ') - end + end return if message.empty? fail VIOLATION_ERROR_MESSAGE @@ -175,12 +175,12 @@ def resolve_changes(changes) formatted_temp_file.close formatted_temp_file.unlink - # generate arrays with: - # 1. Name of offending files - # 2. Suggested patches, in Markdown format + # generate arrays with: + # 1. Name of offending files + # 2. Suggested patches, in Markdown format unless diff.empty? - offending_files.push(file_name) - patches.push(generate_patch(file_name, diff)) + offending_files.push(file_name) + patches.push(generate_patch(file_name, diff)) end end diff --git a/spec/code_style_validation_spec.rb b/spec/code_style_validation_spec.rb index 6a93d27..2e05c67 100755 --- a/spec/code_style_validation_spec.rb +++ b/spec/code_style_validation_spec.rb @@ -16,8 +16,8 @@ module Danger diff = File.read('spec/fixtures/violated_diff.diff') expected_message = File.read('spec/fixtures/violated_diff_message.md') - @my_plugin.github.stub(:pr_diff).and_return diff - @my_plugin.check file_extensions: ['.h', '.m', '.mm', '.C', '.cpp'] + allow(@my_plugin.github).to receive(:pr_diff).and_return diff + @my_plugin.check file_extensions: ['.h', '.m', '.mm', '.cpp'] expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE]) expect(@dangerfile.status_report[:markdowns].map(&:message).join("\n")).to eq(expected_message) @@ -26,7 +26,7 @@ module Danger it 'Does not report error when extension is excluded' do diff = File.read('spec/fixtures/violated_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check file_extensions: ['.h', '.c'] expect(@dangerfile.status_report[:errors]).to eq([]) @@ -35,7 +35,7 @@ module Danger it 'Does not report error when code not violated' do diff = File.read('spec/fixtures/innocent_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check expect(@dangerfile.status_report[:errors]).to eq([]) @@ -44,7 +44,7 @@ module Danger it 'Does not report error for different extension types of files' do diff = File.read('spec/fixtures/ruby_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check expect(@dangerfile.status_report[:errors]).to eq([]) @@ -53,7 +53,7 @@ module Danger it 'Does not report unexpected errors when there are only removals in the diff' do diff = File.read('spec/fixtures/red_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check expect(@dangerfile.status_report[:errors]).to eq([]) @@ -62,7 +62,7 @@ module Danger it 'Ignores files matching ignored patterns' do diff = File.read('spec/fixtures/violated_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check file_extensions: ['.h', '.m'], ignore_file_patterns: [%r{^spec/}] @@ -72,7 +72,7 @@ module Danger it 'Allows single pattern instead of array' do diff = File.read('spec/fixtures/violated_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check ignore_file_patterns: %r{^spec/} expect(@dangerfile.status_report[:errors]).to eq([]) @@ -81,7 +81,7 @@ module Danger it 'Allows single file extension instead of array' do diff = File.read('spec/fixtures/violated_diff.diff') - @my_plugin.github.stub(:pr_diff).and_return diff + allow(@my_plugin.github).to receive(:pr_diff).and_return diff @my_plugin.check file_extensions: '.m' expect(@dangerfile.status_report[:errors]).to eq([DangerCodeStyleValidation::VIOLATION_ERROR_MESSAGE]) From dfaae35836857bef0c3eb8499bbe7ef45c354e22 Mon Sep 17 00:00:00 2001 From: Roberto Di Remigio Date: Mon, 14 Aug 2017 20:07:50 +0200 Subject: [PATCH 10/11] Install clang-format-3.8 also on Linux --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4957453..f7cab6d 100755 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ branches: addons: apt: packages: [ - clang-format-3.6 + clang-format-3.8 ] before_install: From 7eb737ad96dcd40f33cb52cf9fd7977bacf0ba0d Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Tue, 15 Aug 2017 18:26:15 +0200 Subject: [PATCH 11/11] Joins patches with linebreak to make headers render properly --- lib/code_style_validation/plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/code_style_validation/plugin.rb b/lib/code_style_validation/plugin.rb index c3c5a4e..5670c1f 100755 --- a/lib/code_style_validation/plugin.rb +++ b/lib/code_style_validation/plugin.rb @@ -56,7 +56,7 @@ def check(config = {}) message += 'Execute one of the following actions and commit again:' + "\n" message += '1. Run `clang-format` on the offending files' + "\n" message += '2. Apply the suggested patches with `git apply patch`.' + "\n\n" - message += patches.join(' ') + message += patches.join("\n") end return if message.empty?