Cannot read property 'loc' of undefined
See original GitHub issueTell us about your environment
- ESLint Version: v7.13.0
- Node Version: v14.15.1
- npm Version: 6.14.9
What parser (default, @babel/eslint-parser
, @typescript-eslint/parser
, etc.) are you using?
@typescript-eslint/parser
Please show your full configuration:
Configuration
{
"root": true,
"extends": ["xxx", "xxx", "plugin:jest/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6,
"ecmaFeatures": {
"jsx": true
},
"project": "./tsconfig.json"
},
"env": {
"browser": true,
"mocha": true,
"node": true,
"jest": true
},
"plugins": ["jest"],
"rules": {
"indent": ["error", 4, { "SwitchCase": 1 }],
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"jest/no-commented-out-tests": "off"
},
"globals": {
"jQuery": false,
"$": false,
},
"overrides": [
{
"files": ["test/integration/**/*"],
"rules":{
"@typescript-eslint/no-require-imports": "off"
}
}
]
}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint. type const in ts file , output above error messages
[Error - 6:22:23 PM] ESLint stack trace: [Error - 6:22:23 PM] TypeError: Cannot read property ‘loc’ of undefined Occurred while linting /Users/xxx/xxx/test/unit/xxx/src/core/xxxx/xxx/cell/xxxx.spec.ts:1 at Object.VariableDeclaration [as listener] (/Users/xxxx/xxx/node_modules/eslint/lib/rules/indent.js:1422:69) at /Users/xxx/xxx/node_modules/eslint/lib/rules/indent.js:1634:55 at Array.forEach () at Program:exit (/Users/xxxx/xxx/node_modules/eslint/lib/rules/indent.js:1634:26) at /Users/xxxx/xxxx/node_modules/eslint/lib/linter/safe-emitter.js:45:58 at Array.forEach () at Object.emit (/Users/xxxx/sheet/node_modules/eslint/lib/linter/safe-emitter.js:45:38) at NodeEventGenerator.applySelector (/Users/xxx/xxxx/node_modules/eslint/lib/linter/node-event-generator.js:254:26) at NodeEventGenerator.applySelectors (/Users/xxx/xxx/node_modules/eslint/lib/linter/node-event-generator.js:283:22) at NodeEventGenerator.leaveNode (/Users/xxxx/xxx/node_modules/eslint/lib/linter/node-event-generator.js:306:14)
What did you expect to happen?
What actually happened? Please include the actual, raw output from ESLint.
Are you willing to submit a pull request to fix this bug?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Hi @zhongzhong0505, thanks for the issue!
Some core rules don’t work well with typescript code. In that case, replacement rules from @typescript-eslint/eslint-plugin should be used instead. You can find more details here:
https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#i-am-using-a-rule-from-eslint-core-and-it-doesnt-work-correctly-with-typescript-code.
Can you try with
@typescript-eslint/indent
instead of the coreindent
rule:I would recommend to include the amount of indents that are wished: