-
Notifications
You must be signed in to change notification settings - Fork 779
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
fix(rule,check): allow function ids for matches property in rule.configure #2423
Conversation
@@ -9,7 +9,14 @@ export function createExecutionContext(spec) { | |||
return metadataFunctionMap[spec]; | |||
} | |||
|
|||
return new Function('return ' + spec + ';')(); | |||
// execution contexts can only be functions | |||
if (/^\s*function[\s\w]*\(/.test(spec)) { |
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.
What about "arrow functions"?
return this.evaluate(); | ||
}; | ||
var check = new Check({ | ||
evaluate: 'function () { return "foo"; }' |
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.
What happens if we do this:
evaluate: '() => "foo"'
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.
As far as I know we don't allow that. Although it is possible, we only support doT.js template output which uses functions
.
@WilcoFiers do you find this a problem (especially since we deprecated this?)
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 don't think this is a problem, no.
return this.evaluate(); | ||
}; | ||
var check = new Check({ | ||
evaluate: 'function () { return "foo"; }' |
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 don't think this is a problem, no.
@downzer0 discovered this one when trying to configure a rule with a
matches
function ID. I added tests to ensure this should work now as well as throw a more helpful message as the default was eval the string as code and you'd get athing is not defined
error which was super unhelpful. So now you should get an error with the name of the string you used.Reviewer checks
Required fields, to be filled out by PR reviewer(s)