-
Notifications
You must be signed in to change notification settings - Fork 889
[no-object-literal-type-assertion] New option: "allow-arguments" #4521
[no-object-literal-type-assertion] New option: "allow-arguments" #4521
Conversation
Thanks for your interest in palantir/tslint, @karol-majewski! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
083ee70
to
d0f19c6
Compare
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.
Mostly looks good! Just a couple of touchups.
test/rules/no-object-literal-type-assertion/allow-arguments/test.ts.lint
Show resolved
Hide resolved
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.
Awesome, thanks for this @karol-majewski! The implementation LGTM.
I'd like to get feedback from someone from @palantirtech on the design addition here, since it wasn't explicitly stated in the issue.
@adidahiya |
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 otherwise
|
||
* \`${OPTION_ALLOW_ARGUMENTS}\` allows type assertions to be used on object literals inside call expressions.`, | ||
options: { | ||
type: "array", |
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.
you don't need to wrap the object in an array, you can just bring the object out as the top level options
value
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.
Done! Thank you.
PR checklist
Overview of change:
This option allows using a type assertion when an object literal is used as an argument. A common use case is the second parameter for
Array.prototype.reduce
, where an empty object is often used as the initial value.CHANGELOG.md entry:
[new-rule-option]
no-object-literal-type-assertion
rule accepts an option calledallow-arguments
. It allows using type assertions on object literals used inside call expressions.