2018-09-21 11:36:26 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
def get_prettier_files(files)
|
|
|
|
files.select do |file|
|
|
|
|
file.end_with?('.js', '.scss', '.vue')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-16 09:56:03 -04:00
|
|
|
prettier_candidates = get_prettier_files(helper.all_changed_files)
|
2018-09-21 11:36:26 -04:00
|
|
|
|
|
|
|
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-09-06 03:14:30 -04:00
|
|
|
markdown(<<~MARKDOWN)
|
|
|
|
## Pretty print Frontend files
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 03:14:30 -04:00
|
|
|
The following files should have been pretty printed with `prettier`:
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 03:14:30 -04:00
|
|
|
* #{unpretty.map { |path| "`#{path}`" }.join("\n* ")}
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 03:14:30 -04:00
|
|
|
Please run
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 03:14:30 -04:00
|
|
|
```
|
|
|
|
node_modules/.bin/prettier --write \\
|
|
|
|
#{unpretty.map { |path| " '#{path}'" }.join(" \\\n")}
|
|
|
|
```
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 03:14:30 -04:00
|
|
|
Also consider auto-formatting [on-save].
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 03:14:30 -04:00
|
|
|
[on-save]: https://docs.gitlab.com/ee/development/new_fe_guide/style/prettier.html
|
|
|
|
MARKDOWN
|