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 markdown linting #66

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Add markdown linting #66

wants to merge 8 commits into from

Conversation

ntwb
Copy link
Member

@ntwb ntwb commented May 2, 2022

As promised, pretty much a zero-config markdown linting setup...

I opted for Node.js LTS (currently v16.x) as it should facilitate less maintenance of this in the repo, it should work just fine on Node.js v14 too.

To test: npm install & npm test or npm i && npm t

Also, I added a basic GitHub Action to run the task on each pull request and merge to master branch, we should rename this branch to trunk to BTW https://github.com/WordPress/wpcs-docs/actions/workflows/lint.yml

Jest v28 released last week added support for a GitHub Actions Reporter, so once Gutenberg has upgrade to Jest v28 we should be able to also take advantage of line comments reporting from GitHub Actions in the future, it might require a couple of tweaks to be slightly less zero-config

Until all the outstanding lint issues are fixed, GitHub Actions check will fail, but it's not too much to resolve as #65 covers a lot of these changes

@ntwb ntwb marked this pull request as ready for review May 2, 2022 04:59
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Hi @ntwb Thanks for preparing this.

Please don't take my criticism too much to heart, but to me this feels very over the top with 1300 (!!!) Node packages being installed and a 28K line package.json file, while only 36 packages are actually needed for markdownlint.

The hammer vs screwdriver argument comes to mind.

Also, while I appreciate your "zero-config" intentions, it actually is not. You are just "cheating" and re-using a config defined elsewhere, which we have no control over and no influence on (which kind of makes me uncomfortable).

As for the config which is actually used, this config is highly susceptible to the problems I pointed out earlier in #65 (comment):

markdownlint has a default of consistent for a lot of settings, which means it will take the first emphasis marker/bold marker/list marker etc as the "truth" and will demand the rest of the docs follows.
For proper consistent docs, those defaults should be changed as adding a new document, which "happens" to be be scanned first, could otherwise lead to markdownlint demanding all docs to be updated for "consistency".

Other than that:

  • Does the package.json file need to be committed ? Probably a naive question, but this is not a Node project, we are just using a Node tool for QA, so having this committed to the repo would very much misrepresent the project.

We should rename this branch to trunk to BTW

Why ?

Jest v28 released last week added support for a GitHub Actions Reporter, so once Gutenberg has upgrade to Jest v28 we should be able to also take advantage of line comments reporting from GitHub Actions in the future, it might require a couple of tweaks to be slightly less zero-config

No need to wait for that. You can use the below snippet in the GH Actions workflow to achieve the same:

      # @link https://github.com/marketplace/actions/problem-matcher-for-markdownlint-cli
      - name: Enable showing issues in PRs
        uses: xt0rted/markdownlint-problem-matcher@v1

Comment on lines +24 to +30
- name: Setup Cache
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
Copy link
Member

Choose a reason for hiding this comment

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

IIRC this should be unnecessary. The setup-node action has caching build in. Any particular reason why the caching from setup-node isn't sufficient ?

Copy link
Member Author

Choose a reason for hiding this comment

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

No reason, I thought they were separate so I did it separately

Comment on lines +19 to +21
"devDependencies": {
"@wordpress/scripts": "^22"
},
Copy link
Member

Choose a reason for hiding this comment

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

Why are we using this package instead of the markdownlint package ? (also see my remarks about the config in wordpress/scripts)

Copy link
Member

Choose a reason for hiding this comment

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

I have to agree with Juliette here, the wp scripts package will download 349MB node modules worth of packages for just one package that we need. It seems like an overkill IMO :/

package.json Outdated
"bugs": {
"url": "https://github.com/WordPress/wpcs-docs/issues"
},
"main": "index.js",
Copy link
Member

Choose a reason for hiding this comment

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

There is no index.js file in this repo, so what does this refer to ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed in 7296ab4

Comment on lines +22 to +24
"scripts": {
"test": "wp-scripts lint-md-docs"
}
Copy link
Member

Choose a reason for hiding this comment

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

To me, this feels very much like obfuscating what's going on. What is wp-scripts ? Why is this called test ? (it's not running tests, it's checking markdown code style) What does the lint-md-docs script(?) do ? And how is it configured ?

Can we please just stick to the necessities instead of pulling in frameworks with overhead we don't need ?

key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
Copy link
Member

Choose a reason for hiding this comment

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

What does this do ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It installs dependencies from the lock file, that way what is installed are known package versions, it prevents unknown package versions from being installed and is faster for CI services than npm install

Comment on lines +7 to +9
"keywords": [
"wordpress"
],
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if using the wordpress keyword isn't a bit misleading. Are keywords required ? If not, can we just leave this out ?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's from the standard WordPress template for package.json files, so not much thought was given to all this, it will never be published to npmjs.com so is moot for the most part

