Tslint: Errors when using with typescript 3.0

Created on 6 Jul 2018  路  12Comments  路  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.10
  • __TypeScript version__: ^3.0.0-dev.20180704
  • __Running TSLint via__: (pick one) CLI
The 'no-string-literal' rule threw an error in '/Users/chemzqm/vim-dev/coc.nvim/src/language-client/utils/electron.ts':
TypeError: ts.unescapeIdentifier is not a function
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:54:39)
    at visitNode (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15089:24)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15302:24)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
    at visitNode (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15089:24)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15333:24)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
    at visitNodes (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15098:30)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15322:24)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
The 'no-string-literal' rule threw an error in '/Users/chemzqm/vim-dev/coc.nvim/src/extensions/tsserver/utils/configuration.ts':
TypeError: ts.unescapeIdentifier is not a function
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:54:39)
    at visitNodes (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15098:30)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15276:21)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
    at visitNodes (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15098:30)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15276:21)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
    at visitNode (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15089:24)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15304:21)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
The 'no-string-literal' rule threw an error in '/Users/chemzqm/vim-dev/coc.nvim/src/extensions/tsserver/utils/process.ts':
TypeError: ts.unescapeIdentifier is not a function
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:54:39)
    at visitNode (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15089:24)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15302:24)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
    at visitNode (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15089:24)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15333:24)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)
    at visitNodes (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15098:30)
    at Object.forEachChild (/Users/chemzqm/vim-dev/coc.nvim/node_modules/typescript/lib/typescript.js:15322:24)
    at cb (/Users/chemzqm/vim-dev/coc.nvim/node_modules/tslint/lib/rules/noStringLiteralRule.js:60:19)

TypeScript code being linted

Error only happens when I lint project by

./node_modules/.bin/tslint -c tslint.json -p .

with tslint.json configuration:

{
  "extends": "./node_modules/@chemzqm/tslint-config/tslint.json",
  "rules": {
    "eofline": false,
    "no-unbound-method": false,
    "no-use-before-declare": false,
    "no-invalid-template-strings": false,
    "no-unused-expression": false,
    "member-ordering": false,
    "no-unnecessary-qualifier": false,
    "ban-types": false,
    "return-undefined": false,
    "no-unused-variable": false,
    "no-console":true
  },
  "linterOptions": {
    "exclude": [
      "**/catalog.json"
    ]
  }
}

Actual behavior

When using command

./node_modules/.bin/tslint -c tslint.json -p .

I would get a lot of error, but when using global installed tslint like

tslint -c tslint.json -p .

I would not have any error.

Expected behavior

Looks like something is broken when using typescript 3.0 branch.

Most helpful comment

I had the same problem updating all these packages to latest versions did the trick

ts-loader - 5.2.1
tsconfig-paths-webpack-plugin -3.2.0
tslint - 5.11.0
ts-jest - 23.10.4
typescript -3.1.1

All 12 comments

Ref https://github.com/Microsoft/TypeScript/wiki/API-Breaking-Changes

The deprecated functions escapeIdentifier and unescapeIdentifier have been removed. Due to changing how the identifier name API worked in general, they have been identity functions for a few releases, so if you need your code to behave the same way, simply removing the calls should be sufficient. Alternatively, the typesafe escapeLeadingUnderscores and unescapeLeadingUnderscores should be used if the types indicate they are required (as they are used to convert to or from branded __String and string types).

Also this has been fixed upstream
https://github.com/ajafff/tsutils/issues/71
and is correctly referenced as part of the deps, so maybe you need to check the installed version on your side.
That worked for me!

4039

This has been fixed, but the TSLint team hasn't yet published a new version with the fixes.

Ping @johnwiseheart as you touched things last 馃槈

What I'm saying is that you can manually upgrade your local version (and hopefully fix it in your yarn.lock (provided you use yarn) ) as a workaround.

A new version has been released, but waiting until the github flakiness is resolved to push the new docs. Going to close this out - let me know if v5.11.0 isn't working for you by reopening this issue.

@johnwiseheart This issue needs to reopen.

The 'comment-format' rule threw an error in '/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/src/components/FlexCard.tsx':
TypeError: Cannot read property 'kind' of undefined
    at isJsxElementOrFragment (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:433:17)
    at canHaveTrailingTrivia (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:415:74)
    at /Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:404:23
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:366:20)
    at Array.forEach (<anonymous>)
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:368:50)
The 'jsdoc-format' rule threw an error in '/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/src/components/FlexCard.tsx':
TypeError: Cannot read property 'kind' of undefined
    at isJsxElementOrFragment (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:433:17)
    at canHaveTrailingTrivia (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:415:74)
    at /Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:404:23
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:366:20)
    at Array.forEach (<anonymous>)
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
    at iterate (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/node_modules/tsutils/util/util.js:368:50)
The 'no-shadowed-variable' rule threw an error in '/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/src/components/FlexCard.tsx':
TypeError: Cannot read property 'kind' of undefined
    at cb (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/lib/rules/noShadowedVariableRule.js:191:37)
    at visitNodes (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/typescript/lib/typescript.js:15129:30)
    at Object.forEachChild (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/typescript/lib/typescript.js:15245:21)
    at cb (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/lib/rules/noShadowedVariableRule.js:223:20)
    at visitNode (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/typescript/lib/typescript.js:15120:24)
    at Object.forEachChild (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/typescript/lib/typescript.js:15213:21)
    at cb (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/lib/rules/noShadowedVariableRule.js:228:27)
    at visitNodes (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/typescript/lib/typescript.js:15129:30)
    at Object.forEachChild (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/typescript/lib/typescript.js:15362:24)
    at cb (/Users/ingrowth/Documents/Projects/sqlgate-drive/drive-web/src/main/node/node_modules/tslint/lib/rules/noShadowedVariableRule.js:228:27)
    "tslint": "^5.11.0",
    "tslint-config-prettier": "^1.14.0",
    "tslint-react": "^3.6.0",
    "tsutils": "^3.0.0",

Hi @gimdongwoo, can you please make a new issue for this, seeing as your stack trace is significantly different to the original posters?

@johnwiseheart All error's origin is equal.

The messages are depended on rules.

Sure, the origin of being because of typescript 3.0 may be the same, but all of the original posters issues are specific to the no-string-literal rule with error message ts.unescapeIdentifier is not a function. This was caused by using an old version of tsutils (and was fixed). Your errors are all Cannot read property 'kind' of undefined (which is an error in a different file to the OP), and someone wanting to fix your issue is more likely to find your stacktrace if you make a new issue.

I'm getting this error in the rule no-parameter-reassignment.

javascript The 'no-parameter-reassignment' rule threw an error in 'client/src/main.ts': TypeError: ts.unescapeIdentifier is not a function

I had the same problem updating all these packages to latest versions did the trick

ts-loader - 5.2.1
tsconfig-paths-webpack-plugin -3.2.0
tslint - 5.11.0
ts-jest - 23.10.4
typescript -3.1.1

I also got the TypeError: ts.unescapeIdentifier is not a function errormessage, but it was due to a typo in the sonar.issue.ignore.multicriteria values in one of packages' sonar-project.properties file.

Was this page helpful?
0 / 5 - 0 ratings