Skip to content

Commit

Permalink
fix: pre-commit linting (#703)
Browse files Browse the repository at this point in the history
## Description
numerous times lately I have pushed commits that break our linting (
typically the end of file new line ) but on occasion also spacing
changes. I've noticed others occasionally have the same issue. Setup a
pre-commit check that runs the same linting command that `uds run lint`
uses.

If lint is successful the commit is made, if lint failed commit is not
made and user is notified of what failed lint so they can fix. This also
only tests staged files.

Also could be built out a bit more to add restrictions to commit
messages and other things if we wanted, or even logic to run the
lint-fix ( which doesn't always work ).

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor
Guide](https://github.com/defenseunicorns/uds-template-capability/blob/main/CONTRIBUTING.md)
followed
  • Loading branch information
UnicornChance authored Sep 11, 2024
1 parent f94daf1 commit c3a2f62
Show file tree
Hide file tree
Showing 15 changed files with 1,138 additions and 347 deletions.
5 changes: 5 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Lint Codespell configurations
[codespell]
skip = .codespellrc,.git,node_modules,build,dist,*.zst,CHANGELOG.md
ignore-words-list = NotIn,AKS
enable-colors =
12 changes: 12 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

OUTPUT=$(npx lint-staged > /dev/null && echo $? || echo $?)

if [ $OUTPUT -eq 0 ]; then
echo "\n\n✅ Lint Check Passed. ✅\n\n"
exit 0
else
echo "\n\n❌ Lint Check failed... Run \`uds run lint-fix\` to resolve issues and re-commit. ❌\n\n"
exit 1
fi
11 changes: 11 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"*": [
"codespell"
],
"*.yaml": [
"yamllint -c .yamllint --no-warnings"
],
"*.ts": [
"npx pepr format --validate-only"
]
}
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ignore:
- 'node_modules/**'
- 'dist/**'
- 'src/pepr/uds-operator-config/templates**'
- '.codespellrc'
- '.lintstagedrc.json'

rules:
anchors: enable
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ Specifically:
* Continuous integration (CI) pipeline tests are definitive
* We create immutable release artifacts

Commits:

We use [codespell](https://github.com/codespell-project/codespell) and [yamllint](https://yamllint.readthedocs.io/en/stable/) for our precommit checking. It is recommended to have these installed before attempting to commit to the a branch otherwise your commit will not finalize and you will be shown an error.

To install both of these tools you can run `uds run lint-check` to install them or utilize `pip` to install them manually.

```bash
pip install yamllint codespell
```

## Definition of Done

We apply these general principles to all User Stories and activities contributing to the UDS.
Expand Down
2 changes: 1 addition & 1 deletion bundles/k3d-slim-dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This bundle is a trimmed-down version of [UDS Core](../k3d-standard/README.md) b

The k3d uds-dev-stack provides:

- [K3d](https://k3d.io/) - Containerized K3s Kubernetes Enviroment
- [K3d](https://k3d.io/) - Containerized K3s Kubernetes Environment
- [Minio](https://min.io/) - In-cluster S3 Object Storage (See below for more details)
- [Local Path Provisioner](https://github.com/rancher/local-path-provisioner/) - Local Storage with RWX
- [MetalLB](https://metallb.universe.tf/) - Provides type: LoadBalancer for cluster resources and Istio Gateways
Expand Down
2 changes: 1 addition & 1 deletion bundles/k3d-standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This bundle is used for demonstration, development, and testing of UDS Core. In addition to the [UDS Core applications](../../README.md#core-applications), the included k3d uds-dev-stack provides:

- [K3d](https://k3d.io/) - Containerized K3s Kubernetes Enviroment
- [K3d](https://k3d.io/) - Containerized K3s Kubernetes Environment
- [Minio](<https://min.io/>) - In-cluster S3 Object Storage (See below for more details)
- [Local Path Provisioner](<https://github.com/rancher/local-path-provisioner>) - Storage Provider with RWX configured
- [MetalLB](https://metallb.universe.tf/) - Provides type: LoadBalancer for cluster resources and Istio Gateways
Expand Down
16 changes: 8 additions & 8 deletions compliance/oscal-assessment-results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ assessment-results:
uuid: c7c56dc6-9189-48e6-8153-541f8e7f129e
- description: |
Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Implemented Requirement: 0AE59B43-50A7-4420-881B-E0635CCB8424
Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments in the event of an accessibility disruptions.
Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availability) and on-premise environments in the event of an accessibility disruptions.
target:
status:
state: not-satisfied
Expand All @@ -713,7 +713,7 @@ assessment-results:
uuid: 6cf300c3-516b-4864-8049-a5d423c5bddc
- description: |
Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Implemented Requirement: D74C3A8C-E5B0-4F81-895D-FB2A318D723B
Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments in the event of an accessibility disruptions.
Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availability) and on-premise environments in the event of an accessibility disruptions.
target:
status:
state: not-satisfied
Expand All @@ -723,7 +723,7 @@ assessment-results:
uuid: 003c98fa-877a-4571-9bb7-f8ad72b88768
- description: |
Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Implemented Requirement: 72D7145F-7A3F-47AF-835F-7E3D6EFAE1CC
Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments in the event of an accessibility disruptions.
Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availability) and on-premise environments in the event of an accessibility disruptions.
target:
status:
state: not-satisfied
Expand Down Expand Up @@ -768,7 +768,7 @@ assessment-results:
uuid: f4c55319-50b5-4219-bf6f-22c66421f441
- description: |
Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Implemented Requirement: C650411C-33FD-4B59-8899-AC34B43C860F
Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments.
Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availability) and on-premise environments.
target:
status:
state: not-satisfied
Expand Down Expand Up @@ -2014,7 +2014,7 @@ assessment-results:
type: objective-id
title: 'Validation Result - Component:3127D34A-517B-473B-83B0-6536179ABE38 / Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Control: cp-6.2'
uuid: fde3d548-4c98-451e-8ad1-08ebf918ec1f
- description: Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments in the event of an accessibility disruptions.
- description: Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availability) and on-premise environments in the event of an accessibility disruptions.
target:
status:
state: not-satisfied
Expand All @@ -2030,15 +2030,15 @@ assessment-results:
type: objective-id
title: 'Validation Result - Component:3127D34A-517B-473B-83B0-6536179ABE38 / Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Control: cp-7'
uuid: 30788898-87df-4185-ab1c-9becdee50f6c
- description: Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments in the event of an accessibility disruptions.
- description: Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availability) and on-premise environments in the event of an accessibility disruptions.
target:
status:
state: not-satisfied
target-id: cp-7.1
type: objective-id
title: 'Validation Result - Component:3127D34A-517B-473B-83B0-6536179ABE38 / Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Control: cp-7.1'
uuid: a718a683-1df0-4cac-9b9e-f61792134683
- description: Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments in the event of an accessibility disruptions.
- description: Velero supports back-ups to and restores from multiple cloud environments (including geo-separated locations for high availability) and on-premise environments in the event of an accessibility disruptions.
target:
status:
state: not-satisfied
Expand Down Expand Up @@ -2076,7 +2076,7 @@ assessment-results:
type: objective-id
title: 'Validation Result - Component:3127D34A-517B-473B-83B0-6536179ABE38 / Control Implementation: 5108E5FC-C45F-477B-8542-9C5611A92485 / Control: cp-9.2'
uuid: 2134ba61-df24-4258-80fc-a406ee86e4df
- description: Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availibility) and on-premise environments.
- description: Velero supports back-ups to multiple cloud environments (including geo-separated locations for high availability) and on-premise environments.
target:
status:
state: not-satisfied
Expand Down
Loading

0 comments on commit c3a2f62

Please sign in to comment.