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

chore(cdk-lint): add linting to README.md files #11708

Merged
merged 14 commits into from
Dec 2, 2020

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Nov 25, 2020

Consistent heading structure in the README.md files is necessary in
order to ensure consistent rendering in the Python documentation, as the
rendering of the TOC tree is dependent on heading levels. The best
experience is achieved by having all README.md files start with a H1
heading, and subsequently contain only H2 and deeper headings. It is
also important that no heading level is skipped (i.e: a H4 "nested" in
a H2).

This adds a cdk-lint stage that executes markdownlint on the
README.md files, with a configuration that is crafted specifically to
maximize compatibility with most Markdown parsers, and to ensure
correct rendering in the Python docs. Many of these offenses can be
automatically fixed by running cdk-lint --fix or yarn lint --fix, however
some cannot be automatically fixed by the tool and will require human
intervention.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Consistent heading structure in the `README.md` files is necessary in
order to ensure consistent rendering in the Python documentation, as the
rendering of the TOC tree is dependent on heading levels. The best
experience is achieved by having all `README.md` files start with a `H1`
heading, and subsequently contain only `H2` and deeper headings. It is
also important that no heading level is skipped (i.e: a `H4` "nested" in
a `H2`).

This adds a `pkglint` rule that parses the `README.md` files using the
`commonmark` parser, and ensures the heading structure is consistent per
the above rules, and registers fixable offenses otherwise.

Each offense is reported (and fixed) independently in an effort to
provide "more actionnable" feedback in the context of PR validation, and
to avoid risking to modify other parts of the document if we were to
simply "re-render" the updated Markdown.
@RomainMuller RomainMuller added the docs/generated Related to the generated API Reference documentation label Nov 25, 2020
@RomainMuller RomainMuller requested a review from a team November 25, 2020 15:22
@RomainMuller RomainMuller self-assigned this Nov 25, 2020
@gitpod-io
Copy link

gitpod-io bot commented Nov 25, 2020

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Nov 25, 2020
@RomainMuller RomainMuller added the pr/do-not-merge This PR should not be merged at this time. label Nov 25, 2020
@RomainMuller
Copy link
Contributor Author

Note: this probably should be merged only after https://github.com/aws/cdk-ops/pull/945 has been merged.

tools/pkglint/lib/rules.ts Outdated Show resolved Hide resolved
Comment on lines +6 to +11
Features | Stability
-------------------------------------------|--------------------------------------------------------
CFN Resources | ![Stable](https://img.shields.io/badge/stable-success.svg?style=for-the-badge)
Higher level constructs for HTTP APIs | ![Experimental](https://img.shields.io/badge/experimental-important.svg?style=for-the-badge)
Higher level constructs for Websocket APIs | ![Not Implemented](https://img.shields.io/badge/not--implemented-black.svg?style=for-the-badge)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is such that the table reads better when looking at it in the source. I find it's a neat improvement.

Copy link
Contributor

Choose a reason for hiding this comment

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

Love it!

@@ -1580,5 +1594,5 @@ function toRegExp(str: string): RegExp {
}

function readBannerFile(file: string): string {
return fs.readFileSync(path.join(__dirname, 'banners', file), { encoding: 'utf-8' });
return fs.readFileSync(path.join(__dirname, 'banners', file), { encoding: 'utf-8' }).trim();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This trim() ensures we don't insert too much vertical space in the stability banners, as markdownlint would subsequently consider those are formatting errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding this comment directly into the code.

@RomainMuller RomainMuller changed the title chore(pkglint): rule to ensure heading consistency in README.md chore(cdk-lint): add listing to README.md files Nov 26, 2020
@RomainMuller RomainMuller changed the title chore(cdk-lint): add listing to README.md files chore(cdk-lint): add linting to README.md files Nov 30, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Minor comments below.

@@ -0,0 +1,30 @@
{
"default": false,
"MD001": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use the rule name instead of the code?
Tells us which rule this is without having to reference somewhere, at least a first approximation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can yeah. I had initially decided against because rules have multiple names... But I guess you're right this might be better In the long run. If only JSON supported comments... -_-

@@ -2,19 +2,19 @@
"compilerOptions": {
"target": "ES2018",
"module": "commonjs",
"lib": ["es2018"],
"lib": ["dom", "es2018"],
Copy link
Contributor

Choose a reason for hiding this comment

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

add comment on why dom is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh - good you'd ask... It was needed in one stage of my experiments there but is no longer needed!

"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"composite": true,
"incremental": true
"incremental": true,
"importHelpers": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

add a comment on why this option is needed.

Comment on lines +6 to +11
Features | Stability
-------------------------------------------|--------------------------------------------------------
CFN Resources | ![Stable](https://img.shields.io/badge/stable-success.svg?style=for-the-badge)
Higher level constructs for HTTP APIs | ![Experimental](https://img.shields.io/badge/experimental-important.svg?style=for-the-badge)
Higher level constructs for Websocket APIs | ![Not Implemented](https://img.shields.io/badge/not--implemented-black.svg?style=for-the-badge)

Copy link
Contributor

Choose a reason for hiding this comment

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

Love it!

@RomainMuller RomainMuller removed the pr/do-not-merge This PR should not be merged at this time. label Dec 2, 2020
@mergify
Copy link
Contributor

mergify bot commented Dec 2, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: ad590f5
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Dec 2, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 2b1160f into master Dec 2, 2020
@mergify mergify bot deleted the rmuller/normalize-readme-headings branch December 2, 2020 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. docs/generated Related to the generated API Reference documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants