azz / prettier-tslint

Code ➡️ prettier ➡️ tslint --fix ➡️ Formatted Code ✨
https://npm.im/prettier-tslint
MIT License
225 stars 13 forks source link

Incomprehensible errors #10

Closed splincode closed 5 years ago

splincode commented 6 years ago

image

image

azz commented 6 years ago

Hmm, difficult to diagnose from just the stack traces. Could you share:

As well as try to build a minimal reproduction (just delete code until just before the error goes away)?

splincode commented 6 years ago
$ npm ls prettier
rosnfo-ui-app@0.0.0 C:\Develop\rosnfo-ui\rosnfo-ui
`-- prettier@1.10.2
$ npm ls prettier-tslint
rosnfo-ui-app@0.0.0 C:\Develop\rosnfo-ui\rosnfo-ui
`-- prettier-tslint@0.3.0
$ npm ls tslint
rosnfo-ui-app@0.0.0 C:\Develop\rosnfo-ui\rosnfo-ui
+-- prettier-tslint@0.3.0
| `-- tslint@5.9.1
`-- tslint@5.3.2
splincode commented 6 years ago

error occurs on each file

ritesh404 commented 6 years ago

Facing the same issues here as well

dkpalmer commented 6 years ago

I just ran into something similar..

The 'quotemark' rule threw an error in 'src/screens/Screen.tsx':
TypeError: Cannot read property 'kind' of undefined
    at cb (/Users/danny.palmer/project/node_modules/tslint/lib/rules/quotemarkRule.js:83:49)
    at visitNode (/Users/danny.palmer/project/node_modules/typescript/lib/typescript.js:14800:24)
    at Object.forEachChild (/Users/danny.palmer/project/node_modules/typescript/lib/typescript.js:15144:21)
    at cb (/Users/danny.palmer/project/node_modules/tslint/lib/rules/quotemarkRule.js:109:12)
    at visitNodes (/Users/danny.palmer/project/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (/Users/danny.palmer/project/node_modules/typescript/lib/typescript.js:15035:24)
    at walk (/Users/danny.palmer/project/node_modules/tslint/lib/rules/quotemarkRule.js:78:8)
    at Rule.AbstractRule.applyWithFunction (/Users/danny.palmer/project/node_modules/tslint/lib/language/rule/abstractRule.js:39:9)
    at Rule.apply (/Users/danny.palmer/project/node_modules/tslint/lib/rules/quotemarkRule.js:41:21)
    at Linter.applyRule (/Users/danny.palmer/project/node_modules/tslint/lib/linter.js:197:29)

prettier@1.13.7 prettier-tslint@0.4.0 tslint@5.11.0

svipas commented 6 years ago
The 'trailing-comma' rule threw an error in 'hidden.ts':
TypeError: Cannot read property 'end' of undefined
    at cb (/Users/svipben/hidden/node_modules/tslint/lib/rules/trailingCommaRule.js:163:133)
...

P.S. I got even more of them and seems it doesn't format as expected by TSLint.

JimiC commented 6 years ago

prettier-tslint is unusable atm due to those errors.

InExtremaRes commented 6 years ago

I can confirm this happens in our code. Is someone working in this ATM? This issue have a long time.

InExtremaRes commented 6 years ago

@azz I created a minimal repo that reproduces this issue (for me, at least)

https://github.com/InExtremaRes/prettier-tslint-throws

vangelov commented 6 years ago

I'm also getting these errors. It's strange because I'm using VS code with the prettiter-vscode extension which internally uses prettier-tslint and everything works perfectly.

karlhorky commented 6 years ago

I also have these errors on a new project using prettier-tslint on the command line with the following command (no npm script defined in package.json):

# Runs "node_modules/.bin/prettier-tslint fix 'src/**/*.ts'"
yarn prettier-tslint fix 'src/**/*.ts'

This is happening with the following versions (ascertained by using yarn list <package>:

prettier@1.14.3
prettier-tslint@0.4.0
tslint@5.11.0

@azz is there anything else that would help figuring this out? Would you prefer that we open a new issue for this?

Seems like it could be similar to this issue: https://github.com/palantir/tslint/issues/3711


Excerpt of error messages:

➜  keycloak-admin git:(override-config-after-first-auth) ✗ yarn prettier-tslint fix 'src/**/*.ts'
yarn run v1.9.4
$ node_modules/.bin/prettier-tslint fix 'src/**/*.ts'
The 'no-shadowed-variable' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'kind' of undefined
    at cb (keycloak-admin/node_modules/tslint/lib/rules/noShadowedVariableRule.js:191:37)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:14925:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/noShadowedVariableRule.js:223:20)
    at keycloak-admin/node_modules/tslint/lib/rules/noShadowedVariableRule.js:239:24
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15108:21)
    at NoShadowedVariableWalker.visitClassLikeDeclaration (keycloak-admin/node_modules/tslint/lib/rules/noShadowedVariableRule.js:237:12)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/noShadowedVariableRule.js:171:27)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
