Skip to content

Commit

Permalink
enhancement: YAMLLINT using --strict causes error and incorrect error…
Browse files Browse the repository at this point in the history
… count (#3612)
  • Loading branch information
TommyE123 authored Jun 10, 2024
1 parent a53e391 commit 461ed33
Show file tree
Hide file tree
Showing 20 changed files with 377 additions and 53 deletions.
44 changes: 44 additions & 0 deletions .automation/test/yaml/bad/yml_bad_01.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#####################
#####################
## Azure Pipelines ##
#####################
#####################

# Error: 6:1 [trailing-spaces] trailing spaces
trigger: main
# Warning: 8:1 [document-start] missing document start "---"

pool:
vmImage: 'ubuntu-latest'
jobs:
- job: Build
# Error: trailing-spaces] trailing spaces

steps:
- task: UseNode@1
inputs:
versionSpec: 12.x
checkLatest: true
empty:
# Error: [indentation] wrong indentation: expected 2 but found 0

- job: Test
steps:

# Error: [empty-lines] too many blank lines (3 > 2)



- script: npm install
# Error: [indentation] wrong indentation: expected 4 but found 2
- script: npm test
- script: echo "Testing!"

# Error: [trailing-spaces] trailing spaces


# Error: [indentation] wrong indentation: expected 4 but found 2
- script: npm test
# Error: [empty-lines] too many blank lines (1 > 0)


28 changes: 28 additions & 0 deletions .automation/test/yaml/bad/yml_bad_02.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#####################
#####################
## GitHub Actions ##
#####################
#####################

# Rule: document-start - Missing document start marker
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest # Rule: trailing-spaces - Trailing spaces are disallowed
steps:
- uses: actions/checkout@v2 # Rule: indentation - Expected 6 spaces but found 5
- name: Run a one-line script # Rule: syntax - Expected <block end>, but found '-'
# Rule: trailing-spaces - Trailing spaces are disallowed
run: echo Hello, world!
- name: Two-line script
run: |
echo Add other actions to build,
echo test
- name: Three-line script
run: |
echo Line 1
echo Line 2 # Rule: indentation - Expected 6 spaces but found 5
echo Line 3 # Rule: trailing-spaces - Trailing spaces are disallowed
# Rule: empty-lines - Too many blank lines (1 > 0)

26 changes: 26 additions & 0 deletions .automation/test/yaml/bad/yml_bad_03.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#####################
#####################
##### GitLab CI #####
#####################
#####################

# Rule: document-start - Missing document start marker
stages:
# Rule: wrong indentation: expected at least 1
- build
- test
build_job:
stage: build
script:
- echo "Building..." # Rule: trailing-spaces - Trailing spaces are disallowed
# Rule: syntax error: expected <block end>, but found '<block sequence start>' (syntax)
- echo "Build complete!" # Rule: empty-lines - Empty lines in a block avoided
test_job:
stage: test
script:
- echo "Testing..."
- # Rule: empty-values - Empty values should be avoided
- echo "Test complete!"
- echo "Another test"
# Rule: empty-lines - Too many blank lines (1 > 0)

40 changes: 40 additions & 0 deletions .automation/test/yaml/bad/yml_bad_04.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
########################
########################
## Data Serialization ##
########################
########################

# Rule: document-start - Missing document start marker
# Rule: empty-lines - Too many blank lines (4 > 2)




data:
- id: 1
name: John Doe
- id: 2
name: Jane Smith
- id: 3
- &anchor
foo: bar
# Rule: anchors - found undeclared alias "unknown"
- <<: *unknown
extra: value
- &anchor Foo Bar
- &anchor [item 1, item 2]
- items:
- item1
- item2
name: Alice Johnson # Rule: indentation - Inconsistent indentation
address:
# Rule: trailing-spaces - Trailing spaces are disallowed
street: 123 Main St
city: Anytown
zip: 12345
state: CA
country: USA
garage: { key1: 4, key2: 8 }
phone:
# Rule: empty-lines - Too many blank lines (1 > 0)

23 changes: 23 additions & 0 deletions .automation/test/yaml/bad/yml_bad_05.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##########################
##########################
## Kubernetes Manifests ##
##########################
##########################

# Rule: document-start - Missing document start marker
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mycontainer # Rule: indentation - Inconsistent indentation
image: myimage
# Rule: trailing-spaces - Trailing spaces are disallowed
ports:
- containerPort: 80 # Rule: indentation - Inconsistent indentation
- containerPort: 443 # Rule: indentation - Inconsistent indentation
- name: mysidecar
image: sidecarimage
ports:
- containerPort: 8080
25 changes: 25 additions & 0 deletions .automation/test/yaml/bad/yml_bad_06.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#######################
#######################
## Ansible Playbooks ##
#######################
#######################

# Rule: document-start - Missing document start marker
- hosts: localhost
tasks:
- name: Install package
# Rule: trailing-spaces - Trailing spaces are disallowed
apt:
name: nginx
state: present
# syntax error: expected <block end>, but found '<block sequence start>' (syntax)
- name: Start service
service: # Rule: indentation - Inconsistent indentation
name: nginx # Rule: indentation - Inconsistent indentation
state: started # Rule: indentation - Inconsistent indentation
- hosts: all
tasks:
- name: Echo message
command: echo "Hello World"
# Rule: empty-lines - Too many blank lines (1 > 0)

27 changes: 27 additions & 0 deletions .automation/test/yaml/bad/yml_bad_07.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################
########################
## Configuration File ##
########################
########################

# Rule: document-start - Missing document start marker
database:
host: localhost
port: 5432
user: admin
password: admin
server:
host: 0.0.0.0
port: 8080
ssl:
enabled: true
certificate: /path/to/cert.pem
key: /path/to/key.pem
# Rule: trailing-spaces - Trailing spaces are disallowed
logging:
level: DEBUG # Rule: indentation - Inconsistent indentation
# syntax error: expected <block end>, but found '<block sequence start>' (syntax)
file: /var/log/webapp.log
features:
enable_feature_x: True
enable_feature_y: false
File renamed without changes.
25 changes: 25 additions & 0 deletions .automation/test/yaml/good/yml_good_01.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#####################
#####################
## Azure Pipelines ##
#####################
#####################
---
trigger:
- main

pool:
vmImage: "ubuntu-latest"

jobs:
- job: Build
steps:
- task: UseNode@1
inputs:
versionSpec: "12.x"
checkLatest: true

- job: Test
steps:
- script: npm install
- script: npm test
- script: echo "Testing!"
24 changes: 24 additions & 0 deletions .automation/test/yaml/good/yml_good_02.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#####################
#####################
## GitHub Actions ##
#####################
#####################
---
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo Hello, world!
- name: Two-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
- name: Three-line script
run: |
echo Line 1
echo Line 2
echo Line 3
22 changes: 22 additions & 0 deletions .automation/test/yaml/good/yml_good_03.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#####################
#####################
##### GitLab CI #####
#####################
#####################
---
stages:
- build
- test

build_job:
stage: build
script:
- echo "Building..."
- echo "Build complete!"

test_job:
stage: test
script:
- echo "Testing..."
- echo "Test complete!"
- echo "Another test"
20 changes: 20 additions & 0 deletions .automation/test/yaml/good/yml_good_04.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
########################
########################
## Data Serialization ##
########################
########################
---
data:
- id: 1
name: John Doe
- id: 2
name: Jane Smith
- id: 3
name: Alice Johnson

address:
street: 123 Main St
city: Anytown
zip: 12345
state: CA
country: USA
21 changes: 21 additions & 0 deletions .automation/test/yaml/good/yml_good_05.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##########################
##########################
## Kubernetes Manifests ##
##########################
##########################
---
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mycontainer
image: myimage
ports:
- containerPort: 80
- containerPort: 443
- name: mysidecar
image: sidecarimage
ports:
- containerPort: 8080
21 changes: 21 additions & 0 deletions .automation/test/yaml/good/yml_good_06.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#######################
#######################
## Ansible Playbooks ##
#######################
#######################
---
- hosts: localhost
tasks:
- name: Install package
apt:
name: nginx
state: present
- name: Start service
service:
name: nginx
state: started

- hosts: all
tasks:
- name: Echo message
command: echo "Hello World"
27 changes: 27 additions & 0 deletions .automation/test/yaml/good/yml_good_07.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################
########################
## Configuration File ##
########################
########################
---
database:
host: localhost
port: 5432
user: admin
password: admin

server:
host: 0.0.0.0
port: 8080
ssl:
enabled: true
certificate: /path/to/cert.pem
key: /path/to/key.pem

logging:
level: DEBUG
file: /var/log/webapp.log

features:
enable_feature_x: true
enable_feature_y: false
Loading

0 comments on commit 461ed33

Please sign in to comment.