debian-mirror-gitlab/danger/prettier/Dangerfile

42 lines
1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
def get_prettier_files(files)
files.select do |file|
file.end_with?('.js', '.scss', '.vue')
end
end
2018-12-13 13:39:08 +05:30
prettier_candidates = get_prettier_files(helper.all_changed_files)
2018-12-05 23:21:45 +05:30
return if prettier_candidates.empty?
unpretty = `node_modules/prettier/bin-prettier.js --list-different #{prettier_candidates.join(" ")}`
.split(/$/)
.map(&:strip)
.reject(&:empty?)
return if unpretty.empty?
warn 'This merge request changed frontend files without pretty printing them.'
2019-12-04 20:38:33 +05:30
if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Pretty print Frontend files
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
The following files should have been pretty printed with `prettier`:
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
* #{unpretty.map { |path| "`#{path}`" }.join("\n* ")}
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
Please run
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
```
node_modules/.bin/prettier --write \\
#{unpretty.map { |path| " '#{path}'" }.join(" \\\n")}
```
2018-12-05 23:21:45 +05:30
2019-12-04 20:38:33 +05:30
Also consider auto-formatting [on-save].
2018-12-05 23:21:45 +05:30
2020-01-01 13:55:28 +05:30
[on-save]: https://docs.gitlab.com/ee/development/fe_guide/tooling.html#formatting-with-prettier
2019-12-04 20:38:33 +05:30
MARKDOWN
end