Copy link
Member

Choose a reason for hiding this comment

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

In that case, can we strip down the package.json to the essentials ? As everything else is moot anyway.

"keywords": [
"wordpress"
],
"homepage": "https://github.com/WordPress/wpcs-docs#readme",
Copy link
Member

Choose a reason for hiding this comment

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

Should this point to the canonical WPCS docs URL in Make ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Moot as well, will never be used because the package will never be published,but npm likes to have a somewhat feature-complete file with these fields.

If someone ever wants to run npm home it will open that URL for you though....

README.md Outdated Show resolved Hide resolved

on:
push:
branches: [master]
Copy link
Member

Choose a reason for hiding this comment

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

Why is branch selection being used ? Feels unnecessary/inhibiting as this action should always run.

Branch selection on push prevents someone from seeing any markdown errors before creating a PR, which generally leads to lots of "Fix code style" commits, which I'd much rather ban altogether.

Branch selection on pull prevents the same for cumulative branches.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, should we remove this entire section then? This has always been a bit of a mystery to me this branch foo in GA

Copy link
Member

Choose a reason for hiding this comment

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

Not the entire section, IMO, it should probably read like this:

on:
  push:
  pull_request:
  # Also allow manually triggering the workflow.
  workflow_dispatch:

@ntwb ntwb mentioned this pull request May 2, 2022
@jrfnl
Copy link
Member

jrfnl commented May 2, 2022

Regarding the workflow - might also be good to add this (below on, above jobs):

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
  # The concurrency group contains the workflow name and the branch name.
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

@ntwb
Copy link
Member Author

ntwb commented May 2, 2022

Note: I'm drafting a longer comment about a hill I'm willing to die on, I'll share why I chose this approach shortly 😏


Other than that:

  • Does the package.json file need to be committed ? Probably a naive question, but this is not a Node project, we are just using a Node tool for QA, so having this committed to the repo would very much misrepresent the project.

Yes, it does, It's a trivial way to have the ability to install packages locally without adding additional tooling, be it good or bad, the majority of WordPress development requires PHP & JS tooling to be installed these days, and I'd like this tooling for this repo to be available to devs locally and not just in GitHub Actions, and this is a quick and easy way to use tooling most WordPress developers would already have installed on their local machine.


We should rename this branch to trunk to BTW

Why ?

This was documented and decided here on make/core some time ago:
https://make.wordpress.org/core/2020/06/18/proposal-update-all-git-repositories-to-use-main-instead-of-master/

@jrfnl
Copy link
Member

jrfnl commented May 2, 2022

Note: I'm drafting a longer comment about a hill I'm willing to die on, I'll share why I chose this approach shortly 😏

Eagerly waiting to see your arguments. 😇

  • Does the package.json file need to be committed ? Probably a naive question, but this is not a Node project, we are just using a Node tool for QA, so having this committed to the repo would very much misrepresent the project.

Yes, it does, It's a trivial way to have the ability to install packages locally without adding additional tooling, be it good or bad, the majority of WordPress development requires PHP & JS tooling to be installed these days, and I'd like this tooling for this repo to be available to devs locally and not just in GitHub Actions, and this is a quick and easy way to use tooling most WordPress developers would already have installed on their local machine.

Sorry, my bad - I meant the package.lock file....

The package.json file I understand as it defines the dependencies. The package.lock file, I don't understand as just for using markdownlint, we shouldn't be too strictly bound to a specific version anyway (other than just latest). And if we do want to be bound to a specific version, it should be straight-forward to fix that via the package.json.

We should rename this branch to trunk to BTW

Why ?

This was documented and decided here on make/core some time ago: https://make.wordpress.org/core/2020/06/18/proposal-update-all-git-repositories-to-use-main-instead-of-master/

Ah yes, but this isn't really a code repo and I wonder if renaming the branch wouldn't break the auto-updating of the docs in the manual.

@ntwb
Copy link
Member Author

ntwb commented May 2, 2022

Ah yes, but this isn't really a code repo and I wonder if renaming the branch wouldn't break the auto-updating of the docs in the manual.

Nice catch, this will need updating at some point, but GitHub automatically sets up redirects so we should be safe:

https://github.com/WordPress/wordpress.org/blob/4ca46fdfef77f45b166e98b402c24082d78689e4/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/import-coding-standards.php#L11

But we can coordinate this with the meta team and get this change committed at the same time (I can handle that commit, I think)

@ntwb
Copy link
Member Author

ntwb commented May 2, 2022

Thanks @jrfnl

Please don't take my criticism too much to heart, but to me this feels very over the top with 1300 (!!!) Node packages being installed and a 28K line package.json file, while only 36 packages are actually needed for markdownlint.

