Skip to content

Commit 4d00b7d

Browse files
authored
Adds a pre-commit config (#3)
- adds a pre-commit config - includes prettier formatting configuration - fixes title in README - adds a CircleCI config - sets default pre-commit stage to commit
1 parent daf2624 commit 4d00b7d

4 files changed

Lines changed: 97 additions & 3 deletions

File tree

.circleci/config.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: 2.1
2+
3+
workflows:
4+
version: 2
5+
verify:
6+
jobs:
7+
- pre-commit:
8+
filters:
9+
tags: &filter-all-tags # run for all tags
10+
only: /.*/
11+
12+
jobs:
13+
pre-commit:
14+
parameters:
15+
config_file:
16+
default: ./.pre-commit-config.yaml
17+
description: Optional, path to pre-commit config file.
18+
type: string
19+
cache_prefix:
20+
default: ''
21+
description: |
22+
Optional cache prefix to be used on CircleCI. Can be used for cache busting or to ensure multiple jobs use different caches.
23+
type: string
24+
docker:
25+
- image: speckle/pre-commit-runner:latest
26+
resource_class: medium
27+
working_directory: &workingdir /tmp/ci
28+
steps:
29+
- checkout
30+
- restore_cache:
31+
keys:
32+
- cache-pre-commit-<<parameters.cache_prefix>>-{{ checksum "<<parameters.config_file>>" }}
33+
- run:
34+
name: Install pre-commit hooks
35+
command: pre-commit install-hooks --config <<parameters.config_file>>
36+
- save_cache:
37+
key: cache-pre-commit-<<parameters.cache_prefix>>-{{ checksum "<<parameters.config_file>>" }}
38+
paths:
39+
- ~/.cache/pre-commit
40+
- run:
41+
name: Run pre-commit
42+
command: pre-commit run --all-files --config <<parameters.config_file>>
43+
- run:
44+
command: git --no-pager diff
45+
name: git diff
46+
when: on_fail

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
default_stages:
2+
- 'commit'
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/mirrors-prettier
6+
rev: 'v2.7.1'
7+
hooks:
8+
- id: prettier
9+
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: 'v4.3.0'
12+
hooks:
13+
- id: check-yaml
14+
- id: check-merge-conflict
15+
- id: check-executables-have-shebangs
16+
- id: check-shebang-scripts-are-executable
17+
- id: check-symlinks
18+
- id: check-vcs-permalinks
19+
- id: trailing-whitespace
20+
- id: end-of-file-fixer
21+
22+
- repo: https://github.com/syntaqx/git-hooks
23+
rev: 'v0.0.17'
24+
hooks:
25+
- id: forbid-binary
26+
27+
- repo: https://github.com/pre-commit/pre-commit
28+
rev: 'v2.20.0'
29+
hooks:
30+
- id: validate_manifest
31+
32+
ci:
33+
autoupdate_schedule: quarterly

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"trailingComma": "none",
3+
"tabWidth": 2,
4+
"semi": false,
5+
"endOfLine": "auto",
6+
"bracketSpacing": true,
7+
"vueIndentScriptAndStyle": false,
8+
"htmlWhitespaceSensitivity": "ignore",
9+
"printWidth": 88,
10+
"singleQuote": true
11+
}

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Speckle Repo Management Templates
1+
# Speckle Pre-Commit Hooks
22

33
[![Twitter Follow](https://img.shields.io/twitter/follow/SpeckleSystems?style=social)](https://twitter.com/SpeckleSystems) [![Community forum users](https://img.shields.io/discourse/users?server=https%3A%2F%2Fdiscourse.speckle.works&style=flat-square&logo=discourse&logoColor=white)](https://discourse.speckle.works) [![website](https://img.shields.io/badge/https://-speckle.systems-royalblue?style=flat-square)](https://speckle.systems) [![docs](https://img.shields.io/badge/docs-speckle.guide-orange?style=flat-square&logo=read-the-docs&logoColor=white)](https://speckle.guide/dev/)
44

@@ -17,6 +17,7 @@ Comprehensive developer and user documentation for Speckle can be found in our:
1717
## Usage
1818

1919
1. Add the following to your `.pre-commit-config.yaml` file:
20+
2021
```
2122
- repo: https://github.com/specklesystems/pre-commit
2223
rev: '0.1.0'
@@ -27,11 +28,14 @@ Comprehensive developer and user documentation for Speckle can be found in our:
2728
## Developing & Debugging
2829

2930
1. install:
30-
- `git`
31-
- `pre-commit`
31+
32+
- `git`
33+
- `pre-commit`
34+
3235
1. Git clone this repository. Detailed steps on how to do that can be found on [GitHub's documentation](https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls).
3336
1. In a terminal, `cd` into a directory containing code that you wish to try the pre-commit hook on. e.g. Speckle's `speckle-server` repository.
3437
1. Run the following command to run a pre-commit hook directly from this repository. Replace `<pre-commit hook to run>` with the name of the hook you wish to run:
38+
3539
```shell
3640
pre-commit try-repo ./path/to/cloned/specklesystems/pre-commit <pre-commit hook to run>
3741
```

0 commit comments

Comments
 (0)