Add linting of source in markdown files #19518
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds eslint-plugin-markdown and the new command
lint-md
This allows for linting of code blocks that are marked js, javascript, or jsx, if a code block is not marked as such it should be skipped.At the moment this uses the same base eslint rules, however we probably will want to adjust these rules for documentation. Most code blocks in documentation are snippets and incomplete chunks of code, so a fair amount of the current errors are due to
no-unused-vars
andno-undef
rules. For example, a chunk of code might show how to set something, but not necessarily using what is set.The first run through all docs:
How has this been tested?
npm install
to install new packagesTo run across all documentation:
3a. Run
npm lint-md
To run across a single file:
3b. $(npm bin)/wp-scripts lint-md docs/designers-developers/key-concepts.md
Types of changes
lint-md
to wp-scriptsNext Steps
We probably want to test out and adjust the rules to make sense for documentation.
Once we get it to a decent config, we can run it against the docs and fix up code that needs fixing and then include in the CI builds.