The hammer vs screwdriver argument comes to mind.

Also, while I appreciate your "zero-config" intentions, it actually is not. You are just "cheating" and re-using a config defined elsewhere, which we have no control over and no influence on (which kind of makes me uncomfortable).

Thanks @jrfnl, your feedback is always welcome and always appreciated 💯

Jest

Jest v28 released last week added support for a GitHub Actions Reporter, so once Gutenberg has upgrade to Jest v28 we should be able to also take advantage of line comments reporting from GitHub Actions in the future, it might require a couple of tweaks to be slightly less zero-config

No need to wait for that. You can use the below snippet in the GH Actions workflow to achieve the same:

Potentially we can look at this change later, but I prefer to use the Jest option I've referenced because of the tight integration into the @wordpress/scripts package and it's use in Gutenberg. (more on this below)

@wordpress/scripts

The @wordpress/scripts package is a long term WordPress project, the original incarnation of this began ~5 years ago which is now archived at https://github.com/wordpress/packages.

Around ~4 years we archived the packages repo and migrated it into the Gutenberg repo and it became the foundation to what is now the @wordpress/scripts package, it's worth citing the opening readme here for additional context:

https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/README.md

This is a collection of reusable scripts tailored for WordPress development. For convenience, every tool provided in this package comes with an integrated recommended configuration.

When working seamlessly, sophisticated command-line interfaces help to turn work with a project into a more pleasant experience. However, it’s a misleading assumption that developers can easily pick the proper tools in the first place and then ensure that they play along with each other, including all their extensions. Besides, it’s still not enough because developers are left on their own to keep all configurations and dependent tools up to date. This problem multiplies when they support more than one project which shares the same setup.

Fortunately, there is a pattern that can simplify maintainers life – reusable scripts. The idea boils down to moving all the necessary configurations and scripts to one single tool dependency. In most cases, it should be possible to accomplish all tasks using the default settings, but some customization is allowed, too. With all that in place, updating all projects should become a very straightforward task.

The @wordpress/scripts package is canonical home of the WordPress JavaScript & CSS coding standard configurations that are published to npmjs.com for reuse with ESLint and Stylelint, @worpress/scripts also includes Markdownlint config, Prettier config, NPM Package Lint, and various other cli utilities.

Hence, this is where that unfamiliar syntax for the npm test command comes from, the @wordpress/scripts package includes these executable cli commands, for example, common commands are:

wp-scripts lint-style
wp-scripts lint-js
wp-scripts lint-md-docs
wp-scripts lint-pkg-json

Aside: npm test is one the top-level default npm commands, it doesn't require the run parameter (npm run test) to be in the command so developers can use the short format syntax of npm t as it is a common practice in the Node.js world, it doesn't always include actual "tests" and can include build, compile, and lint steps as part of any build and test pipeline.

Who uses @wordpress/scripts?

The @wordpress/scripts package is used by tens of thousands of repos, this isn't the greatest of GitHub searches, but the package is widely used by WordPress projects and WordPress agencies and a goal of this project is to increase this projects usage.

The goal of @wordpress/scripts is to bring this advanced tooling for WordPress Coding Standards to a wider audience with 1) ease of install, 2) ease of maintenance, 3) A-grade WPCS tooling for Node.js based tooling

WP.org Parser

As for the config which is actually used, this config is highly susceptible to the problems I pointed out earlier in #65 (comment):

markdownlint has a default of consistent for a lot of settings, which means it will take the first emphasis marker/bold marker/list marker etc as the "truth" and will demand the rest of the docs follows.
For proper consistent docs, those defaults should be changed as adding a new document, which "happens" to be be scanned first, could otherwise lead to markdownlint demanding all docs to be updated for "consistency".

The Gutenberg project also uses this same markdownlint configuration for its ~350 pages published at https://developer.wordpress.org/block-editor which are also synced via the same process this repo uses to publish it's pages at https://developer.wordpress.org/coding-standards.

The Gutenberg project is far more actively developed than this repo is, this is one of the reasons that this markdownlint configuration exists in that repo, but the primary reason it is published in the Gutenberg repo is for it to be included in the @wordpress/scripts package to be available for other meta projects that sync markdown docs to developer.wordpress.org. with little to no configuration, aka the zero-config, and reduce the maintenance burden or WP meta projects.

Future iterations for wpcs-docs

In the future we can here at wpcs-docs use ESLint & Stylelint configs (and maybe create HTML configs) to also lint code in the markdown fenced code blocks, so the @wordpress/scripts package includes support for this too out-of-the-box, but that is for a follow up iteration pull request to add that support.

Bloat & Maintenance

