-
Notifications
You must be signed in to change notification settings - Fork 72
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
refactor: Errors do not need "new" #2445
base: master
Are you sure you want to change the base?
Conversation
7e45a4d
to
e0fb0a1
Compare
Closes: #XXXX Refs: endojs/endo#2445 ## Description Errors do not need `new` For all construction calls to a `*Error` constructor, the `new` is not needed. IOW, just calling the `*Error` constructor as a function has the same effect. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations none ### Testing Considerations none ### Compatibility Considerations none ### Upgrade Considerations none
e0fb0a1
to
a6852c9
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.
If this change is worth making, it's worth making durably.
Requesting that the lint rules be configured to error on new Error
:
{
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "NewExpression[callee.name='Error']",
"message": "Use Error(msg) instead of new Error(msg)"
}
]
}
}
Should this handle other Error constructors, maybe with a RegExp attribute selector? |
Yes! {
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "NewExpression[callee.name=/^([A-Z]\\w*)?Error$/]",
"message": "Use Error(msg) instead of new Error(msg)"
}
]
}
} |
a6852c9
to
0899aec
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.
👍 assuming ESLint is configured to enforce this (either in this PR or a different one).
0899aec
to
5727d9c
Compare
5727d9c
to
028de23
Compare
Closes: #XXXX
Refs: Agoric/agoric-sdk#10030
Description
Errors do not need
new
For all construction calls to a
*Error
constructor, thenew
is not needed. IOW, just calling the*Error
constructor as a function has the same effect.Security Considerations
none
Scaling Considerations
none
Documentation Considerations
none
Testing Considerations
none
Compatibility Considerations
none
Upgrade Considerations
none