Skip to content

Commit 42e51c8

Browse files
committed
chore: Improve project-wide prettier formatting and ignored files
1 parent c505e8b commit 42e51c8

11 files changed

+343
-88
lines changed

.gitignore

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,32 @@
1-
###############################################################################
2-
# NOTICE #
3-
# If you change this file, kindly copy-pasta your change into .prettierignore #
4-
# and .eslintignore as well. See the following discussions to understand why #
5-
# we have to resort to this duplication (at least for now): #
6-
# #
7-
# https://github.com/prettier/prettier/issues/8048 #
8-
# https://github.com/prettier/prettier/issues/8506 #
9-
# https://github.com/prettier/prettier/issues/8679 #
10-
###############################################################################
11-
12-
node_modules
13-
vendor
1+
# Common ignore patterns, these rules applies in both root and subdirectories.
2+
.DS_Store
143
.eslintcache
15-
yarn-error.log
4+
.gitpod.yml
5+
.idea
6+
**/*.swp
167
gotests.coverage
178
gotests.xml
189
gotestsum.json
19-
.idea
20-
.gitpod.yml
21-
.DS_Store
10+
node_modules/
11+
vendor/
12+
yarn-error.log
2213

23-
# Make target for updating golden files.
24-
cli/testdata/.gen-golden
14+
# VSCode settings.
15+
.vscode/
16+
# Allow VSCode recommendations and default settings in project root.
17+
!/.vscode/extensions.json
18+
!/.vscode/settings.json
2519

26-
# Front-end ignore
20+
# Front-end ignore patterns.
2721
.next/
28-
site/.eslintcache
29-
site/.next/
30-
site/node_modules/
31-
site/storybook-static/
32-
site/test-results/
33-
site/yarn-error.log
34-
coverage/
3522
site/**/*.typegen.ts
3623
site/build-storybook.log
24+
site/coverage/
25+
site/storybook-static/
26+
site/test-results/
27+
28+
# Make target for updating golden files.
29+
cli/testdata/.gen-golden
3730

3831
# Build
3932
/build/
@@ -46,10 +39,7 @@ site/out/
4639
*.lock.hcl
4740
.terraform/
4841

49-
.vscode/*.log
50-
.vscode/launch.json
51-
**/*.swp
52-
.coderv2/*
42+
/.coderv2/*
5343
**/__debug_bin
5444

5545
# direnv

.prettierignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#
2+
# Generated from [.gitignore .prettierignore.include] by Makefile; DO NOT EDIT.
3+
#
4+
# .gitignore:
5+
# Common ignore patterns, these rules applies in both root and subdirectories.
6+
.DS_Store
7+
.eslintcache
8+
.gitpod.yml
9+
.idea
10+
**/*.swp
11+
gotests.coverage
12+
gotests.xml
13+
gotestsum.json
14+
node_modules/
15+
vendor/
16+
yarn-error.log
17+
18+
# VSCode settings.
19+
.vscode/
20+
# Allow VSCode recommendations and default settings in project root.
21+
!/.vscode/extensions.json
22+
!/.vscode/settings.json
23+
24+
# Front-end ignore patterns.
25+
.next/
26+
site/**/*.typegen.ts
27+
site/build-storybook.log
28+
site/coverage/
29+
site/storybook-static/
30+
site/test-results/
31+
32+
# Make target for updating golden files.
33+
cli/testdata/.gen-golden
34+
35+
# Build
36+
/build/
37+
/dist/
38+
site/out/
39+
40+
*.tfstate
41+
*.tfstate.backup
42+
*.tfplan
43+
*.lock.hcl
44+
.terraform/
45+
46+
/.coderv2/*
47+
**/__debug_bin
48+
49+
# direnv
50+
.envrc
51+
# .prettierignore.include:
52+
# Helm templates contain variables that are invalid YAML and can't be formatted
53+
# by Prettier.
54+
helm/templates/*.yaml
55+
56+
# Terraform state files used in tests, these are automatically generated.
57+
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json
58+
**/testdata/**/*.tf*.json
59+
60+
# Testdata shouldn't be formatted.
61+
scripts/apitypings/testdata/**/*.ts

.prettierignore.include

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Helm templates contain variables that are invalid YAML and can't be formatted
2+
# by Prettier.
3+
helm/templates/*.yaml
4+
5+
# Terraform state files used in tests, these are automatically generated.
6+
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json
7+
**/testdata/**/*.tf*.json
8+
9+
# Testdata shouldn't be formatted.
10+
scripts/apitypings/testdata/**/*.ts

