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.'
|
|
|
|
|
2021-03-12 07:09:33 -05:00
|
|
|
if helper.ci?
|
2019-09-06 07:21:53 -04:00
|
|
|
markdown(<<~MARKDOWN)
|
|
|
|
## Pretty print Frontend files
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 07:21:53 -04:00
|
|
|
The following files should have been pretty printed with `prettier`:
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 07:21:53 -04:00
|
|
|
* #{unpretty.map { |path| "`#{path}`" }.join("\n* ")}
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 07:21:53 -04:00
|
|
|
Please run
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 07:21:53 -04:00
|
|
|
```
|
|
|
|
node_modules/.bin/prettier --write \\
|
|
|
|
#{unpretty.map { |path| " '#{path}'" }.join(" \\\n")}
|
|
|
|
```
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-09-06 07:21:53 -04:00
|
|
|
Also consider auto-formatting [on-save].
|
2018-09-21 11:36:26 -04:00
|
|
|
|
2019-12-11 01:07:52 -05:00
|
|
|
[on-save]: https://docs.gitlab.com/ee/development/fe_guide/tooling.html#formatting-with-prettier
|
2019-09-06 07:21:53 -04:00
|
|
|
MARKDOWN
|
|
|
|
end
|