Skip to content

Commit c7f6e9c

Browse files
committed
Add linting for yaml files (nginx#916)
Add yamllint to pre-commit and CI
1 parent fceaaf4 commit c7f6e9c

File tree

9 files changed

+89
-17
lines changed

9 files changed

+89
-17
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
# and modify them (or add more) to build your code if your project
6363
# uses a compiled language
6464

65-
#- run: |
65+
# - run: |
6666
# make bootstrap
6767
# make release
6868

.github/workflows/conformance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
108108
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
109109
if [ ${{ github.event_name }} == "schedule" ]; then
110-
export GW_API_VERSION=main
110+
export GW_API_VERSION=main
111111
fi
112112
make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
113113
working-directory: ./conformance

.github/workflows/lint.yml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ jobs:
8181
name: Markdown Lint
8282
runs-on: ubuntu-22.04
8383
steps:
84-
- name: Checkout Repository
85-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
84+
- name: Checkout Repository
85+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
8686

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

9292
chart-lint:
9393
name: Chart Lint
@@ -97,3 +97,16 @@ jobs:
9797
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
9898
- name: Lint chart
9999
run: make lint-helm
100+
101+
yaml-lint:
102+
name: Yaml Lint
103+
runs-on: ubuntu-22.04
104+
steps:
105+
- name: Checkout Repository
106+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
107+
108+
- name: Install yamllint
109+
run: pip install yamllint
110+
111+
- name: Lint YAML files
112+
run: yamllint .

.github/workflows/scorecards.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Scorecards supply-chain security
22
on:
33
# Only the default branch is supported.
44
branch_protection_rule:
5+
types: [created, edited, deleted]
56
schedule:
67
- cron: "27 5 * * 0"
78
push:

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ linters-settings:
3434
min-complexity: 15
3535
govet:
3636
enable:
37-
- fieldalignment
37+
- fieldalignment
3838
lll:
3939
line-length: 120
4040
linters:
41-
enable:
41+
enable:
4242
- asciicheck
4343
- errcheck
4444
- errorlint
@@ -63,7 +63,7 @@ linters:
6363
- unparam
6464
- unused
6565
- wastedassign
66-
disable-all: true
66+
disable-all: true
6767
issues:
6868
max-issues-per-linter: 0
6969
max-same-issues: 0

.pre-commit-config.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,20 @@ repos:
4949
- id: golangci-lint
5050
args: [--new-from-patch=/tmp/diff.patch]
5151

52-
# Rules are in .markdownlint-cli2.yaml file
53-
# See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md for rule descriptions
52+
# Rules are in .markdownlint-cli2.yaml file
53+
# See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md for rule descriptions
5454
- repo: https://github.com/DavidAnson/markdownlint-cli2
5555
rev: v0.8.1
5656
hooks:
57-
- id: markdownlint-cli2-fix
57+
- id: markdownlint-cli2-fix
58+
59+
# Rules are in .yamllint.yaml file
60+
# See https://yamllint.readthedocs.io/en/stable/rules.html# for rule descriptions
61+
- repo: https://github.com/adrienverge/yamllint.git
62+
rev: v1.29.0
63+
hooks:
64+
- id: yamllint
5865

5966
ci:
60-
skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix]
67+
skip: [golang-diff, golangci-lint, prettier, markdownlint-cli2-fix, yamllint]
6168
autofix_prs: false

.yamllint.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
3+
yaml-files:
4+
- '*.yaml'
5+
- '*.yml'
6+
7+
ignore:
8+
- deploy/helm-chart/templates/
9+
- deploy/helm-chart/crds/
10+
11+
rules:
12+
braces: enable
13+
brackets: enable
14+
colons: enable
15+
commas: enable
16+
comments:
17+
require-starting-space: true
18+
ignore-shebangs: true
19+
min-spaces-from-content: 1
20+
comments-indentation: enable
21+
document-end: disable
22+
document-start: disable
23+
empty-lines: enable
24+
empty-values: enable
25+
float-values: disable
26+
hyphens: enable
27+
indentation:
28+
spaces: consistent
29+
indent-sequences: consistent
30+
check-multi-line-strings: true
31+
ignore: |
32+
deploy/manifests/nginx-gateway.yaml
33+
deploy/manifests/njs-modules.yaml
34+
key-duplicates: enable
35+
key-ordering: disable
36+
line-length:
37+
max: 120
38+
allow-non-breakable-words: true
39+
allow-non-breakable-inline-mappings: true
40+
ignore: |
41+
.github/workflows/
42+
deploy/manifests/nginx-gateway.yaml
43+
new-line-at-end-of-file: enable
44+
new-lines: enable
45+
octal-values: disable
46+
quoted-strings: disable
47+
trailing-spaces: enable
48+
truthy:
49+
ignore: |
50+
.github/workflows/

examples/http-header-filter/echo-route.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ spec:
2222
add:
2323
- name: Accept-Encoding
2424
value: compress
25-
- name: My-cool-header
25+
- name: My-cool-header
2626
value: this-is-an-appended-value
2727
remove:
2828
- User-Agent

examples/http-header-filter/headers.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ apiVersion: v1
3030
kind: ConfigMap
3131
metadata:
3232
name: headers-config
33+
# yamllint disable rule:indentation
3334
data:
3435
nginx.conf: |-
3536
user nginx;
@@ -61,7 +62,7 @@ data:
6162
return s;
6263
}
6364
export default {getRequestHeaders};
64-
65+
# yamllint enable rule:indentation
6566
---
6667
apiVersion: v1
6768
kind: Service

0 commit comments

Comments
 (0)