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

ci: use markdownlint to enforce mkdocs compatibility #14114

Merged
merged 1 commit into from May 1, 2024

Conversation

BlaineEXE
Copy link
Member

@BlaineEXE BlaineEXE commented Apr 22, 2024

mkdocs uses a markdown renderer that is hardcoded to 4 spaces per tab
for detecting indentation levels, including ordered- and
unordered-lists. Since we cannot easily change the renderer, begin using
a markdown linter in CI that will fail if official docs do not adhere to
the spacing rules.

As a starting point, the markdownlint config does not begin with the
default set of checks, which might overwhelm attempts to fix them.
Instead, focus on list-tab-spacing rules and a few other highly useful
checks.

markdownlint also has some gaps in its abilities that allow common Rook
doc issues to pass acceptance. However, it allows creating custom
linting plugins. Create 2 such linting plugins to check 2 things:

  • all doc lines (except code blocks) must be aligned to a 4-space
    boundary, without exception. This ensures that markdown will render
    correctly with mkdocs. This unfortunately makes it possible to create
    lists that are internally aligned strangely.
  • admonitions must all follow the same format of
    !!! header
        body
    

For the strange lists, this is allowed and renders correctly, but it
looks strange:

- first bullet
- second bullet
    still second bullet
- third bullet

    has a paragraph
    of text inside

- last bullet

Checklist:

  • Commit Message Formatting: Commit titles and messages follow guidelines in the developer guide.
  • Reviewed the developer guide on Submitting a Pull Request
  • Pending release notes updated with breaking and/or notable changes for the next minor release.
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

@BlaineEXE BlaineEXE force-pushed the markdown-force-4-space-tabs branch 3 times, most recently from 55f04e9 to 0f80258 Compare April 22, 2024 18:06
@BlaineEXE
Copy link
Member Author

@travisn @parth-gr @galexrt related to this PR (and others) #13968 (comment)

mkdocs's yaml parser is adamant that they will not support 2-spaces-per-tab, and they require 4 spaces. Mkdocs devs are adamant that they won't support modifying the parser or this particular behavior. This means that our current docs will render fine in github/vscode, but not on the website.

The best way I could find to fix our docs without switching to something other than mkdocs is to do 2 things:

  • set rook-project vscode configs to use 4 spaces per tab for markdown and to not "interpret" current spacing
  • lint the docs using markdownlint

As of now, I haven't fixed any lint issues. I wanted to discuss and decide how to proceed from here before doing that.

