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
Allow processor API to be configurable and to formally be able to lint both a file and its blocks #14745
Comments
Can you explain how you're using |
Sure, basically we allow users to store the configuration they want to be used for their While users can pass in a For example, the default behavior for |
This use case sounds very similar to #14198. Here, we want to lint a JS file and separately lint expressions from JSDoc comments. #14198 wants to lint a Markdown file and separately lint the code blocks within. I’m not thrilled about the API proposed in #14198. Similarly, the API proposed in this issue has some downsides including performance as you’ve already mentioned. Looking at these two use cases together gave me an idea:
What if we removed that limitation? If we could lint both |
@btmills If I don't understand incorrectly, it is not true. const jsoc = {
preprocess(text, filename) {
return [
text, // presents the parent file
...extractExamplesInJsDoc(text), // lint examples at the same time
]
}
} We're using this pattern at eslint-plugin-mdx. |
Ok, good info and sounds promising as a possibility, but a few concerns with the processor approach at this point (not sure anything else would come up) are:
|
I think code block with custom filename + const jsdoc = {
preprocess() {
return [
text,
{
filename: 'jsdoc-example' + getExtFromJsdoc(text),
},
]
},
} {
"overrides": [
{
"files": ["*.js", "*.ts"],
"processor": "jsdoc/example" // a pretended value here
},
{
"files": [
"*.js/*_jsdoc-example.js",
"*.ts/*_jsdoc-example.js",
"*.js/*_jsdoc-example.ts"
],
"rules": {
// specific rules for examples in jsdoc only here
// And other rules for `.js` and `.ts` will also be enabled for them
}
}
]
} |
|
Ok, good to know, and can hopefully look into it on our end to see if it works within the next week or two. But yeah, we would definitely need the full content supplied again, as we wouldn't want chunks taken out of the JSDoc blocks, at least before the rest of
I was just curious if an expression like Helpful to consider the idea though of passing on a special case for any unrecognized blocks, e.g., perhaps we can still extract out the contents within the likes of:
No, thanks, I meant that since the rules for |
Aha, now I think I see how Markdown figures in. When you see an Given a file I might recommend getting even more specific in case someone needs to configure JSDoc blocks separately from regular Markdown blocks. For example, you could return If instead someone wrote their examples in TS without wrapping them in Markdown code blocks, they could configure Using a specific extension gives the user the ability to target JSDoc’s code blocks specifically in their config. |
You've gotten the important gist in the rest of your message, but FWIW, the main reasons I've mentioned Markdown are:
## Usage
Here's how to use it:
```js
const result = runMe();
``` ...tends to need to have similar rules disabled (such as /**
* @example
* const result = runMe();
*/
function runMe () {
} But also, yes, the (Markdown-inspired) fenced block syntax is something which we've optionally allowed to denote the coding language within Btw, another problem I see with our going with a processor approach is that with a rule we can have configuration like these optional regexes (important in this case since JSDoc doesn't really formalize how We also have config (that a processor couldn't implement without some ability to supply configuraton to it) for:
Almost exactly except that, being aware of the more recent ESLint processor syntax, we've already switched from simulating (in
Sure. As a processor that approach makes sense (and in fact we do add custom extensions currently for |
Thank you for getting me up to speed here. As I understand it, there are two limitations of the processor API that would need to be resolved before it’s a good fit for
Digging into some of your configuration cases, some might be possible today by configuring rules without having to configure a processor:
This could be configured by
If the processor were to return specific extensions, these could be configured via The other cases (whether to allow
|
Sounds right.
Ah, elegant, hadn't thought of that, thanks. I kind of like how it is all in one place now, but your approach feels right being as it is a kind of config, and could be reusable (e.g., even to just apply the rules elsewhere instead, like with Markdown).
Sure, makes sense too.
Yeah. I guess a Also, FWIW, I wonder if having such config might help with allowing
Yup.
Yes, I think it sounds very good. And glad the rule won't be blocking, as the RC reading does make the rule more processor intensive than the other rules. |
What’s the next step here? If there’s an agreement on the category of this issue, it should be moved out of Triaging. |
To adapt @btmills ' reply #14745 (comment) accurate summary of the remaining needs, it would be to address two limitations of the processor API:
Need to determine whether to standardize the current informal
|
So is the next step here to wait for an RFC? @btmills |
Yes, assuming there are no objections, I need to write an RFC that will allow linting a file and extracting its blocks with a processor and linting those too. There's already an unofficial way to do that mentioned in #14198, so the RFC may just pave that cow path and add make it configurable. The second half of this is asking for processor configuration, but if the RFC unblocks the first half, I believe the second half can be achieved with parser options for the processor's parser and may not need any further changes. |
* feat: support ESLint 8.x and Node 17 BREAKING CHANGE: - This update requires the disabling of the `jsdoc/check-examples` rule! We can hopefully restore this rule after eslint/eslint#14745 - Requires ESLint@^7.0.0 || ^8.0.0 - Updates `jsdoc-type-pratt-parser` and `jsdoccomment` Co-authored-by: Brett Zamir <[email protected]>
@eladavron thats too off topic for this issue. Please open a discussion if you’d like to discuss further. |
I looked at standardizing the existing workaround in which I'm now thinking the const config = {
files: ["*.js"],
processor: [
// Continue to lint this file as normal...
"passthrough",
// ...but also extract and lint any JSDoc blocks.
"jsdoc/processor"
]
}; |
I like the idea behind this, though I’m not thrilled with having a special valid to consider. And would it be possible to specify additional processors too? Like let’s say we have a markdown file with both JS and CSS codeblocks? |
Sure! Your specific example, a Markdown file containing JS and CSS code blocks doesn’t need it because However, let’s say you wanted to extract all fenced code blocks using Or, if you had a JSDoc-annotated JS file that had embedded GraphQL queries and CSS-in-JS rules, you’d want to lint the JS and extract the JSDoc examples, GraphQL queries, and CSS rules to run with their own sub-linters:
Assuming you meant “value” about Another option I considered was shipping a built-in I also considered a boolean |
Maybe “eslint:default” would be a better fit than “passthrough” (matching “eslint:recommended”)? In any event, I like the direction. Being able to lint all of the various code blocks inside of a file is a super power I’ve wanted for a long time. |
Thanks for the feedback. Since you’re on board with the direction, that’s enough for me to continue sketching out a prototype implementation and write up an RFC. It’ll be easy to change the special value, so I’ll explore the tradeoffs of each option in the RFC and we can decide which way to go there. |
Disable `jsdoc/check-examples` until eslint 8 related issue is fixed. eslint/eslint#14745
Disable `jsdoc/check-examples` until eslint 8 related issue is fixed. eslint/eslint#14745
Disable `jsdoc/check-examples` until eslint 8 related issue is fixed. eslint/eslint#14745
Disable `jsdoc/check-examples` until eslint 8 related issue is fixed. eslint/eslint#14745
We cannot update `eslint-plugin-unicorn` because we need to remain on `eslint` v7 until this issue is resolved: eslint/eslint#14745 (which prevents `jsdoc/check-examples` rule from running)
Proposed a solution to improve this: eslint/rfcs#115, feedback appreciated. |
This feature has already been supported but not well-documented. Please read the context more carefully. |
The solution to this problem will likely be based on this RFC: eslint/rfcs#105 |
Update: see updated description below
The version of ESLint you are using.
7.29.0
The problem you want to solve.
A few facts:
Per the v7.29.0 blog release, further changes are anticpated toward dropping
CLIEngine
.Its replacement, the ESLint class, relies on some async-only methods.
However, ESLint rules do not, and per @nzakas in this comment, there have been no discussions or apparent interest in making
Linter
async so that asynchronous rules could be supported.This all means that if
CLIEngine
is dropped, rules cannot take advantage of ESLint linting within their own rules.Why would one want to run linting within a linting rule?
In
eslint-plugin-jsdoc
, we allow it in three cases all within our jsdoc/check-examples rule:To lint JavaScript code within
@example
tagsTo lint a JavaScript value within @default/@defaultvalue tags
To lint a JavaScript expression within the likes of
@param {type} [name=default]
or@property {type} [name=default]
Your take on the correct solution to problem.
Besides adding synchronous methods, I would think that allowing some config to be passed to the
ESLint
class which triggered use of the synchronous rather than asynchronous methods would be sufficient.Are you willing to submit a pull request to implement this change?
Yes (if my health-based limits on energy and concentration allow).
The text was updated successfully, but these errors were encountered: