mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
fixes dangerfile (#6158)
This commit is contained in:
parent
1ac643d71c
commit
75b03dab84
35
Dangerfile
35
Dangerfile
@ -1,29 +1,38 @@
|
|||||||
require 'json'
|
require 'json'
|
||||||
|
require 'shellwords'
|
||||||
|
|
||||||
if git.lines_of_code > 500
|
if git.lines_of_code > 500
|
||||||
warn("This PR seems big, we prefer smaller PR. Please be sure this is needed and can’t be split in smaller commits.")
|
warn("This PR seems big, we prefer smaller PR. Please be sure this is needed and can't be split in smaller PRs.")
|
||||||
end
|
end
|
||||||
|
|
||||||
rubocop_output = `bundle exec rubocop --parallel`
|
to_lint = git.modified_files + git.added_files
|
||||||
|
files_to_lint = Shellwords.join(to_lint)
|
||||||
|
|
||||||
|
rubocop_output = `bundle exec rubocop -f json --parallel #{files_to_lint}`
|
||||||
if !rubocop_output.empty?
|
if !rubocop_output.empty?
|
||||||
offenses = JSON.parse(rubocop_output)['files']
|
offenses = JSON.parse(rubocop_output)['files']
|
||||||
.select { |f| f['offenses'].any? }
|
.select { |f| f['offenses'].any? }
|
||||||
|
|
||||||
fail(%{
|
def format_offense(offense)
|
||||||
This PR has multiple rubocop offenses:
|
output = "file: #{offense['path']}\n"
|
||||||
|
offense['offenses'].each do |o|
|
||||||
|
output << "#{o['message']} (line:#{o['location']['start_line']}, col:#{o['location']['start_column']})\n"
|
||||||
|
end
|
||||||
|
output << "\n"
|
||||||
|
end
|
||||||
|
|
||||||
#{offenses.join("\n")}
|
if !offenses.empty?
|
||||||
|
fail(%{
|
||||||
|
This PR has multiple rubocop offenses:\n
|
||||||
|
#{offenses.map { |o| format_offense(o) }.join('\n') }
|
||||||
})
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
prettier_output = `prettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.es6" "test/javascripts/**/*.es6" "plugins/**/*.scss" "plugins/**/*.es6"`
|
prettier_offenses = `prettier --list-different #{files_to_lint}`.split('\n')
|
||||||
if !prettier_output.empty?
|
if !prettier_offenses.empty?
|
||||||
offenses = JSON.parse(prettier_output)['files']
|
|
||||||
.select { |f| f['offenses'].any? }
|
|
||||||
|
|
||||||
fail(%{
|
fail(%{
|
||||||
This PR has multiple prettier offenses:
|
This PR has multiple prettier offenses (we recommend configuring prettier linting in your editor):\n
|
||||||
|
#{prettier_offenses.join("\n")}
|
||||||
#{offenses.join("\n")}
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user