The 'one-line' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'statements' of undefined
    at Object.isBlockLike (keycloak-admin/node_modules/tsutils/typeguard/2.8/node.js:56:17)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/oneLineRule.js:76:36)
    at visitNode (keycloak-admin/node_modules/typescript/lib/typescript.js:14800:24)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:14928:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/oneLineRule.js:139:23)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15108:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/oneLineRule.js:139:23)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15035:24)
The 'ordered-imports' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode (keycloak-admin/node_modules/typescript/lib/typescript.js:8984:72)
    at NodeObject.getStart (keycloak-admin/node_modules/typescript/lib/typescript.js:106669:23)
    at ImportsBlock.getStartOffset (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:351:25)
    at ImportsBlock.addImportDeclaration (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:297:26)
    at Walker.checkSource (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:181:34)
    at Walker.checkImportDeclaration (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:159:14)
    at Walker.checkStatement (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:137:18)
    at Walker.walk (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:124:18)
    at Rule.AbstractRule.applyWithWalker (keycloak-admin/node_modules/tslint/lib/language/rule/abstractRule.js:31:16)
    at Rule.apply (keycloak-admin/node_modules/tslint/lib/rules/orderedImportsRule.js:29:21)
The 'prefer-const' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'kind' of undefined
    at cb (keycloak-admin/node_modules/tslint/lib/rules/preferConstRule.js:151:33)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/preferConstRule.js:121:33)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15108:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/preferConstRule.js:169:20)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15035:24)
    at PreferConstWalker.walk (keycloak-admin/node_modules/tslint/lib/rules/preferConstRule.js:178:16)
    at Rule.AbstractRule.applyWithWalker (keycloak-admin/node_modules/tslint/lib/language/rule/abstractRule.js:31:16)
    at Rule.apply (keycloak-admin/node_modules/tslint/lib/rules/preferConstRule.js:40:21)
The 'quotemark' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'kind' of undefined
    at cb (keycloak-admin/node_modules/tslint/lib/rules/quotemarkRule.js:83:49)
    at visitNode (keycloak-admin/node_modules/typescript/lib/typescript.js:14800:24)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15144:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/quotemarkRule.js:109:12)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15035:24)
    at walk (keycloak-admin/node_modules/tslint/lib/rules/quotemarkRule.js:78:8)
    at Rule.AbstractRule.applyWithFunction (keycloak-admin/node_modules/tslint/lib/language/rule/abstractRule.js:39:9)
    at Rule.apply (keycloak-admin/node_modules/tslint/lib/rules/quotemarkRule.js:41:21)
    at Linter.applyRule (keycloak-admin/node_modules/tslint/lib/linter.js:197:29)
The 'variable-name' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'kind' of undefined
    at cb (keycloak-admin/node_modules/tslint/lib/rules/variableNameRule.js:95:37)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:14972:24)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/variableNameRule.js:120:19)
    at visitNode (keycloak-admin/node_modules/typescript/lib/typescript.js:14800:24)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:14890:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/variableNameRule.js:120:19)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15042:24)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/variableNameRule.js:120:19)
