Skip to content

Commit

Permalink
GH Actions: add new check with additional QA for markdown files
Browse files Browse the repository at this point in the history
While MarkdownLint is absolutely great for finding formatting issues, Remark offers some additional "rules" which are useful, such as checking that links and link definitions match up, verifying all used links work and some additional formatting checks which markdownlint just doesn't offer.

An extensive effort has been made to prevent duplication of messages between the Markdownlint and the Remark check. This includes ensuring there are no conflicting rules.

The rule configuration is contained in the `.remarkrc` file.

Files/directories to be ignored can be listed in the `.remarkignore` file which supports glob syntax, like `.gitignore`.
Note: `.`-prefixed files and directories are excluded by default. To include those in the scan, they have to be passed explicitly on the command-line.

To run locally, follow the same steps as per the GitHub actions workflow.

Note: the workflow contains a double-run of remark-lint to allow viewing the results both in a human readable way in the actions transscripts, as well as getting annotations for found issue in PRs.

Refs:
* https://github.com/remarkjs/remark/tree/main/packages/remark-cli
* https://github.com/remarkjs/remark-lint
* https://github.com/remarkjs/remark-gfm
* https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent
* https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-recommended
* https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide

Additional (external) plugins included:
* https://github.com/vhf/remark-lint-heading-whitespace
* https://github.com/wemake-services/remark-lint-list-item-punctuation
* https://github.com/laysent/remark-lint-plugins/tree/HEAD/packages/remark-lint-match-punctuation
* https://github.com/olizilla/remark-lint-no-hr-after-heading
* https://github.com/wemake-services/remark-lint-are-links-valid
* https://github.com/remarkjs/remark-validate-links
  • Loading branch information
jrfnl committed Apr 19, 2022
1 parent d94fbc4 commit 1c7d576
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/basics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,65 @@ jobs:

- name: Check markdown with CLI2
run: markdownlint-cli2

remark:
name: 'QA Markdown'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up node and enable caching of dependencies
uses: actions/setup-node@v3
with:
node-version: '16'

# To make the command available on CLI, it needs to be installed globally.
- name: Install Remark CLI globally
run: npm install --global remark-cli --foreground-scripts true --fund false

# To allow for creating a custom config which references rules which are included
# in the presets, without having to install all rules individually, a local install
# works best (and installing the presets in the first place, of course).
#
# Note: the first group of packages are all part of the mono "Remark lint" repo.
# The second group of packages (heading-whitespace and down) are additional
# "external" rules/plugins.
- name: Install Remark rules locally
run: >
npm install --foreground-scripts true --fund false
remark-lint
remark-gfm
remark-preset-lint-consistent
remark-preset-lint-recommended
remark-preset-lint-markdown-style-guide
remark-lint-checkbox-content-indent
remark-lint-linebreak-style
remark-lint-no-duplicate-defined-urls
remark-lint-no-empty-url
remark-lint-no-heading-like-paragraph
remark-lint-no-reference-like-url
remark-lint-no-unneeded-full-reference-image
remark-lint-no-unneeded-full-reference-link
remark-lint-strikethrough-marker
remark-lint-heading-whitespace
remark-lint-list-item-punctuation
remark-lint-match-punctuation
remark-lint-no-hr-after-heading
remark-lint-are-links-valid-alive
remark-lint-are-links-valid-duplicate
remark-validate-links
- name: Run Remark-lint
run: remark . --frail

# @link https://github.com/reviewdog/action-remark-lint
- name: Show Remark-lint annotations in PR
if: ${{ failure() && github.event_name == 'pull_request' }}
uses: reviewdog/action-remark-lint@v5
with:
fail_on_error: true
install_deps: false
level: info
reporter: github-pr-check
6 changes: 6 additions & 0 deletions .remarkignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore rules for Remark.
# Docs: https://github.com/unifiedjs/unified-engine/blob/HEAD/doc/ignore.md

/docs/index.md
/node_modules/
/vendor/
36 changes: 36 additions & 0 deletions .remarkrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"plugins": [
"remark-gfm",
["remark-lint-checkbox-character-style", "consistent"],
["remark-lint-checkbox-content-indent", "consistent"],
"remark-lint-definition-spacing",
"remark-lint-file-extension",
["remark-lint-linebreak-style", "unix"],
["remark-lint-link-title-style", "\""],
["remark-lint-ordered-list-marker-style", "."],
"remark-lint-no-duplicate-defined-urls",
"remark-lint-no-duplicate-definitions",
"remark-lint-no-empty-url",
"remark-lint-no-file-name-consecutive-dashes",
"remark-lint-no-file-name-irregular-characters",
"remark-lint-no-file-name-outer-dashes",
"remark-lint-no-heading-like-paragraph",
"remark-lint-no-literal-urls",
"remark-lint-no-reference-like-url",
"remark-lint-no-shortcut-reference-image",
"remark-lint-no-table-indentation",
"remark-lint-no-undefined-references",
"remark-lint-no-unneeded-full-reference-image",
"remark-lint-no-unneeded-full-reference-link",
"remark-lint-no-unused-definitions",
["remark-lint-strikethrough-marker", "~~"],
["remark-lint-table-cell-padding", "consistent"],
"remark-lint-heading-whitespace",
"remark-lint-list-item-punctuation",
"remark-lint-match-punctuation",
"remark-lint-no-hr-after-heading",
"remark-lint-are-links-valid-alive",
"remark-lint-are-links-valid-duplicate",
"remark-validate-links"
]
}

0 comments on commit 1c7d576

Please sign in to comment.