.prettierrc.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
printWidth: 80
2+
semi: false
3+
trailingComma: all
4+
overrides:
5+
- files:
6+
- README.md
7+
options:
8+
proseWrap: preserve
9+
- files:
10+
- "site/**/*.yaml"
11+
- "site/**/*.yml"
12+
options:
13+
proseWrap: always

Makefile

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ fmt/prettier:
369369
cd site
370370
# Avoid writing files in CI to reduce file write activity
371371
ifdef CI
372-
yarn run format:check . ../*.md ../docs
372+
yarn run format:check
373373
else
374-
yarn run format:write . ../*.md ../docs
374+
yarn run format:write
375375
endif
376376
.PHONY: fmt/prettier
377377

@@ -411,13 +411,31 @@ gen: \
411411
provisionerd/proto/provisionerd.pb.go \
412412
site/src/api/typesGenerated.ts \
413413
docs/admin/prometheus.md \
414-
coderd/apidoc/swagger.json
414+
coderd/apidoc/swagger.json \
415+
.prettierignore.include \
416+
.prettierignore \
417+
site/.prettierrc.yaml \
418+
site/.prettierignore \
419+
site/.eslintignore
415420
.PHONY: gen
416421

417422
# Mark all generated files as fresh so make thinks they're up-to-date. This is
418423
# used during releases so we don't run generation scripts.
419424
gen/mark-fresh:
420-
files="coderd/database/dump.sql coderd/database/querier.go provisionersdk/proto/provisioner.pb.go provisionerd/proto/provisionerd.pb.go site/src/api/typesGenerated.ts docs/admin/prometheus.md coderd/apidoc/swagger.json"
425+
files="\
426+
coderd/database/dump.sql \
427+
coderd/database/querier.go \
428+
provisionersdk/proto/provisioner.pb.go \
429+
provisionerd/proto/provisionerd.pb.go \
430+
site/src/api/typesGenerated.ts \
431+
docs/admin/prometheus.md \
432+
coderd/apidoc/swagger.json \
433+
.prettierignore.include \
434+
.prettierignore \
435+
site/.prettierrc.yaml \
436+
site/.prettierignore \
437+
site/.eslintignore \
438+
"
421439
for file in $$files; do
422440
echo "$$file"
423441
if [ ! -f "$$file" ]; then
@@ -463,21 +481,101 @@ site/src/api/typesGenerated.ts: scripts/apitypings/main.go $(shell find ./coders
463481
docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics
464482
go run scripts/metricsdocgen/main.go
465483
cd site
466-
yarn run format:write ../docs/admin/prometheus.md
484+
yarn run format:write:only ../docs/admin/prometheus.md
467485

468486
coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen -not \( -path './scripts/apidocgen/node_modules' -prune \) -type f) $(wildcard coderd/*.go) $(wildcard codersdk/*.go)
469487
./scripts/apidocgen/generate.sh
470488
cd site
471-
yarn run format:write ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
489+
yarn run format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json
472490

473491
update-golden-files: cli/testdata/.gen-golden
474492
.PHONY: update-golden-files
475493

476494
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(GO_SRC_FILES)
477-
478495
go test ./cli -run=TestCommandHelp -update
479496
touch "$@"
480497

498+
# Ensure there's a .prettierrc.yaml project-wide when prettier is run outside
499+
# the site package.
500+
site/.prettierrc.yaml: .prettierrc.yaml Makefile
501+
echo "#" > "$@"
502+
echo "# Generated from ../$< by Makefile; DO NOT EDIT." >> "$@"
503+
echo "#" >> "$@"
504+
505+
# Simplistic approach to rewriting override paths relative to site/.
506+
isfile=0
507+
IFS=$$'\n'
508+
while read -r line; do
509+
case "$$line" in
510+
*files:*)
511+
isfile=1
512+
;;
513+
*"- "*)
514+
if [[ "$$isfile" == 1 ]]; then
515+
if [[ "$${line}" = *'- "'* ]]; then
516+
line=$${line//- \"/- \"..\/}
517+
else
518+
line=$${line//- /- ..\/}
519+
fi
520+
line=$${line//\/\//\/}
521+
line=$${line//..\/site\//.\/}
522+
fi
523+
;;
524+
*)
525+
isfile=0
526+
;;
527+
esac
528+
echo "$$line" >> "$@"
529+
done < "$<"
530+
531+
# Workaround for `.prettierignore` depending on Makefile but using $^ instead of $<.
532+
.prettierignore.include: Makefile
533+
touch .prettierignore.include
534+
535+
# Combine .gitignore with .prettierignore.include to generate .prettierignore.
536+
.prettierignore: .gitignore .prettierignore.include
537+
echo "#" > "$@"
538+
echo "# Generated from [$^] by Makefile; DO NOT EDIT." >> "$@"
539+
echo "#" >> "$@"
540+
for f in $^; do
541+
echo "# $${f}:" >> "$@"
542+
cat "$$f" >> "$@"
543+
done
544+
545+
# Generate ignore files based on gitignore into the site directory. We only
546+
# include rules relevant for the site directory to prevent false-positives.
547+
#
548+
# https://git-scm.com/docs/gitignore#_pattern_format
549+
#
550+
# This is done for compatibility reasons, see:
551+
# https://github.com/prettier/prettier/issues/8048
552+
# https://github.com/prettier/prettier/issues/8506
553+
# https://github.com/prettier/prettier/issues/8679
554+
site/.eslintignore site/.prettierignore: .prettierignore Makefile
555+
rm -f "$@"
556+
touch "$@"
557+
# Skip generated by header, inherit `.prettierignore` header as-is.
558+
while read -r rule; do
559+
# Remove leading ! if present to simplify rule, added back at the end.
560+
tmp="$${rule#!}"
561+
ignore="$${rule%"$$tmp"}"
562+
rule="$$tmp"
563+
case "$$rule" in
564+
# Comments or empty lines (include).
565+
\#*|'') ;;
566+
# Generic rules (include).
567+
\*\**) ;;
568+
# Site prefixed rules (include).
569+
site/*) rule="$${rule#site/}";;
570+
./site/*) rule="$${rule#./site/}";;
571+
# Rules that are non-generic and don't start with site (rewrite).
572+
/*) rule=.."$$rule";;
573+
*/?*) rule=../"$$rule";;
574+
*) ;;
575+
esac
576+
echo "$${ignore}$${rule}" >> "$@"
577+
done < "$<"
578+
481579
test: test-clean
482580
gotestsum --debug -- -v -short ./...
483581
.PHONY: test

