-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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: check code examples syntax #7396
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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 just one question
why didn't this catch #7402 ? that seems like a pretty great test case for this... |
Yep, I will investigate this. |
I looked into it, and it turns out this is somewhat expected—the code syntax is correct. |
@@ -168,6 +192,11 @@ export default function rehypeShikiji() { | |||
// Grabs the relevant alias/name of the language | |||
const languageId = codeLanguage.slice(languagePrefix.length); | |||
|
|||
// Check code for syntax errors | |||
if (!checkCodeSyntax(preElementContents, languageId)) { |
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 this a good idea? I would rather have a separate CI process that verifies this rather than Acorn right here. Otherwise it will just dramatically slow down the build process.
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 have mixed feelings with its current implementation. I think this should be a standalone script (like we have on the apps/site/scripts folder) and that is added to the package.json and then invoked as one of the test/linting steps.
I agree, I will create this script |
Closing this PR, I will create another one when the script is ready. |
Description
Check if JavaScript code blocks have valid syntax using the acorn parser. We could use Node's vm module to execute the code, but I feel it would be slower and wouldn't work with incomplete code examples.
Validation
Manually edit any code example to broken code
Related Issues
Fixes #7293
Check List
npm run format
to ensure the code follows the style guide.npm run test
to check if all tests are passing.npx turbo build
to check if the website builds without errors.