Skip to content

Commit e6e9c7b

Browse files
committed
[core] add prettier to CircleCI
A file can be formatted without knowledge about other files. For this reason we only check the format for files which were changed compared to master. A broken format that was merged into master will not be picked up by CI until the file was changed again. This can be a good thing since this will not trigger CI errors in unrelated builds and since we are only talking about code style this a manageable tradeoff especially because formatting can be very expensive.
1 parent 96d2c38 commit e6e9c7b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

.circleci/config.yml

+15
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ jobs:
4242
<<: *defaults
4343
steps:
4444
- *restore_repo
45+
- run:
46+
name: Check if yarn prettier was run
47+
command: |
48+
# Files changed on this branch
49+
CHANGED_FILES=$(git diff --name-only master...)
50+
# Files that should have been formatted while working on this branch
51+
FORMATTED_FILES=$(yarn --silent prettier:files | grep "$CHANGED_FILES")
52+
# if we run prettier unconditionally prettier will exit with non-zero
53+
# because no file path was given
54+
if [ $FORMATTED_FILES ]; then
55+
echo "changes, let's check if they are formatted"
56+
yarn prettier:ci "$FORMATTED_FILES"
57+
else
58+
echo "no changes"
59+
fi
4560
- run:
4661
name: Lint
4762
command: yarn lint

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
"docs:deploy": "git push material-ui-docs master:latest",
3535
"lint": "eslint . --cache && echo \"eslint: no lint errors\"",
3636
"lint:fix": "eslint . --cache --fix && echo \"eslint: no lint errors\"",
37-
"prettier": "find . -name \"*.js\" -o -name \"*.d.ts\" -o -name \"*.tsx\" | grep -v -f .eslintignore | xargs prettier --write",
37+
"prettier": "yarn --silent prettier:files | xargs prettier --write",
38+
"prettier:files": "find . -name \"*.js\" -o -name \"*.d.ts\" -o -name \"*.tsx\" | grep -v -f .eslintignore",
39+
"prettier:check": "yarn --silent prettier:files | xargs prettier --list-different",
40+
"prettier:ci": "prettier --list-different",
3841
"size": "size-limit",
3942
"size:why": "size-limit --why packages/material-ui/build/index.js",
4043
"size:overhead:why": "size-limit --why ./test/size/overhead.js",

0 commit comments

Comments
 (0)