-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Added hook to validate if headings are present or not #4143
Added hook to validate if headings are present or not #4143
Conversation
Size Changes📦 Next.js Bundle AnalysisThis analysis was generated by the next.js bundle analysis action 🤖 This PR introduced no changes to the javascript bundle 🙌 |
We could check only the staged files instead of the entire docs. I find this package useful (used in the Japanese fork to run additional linting for style problems): https://www.npmjs.com/package/lint-staged // package.json
{
"dependencies": {
"lint-staged": "^12.1.2"
},
"scripts": {
"docs:validate-ids": "lint-staged"
},
"lint-staged": {
"*.md": [
"scripts/generateId.js" // this can either auto-add IDs or exit with an error
]
}
} |
@smikitky Yea we could do that but consider someone force merges the markdowns without heading ID. we will not be able to generate headings for that later on since it won't be detected in other's commits (until they work on same file). If we validate headings IDs only for staged files we should add a CI check for the PR to ensure we don't miss headings. (That will be added in all forked translation versions). Should we validate headings only for staged files? and add a CI check ? Or rather would it make sense to validate heading IDs for all markdowns pre commit? |
@harish-sethuraman IMHO, ideally, it's best to have both a CI that checks everything and a pre-commit hook that checks (and optionally fixes) only the staged files. On second thought, however, at the moment, even prettier and eslint run on the entire codebase before every commit, so it may not make much sense to introduce lint-staged only around this topic... What I don't like is that unrelated files may get committed without me noticing, so as long as that doesn't happen, I'm fine. |
Yep we need to have checks consistent. We have been running ESlint and prettier for the whole repo even in the old site. PS: @smikitky wanna try adding validate heading id check for CI ? @gaearon your thoughts ? Shall we move all checks to lint staged ? |
@harish-sethuraman I think we can just add the new Perhaps the hardest remaining task is getting |
Yep we somehow have to figure out a way to validate headings only for staged files.
Added to CI check |
Whatever the policy will be, it would be very helpful to unify the scripts and having the API consistent with ESLint: # checks all files and causes an error (process.exit(1)) if an ID is missing
# (currently validateHeadingIds)
lint-heading-ids.js
# checks all files and adds IDs if missing
# (currently generateHeadingIds)
lint-heading-ids.js --fix
# checks the specified files and causes an error if an ID is missing
# (used by hand or by lint-staged)
lint-heading-ids.js fileA.md path/to/fileB.md
# fix the specified files
# (used by hand or by lint-staged)
lint-heading-ids.js --fix fileA.md path/to/fileB.md
|
@smikitky Is this okay? These changes might help when we try to use lint staged as well |
@harish-sethuraman Yes the API looks perfect to me! |
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.
seems fine, a few nits
@@ -2,7 +2,6 @@ | |||
. "$(dirname "$0")/_/husky.sh" | |||
|
|||
cd beta | |||
# yarn generate-ids | |||
# git add -u src/pages/**/*.md | |||
yarn lint-heading-ids |
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.
Why not fix them instead? Other scripts in this file fix things.
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 did not want to fix the heading ids since other files without heading are modified while doing translations. Rather we wanted to just throw error so that we dont miss it in the main repo?
Addressing #4135 (comment) and followup for #4139
Going forward we will validate if the headings are present or not in the beta site's markdown files.
We will let the contributor decide which files to add and with pre commit hook we can make sure that we don't miss out any headings.
EDIT:
yarn lint-heading-ids
--> Checks all files and causes an error if heading ID is missingyarn lint-heading-ids --fix
--> Fixes all markdown file's heading IDsyarn lint-heading-ids path/to/markdown.md
--> Checks that particular file for missing heading ID(path can be a directory or particular file)
yarn lint-heading-ids --fix path/to/markdown.md
--> Fixes that particular file's markdown IDs(path can be a directory or particular file)
Making it a linter and added auto fixable option.