Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

arguments-order rule threw an error #836

Open
Arielliv opened this issue Mar 11, 2019 · 4 comments
Open

arguments-order rule threw an error #836

Arielliv opened this issue Mar 11, 2019 · 4 comments
Labels

Comments

@Arielliv
Copy link

Arielliv commented Mar 11, 2019

I want to report a bug.
I want to report a bug where 'arguments-order' rule threw an error for a specific code.

SonarTS version: 1.9.0

Node.js version: 10.14.2

TypeScript version: 3.3.3333

TSLint version: 5.13.1

Rule key: 'arguments-order'

Reproducer

const params = {
  name: 'name',
};
expect('string').toHaveBeenCalledWith('something to test', params);

Logs

The 'arguments-order' rule threw an error in '/Users/ariell/Projects/client/page/src/components/Options/Options.spec.ts':
TypeError: Cannot read property 'name' of undefined
    at Visitor.getSwappedPairArgument (node_modules/tslint-sonarts/lib/rules/argumentsOrderRule.js:68:47)
    at Visitor.visitCallExpression (node_modules/tslint-sonarts/lib/rules/argumentsOrderRule.js:51:54)
    at Visitor.visitNode (node_modules/tslint-sonarts/lib/utils/visitor.js:350:22)
    at ts.forEachChild.child (node_modules/tslint-sonarts/lib/utils/visitor.js:585:45)
    at visitNode (node_modules/typescript/lib/typescript.js:16215:24)
    at Object.forEachChild (/node_modules/typescript/lib/typescript.js:16461:24)
    at Visitor.visitChildren (node_modules/tslint-sonarts/lib/utils/visitor.js:585:12)
    at Visitor.visitExpressionStatement (node_modules/tslint-sonarts/lib/utils/visitor.js:119:14)
    at Visitor.visitNode (node_modules/tslint-sonarts/lib/utils/visitor.js:407:22)
    at ts.forEachChild.child (node_modules/tslint-sonarts/lib/utils/visitor.js:585:45)

Expected behavior
not to throw an error.

i changed the varible name from params to parameters and it fixed it

@buffcode
Copy link

buffcode commented Apr 4, 2019

I can reproduce the exact same error using different code:

export interface Logger {
  debug: (...args: any[]) => void;
}

(({} as Logger).debug(command, args));

whereas the args parameter in line 4 when calling must be named exactly the same as in line 2.

This throws

ERROR: Rule error during analysis of : index.ts TypeError: Cannot read property 'name' of undefined
ERROR:     at Visitor.getSwappedPairArgument (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\rules\argumentsOrderRule.js:68:47)
ERROR:     at Visitor.visitCallExpression (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\rules\argumentsOrderRule.js:51:54)
ERROR:     at Visitor.visitNode (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\utils\visitor.js:350:22)
ERROR:     at ts.forEachChild.child (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\utils\visitor.js:585:45)
ERROR:     at visitNode (node_modules\typescript\lib\typescript.js:16135:24)
ERROR:     at Object.forEachChild (node_modules\typescript\lib\typescript.js:16333:24)
ERROR:     at Visitor.visitChildren (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\utils\visitor.js:585:12)
ERROR:     at Visitor.visitParenthesizedExpression (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\utils\visitor.js:215:14)
ERROR:     at Visitor.visitNode (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\utils\visitor.js:494:22)
ERROR:     at ts.forEachChild.child (.scannerwork\sonarts-bundle\node_modules\tslint-sonarts\lib\utils\visitor.js:585:45)

Version info:

INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: User cache: C:\Users\Laurens\.sonar\cache
INFO: SonarQube server 7.7.0

@mrdulin
Copy link

mrdulin commented Jun 12, 2019

same issue.

@Mboulianne
Copy link

We've got the same issue

@vilchik-elena
Copy link
Contributor

@Mboulianne can you reproduce with latest release? TS is now analyzed by SonarJS 6.1

If yes, please report it in https://github.com/SonarSource/SonarJS

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants