Skip to content
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

Add linting of source in markdown files #19518

Merged
merged 6 commits into from
Jan 9, 2020
Merged

Add linting of source in markdown files #19518

merged 6 commits into from
Jan 9, 2020

Conversation

mkaz
Copy link
Member

@mkaz mkaz commented Jan 8, 2020

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 and no-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:

✖ 2103 problems (2090 errors, 13 warnings)

How has this been tested?

  1. Test by applying this PR
  2. Run: npm install to install new packages

To 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

  1. Adds new script lint-md to wp-scripts
  2. Adds eslint-plugin-markdown js package
  3. Adds new command lint-md to main scripts

Next 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.

Adds eslint-plugin-markdown https://github.com/eslint/eslint-plugin-markdown
This allows for linting of code blocks marked js, javascript, or jsx if
a code block is not marked it is skipped.
@mkaz mkaz self-assigned this Jan 8, 2020
@mkaz mkaz added the [Type] Developer Documentation Documentation for developers label Jan 8, 2020
@mkaz mkaz changed the title Add linting of markdown files Add linting of source in markdown files Jan 8, 2020
@ntwb
Copy link
Member

ntwb commented Jan 9, 2020

Nice, and FYI, I’m working on the coding standards docs in https://github.com/WordPress/wpcs-docs repo (No pull request yet, working on it locally) and will be creating a new package here @wordpress/remark-config for a shared config for Remark Lint to ensure markdown is compatible with the w.org handbooks and will plan on adding it also to @wordpress/scripts

@ntwb
Copy link
Member

ntwb commented Jan 9, 2020

Further, I’ll look at what stylelint options are available to support listing CSS & SCSS in markdown files too

@ntwb ntwb added the [Tool] WP Scripts /packages/scripts label Jan 9, 2020
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

This is great, thanks for opening it.

package.json Outdated Show resolved Hide resolved
packages/scripts/scripts/lint-md.js Outdated Show resolved Hide resolved
@gziolo
Copy link
Member

gziolo commented Jan 9, 2020

I think this PR addresses #12426, well at least the part for linting markdown.

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 and no-undef rules. For example, a chunk of code might show how to set something, but not necessarily using what is set.

It might end up with having two ESLint configs for wp-scripts, since we will need to disable some rules. I would say, let's start simple and disable the noisiest errors and evaluate later the next steps. I'm thinking in terms of a follow-up PR, to be clear.

mkaz and others added 4 commits January 9, 2020 10:47
Co-Authored-By: Grzegorz (Greg) Ziółkowski <grzegorz@gziolo.pl>
- Creates a new eslintrc-md.js config for use for markdown docs

- The lint-md command uses this config unless another is specified

- The config allows for undef and unused vars due to docs contain
snippets of code that may be incomplete
@mkaz mkaz merged commit 5714888 into master Jan 9, 2020
@mkaz mkaz deleted the try/lint-markdown branch January 9, 2020 20:26
@mkaz mkaz mentioned this pull request Jan 9, 2020
@ellatrix ellatrix added this to the Gutenberg 7.3 milestone Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] WP Scripts /packages/scripts [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants