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

feat(husky): run fix-redirects command in precommit #33485

Merged
merged 2 commits into from
May 14, 2024

Conversation

OnkarRuikar
Copy link
Contributor

@OnkarRuikar OnkarRuikar commented May 8, 2024

Issue

Sometimes we have to manually edit the redirects file which may introduce errors. Command yarn content validate-redirects en-us --strict is run in GitHub PR checks. We have to wait for GitHub workflow to know about the error. Also, yari errors messages are not intuitive:

error: _redirects.txt for en-us is causing issues: Error: Invalid redirect for /en-US/docs/AJAX/Community -> /en-US/docs/Learn/JavaScript/Client-side_web_APIs/Fetching_data or /en-US/docs/AJAX -> /en-US/docs/Learn/JavaScript/Client-side_web_APIs/Fetching_data

From the log message above it is not clear that this is a sorting issue. The issue is auto fixable and one shouldn't be bothered to fix it manually.

Solution

It would be good if we auto fix fixable errors in husky pre-commit hook itself by running yarn content fix-redirects en-US and do redirects check as well.
⚠️ Note: The script suggested in this PR runs only when _redirects.txt is modified and it doesn't run on all commits.

In case of .lintstagedrc.json, all modified file paths are appended to the commands, this is not desirable for the fix-redirects command. It throws invalid locale error. In order to avoid appending file paths to commands .lintstagedrc.js file has been introduced to the repo.

@OnkarRuikar OnkarRuikar requested a review from a team as a code owner May 8, 2024 05:34
@github-actions github-actions bot added system [PR only] Infrastructure and configuration for the project size/s [PR only] 6-50 LoC changed labels May 8, 2024
Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

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

👍 Let's try this.

@teoli2003 teoli2003 merged commit 1e3ee81 into mdn:main May 14, 2024
6 checks passed
@OnkarRuikar OnkarRuikar deleted the feat_fix_redirect branch May 15, 2024 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/s [PR only] 6-50 LoC changed system [PR only] Infrastructure and configuration for the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants