Skip to content

Commit c233e69

Browse files
robertodrnikolaykasyanov
authored andcommitted
Passes name of code style validator
1 parent 559b2df commit c233e69

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/code_style_validation/plugin.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class DangerCodeStyleValidation < Plugin
2727
#
2828
# @return [void]
2929
def check(config = {})
30-
defaults = {file_extensions: ['.h', '.m', '.mm'], ignore_file_patterns: []}
30+
defaults = {validator: ['clang-format'], file_extensions: ['.h', '.m', '.mm'], ignore_file_patterns: []}
3131
config = defaults.merge(config)
32+
validator = *config[:validator]
3233
file_extensions = [*config[:file_extensions]]
3334
ignore_file_patterns = [*config[:ignore_file_patterns]]
3435

@@ -45,7 +46,7 @@ def check(config = {})
4546
end
4647

4748
changes = get_changes(diff, file_extensions, ignore_file_patterns)
48-
offending_files, patches = resolve_changes(changes)
49+
offending_files, patches = resolve_changes(validator, changes)
4950

5051
message = ''
5152
unless offending_files.empty?
@@ -145,7 +146,7 @@ def generate_patch(title, content)
145146
markup_patch
146147
end
147148

148-
def resolve_changes(changes)
149+
def resolve_changes(validator, changes)
149150
# Parse all patches from diff string
150151

151152
offending_files = []
@@ -159,7 +160,7 @@ def resolve_changes(changes)
159160
end
160161

161162
changed_lines_command = changed_lines_command_array.join(' ')
162-
format_command_array = ['clang-format', changed_lines_command, file_name]
163+
format_command_array = [validator, changed_lines_command, file_name]
163164

164165
# clang-format command for formatting JUST changed lines
165166
formatted = `#{format_command_array.join(' ')}`

spec/code_style_validation_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module Danger
2727
diff = File.read('spec/fixtures/violated_diff.diff')
2828

2929
allow(@my_plugin.github).to receive(:pr_diff).and_return diff
30-
@my_plugin.check file_extensions: ['.h', '.c']
30+
@my_plugin.check validator: 'clang-format',
31+
file_extensions: ['.h', '.c']
3132

3233
expect(@dangerfile.status_report[:errors]).to eq([])
3334
end

0 commit comments

Comments
 (0)