Skip to content

Commit

Permalink
Add linting for yaml files (#916)
Browse files Browse the repository at this point in the history
Add yamllint to pre-commit and CI
  • Loading branch information
ciarams87 authored Aug 3, 2023
1 parent 1d615c4 commit 29fdf4a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# - run: |
# make bootstrap
# make release

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
if [ ${{ github.event_name }} == "schedule" ]; then
export GW_API_VERSION=main
export GW_API_VERSION=main
fi
make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
working-directory: ./conformance
Expand Down
25 changes: 19 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ jobs:
name: Markdown Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- uses: DavidAnson/markdownlint-cli2-action@8f3516061301755c97ff833a8e933f09282cc5b5 # v11.0.0
with:
config: ${{ github.workspace }}/.markdownlint-cli2.yaml
globs: '**/*.md'
- uses: DavidAnson/markdownlint-cli2-action@8f3516061301755c97ff833a8e933f09282cc5b5 # v11.0.0
with:
config: ${{ github.workspace }}/.markdownlint-cli2.yaml
globs: '**/*.md'

chart-lint:
name: Chart Lint
Expand All @@ -97,3 +97,16 @@ jobs:
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Lint chart
run: make lint-helm

yaml-lint:
name: Yaml Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Install yamllint
run: pip install yamllint

- name: Lint YAML files
run: yamllint .
1 change: 1 addition & 0 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Scorecards supply-chain security
on:
# Only the default branch is supported.
branch_protection_rule:
types: [created, edited, deleted]
schedule:
- cron: "27 5 * * 0"
push:
Expand Down
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ linters-settings:
min-complexity: 15
govet:
enable:
- fieldalignment
- fieldalignment
lll:
line-length: 120
linters:
enable:
enable:
- asciicheck
- errcheck
- errorlint
Expand All @@ -63,7 +63,7 @@ linters:
- unparam
- unused
- wastedassign
disable-all: true
disable-all: true
issues:
max-issues-per-linter: 0
max-same-issues: 0
Expand Down
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ repos:
- id: golangci-lint
args: [--new-from-patch=/tmp/diff.patch]

# Rules are in .markdownlint-cli2.yaml file
# See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md for rule descriptions
# Rules are in .markdownlint-cli2.yaml file
# See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md for rule descriptions
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.8.1
hooks:
- id: markdownlint-cli2-fix
- id: markdownlint-cli2-fix

# Rules are in .yamllint.yaml file
# See https://yamllint.readthedocs.io/en/stable/rules.html# for rule descriptions
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.29.0
hooks:
- id: yamllint

ci:
skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix]
skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix, yamllint]
autofix_prs: false
50 changes: 50 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---

yaml-files:
- '*.yaml'
- '*.yml'

ignore:
- deploy/helm-chart/templates/
- deploy/helm-chart/crds/

rules:
braces: enable
brackets: enable
colons: enable
commas: enable
comments:
require-starting-space: true
ignore-shebangs: true
min-spaces-from-content: 1
comments-indentation: enable
document-end: disable
document-start: disable
empty-lines: enable
empty-values: enable
float-values: disable
hyphens: enable
indentation:
spaces: consistent
indent-sequences: consistent
check-multi-line-strings: true
ignore: |
deploy/manifests/nginx-gateway.yaml
deploy/manifests/njs-modules.yaml
key-duplicates: enable
key-ordering: disable
line-length:
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
ignore: |
.github/workflows/
deploy/manifests/nginx-gateway.yaml
new-line-at-end-of-file: enable
new-lines: enable
octal-values: disable
quoted-strings: disable
trailing-spaces: enable
truthy:
ignore: |
.github/workflows/
2 changes: 1 addition & 1 deletion examples/http-header-filter/echo-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
add:
- name: Accept-Encoding
value: compress
- name: My-cool-header
- name: My-cool-header
value: this-is-an-appended-value
remove:
- User-Agent
Expand Down
3 changes: 2 additions & 1 deletion examples/http-header-filter/headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: headers-config
# yamllint disable rule:indentation
data:
nginx.conf: |-
user nginx;
Expand Down Expand Up @@ -61,7 +62,7 @@ data:
return s;
}
export default {getRequestHeaders};
# yamllint enable rule:indentation
---
apiVersion: v1
kind: Service
Expand Down

0 comments on commit 29fdf4a

Please sign in to comment.