feat(no-use, require-description): additionalDirectives option#267
feat(no-use, require-description): additionalDirectives option#267brettz9 wants to merge 10 commits intoeslint-community:mainfrom
no-use, require-description): additionalDirectives option#267Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #267 +/- ##
==========================================
- Coverage 97.87% 91.95% -5.93%
==========================================
Files 17 18 +1
Lines 282 323 +41
==========================================
+ Hits 276 297 +21
- Misses 6 26 +20 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
27a8384 to
8a09c71
Compare
ota-meshi
left a comment
There was a problem hiding this comment.
Could you please add documentation for the new options?
It would also be useful for users to note that in the require-description rule, the comment format for additional directives must follow ESLint's directive format (directive -- description).
My apologies—added.
Sure, done. |
94ba00c to
75bda61
Compare
lumirlumir
left a comment
There was a problem hiding this comment.
I'm also fairly new to this codebase, so, I have left comments only on the parts I could clearly identify. :)
| const comments = sourceCode.getAllComments | ||
| ? sourceCode.getAllComments() | ||
| : // istanbul ignore next -- CSS doesn't have these comments | ||
| sourceCode.ast.comments || [] |
There was a problem hiding this comment.
I noticed that comments are included in nodes in markdown's AST (not comments property).
https://github.com/eslint/markdown/blob/main/src/language/markdown-source-code.js
This means that the additionalDirectives option cannot be used with markdown.
I think we should change it so that if the sourceCode don't have either getAllComments() or ast.comments, the additionalDirectives option is ignored and we use getAllDirectiveCommentsFromInlineConfigNodes().
We may also need to document this behavior.
There was a problem hiding this comment.
I've added a commit which I think should support Markdown (since it's now checking for .ast.comments as well as .comments)—let me know if you want me to add @eslint/markdown to devDependencies and test it, but I have documented the fact that we may not be able to successfully find comments.
There was a problem hiding this comment.
Just a quick question here.
As far as I know, the Markdown plugin's MarkdownSourceCode and its AST do not include ast.comments.
Currently, there is no direct way or public API to access Markdown's AST comments. It only yields HTML, so if we want to extract comments, I think we'd need to pull them from that HTML.
Am I missing something here?
There was a problem hiding this comment.
Just a quick question here.
As far as I know, the Markdown plugin's
MarkdownSourceCodeand its AST do not includeast.comments.Currently, there is no direct way or public API to access Markdown's AST comments. It only yields HTML, so if we want to extract comments, I think we'd need to pull them from that HTML.
Am I missing something here?
No, you're right. I had just been thinking that .ast.comments could exist because there was .ast (and was vaguely thinking maybe comments in fenced JavaScript blocks could be there, but I see that is not the case). Since the intent here is really just to support the JavaScript-style comments, maybe we can leave any HTML comment parsing to another PR.
There was a problem hiding this comment.
Thanks for confirming!
Thinking about it more, I think this issue can be easily resolved by supporting access to its comments via MarkdownSourceCode#comments, similar to how the JSON/CSS language does.
Could I get some more opinions on this? @ota-meshi @brettz9
I think adding a new public API to expose MarkdownSourceCode#comments would make sense for the use cases here and for consistency with other language plugins. I can open a separate issue in @eslint/markdown if others think that's appropriate.
There was a problem hiding this comment.
SGTM if there is no problem with potential confusability with JavaScript comments using the same API.
There was a problem hiding this comment.
Great — I'll work on this soon, and I hope this PR can be merged shortly after we drop support for older ESLint and Node.js versions, as it includes some workarounds in comments and tests. Please bear with me for a little while.
c5bd398 to
3a381d3
Compare
Co-authored-by: 루밀LuMir <rpfos@naver.com>
Co-authored-by: 루밀LuMir <rpfos@naver.com>
3a381d3 to
ab64dda
Compare
Fixes #265.