discourse/Dangerfile

38 lines
1.3 KiB
Plaintext
Raw Normal View History

2018-07-24 10:12:15 -04:00
require 'json'
2018-07-24 11:31:57 -04:00
require 'shellwords'
2018-07-24 10:12:15 -04:00
if git.lines_of_code > 500
2018-07-24 11:31:57 -04:00
warn("This PR seems big, we prefer smaller PR. Please be sure this is needed and can't be split in smaller PRs.")
2018-07-24 10:12:15 -04:00
end
2018-07-24 11:31:57 -04:00
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}`
2018-07-24 10:12:15 -04:00
if !rubocop_output.empty?
offenses = JSON.parse(rubocop_output)['files']
.select { |f| f['offenses'].any? }
2018-07-24 11:31:57 -04:00
def format_offense(offense)
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
2018-07-24 10:12:15 -04:00
2018-07-24 11:31:57 -04:00
if !offenses.empty?
fail(%{
2018-07-24 13:10:54 -04:00
This PR has multiple rubocop offenses. We recommend configuring prettier linting in your editor:\n
#{offenses.map { |o| format_offense(o) }.join('\n') }
2018-07-24 11:31:57 -04:00
})
end
2018-07-24 10:12:15 -04:00
end
2018-07-24 13:10:54 -04:00
prettier_offenses = `prettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.es6" "test/javascripts/**/*.es6" "plugins/**/*.scss" "plugins/**/*.es6"`.split('\n')
2018-07-24 11:31:57 -04:00
if !prettier_offenses.empty?
2018-07-24 10:12:15 -04:00
fail(%{
2018-07-24 13:10:54 -04:00
This PR has multiple prettier offenses (prettier.io). We recommend configuring prettier linting in your editor:\n
#{prettier_offenses.join("\n")}
2018-07-24 10:12:15 -04:00
})
end