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

Trailing Comma error in JS files and CallSignature #3830

Closed
SophieLeeroy opened this issue Apr 12, 2018 · 3 comments
Closed

Trailing Comma error in JS files and CallSignature #3830

SophieLeeroy opened this issue Apr 12, 2018 · 3 comments

Comments

@SophieLeeroy
Copy link

SophieLeeroy commented Apr 12, 2018

Bug Report

  • TSLint version:5.9.1
  • TypeScript version:2.8.1
  • Running TSLint via: VSCode

TypeScript code being linted

lot of .ts and .tsx files and 3 pure JavaScript files

with `tslint.json` configuration:
{
	"defaultSeverity": "error",
	"extends": ["tslint:recommended", "tslint-react", "tslint-microsoft-contrib"],
	"jsRules": {},
	"linterOptions": {
		"exclude": ["**/*.js"]
	},
	"rules": {
		"linebreak-style": false,
		"missing-jsdoc": false,
		"typedef": false,
		"quotemark": [false, "double"],
		"indent": [true, "tabs"],
		"member-access": false,
		"jsx-curly-spacing": false,
		"completed-docs": false,
		"react-tsx-curly-spacing": false,
		"no-unsafe-any": false,
		"ordered-imports": false,
		"import-name": false,
		"no-default-export": false,
		"trailing-comma": false,
		"variable-name": false,
		"interface-name": false,
		"export-name": false,
		"strict-boolean-expressions": false,
		"no-relative-imports": false,
		"jsx-no-multiline-js": false,
		"member-ordering": false,
		"eofline": false,
		"jsx-no-lambda": false,
		"react-this-binding-issue": [true, { "allow-anonymous-listeners": true }],
		"match-default-export-name": false,
		"semicolon": false,
		"react-a11y-img-has-alt": false,
		"react-a11y-role-has-required-aria-props": false,
		"react-a11y-anchors": false,
		"react-anchor-blank-noopener": false,
		"no-any": false,
		"no-useless-files": false,
		"no-console": false,
		"no-non-null-assertion": false,
		"align": false,
		"prefer-for-of": false,
		"no-increment-decrement": false,
		"prefer-template": false,
		"restrict-plus-operands": false,
		"insecure-random": false,
		"promise-function-async": false,
		"no-floating-promises": false,
		"prefer-type-cast": false,
		"prefer-array-literal": false,
		"no-suspicious-comment": false,
		"no-unused-variable": true,
		"jsx-boolean-value": false,
		"max-func-body-length": false,
		"max-line-length": false,
		"no-use-before-declare": false,
		"no-single-line-block-comment": false,
		"no-void-expression": false,
		"react-a11y-event-has-role": false,
		"no-implicit-dependencies": false,
		"no-submodule-imports": false,
		"no-import-side-effect": false,
		"number-literal-format": false,
		"binary-expression-operand-order": false,
		"no-parameter-reassignment": false,
		"chai-vague-errors": false,
		"no-http-string": false,
		"no-require-imports": false,
		"function-name": false,
		"no-var-requires": false
	},
	"rulesDirectory": []
}

Note: in tsconfig.json I have already added:
....
"exclude": ["node_modules"]

Actual behavior

TypeError: Cannot read property 'end' of undefined
at cb (.....\node_modules\tslint\lib\rules\trailingCommaRule.js:163:133)
at visitNode (....\node_modules\typescript\lib\typescript.js:13990:24)
at Object.forEachChild (....\node_modules\typescript\lib\typescript.js:14109:21)
at cb (.....\node_modules\tslint\lib\rules\trailingCommaRule.js:170:23)
at visitNode (.....\node_modules\typescript\lib\typescript.js:13990:24)
at Object.forEachChild (....\node_modules\typescript\lib\typescript.js:14204:21)
at cb (....\node_modules\tslint\lib\rules\trailingCommaRule.js:170:23)
at visitNode (....\node_modules\typescript\lib\typescript.js:13990:24)
at Object.forEachChild (....\node_modules\typescript\lib\typescript.js:14251:24)
at cb (....\src\node_modules\tslint\lib\rules\trailingCommaRule.js:170:23)

Expected behavior

Running without error.

I have tried (I know it is not nice, was just experiment) to rewrite ...node_modules\tslint\lib\rules\trailingCommaRule.js at line 162. I have added the same if === undefined, like you guys also did in case of ArrowFunction and it is working like charm.
Can it be that I was looking over something or it is an error in the Force?
Or probably the main problem that the JS files are not excluded.

@JoshuaKGoldberg
Copy link
Contributor

@SophieLeeroy it sounds like you've found a solution (great!) but it's hard to verify the problem or write tests for it without a code snippet that can reproduce the crash. Any chance you can share the specific .ts/.tsx file it crashes on?

Since you're already playing around with the compiled TSLint js, if you add a console log for sourceFile.fileName on line 163 of trailingCommaRule.js it'll tell you which file(s) it's crashing on:

                case ts.SyntaxKind.CallSignature:
                    console.log("Oh my!", sourceFile.fileName);
                    _this.checkList(node.parameters, tsutils_1.getChildOfKind(node, ts.SyntaxKind.CloseParenToken, _this.sourceFile).end, "functions", isRestParameter);
                    break;

@SophieLeeroy
Copy link
Author

SophieLeeroy commented Apr 13, 2018

hi @JoshuaKGoldberg thanks for the help!
I did it and funnily (or not) it is my bundle.js...hmm... I still belive that my JS files create the error, since I have the project without them too and there it is working without issues.
I am using ChartJS library with React and TypeScript. I will try to extract ithe corresponding codeparts to an app that you can check it as well.

Oh my! ...front-end/public/js/bundle.js TypeError: Cannot read property 'end' of undefined at TrailingCommaWalker.checkTypeLiteral (....\node_modules\tslint\lib\rules\trailingCommaRule.js:181:20) at cb (...\node_modules\tslint\lib\rules\trailingCommaRule.js:171:27)

@JoshuaKGoldberg
Copy link
Contributor

👋 @SophieLeeroy - closing this issue as non-actionable for now, but if this is still showing up for you, please do post those codeparts and we can take another look!

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

No branches or pull requests

2 participants