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
Add JSDoc type annotations #3731
base: master
Are you sure you want to change the base?
Changes from 2 commits
f2c6548
3465df0
32d4165
9018532
fc04de6
88d2280
4a99c2a
4ae24a2
844d483
0ea8000
eb44ba7
ecee17c
25e6afd
a5ac70f
040d77c
b6856ed
d59ac20
5e77d12
4161d14
aa96591
e2c3497
b392497
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ const messages = { | |
forbiddenValue: '"{{value}}" is an invalid value for button type attribute', | ||
}; | ||
|
||
/** @type { import('eslint').Rule.RuleModule } */ | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
|
@@ -149,9 +150,11 @@ module.exports = { | |
} | ||
|
||
const props = node.arguments[1].properties; | ||
const typeProp = props.find((prop) => prop.key && prop.key.name === 'type'); | ||
const typeProp = props.find( | ||
(prop) => prop.type === "Property" && prop.key && prop.key.type === "PrivateIdentifier" && prop.key.name === 'type' | ||
); | ||
|
||
if (!typeProp) { | ||
if (typeProp.type !== "Property") { | ||
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. these changes aren't simple annotation changes. can they be extracted at least to a different commit, if not to a different PR? 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. I see. My apologies 🙇♂️ 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. yes, that would be fine. any non-type changes that are needed must be accompanied by tests - if the ostensible type error can't be reproduced, then the type system is wrong. |
||
reportMissing(node); | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ const messages = { | |
forbiddenElement_message: '<{{element}}> is forbidden, {{message}}', | ||
}; | ||
|
||
/** @type { import('eslint').Rule.RuleModule } */ | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
|
@@ -103,13 +104,11 @@ module.exports = { | |
return; | ||
} | ||
|
||
const argType = argument.type; | ||
|
||
if (argType === 'Identifier' && /^[A-Z_]/.test(argument.name)) { | ||
if (argument.type === 'Identifier' && /^[A-Z_]/.test(argument.name)) { | ||
reportIfForbidden(argument.name, argument); | ||
} else if (argType === 'Literal' && /^[a-z][^.]*$/.test(argument.value)) { | ||
} else if (argument.type === 'Literal' && /^[a-z][^.]*$/.test(argument.value.toString())) { | ||
reportIfForbidden(argument.value, argument); | ||
} else if (argType === 'MemberExpression') { | ||
} else if (argument.type === 'MemberExpression') { | ||
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. the original only has one observable lookup; this has 3. why is this an improvement? also, 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.
The reason is because the following error message occurs during the execution of the type-check script.
thanks! Fixed in 4ae24a2 . |
||
reportIfForbidden(context.getSourceCode().getText(argument), argument); | ||
} | ||
}, | ||
|
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.
is the type of
node
properly narrowed to a CallExpression node here? if not, let's do that as an annotation on the visitor function rather than needing to add all these runtime changes.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 attempted to make corrections in 040d77c, but is my understanding correct?Sorry. I didn't fully understand it.
The type of node is not properly narrowed down.
It's
(parameter) node: CallExpression & Rule.NodeParentExtension
.