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
docs: show red underlines in examples in rules docs #18041
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
It seems that CI does not install root dependencies, which causes the documentation to fail to build. |
Thanks for this PR! CI is failing because the job that builds the docs now requires ESLint dependencies to be installed, but only deps in the docs package (in the subfolder) are installed at that point: eslint/.github/workflows/docs-ci.yml Lines 34 to 36 in 1bf2520
We could run |
docs/package.json
Outdated
@@ -20,7 +20,8 @@ | |||
"lint:scss": "stylelint \"**/*.{scss,html}\"", | |||
"lint:fix:scss": "npm run lint:scss -- --fix", | |||
"build:minify-images": "imagemin '_site/assets/images' --out-dir='_site/assets/images'", | |||
"start": "npm-run-all build:sass build:postcss --parallel *:*:watch" | |||
"start": "npm-run-all build:sass build:postcss --parallel *:*:watch", | |||
"postinstall": "cd .. && npm install -f" |
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 temporarily added postinstall so that we can check the results of this PR with netlify. I think we should probably replace this PR with another method before merging.
https://deploy-preview-18041--docs-eslint.netlify.app/rules/array-callback-return
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 can add the top-level install to the workflow. 👍
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 removed the postinstall
and changed the workflow.
I think we probably need to modify the netlify script, but how should I do that?
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.
Hmm. There is no Netlify script. It just checks out docs
and does npm install
.
I wonder, could we just list "eslint": "file:../"
in docs/package.json
and that will work?
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 wonder, could we just list "eslint": "file:../" in docs/package.json and that will work?
I tried that locally but it doesn't seem to work. eslint
dependencies were not installed 😓
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.
Do you think putting the netlify.toml
and adding the command config will work fine?
https://docs.netlify.com/configure-builds/file-based-configuration/#build-settings
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.
Let's try it. I'm out of other ideas.
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 tried adding netlify.toml
and it seems to be working fine 🎉
https://deploy-preview-18041--docs-eslint.netlify.app/rules/array-callback-return
1c54f4c
to
2b6af6b
Compare
I think it's okay to update the CI in this PR. This looks really good, thanks! Can we change the red underline to look more like the one VS Code uses? (A little squiggly.) I'm pretty sure it's just a repeating image that we can find in the VS Code repo. |
docs/tools/prism-eslint-hook.js
Outdated
|
||
/** | ||
* Add content that needs to be marked. | ||
* @param {string} content Source code content that marks eslint errors. |
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.
* @param {string} content Source code content that marks eslint errors. | |
* @param {string} content Source code content that marks ESlint errors. |
This is looking really nice. Is it possible to add a tooltip over the red-underlined code that includes the error message? |
Hmm. It seems difficult to do that with Prism's hooks for now. |
I tried it but it didn't work well. During the |
Is it possible to add a |
I don't know how to add |
I tried that. If someone doesn't like it that way, we can change it back. https://deploy-preview-18041--docs-eslint.netlify.app/rules/array-callback-return |
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.
This looks amazing. ❤️
We can update the docs CI to install the top-level packages and I think this is ready to go.
docs/package.json
Outdated
@@ -20,7 +20,8 @@ | |||
"lint:scss": "stylelint \"**/*.{scss,html}\"", | |||
"lint:fix:scss": "npm run lint:scss -- --fix", | |||
"build:minify-images": "imagemin '_site/assets/images' --out-dir='_site/assets/images'", | |||
"start": "npm-run-all build:sass build:postcss --parallel *:*:watch" | |||
"start": "npm-run-all build:sass build:postcss --parallel *:*:watch", | |||
"postinstall": "cd .. && npm install -f" |
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 can add the top-level install to the workflow. 👍
Nice work! LGTM when the build is fixed. |
docs/tools/prism-eslint-hook.js
Outdated
const { Linter } = require("../../lib/api"); | ||
const astUtils = require("../../lib/shared/ast-utils"); |
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.
How would this work for https://github.com/eslint/zh-hans.docs.eslint.org, where we don't have these 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.
Oh... I don't think it will work as it is now.
@kecrily Do you have any ideas how to solve it?
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.
What do you think about changing this PR as below?
astUtils
is used only to get the regex, so it inlines the regex.- Try
require("../../lib/api").Linter
andrequire("eslint").Linter
and use the one that does not cause an error as theLinter
. - Change the install script of
zh-hans.docs.eslint.org
to install eslint as a dependency.
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.
Another option is to not do red underlines outside of the US site. We could check to see if these utilities exist, and if not, just don't do the linting.
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.
Another option is to not do red underlines outside of the US site. We could check to see if these utilities exist, and if not, just don't do the lining.
I'd prefer this option.
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.
Another option is to not do red underlines outside of the US site. We could check to see if these utilities exist, and if not, just don't do the linting.
I've made changes to this PR to make it so 👍
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.
This looks great ⭐ , thanks!
Leaving it open for @mdjermanovic
docs/tools/prism-eslint-hook.js
Outdated
if ( | ||
env.content === "" || | ||
env.content === "\n" || | ||
env.content === "\r\n" || | ||
env.content === "\ufeff" | ||
) { | ||
env.classes.push(CLASS_ESLINT_MARKED_ON_ZERO_WIDTH); | ||
} |
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.
In this case, nothing is underlined in the fourth example as the reported text is \n\n
:
https://deploy-preview-18041--docs-eslint.netlify.app/rules/padded-blocks#never
VS Code, for example, always underlines linebreaks at the start of the range, and linebreaks of empty lines within the range (so that the range always looks continuous), so this example looks like this:
Would it be possible to do something similar? If not, could we maybe also add CLASS_ESLINT_MARKED_ON_ZERO_WIDTH
in case the entire content consists of only linebreaks?
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 changed this PR to make it look like VSCode by extracting the newline code character by character into tokens 👍
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.
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 added CSS and changed it to look like that.
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.
Looks great, thanks!
nice 🎉 |
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.
Great work, thanks!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
This PR modifies
docs/src/_plugins/md-syntax-highlighter.js
to indicate where an error occurs with a red marker in the examples in the rules document.Is there anything you'd like reviewers to focus on?
close #16227
after-tokenize
hook.Content that starts with/* eslint
and whose language is js is considered an example of an eslint rule.It is now consider it an example of an ESLint rule only if it is wrapped in a custom container (that is, if parser options are passed from the custom container's rendering process).
I would like to hear your opinion if this will work.