Skip to content

Commit b2af933

Browse files
committed
GH Actions: add new check for consistency in markdown files
This new check uses the NPM MarkdownLint-CLI2 package via the `DavidAnson/markdownlint-cli2-action` action runner from the same maintainer. It executes a loose check for consistency and some common errors. Some of the more annoying rules/rules which could impact display of markdown files on GitHub have been disabled. All necessary configuration is contained in the `.markdownlint-cli2.yaml` file. To run locally, install via: ```bash npm install -g markdownlint-cli2 ``` ... and then run via: ```bash markdownlint-cli2 ``` Includes a problem matcher which _should_ allow for displaying the results inline in GitHub PR code review view. Includes adding `node_modules` to the `.gitignore` in case anyone would install these tools locally (to prevent them committing them). Refs: * https://github.com/DavidAnson/markdownlint * https://github.com/DavidAnson/markdownlint-cli2 * https://github.com/marketplace/actions/markdownlint-cli2-action
1 parent 8f4eb98 commit b2af933

File tree

4 files changed

+139
-12
lines changed

4 files changed

+139
-12
lines changed

.gitattributes

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production/
66
# https://blog.madewithlove.be/post/gitattributes/
77
#
8-
.github/ export-ignore
9-
scripts/ export-ignore
10-
.cspell.json export-ignore
11-
.gitattributes export-ignore
12-
.gitignore export-ignore
13-
.yamllint.yml export-ignore
14-
phpcs.xml.dist export-ignore
15-
phpstan.neon.dist export-ignore
16-
phpunit.xml.dist export-ignore
8+
.github/ export-ignore
9+
scripts/ export-ignore
10+
.cspell.json export-ignore
11+
.gitattributes export-ignore
12+
.gitignore export-ignore
13+
.markdownlint-cli2.yaml export-ignore
14+
.yamllint.yml export-ignore
15+
phpcs.xml.dist export-ignore
16+
phpstan.neon.dist export-ignore
17+
phpunit.xml.dist export-ignore
1718

1819
#
1920
# Declare files that should always have CRLF line endings on checkout.

.github/workflows/validate.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ name: Validate
22

33
on:
44
# Run on all pushes and on all pull requests.
5-
# Prevent the build from running when there are only irrelevant changes.
65
push:
7-
paths-ignore:
8-
- '**.md'
96
pull_request:
107
# Allow manually triggering the workflow.
118
workflow_dispatch:
@@ -78,3 +75,22 @@ jobs:
7875
- name: Pipe Yamllint results on to GH for inline display
7976
if: ${{ failure() }}
8077
run: yamllint . --format github --strict
78+
79+
markdownlint:
80+
name: 'Lint Markdown'
81+
runs-on: ubuntu-latest
82+
83+
# Don't run the cronjob in this workflow on forks.
84+
if: github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'PHPCSStandards')
85+
86+
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v4
89+
90+
# @link https://github.com/marketplace/actions/problem-matcher-for-markdownlint-cli
91+
- name: Enable showing issue in PRs
92+
uses: xt0rted/markdownlint-problem-matcher@v3
93+
94+
# @link https://github.com/marketplace/actions/markdownlint-cli2-action
95+
- name: Check markdown with CLI2
96+
uses: DavidAnson/markdownlint-cli2-action@v16

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/vendor/
88
composer.lock
99
phpstan.neon
10+
/node_modules/

.markdownlint-cli2.yaml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#
2+
# Configuration file for MarkdownLint-CLI2.
3+
#
4+
# Example file with all options:
5+
# https://github.com/DavidAnson/markdownlint-cli2/blob/main/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml
6+
# Example file with all rules:
7+
# https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
8+
#
9+
10+
# Define glob expressions to use (only valid at root).
11+
globs:
12+
- "**/*.md"
13+
- ".github/**/*.md"
14+
15+
# Show found files on stdout (only valid at root)
16+
showFound: true
17+
18+
# Define glob expressions to ignore.
19+
ignores:
20+
- "node_modules/"
21+
- "vendor/"
22+
23+
# Disable inline config comments.
24+
noInlineConfig: true
25+
26+
# Disable progress on stdout (only valid at root).
27+
noProgress: false
28+
29+
# Adjust the configuration for some built-in rules.
30+
# For full information on the options and defaults, see:
31+
# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
32+
config:
33+
######################
34+
# Disable a few rules.
35+
######################
36+
# MD031/blanks-around-fences - Fenced code blocks should be surrounded by blank lines.
37+
MD031: false
38+
# MD032/blanks-around-lists - Lists should be surrounded by blank lines.
39+
MD032: false
40+
41+
##############################
42+
# Customize a few other rules.
43+
##############################
44+
# MD003/heading-style/header-style - Heading style.
45+
MD003:
46+
# Heading style - Always use hashes.
47+
style: "atx"
48+
49+
# MD007/ul-indent - Unordered list indentation.
50+
MD007:
51+
indent: 4
52+
# Whether to indent the first level of the list.
53+
start_indented: false
54+
55+
# MD012/no-multiple-blanks - Multiple consecutive blank lines.
56+
MD012:
57+
maximum: 2
58+
59+
# MD013/line-length - Line length.
60+
MD013:
61+
# Number of characters. No need for being too fussy.
62+
line_length: 1000
63+
# Number of characters for headings.
64+
heading_line_length: 100
65+
# Number of characters for code blocks.
66+
code_block_line_length: 100
67+
# Stern length checking (applies to tables, code blocks etc which have their own max line length).
68+
stern: true
69+
70+
# MD022/blanks-around-headings : Headings should be surrounded by blank lines : https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md022.md
71+
MD022:
72+
# Blank lines above heading
73+
lines_above: [2, 1, 1, 1, 1]
74+
# Blank lines below heading
75+
lines_below: [1, 1, -1, -1, -1]
76+
77+
# MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content.
78+
MD024:
79+
# Only check sibling headings.
80+
siblings_only: true
81+
82+
# MD033/no-inline-html - Inline HTML.
83+
MD033:
84+
# Allowed elements.
85+
allowed_elements:
86+
- div
87+
88+
# MD044/proper-names - Proper names should have the correct capitalization.
89+
MD044:
90+
# List of proper names.
91+
names: ["PHP", "PHP_CodeSniffer", "CodeSniffer", "PHPUnit", "Xdebug"]
92+
# Include code blocks.
93+
code_blocks: false
94+
95+
# MD046/code-block-style - Code block style
96+
MD046:
97+
style: "fenced"
98+
99+
# MD048/code-fence-style - Code fence style
100+
MD048:
101+
style: "backtick"
102+
103+
# MD049/emphasis-style - Emphasis style should be consistent
104+
MD049:
105+
style: "underscore"
106+
107+
# MD050/strong-style - Strong style should be consistent
108+
MD050:
109+
style: "asterisk"

0 commit comments

Comments
 (0)