site/.eslintignore

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,61 @@
1-
###############################################################################
2-
# COPY PASTA OF .gitignore
3-
###############################################################################
4-
5-
.idea
1+
#
2+
# Generated from [.gitignore .prettierignore.include] by Makefile; DO NOT EDIT.
3+
#
4+
# .gitignore:
5+
# Common ignore patterns, these rules applies in both root and subdirectories.
6+
.DS_Store
7+
.eslintcache
68
.gitpod.yml
7-
node_modules
8-
vendor
9-
out
10-
coverage
11-
.next
12-
storybook-static
13-
test-results
14-
**/*.typegen.ts
9+
.idea
1510
**/*.swp
16-
.coderv2/*
11+
gotests.coverage
12+
gotests.xml
13+
gotestsum.json
14+
node_modules/
15+
vendor/
16+
yarn-error.log
17+
18+
# VSCode settings.
19+
.vscode/
20+
# Allow VSCode recommendations and default settings in project root.
21+
!../.vscode/extensions.json
22+
!../.vscode/settings.json
23+
24+
# Front-end ignore patterns.
25+
.next/
26+
**/*.typegen.ts
27+
build-storybook.log
28+
coverage/
29+
storybook-static/
30+
test-results/
31+
32+
# Make target for updating golden files.
33+
../cli/testdata/.gen-golden
34+
35+
# Build
36+
../build/
37+
../dist/
38+
out/
39+
40+
*.tfstate
41+
*.tfstate.backup
42+
*.tfplan
43+
*.lock.hcl
44+
.terraform/
45+
46+
../.coderv2/*
47+
**/__debug_bin
48+
49+
# direnv
50+
.envrc
51+
# .prettierignore.include:
52+
# Helm templates contain variables that are invalid YAML and can't be formatted
53+
# by Prettier.
54+
../helm/templates/*.yaml
55+
56+
# Terraform state files used in tests, these are automatically generated.
57+
# Example: provisioner/terraform/testdata/instance-id/instance-id.tfstate.json
58+
**/testdata/**/*.tf*.json
59+
60+
# Testdata shouldn't be formatted.
61+
../scripts/apitypings/testdata/**/*.ts

0 commit comments

Comments
 (0)