diff options
author | Lukas Eipert <leipert@gitlab.com> | 2018-09-21 17:36:26 +0200 |
---|---|---|
committer | Lukas Eipert <leipert@gitlab.com> | 2018-09-28 22:04:26 +0200 |
commit | 4df24e5f046f94a04b379fcd1d6d57ef49cfd6dc (patch) | |
tree | 40dfba20f0ba04528cdd9c5d6431273dc3d2eb6f /danger/prettier | |
parent | ab6b4488033e6291ba1c2295ea87884ff37e7508 (diff) | |
download | gitlab-ce-4df24e5f046f94a04b379fcd1d6d57ef49cfd6dc.tar.gz |
Danger check for unprettified JavaScript
This adds a Dangerfile which executes `prettier` to find out if someone
touched Frontend files and forgot to run it on their current branch.
Diffstat (limited to 'danger/prettier')
-rw-r--r-- | danger/prettier/Dangerfile | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/danger/prettier/Dangerfile b/danger/prettier/Dangerfile new file mode 100644 index 00000000000..86f9f6af475 --- /dev/null +++ b/danger/prettier/Dangerfile @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +def get_prettier_files(files) + files.select do |file| + file.end_with?('.js', '.scss', '.vue') + end +end + +prettier_candidates = get_prettier_files(git.added_files + git.modified_files) + +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.' + +markdown(<<~MARKDOWN) + ## Pretty print Frontend files + + The following files should have been pretty printed with `prettier`: + + * #{unpretty.map { |path| "`#{path}`" }.join("\n* ")} + + Please run + + ``` + node_modules/.bin/prettier --write \\ + #{unpretty.map { |path| " '#{path}'" }.join(" \\\n")} + ``` + + Also consider auto-formatting [on-save]. + + [on-save]: https://docs.gitlab.com/ee/development/new_fe_guide/style/prettier.html +MARKDOWN |