So, yes, right now at the moment it appears the @wordpress/scripts package comes with some additional bloat, it is one single package, and albeit as cited with ~1300 dependencies, but per what I have mentioned above it includes far more than what this initial pull request is enabling or alludes to.

The befits to the wpcs-docs package here is that one single package dependency can be used for much more than this initial pull request contains, and again, without the maintenance burden on wpcs-docs to maintain this.

Summary

I hope my comments above showed my passion for the @wordpress/scripts package, although it has somewhat widespread knowledge, it's also not that well known either.

The @wordpress/scripts project has been a project I've been closely associated with since it's inception ~5 years ago, the project continues to mature, and I continue to be incredibly passionate about it now in expanding it's use both internally in WordPress projects and with the wider WordPress community.

Whilst it's not readily clear what and why I took this approach in this PR I hope the above has helped explain some of that context.

Zero-Config

So, yeah, I was fully aware of all of the above when I made my zero-config statement, I should have expanded on that in this PR to add the context I've now shared here in this comment, not everything is perfect, yet, there's some nice changes in the pipeline such as GitHub Annotations, there's fenced block linting to ensure code examples used in this repo also meet the WordPress Coding Standards, and I'm sure there are many more improvements that can be implemented that will benefit all that use @wordpress/scripts.

So, yeah, @wordpress/scripts and dying on hills is a thing for me, there's little to no maintenance for the wpcs-docs project to maintain, it's all gravy for us here to enjoy the shared spoils of what this package offers both now currently and in the future.

Thanks 🙇🏼‍♂️

@jrfnl
Copy link
Member

jrfnl commented May 2, 2022

@ntwb I can see your passion in every line of your hill to die on comment and I appreciate you taking the time to write it up (and all your work on the package for which I can definitely see good uses).

Unfortunately, your arguments do nothing to convince me that this package is the right choice for this repo.

This is a collection of reusable scripts tailored for WordPress development.
A-grade WPCS tooling for Node.js based tooling

I would fully understand the choice for using the package as a basis for a (new) JS/CSS project in the WordPress sphere and based on your insights, I would probably even recommend it.

However, this project is not a JS/CSS project, which makes most of the arguments fall flat as they are based on an incorrect premise.

Secondly, it does nothing to address my comment about the config being unusable. Zero-config is all nice and dandy if there is an actual properly set up config.

However, the wordpress/scripts repo does not have that.

Not to put too fine a point to it, but the configuration which is proposed to be used is actually pretty crappy and I strongly recommend AGAINST using that config as it will make the markdown unstable and liable to be forced to change based on whichever document is scanned first.

Please have a look at the defaults used by markdownlint for everything which is not included in the config and you should see what I mean - especially all those rules which have "consistent" as the default.

The Gutenberg project is far more actively developed than this repo is, this is one of the reasons that this markdownlint configuration exists in that repo, but the primary reason it is published in the Gutenberg repo is for it to be included in the @wordpress/scripts package to be available for other meta projects that sync markdown docs to developer.wordpress.org. with little to no configuration, aka the zero-config, and reduce the maintenance burden or WP meta projects.

That's not a valid argument.

The fact that another project does not understand the tooling it is using and is using it incorrectly, does not make a good case for using it here.

So, yes, right now at the moment it appears the @wordpress/scripts package comes with some additional bloat

We're not talking "some additional bloat", we're talking a massive mamout amount of bloat (1300 packages) versus the mouse we need (36 packages) and the mamout doesn't even come with the configuration we need.

To be blunt, I honestly don't care whether it is used by 10 or 10.000.000 other projects. It should only be used when it is the right tool for the job. And in this case I still don't think it is.

If nothing else, including this package would now clasify this project as a JS project (due to the MASSIVE package.lock file), while it is in actual fact a markdown project.

In the future we can here at wpcs-docs use ESLint & Stylelint configs (and maybe create HTML configs) to also lint code in the markdown fenced code blocks, so the @wordpress/scripts package includes support for this too out-of-the-box, but that is for a follow up iteration pull request to add that support.

Again, not an argument for using this package. I've (recently) looked at tooling to lint code samples in markdown fenced code blocks before and in my experience those available are extremely limited in their ability and often very buggy, so being able to maybe, potentially use something a few years in the future is no reason to use this package now.

We can re-evaluate if and when the time comes this would actually be a viable addition.

Also note: that AFAIK there is no linting, nor code style check for fenced codeblocks for PHP available anywhere and while something is better than nothing, that omission is something which I find problematic for the documentation maintained here.

Potentially we can look at this change later, but I prefer to use the Jest option I've referenced because of the tight integration into the @wordpress/scripts package and it's use in Gutenberg.

Why wait for something to be added later when a two line addition to the GH Actions script can let us have the same NOW ?

I honestly don't understand that argument.

@jrfnl jrfnl mentioned this pull request Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants