-
Notifications
You must be signed in to change notification settings - Fork 73
feat: add allow options to no-empty-definitions #455
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,7 +10,7 @@ | |||||||||||||
/** | ||||||||||||||
* @import { MarkdownRuleDefinition } from "../types.js"; | ||||||||||||||
* @typedef {"emptyDefinition" | "emptyFootnoteDefinition"} NoEmptyDefinitionsMessageIds | ||||||||||||||
* @typedef {[{ checkFootnoteDefinitions?: boolean }]} NoEmptyDefinitionsOptions | ||||||||||||||
* @typedef {[{ allowDefinitions?: string[], allowFootnoteDefinitions?: string[], checkFootnoteDefinitions?: boolean }]} NoEmptyDefinitionsOptions | ||||||||||||||
* @typedef {MarkdownRuleDefinition<{ RuleOptions: NoEmptyDefinitionsOptions, MessageIds: NoEmptyDefinitionsMessageIds }>} NoEmptyDefinitionsRuleDefinition | ||||||||||||||
*/ | ||||||||||||||
|
||||||||||||||
|
@@ -56,6 +56,20 @@ export default { | |||||||||||||
{ | ||||||||||||||
type: "object", | ||||||||||||||
properties: { | ||||||||||||||
allowDefinitions: { | ||||||||||||||
type: "array", | ||||||||||||||
items: { | ||||||||||||||
type: "string", | ||||||||||||||
}, | ||||||||||||||
uniqueItems: true, | ||||||||||||||
}, | ||||||||||||||
allowFootnoteDefinitions: { | ||||||||||||||
type: "array", | ||||||||||||||
items: { | ||||||||||||||
type: "string", | ||||||||||||||
}, | ||||||||||||||
uniqueItems: true, | ||||||||||||||
}, | ||||||||||||||
checkFootnoteDefinitions: { | ||||||||||||||
type: "boolean", | ||||||||||||||
}, | ||||||||||||||
|
@@ -64,15 +78,28 @@ export default { | |||||||||||||
}, | ||||||||||||||
], | ||||||||||||||
|
||||||||||||||
defaultOptions: [{ checkFootnoteDefinitions: true }], | ||||||||||||||
defaultOptions: [ | ||||||||||||||
{ | ||||||||||||||
allowDefinitions: ["//"], | ||||||||||||||
allowFootnoteDefinitions: [], | ||||||||||||||
checkFootnoteDefinitions: true, | ||||||||||||||
}, | ||||||||||||||
], | ||||||||||||||
}, | ||||||||||||||
|
||||||||||||||
create(context) { | ||||||||||||||
const allowDefinitions = new Set(context.options[0]?.allowDefinitions); | ||||||||||||||
const allowFootnoteDefinitions = new Set( | ||||||||||||||
context.options[0]?.allowFootnoteDefinitions, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using optional chaining here assumes
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback
TKDev7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
); | ||||||||||||||
const [{ checkFootnoteDefinitions }] = context.options; | ||||||||||||||
|
||||||||||||||
return { | ||||||||||||||
definition(node) { | ||||||||||||||
if (!node.url || node.url === "#") { | ||||||||||||||
if ( | ||||||||||||||
(!node.url || node.url === "#") && | ||||||||||||||
!allowDefinitions.has(node.identifier) | ||||||||||||||
) { | ||||||||||||||
context.report({ | ||||||||||||||
loc: node.position, | ||||||||||||||
messageId: "emptyDefinition", | ||||||||||||||
|
@@ -83,6 +110,7 @@ export default { | |||||||||||||
footnoteDefinition(node) { | ||||||||||||||
if ( | ||||||||||||||
checkFootnoteDefinitions && | ||||||||||||||
!allowFootnoteDefinitions.has(node.identifier) && | ||||||||||||||
(node.children.length === 0 || | ||||||||||||||
node.children.every( | ||||||||||||||
child => | ||||||||||||||
|
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.
Because ESLint does not deep-merge defaultOptions with a user-supplied options object, users who specify only one property will lose the defaults for the others. Consider destructuring
context.options[0]
with in-function defaults (e.g.,const { allowDefinitions = ["//"], allowFootnoteDefinitions = [], checkFootnoteDefinitions = true } = context.options[0] || {};
) to ensure all defaults apply even when partial options are provided.Copilot uses AI. Check for mistakes.