-
Notifications
You must be signed in to change notification settings - Fork 22.5k
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: make Markdownlint a dependency and script #12316
Conversation
Need to call |
4f744a6
to
ac508e7
Compare
fbcdb3f
to
a9342b7
Compare
@hamishwillee I rebased for the conflicts, do you want to take a look at this? |
@nschonni Would love to. I was able to install it - though first it says I needed to install Node 14 (oddly when I used 12 it told me I needed >=14, but when I tried 17.4 it told me I needed < 17). But I need a bit more info on how to test it - how is is supposed to work? I can see you have add
Further it looks like perhaps this is run on a workflow just on the pages you have modified. Upshot, what do you expect this to do/how is it triggered? Then I can tell you if it does that :-) |
This still isn't running on all pages, it only runs on the root MD and RFC files like it does today. This just pins it to the latest version of Markdownlint and adds a problem matcher for any issues that the CI picks up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These would be the required changes to expand the linting to all files
7636f2b
to
a02af35
Compare
@hamishwillee I added a separate commit expanding the globs, so it's easy to reverse. I think last time the larger glob stalled out pending some discussion around documentation and/or integrating it in with the other flaw checks. |
@nschonni That's actually pretty cool. The things that spring to mind:
|
Those will show up inline in the changed files as well, but at the start, there may be a few that show up the "Other files" as PRs land with markdownlint issues at the start
You can get the same thing locally by running |
Then it sounds great to me. It's certainly a good start, and not much impact if people want to ignore it. i.e. I'd be happy to merge this. We should get a sanity check from someone else in the team though - probably Will Bamberg would be my first suggestion. PS Though not completely clear on your response to "1". To be clear in my response, a report like this is only useful if I can still "see the wood for the trees". If there are too many files in a report that I did not touch then I won't bother looking at it. |
The "Other files" section caps out at the first 10 as far as I know, and the files actually touched will have the inline annotations on the files in the regular file diff lines. People/reviewers can ignore and merge the PR if the only issues are in the "Other files" section, but the build will show as failing |
@wbamberg do you want to take a look too? |
@@ -11,11 +11,13 @@ | |||
"start": "yarn up-to-date-check && env-cmd --silent cross-env CONTENT_ROOT=files REACT_APP_DISABLE_AUTH=true BUILD_OUT_ROOT=build node node_modules/@mdn/yari/server", | |||
"filecheck": "env-cmd --silent cross-env CONTENT_ROOT=files node node_modules/@mdn/yari/filecheck/cli.js --cwd=.", | |||
"content": "env-cmd --silent cross-env CONTENT_ROOT=files node node_modules/@mdn/yari/tool/cli.js", | |||
"build": "env-cmd --silent cross-env CONTENT_ROOT=files BUILD_OUT_ROOT=build node node_modules/@mdn/yari/build/cli.js" | |||
"build": "env-cmd --silent cross-env CONTENT_ROOT=files BUILD_OUT_ROOT=build node node_modules/@mdn/yari/build/cli.js", | |||
"lint:md": "markdownlint \"**/*.md\" -i node_modules" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be helpfull to have a "fix" target like fix:md
to go with the lint? EX: "fix:md": "markdownlint \"**/*.md\" -i node_modules --fix"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I would definitely like to auto fix any cases of too many empty lines at the end. But without a better view of the full set of things it might fix, not sure I'd like to do this as a blanket thing.
I guess perhaps the answer should be "yes" and then we tune it until that is something we're happy to just do. Otherwise this can never be a CI mandated thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I can add the extra target. Does it make sense to keep the scoped :md
, or just have them as lint
and fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it matters all that much, but personally I'd keep md because there are some html docs still in-tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason not to use lint
instead of lint:md
, and remove fix:md
, as folks can just run npm run lint -- --fix
themselves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We know about the --fix
, and it could be documented, but it's more user friendly to have the fix target for new users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I understand. Maybe still call it lint
and lint-fix
, since there aren't any other lint scripts for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caugner There is going to be one for JavaScript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, makes sense then. Maybe linting JavaScript and Markdown could be integrated via ESLint (eslint-plugin-markdownlint + eslint-plugin-prettier) in the future.
Added the fix, and opened #14231 to cleanup the existing issues |
0765df3
to
ac74bb6
Compare
Was that really all of them? In any case, looking at that issue I'd say that the changes are all reasonable and could be automated by default. |
Yeah, I had cleaned up a bunch over the last few months. Some of the rules in Markdownlint can probably still be cleaned up like MD001, but can't be automatically fixed so I haven't dug into them much. |
Sorry to be slow getting to this. I will have a look tomorrow. |
Thanks for this PR, @nschonni ! I would like to understand what the contributor experience is like with this PR. If someone makes a change that is not md-lint compatible, does it look like a CI failure? What do we as maintainers do with a PR that is not md-lint compatible? Is it easy for us to fix the problems ourselves? I like linting, and think we should have it, but linting is a pretty contributor-hostile thing unless the tooling is helpful. A lot of our contributions are very much casual drive-bys, and most people aren't going to want to deal with tooling that makes contributions harder. So I think it is important to consider contributor experience, not just for markdownlint but for other tools like Prettier and ESLint. |
ac74bb6
to
6c82109
Compare
After this PR lands can we make one improvement? Process only the modified files in PRs. Something like this: [ref]
ATM this processes files which are not part of the PR as well. For example, https://github.com/mdn/content/pull/12316/files#diff-e917862ed5ced988f4072a8ccf20596eccf57cc889f0c897aef8d2c8016bfb72 simplescreenrecorder-2022-08-18_11.53.12.mp4In above video this PR got unrelated files flagged. Which could be confusing to the contributors. And annoying for maintainers. If very first commit in a day creates a lint error then every PR(~30 a day) will get these files flagged throughout the day till the daily markdownlint happens. Even after the daily cleanup happens those flagged files remain in the PRs forever, adding the unnecessary redundancy. It would be great if we could get this done sooner, but let's not stop this PR. |
My understanding is that this very PR will prevent landing a PR that adds a Markdown error in the first place. So this won't happen. But I agree we should test only the updated files (as the others are good anyway), just for performance reasons. A follow-up looks good to me. |
Fixing lint errors shouldn't be mandatory for the contributors or reviewers. They should be allowed to ignore the lint errors for ease of contributing and speed. Also because we are going to have automated daily lint(with fix) job as a safety net. Fixing trailing spaces and missing lines is easy but fixing indentations and lists with code blocks or multiple paragraphs are not easy. Especially definition lists with sub lists gave me hard time. Without using intelligent IDE/editor it's a nightmare. |
We should configure this test as non-blocking merging. (And your Daily markdownlint PR should be created automatically by your bot, with its configuration in this repo so we can discuss and adapt its configuration through PR. What I see is:
So the next steps are to fix these 4-5 errors, land this PR, and configure it to be non-mandatory for merging a PR. |
It's been handled already in Daily markdownlint.
I think we can make this non-mandatory in this PR itself. By simply adding one line |
Let's do this! We can bump it again in a later phase if we want. |
- name: Lint markdown files | ||
run: | | ||
npx markdownlint-cli '*.md' -i LICENSE.md -i CODE_OF_CONDUCT.md | ||
echo "::add-matcher::.github/workflows/markdownlint-problem-matcher.json" | ||
yarn lint:md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yarn lint:md | |
(yarn lint:md || exit 0) |
To not exit the linter with error code 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, as @nschonni has pointed out, the failing check does not prevent a PR from being merged once it is approved.
This is because the following option is disabled in the protection rules for the main
branch:
2ecd7db
to
396a996
Compare
@teoli2003 I rebased, but there are now additional issues. Is the merged blocked by the failing job? My understanding is that because none of the jobs are marked as "Required Checks" for the branch rules, it should disable the merge buttton, but rather just make it not-green |
The red test is not critical: it will be fixed in the next Daily markdownlint PR. The only thing preventing us from merging is to be sure that this is not marked as mandatory so that it can be merged. In a follow-up, we have to be sure it applies only in the files inside the PR because it won't help much (it will be almost forever red, with no way to get it green in the PR – this is happening here.). |
Guys, my suggested changes to make it non blocking work! Lint issues as warning annotations instead of errors:Green
|
I would say go with it, and if proves to be too disruptful after a few weeks, Actions can be disabled from the GitHub UI without actually deleting the file |
396a996
to
c9bee3c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PS: For me, this would be a style(md):
instead of chore:
.
@@ -11,11 +11,13 @@ | |||
"start": "yarn up-to-date-check && env-cmd --silent cross-env CONTENT_ROOT=files REACT_APP_DISABLE_AUTH=true BUILD_OUT_ROOT=build node node_modules/@mdn/yari/server", | |||
"filecheck": "env-cmd --silent cross-env CONTENT_ROOT=files node node_modules/@mdn/yari/filecheck/cli.js --cwd=.", | |||
"content": "env-cmd --silent cross-env CONTENT_ROOT=files node node_modules/@mdn/yari/tool/cli.js", | |||
"build": "env-cmd --silent cross-env CONTENT_ROOT=files BUILD_OUT_ROOT=build node node_modules/@mdn/yari/build/cli.js" | |||
"build": "env-cmd --silent cross-env CONTENT_ROOT=files BUILD_OUT_ROOT=build node node_modules/@mdn/yari/build/cli.js", | |||
"lint:md": "markdownlint \"**/*.md\" -i node_modules" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, makes sense then. Maybe linting JavaScript and Markdown could be integrated via ESLint (eslint-plugin-markdownlint + eslint-plugin-prettier) in the future.
Let's try this! (Especially as we can disable it very easily in case of a problem, so let's try it now in the morning :-) ) |
Not expanding the globs or adding the config like the previous PR.