* `erasureCoded`: Settings for an erasure-coded pool. If specified, `replicated` settings must not be specified. See below for more details on [erasure coding](#erasure-coding).
* `replicasPerFailureDomain`: Sets up the number of replicas to place in a given failure domain. For instance, if the failure domain is a datacenter (cluster is stretched) then you will have 2 replicas per datacenter where each replica ends up on a different host. This gives you a total of 4 replicas and for this, the `size` must be set to 4. The default is 1.
* `subFailureDomain`: Name of the CRUSH bucket representing a sub-failure domain. In a stretched configuration this option represent the "last" bucket where replicas will end up being written. Imagine the cluster is stretched across two datacenters, you can then have 2 copies per datacenter and each copy on a different CRUSH bucket. The default is "host".
* `erasureCoded`: Settings for an erasure-coded pool. If specified, `replicated` settings must not be specified. See below for more details on [erasure coding](#erasure-coding).
Copy link
Member

Choose a reason for hiding this comment

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

Are the spaces between the * and first word intentional? That doesn't seem expected to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. We can chat more about some of the weird things that this is going to be requiring like this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

markdownlint really isn't all that great as a tool. It particularly has gaps in requiring 4-space tabs throughout the full document. It will only force it on list items but not the paragraph conentents of list items.

Rook uses a lot of lists with multiple paragraphs and code blocks inside lists, which mkdocs won't render properly unless those are indented very exactly.

I had to find something else that we could use to help fill in this particular gap. The tool called "Prettier" was commonly recommended for markdown, and I found that using its --tab-width=4 option helps to ensure that paragraph contents (especially code blocks) are spaced appropriately to be rendered by mkdocs and/or flagged as an error by markdownlint.

The downside is that Prettier is VERY opinionated. It requires using - for bullet points, and it requires that bullet points adhere to the tab-width option. It also doesn't like the standard callout/admonition syntax and requires a newline between the callout header and text.

IMO, this is certainly not ideal, but it is much more usable than having docs that render properly on github but silently fail (and create subtle bugs) in user-facing docs.

@BlaineEXE BlaineEXE force-pushed the markdown-force-4-space-tabs branch 11 times, most recently from 9c69946 to 097babe Compare April 22, 2024 21:29
Copy link

mergify bot commented Apr 22, 2024

This pull request has merge conflicts that must be resolved before it can be merged. @BlaineEXE please rebase it. https://rook.io/docs/rook/latest/Contributing/development-flow/#updating-your-fork

@BlaineEXE BlaineEXE force-pushed the markdown-force-4-space-tabs branch 8 times, most recently from 65e6ae1 to 5c91d69 Compare April 22, 2024 21:51
@BlaineEXE BlaineEXE force-pushed the markdown-force-4-space-tabs branch 4 times, most recently from edcd49c to 949508f Compare April 23, 2024 17:52
Copy link

mergify bot commented Apr 23, 2024

This pull request has merge conflicts that must be resolved before it can be merged. @BlaineEXE please rebase it. https://rook.io/docs/rook/latest/Contributing/development-flow/#updating-your-fork

@BlaineEXE BlaineEXE force-pushed the markdown-force-4-space-tabs branch 6 times, most recently from 119f154 to eca9010 Compare April 26, 2024 20:34
@BlaineEXE
Copy link
Member Author

BlaineEXE commented Apr 29, 2024

Latest updates (from Friday)

  • I went through the docs that had merge conflicts (3-4 of them) and made sure things were formatted correctly for the PR
  • I found out that markdownlint supports custom lint rules, so I made one to ensure that our admonitions/callouts are formatted correctly. This actually caught 3 cases where I hadn't captured the formatting correctly, and it will mean that we don't have to be as mindful about checking that in PR reviews

For consideration:

The main reason why I also included 'Prettier' was because markdownlint didn't have a good way of checking that all lines are indented to a 4-space boundary (for mkdocs)

Now that I know how to write custom markdownlint modules, it would be fairly simple to write one to ensure this 4-space boundary

This would allow us to get rid of 'Prettier' if we want, with some pros/cons:

  • Pros
    • admonitions/callouts don't need the extra newline between header and body, which we use as a workaround for Prettier
    • when updating a doc, Prettier might sometimes alter formatting to be something unintended if it misinterprets a typo (like bullets to underscores), so getting rid of it could help
  • Cons
    • Prettier is really nice for automatically (in VScode) turning any typed markdown into the form needed for mkdocs, without the need for users to run mardownlint or wait for CI, and we'd lose that
    • Prettier formats docs with compatibility in mind (e.g., auto-escaping the asterisk in myglob* to myglob\* to ensure the asterisk isn't misinterpreted as intent to italicize), and we'd lose that potential benefit

Copy link
Member

@travisn travisn left a comment

Choose a reason for hiding this comment

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

Are you saying you created that custom rule locally? Or it's part of this PR and we will have it going forward?

If we already have the custom linter, maybe it would be good to get rid of prettier if we don't need it. But whatever you think is simplest to get this done and not spend too much more time on it.

_ `replicasPerFailureDomain`: Sets up the number of replicas to place in a given failure domain. For instance, if the failure domain is a datacenter (cluster is
stretched) then you will have 2 replicas per datacenter where each replica ends up on a different host. This gives you a total of 4 replicas and for this, the `size` must be set to 4. The default is 1.
_ `subFailureDomain`: Name of the CRUSH bucket representing a sub-failure domain. In a stretched configuration this option represent the "last" bucket where replicas will end up being written. Imagine the cluster is stretched across two datacenters, you can then have 2 copies per datacenter and each copy on a different CRUSH bucket. The default is "host".
- `erasureCoded`: Settings for an erasure-coded pool. If specified, `replicated` settings must not be specified. See below for more details on [erasure coding](#erasure-coding).
Copy link
Member

Choose a reason for hiding this comment

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

That local preview is working for you?

@BlaineEXE BlaineEXE marked this pull request as draft April 29, 2024 20:43
@BlaineEXE BlaineEXE force-pushed the markdown-force-4-space-tabs branch 4 times, most recently from 9358397 to 036024d Compare April 29, 2024 23:22
mkdocs uses a markdown renderer that is hardcoded to 4 spaces per tab
for detecting indentation levels, including ordered- and
unordered-lists. Since we cannot easily change the renderer, begin using
a markdown linter in CI that will fail if official docs do not adhere to
the spacing rules.

As a starting point, the markdownlint config does not begin with the
default set of checks, which might overwhelm attempts to fix them.
Instead, focus on list-tab-spacing rules and a few other highly useful
checks.

markdownlint also has some gaps in its abilities that allow common Rook
doc issues to pass acceptance. However, it allows creating custom
linting plugins. Create 2 such linting plugins to check 2 things:

- all doc lines (except code blocks) must be aligned to a 4-space
  boundary, without exception. This ensures that markdown will render
  correctly with mkdocs. This unfortunately makes it possible to create
  lists that are internally aligned strangely.
- admonitions must all follow the same format of
  ```
  !!! header
      body
  ```

For the strange lists, this is allowed and renders correctly, but it
looks strange:

```md
- first bullet
- second bullet
    still second bullet
- third bullet

    has a paragraph
    of text inside

- last bullet

Signed-off-by: Blaine Gardner <blaine.gardner@ibm.com>
@BlaineEXE BlaineEXE marked this pull request as ready for review April 29, 2024 23:30
@BlaineEXE BlaineEXE merged commit e93b710 into rook:master May 1, 2024
47 checks passed
@BlaineEXE BlaineEXE deleted the markdown-force-4-space-tabs branch May 1, 2024 15:42
BlaineEXE added a commit that referenced this pull request May 1, 2024
ci: use markdownlint to enforce mkdocs compatibility (backport #14114)
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.

None yet

3 participants