Skip to content

Add yamllint check for RST code listings #2385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-package-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: Build and deploy docs
on:
"on":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, dropping a config like https://github.com/ansible/awx-plugins/blob/e5f7468/.yamllint into the repo would allow these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally enabling on just for a handful of special YAML files sounds like a bad idea.

Copy link
Member

@webknjaz webknjaz Mar 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there's an issue about this on the tracker.
Apparently, there's an option to allow this just in YAML keys: adrienverge/yamllint#559 (comment). I'll probably go update my typical config...

UPD: the setting isn't actually there.

schedule:
# Run at 05:17 on Tuesday and Thursday
- cron: '17 5 * * 2,4'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Ansible Docsite CI

on:
"on":
schedule:
# Daily
# Daily
- cron: "23 7 * * *"
push:
branches-ignore:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/reusable-nox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
python-versions: "3.11"
- session: "checkers(rstcheck)"
python-versions: "3.11"
- session: "checkers(rst-yamllint)"
python-versions: "3.11"
- session: "checkers(docs-build)"
python-versions: "3.11"
- session: "actionlint"
Expand Down
3 changes: 3 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ check_untyped_defs = True

[mypy-ansible.*]
ignore_missing_imports = True

[mypy-yamllint.*]
ignore_missing_imports = True
68 changes: 68 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
extends: default

ignore:
- /lib/ansible/

rules:
line-length: disable
# max: 160
# level: warning
document-start: disable
document-end: disable
truthy:
level: warning
allowed-values:
- 'true'
- 'false'
- 'True'
- 'False'
- 'TRUE'
- 'FALSE'
- 'yes'
- 'no'
- 'Yes'
- 'No'
- 'YES'
- 'NO'
indentation: disable
# level: warning
# spaces: 2
# indent-sequences: consistent
key-duplicates: disable
# level: warning
# forbid-duplicated-merge-keys: true
trailing-spaces: enable
hyphens: disable
# max-spaces-after: 1
# level: warning
empty-lines:
max: 2
max-start: 0
max-end: 0
level: warning
commas: disable
# max-spaces-before: 0
# min-spaces-after: 1
# max-spaces-after: 1
# level: warning
colons: disable
# max-spaces-before: 0
# max-spaces-after: 1
# level: warning
brackets: disable
# min-spaces-inside: 0
# max-spaces-inside: 0
# level: warning
braces:
min-spaces-inside: 0
max-spaces-inside: 1
level: warning
octal-values: disable
# forbid-implicit-octal: true
# forbid-explicit-octal: true
# level: warning
comments: disable
# min-spaces-from-content: 1
# level: warning
comments-indentation: disable
2 changes: 1 addition & 1 deletion docs/docsite/rst/getting_started_ee/yaml/hosts.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
all:
hosts:
192.168.0.2 # Replace with the IP of your target host
192.168.0.2 # Replace with the IP of your target host
16 changes: 8 additions & 8 deletions docs/docsite/rst/playbook_guide/playbooks_error_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ You can reference simple variables in conditionals to avoid repeating certain te
- name: Example playbook
hosts: myHosts
vars:
log_path: /home/ansible/logfolder/
log_file: log.log
log_path: /home/ansible/logfolder/
log_file: log.log

tasks:
tasks:
- name: Create empty log file
ansible.builtin.shell: mkdir {{ log_path }} || touch {{log_path }}{{ log_file }}
register: tmp
changed_when:
- tmp.rc == 0
- 'tmp.stderr != "mkdir: cannot create directory ‘" ~ log_path ~ "’: File exists"'
ansible.builtin.shell: mkdir {{ log_path }} || touch {{log_path }}{{ log_file }}
register: tmp
changed_when:
- tmp.rc == 0
- 'tmp.stderr != "mkdir: cannot create directory ‘" ~ log_path ~ "’: File exists"'

.. note::
Notice the missing double curly braces ``{{ }}`` around the ``log_path`` variable in the ``changed_when`` statement.
Expand Down
6 changes: 3 additions & 3 deletions examples/DOCUMENTATION.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ options:
default: a string or the word null
choices:
- enable
- disable
- disable
aliases:
- repo_name
version_added: "1.X"
requirements:
- list of required things
- like the factor package
- zypper >= 1.0
seealso:
- zypper >= 1.0
seealso:
- specify references to other modules, useful guides, and so on
notes:
- other things consumers of your module should know
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"hacking/tagger/tag.py",
"noxfile.py",
*iglob("docs/bin/*.py"),
*iglob("tests/checkers/rst-yamllint*.py"), # TODO: also lint others
)
PINNED = os.environ.get("PINNED", "true").lower() in {"1", "true"}
nox.options.sessions = ("clone-core", "lint", "checkers", "make")
Expand Down
9 changes: 9 additions & 0 deletions tests/checkers/rst-yamllint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extensions": [
".rst",
".txt"
],
"ignore_regexs": [
"^docs/docsite/rst/porting_guides/porting_guide_[0-9]+\\.rst$"
]
}
Loading