Skip to content

Commit 7cfe619

Browse files
authored
Contrib note fix and CI/CD pre-commit hook prep (#8314)
1 parent 2caa216 commit 7cfe619

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

content/en/docs/contributing/pr-checks.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ This check will verify that all words in your cSpell ignore list are normalized.
8282
If this check fails, run `npm run fix:dict` locally and push the changes in a
8383
new commit.
8484

85-
### `FILENAME check` {.notranslate lang=en}
85+
### `FILE FORMAT` {.notranslate lang=en}
8686

87-
This check verifies that all
88-
[files are formatted by prettier](../style-guide/#file-format).
87+
This check verifies that all files conform to
88+
[Prettier format rules](../style-guide/#file-format).
8989

9090
If this check fails, run `npm run fix:format` locally and push the changes in a
9191
new commit.
9292

93-
### `FILE FORMAT` {.notranslate lang=en}
93+
### `FILENAME check` {.notranslate lang=en}
9494

9595
This check verifies that all
9696
[file names are in kebab-case](../style-guide/#file-names).

content/en/docs/contributing/style-guide.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,13 @@ title: registryEntryTitle
8888
8989
## File format
9090
91-
We enforce file formatting using [Prettier]. Invoke it using
92-
`npm run fix:format`.
91+
We use [Prettier] to enforce file formatting. Invoke it using:
92+
93+
- `npm run fix:format` to format all files
94+
- `npm run fix:format:diff` to format only the files that have changed since the
95+
last commit
96+
- `npm run fix:format:staged` to format only the files that are staged for the
97+
next commit
9398

9499
## File names
95100

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"__check:links": "make --keep-going check-links",
88
"__check:format:nowrap": "npm run _check:format:any -- --prose-wrap preserve",
99
"_build": "npm run _hugo -- -e dev --buildDrafts --buildFuture --baseURL \"${DEPLOY_PRIME_URL:-http://localhost}\"",
10-
"__check:format": "./scripts/npx-helper.sh prettier",
10+
"__check:format": "./scripts/npx-helper.sh prettier --ignore-unknown",
1111
"_check:format:any": "npm run __check:format -- --check --ignore-path ''",
1212
"_check:format:nowrap": "npm run __check:format:nowrap -- content/ja content/uk content/zh",
1313
"_check:format": "npm run __check:format -- --check .",
@@ -24,7 +24,7 @@
2424
"_fail": "exit 1",
2525
"_filename-error": "echo 'ERROR: the following files violate naming conventions; fix using: `npm run fix:filenames`'; echo; npm run -s _ls-bad-filenames; exit 1",
2626
"_fix:trailing-spaces": "find content -name '*.md' -exec perl -i -pe 's/[ \t]+$//g' {} +",
27-
"_fix:format:diff": "npm run __check:format -- --write $(npm -s run _list:diff)",
27+
"_fix:format:diff": "npm run __check:format -- --write",
2828
"_get:no": "echo SKIPPING get operation",
2929
"_get:submodule": "set -x && git submodule update --init ${DEPTH:- --depth 999}",
3030
"_hugo": "hugo --cleanDestinationDir",
@@ -33,7 +33,8 @@
3333
"_list:check:*": "npm run --loglevel=warn | grep -Ee '^\\s*check:[^:]+$'",
3434
"_list:check:for-test-and-fix": "npm -s run _list:check:* | grep -Ev \"i18n|${CMD_SKIP:-noop}\"",
3535
"_list:dict": "grep '^\\s*\"@cspell' package.json | awk -F: '{print $1}' | tr -d '\"'",
36-
"_list:diff": "git diff --name-only --diff-filter=AM",
36+
"_list:diff-never-empty": "echo README.md && npm run _list:diff",
37+
"_list:diff": "git diff --name-only --diff-filter=AMR",
3738
"_list:fix:*": "npm run --loglevel=warn | grep -Ee '^\\s*fix:[^:]+$' | grep -v 'fix:all'",
3839
"_list:fix:for-test-and-fix": "npm -s run _list:fix:* | grep -Ev \"i18n|refcache|submodule|${CMD_SKIP:-noop}\"",
3940
"_ls-bad-filenames": "find assets content static -name '*_*' ! -name '[_.]*'",
@@ -72,6 +73,8 @@
7273
"fix:dict": "find content layouts -name \"*.md\" -print0 | xargs -0 scripts/normalize-cspell-front-matter.pl",
7374
"fix:expired": "npm run -s check:expired -- -q | xargs -r -I {} sh -c 'echo \"Deleting expired file: {}\" && rm {}'",
7475
"fix:filenames": "npm run _rename-to-kebab-case",
76+
"fix:format:diff": "npm run _fix:format:diff -- $(npm -s run _list:diff-never-empty)",
77+
"fix:format:staged": "npm run _fix:format:diff -- $(npm -s run _list:diff-never-empty -- --cached)",
7578
"fix:format": "npm run format; npm run _fix:trailing-spaces",
7679
"fix:htmltest-config": "scripts/htmltest-config.sh",
7780
"fix:i18n:status": "scripts/check-i18n.sh -D",

scripts/git/pre-commit.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
#
3+
# Pre-commit hook that runs formatting on staged files
4+
#
5+
6+
exec npm run fix:format:staged
7+

0 commit comments

Comments
 (0)