Skip to content

Add prettier to pre-commit, install pre-commit in prebuild #8655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ ports:
onOpen: ignore
- port: 9229
onOpen: ignore
# Go proxy
# Go proxy
- port: 9999
onOpen: ignore
- port: 13001
onOpen: ignore
# Werft
# Werft
- port: 7777
onOpen: ignore
# Dev Theia
# Dev Theia
- port: 13444
tasks:
- name: Add Harvester kubeconfig
Expand All @@ -38,6 +38,7 @@ tasks:
before: scripts/branch-namespace.sh
init: yarn --network-timeout 100000 && yarn build
- name: Go
before: pre-commit install
init: leeway exec --filter-type go -v -- go mod verify
openMode: split-right
vscode:
Expand Down
66 changes: 36 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
#- id: check-yaml
# args: [--allow-multiple-documents]
# - id: end-of-file-fixer
- id: trailing-whitespace
exclude: .*/src/main/java/io/gitpod/supervisor/api/.*
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
#- id: check-yaml
# args: [--allow-multiple-documents]
# - id: end-of-file-fixer
- id: trailing-whitespace
exclude: .*/src/main/java/io/gitpod/supervisor/api/.*

- id: check-symlinks
- id: mixed-line-ending
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict
- id: check-symlinks
- id: mixed-line-ending
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-merge-conflict

# keep fork in sync!
- repo: https://github.com/gitpod-io/pre-commit-hooks
rev: "2.1.5"
hooks:
- id: forbid-binary
exclude: |
(?x)^(
.*example-layer.tar.gz|
.*\.(png|svg|ico|gpg)|
dev/version-manifest/version-manifest|
.*gradle-wrapper\.jar
)$
- id: script-must-have-extension
- id: shellcheck
args: [-e, "SC1090,SC1091"]
exclude: .*/gradlew$

# keep fork in sync!
- repo: https://github.com/gitpod-io/pre-commit-hooks
rev: "2.1.5"
hooks:
- id: forbid-binary
exclude: |
(?x)^(
.*example-layer.tar.gz|
.*\.(png|svg|ico|gpg)|
dev/version-manifest/version-manifest|
.*gradle-wrapper\.jar
)$
- id: script-must-have-extension
- id: shellcheck
args: [-e, "SC1090,SC1091"]
exclude: .*/gradlew$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.5.1"
hooks:
- id: prettier
# Only enabled for WebApp components initially, to build consensus and incrementally onboard others
files: ^components\/(server|gitpod-protocol|gitpod-db|dashboard)\/.*\.ts(x?)$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"tabWidth": 4,
"endOfLine": "auto",
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion .werft/jobs/build/validate-changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function branchNameCheck(werft: Werft, config: JobConfig) {

async function preCommitCheck(werft: Werft) {
werft.log("pre-commit checks", "Running pre-commit hooks.")
const preCommitCmd = exec(`pre-commit run --all-files --show-diff-on-failure`, { slice: "pre-commit checks" });
const preCommitCmd = exec(`pre-commit run --show-diff-on-failure`, { slice: "pre-commit checks" });
Copy link
Member Author

@easyCZ easyCZ Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, there's limited value in running pre-commit on all files. Not only does it prevent incremental lint fix, it also takes longer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with that. I don't think we have a case of "transitive invalidation" in any of our checks,


if (preCommitCmd.code != 0) {
throw new Error(preCommitCmd.stderr.toString().trim())
Expand Down