Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Commit

Permalink
[fix] making sure the identifier is the expression of the property ac…
Browse files Browse the repository at this point in the history
…cess expression

We just need to make sure that the identifier is the caller, we can do
this by making sure that the expression in the PropertyAccessExpression
is the identifier. If this wasn’t the case, then the expression
property will be another PropertyAccessExpression.
  • Loading branch information
Manuel Lopez committed Dec 25, 2016
1 parent 258c24c commit 0a9a882
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/rules/handleCallbackErrRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ class ErrCallbackHandlerWalker extends Lint.RuleWalker {
doCheck = !inPropertyAccess;
} else if (inPropertyAccess) {
// Make sure we are not in nested property access, i.e. caller.caller.error.prop
const isCaller = (node.parent as ts.PropertyAccessExpression).expression === node;
doCheck = isCaller && !this.isPropAccess(node.parent.parent);
doCheck = (node.parent as ts.PropertyAccessExpression).expression === node;
} else {
doCheck = true;
}
Expand Down
30 changes: 30 additions & 0 deletions src/test/rules/handleCallbackErrRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,41 @@ ruleTester.addTestGroup('standard-fail', 'should fail with standard config', [
]);

ruleTester.addTestGroup('custom-error-name-pass', 'should pass with custom error name', [
{
code: dedent`
function isRecoverable (error: TSError) {
return error.diagnostics.every(x => RECOVERY_CODES.indexOf(x.code) > -1)
}`,
options: ['error']
},
{
code: dedent`
const foo = (error: TSError) => {
return error.one.two.three.four.five(0);
}`,
options: ['error']
},
{ code: `function(errorMsg, stream) { console.error(errorMsg) }`, options: ['errorMsg'] },
{ code: `function(err, stream) { }`, options: ['errorMsg'] }
]);

ruleTester.addTestGroup('custom-error-name-fail', 'should fail with custom error name', [
{
code: dedent`
const foo = (error: TSError) => {
return one.two.three.error.four.five(0);
}`,
options: ['error'],
errors: [error]
},
{
code: dedent`
const foo = (error: TSError) => {
return error.one.two.three.four.five(0);
}`,
options: ['error', { allowProperties: false }],
errors: [strictError]
},
{ code: `function(errorMsg, stream) { }`, options: ['errorMsg'], errors: [error] },
{
code: `error => console.error('Could not print the document');`,
Expand Down

0 comments on commit 0a9a882

Please sign in to comment.