-
Notifications
You must be signed in to change notification settings - Fork 73
feat: add no-empty-definitions rule #364
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
Conversation
Currently, definition(node) {
if (!node.url || node.url === "#") {
context.report({
loc: node.position,
messageId: "emptyDefinition",
});
}
} If our goal is merely to lint empty definitions, this approach works well. However, my original intention in proposing this rule was to catch more error-prone definition patterns. For example: > [def]: def
- [def]: def
* [def]: def
+ [def]: def
[def]: def
[def]: def
[def]: def
[def]: def
[def]: def
[def]: def These are all valid definitions and are correctly parsed as such. But if the URL is omitted, it should be flagged. For example: > [def]:
- [def]:
* [def]:
+ [def]:
[def]:
[def]:
[def]:
[def]:
[def]:
[def]: All of the above should be detected as empty or invalid definitions. The challenge is that some of these aren't parsed as proper In fact, the no-missing-label-refs rule takes a similar approach for the same reason—it needs to handle cases where definitions aren’t recognized as valid AST nodes. These examples cover many invalid cases, but there may still be additional edge cases to consider. |
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.
Pull Request Overview
This PR introduces the new ESLint rule "no-empty-definitions" to prevent empty URL definitions in Markdown documents.
- Adds a new rule implementation in src/rules/no-empty-definitions.js
- Provides tests in tests/rules/no-empty-definitions.test.js to validate the rule
- Updates the documentation in docs/rules/no-empty-definitions.md and README.md
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/rules/no-empty-definitions.test.js | Adds test cases to ensure the rule flags empty URL definitions |
src/rules/no-empty-definitions.js | Implements the rule and reports empty definitions |
docs/rules/no-empty-definitions.md | Documents the rule with examples and guidance |
README.md | Updates the rule list to include the new rule |
As I mentioned in the issue this is not two empty definitions. This is a single valid definition with label |
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. Would like @lumirlumir to review before merging.
As I mentioned in the comment above, we should make sure to handle all cases, including the definition node that Pixel998 pointed out. Right now, the rule doesn't seem to be serving much purpose. Since definition node types are often used in comments as well — sometimes with empty definitions — the current implementation doesn't quite align with what I had in mind. If I'm asking for too much with this rule, I'm happy to hear feedback from the rest of the team. @eslint/eslint-team |
@lumirlumir Can you clarify what cases you have in mind? Do you think that a text like |
Sorry for not clarifying this rule earlier. Here's my suggestion that I originally planned to implement.
|
@lumirlumir Instead of holding up this PR, can we merge this and you can add the additional functionality you have in mind? |
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.
Yes, creating a separate PR for my suggestions would be a better choice.
LGTM, would like @nzakas to review before merging.
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. Thanks!
Prerequisites checklist
What is the purpose of this pull request?
This PR adds a new rule
no-empty-definitions
to prevent empty URL definitionsWhat changes did you make? (Give an overview)
Added the
no-empty-definitions
rule that warns on empty URLs (<>) or empty fragment URLs (#), along with documentation and tests.Related Issues
Closes #359
@lumirlumir About including
[foo]:
in the no-empty-definitions rule, I held off because a few weird things popped up when I looked closer.Take these for example:
You'd think that's two errors, right? But this actually one definition where foo is the label and the URL is [bar].
So, because of these quirks, I think we should do what remark-lint does and actually check the definition nodes themselves in the code. That way, we're looking at the real definitions and not just the text, which seems much more reliable.
Is there anything you'd like reviewers to focus on?