The 'whitespace' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'kind' of undefined
    at keycloak-admin/node_modules/tslint/lib/rules/whitespaceRule.js:254:44
    at keycloak-admin/node_modules/tsutils/util/util.js:391:16
    at iterate (keycloak-admin/node_modules/tsutils/util/util.js:366:20)
    at Array.forEach (<anonymous>)
    at iterate (keycloak-admin/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
    at iterate (keycloak-admin/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
    at iterate (keycloak-admin/node_modules/tsutils/util/util.js:368:50)
    at Array.forEach (<anonymous>)
The 'no-return-await' rule threw an error in 'src/client.ts':
TypeError: Cannot read property 'kind' of undefined
    at isUnnecessaryAwait (keycloak-admin/node_modules/tslint/lib/rules/noReturnAwaitRule.js:61:31)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/noReturnAwaitRule.js:50:60)
    at visitNode (keycloak-admin/node_modules/typescript/lib/typescript.js:14800:24)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:14893:21)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/noReturnAwaitRule.js:55:19)
    at visitNodes (keycloak-admin/node_modules/typescript/lib/typescript.js:14809:30)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15042:24)
    at cb (keycloak-admin/node_modules/tslint/lib/rules/noReturnAwaitRule.js:55:19)
    at visitNode (keycloak-admin/node_modules/typescript/lib/typescript.js:14800:24)
    at Object.forEachChild (keycloak-admin/node_modules/typescript/lib/typescript.js:15040:21)
src/client.ts
adyz commented 6 years ago

I get the same type of errors when I run prettier-tslint fix \"src/**/*.tsx\"

    "prettier": "^1.14.3",
    "prettier-tslint": "^0.4.0",
    "tslint": "5.11.0",

The result of this is almost perfect compared with the result I get when I run prettier with vs code having prettier.tslintIntegration set to true.

They have a comment there basically saying that they use this plugin so it's strange how that one works and the command line doesn't.

"Use 'prettier-tslint' instead of 'prettier'. Other settings will only be fallbacks in case they could not be inferred from tslint rules."

karlhorky commented 6 years ago

In this project that I'm working in, yarn list typescript reports typescript@2.9.2. Not sure if that could be a problem too.

patoncrispy commented 5 years ago

Yeah I'm having this issue, too. Same config as @adyz.

kramerc commented 5 years ago

The CLI is running this code:

const linter = new tslint.Linter({ fix }, program);

While prettier-vscode is running this code:

const linter = new tslint.Linter({
  fix: false,
  formatter: "json",
});

When I removed the program parameter in the CLI version I noticed the errors stopped happening. That explains why the VS Code extension works fine because the code it's running doesn't pass that parameter. I wasn't able to figure out why errors were getting thrown by TSLint and TypeScript with the program parameter though.

This module is pretty much the equivalent of running Prettier then TSLint with the --fix option, so a workaround for the CLI is to use the following:

prettier --write **/*.ts && tslint --fix --project .
patoncrispy commented 5 years ago

@kramerc's solution is pretty much what I went with. No need for prettier-tslint, really!

aleclarson commented 5 years ago

No need for prettier-tslint, really!

Not true if you use prettier-vscode with "prettier.tslintIntegration": true.

JimiC commented 5 years ago

@aleclarson At vscode-icons we use prettier with "prettier.tslintIntegration": true in setttings and it works just fine. Explaining further: tslintIntegration works when you use the editors formatting feature (Ctr+Shift+I or Alt+Shift+F or whatever other key combination there is). If you want to use the cli then use prettier --write **/*.ts && tslint -p . --fix

aleclarson commented 5 years ago

@JimiC If you install prettier-tslint as a dev dependency, there should be no issues from the CLI. If this package works in vscode and not CLI, it may be improperly installed.

aleclarson commented 5 years ago

Closing this issue. If anyone here is still having problems, please open a new issue and provide a minimal repro. You can use this repo as a starting point.

aleclarson commented 5 years ago

Looks like many errors were being caused by an undefined parent property on AST nodes, which has now been fixed by e06519376f9acb30d6e05e02be49a4505d0b7dd2 (which will be released soon).