Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while loading rule '@typescript-eslint/dot-notation'

Tags:

Today I run eslint,two script

 "lint-staged": "lint-staged",
 "eslint": "eslint --ext .tsx,.ts --fix ./src -c .eslintrc.js",

When I run npm run eslint // it's ok When I run npm run lint-staged // it's wrong

lint-staged's result ;

> lint-staged
  ❯ Running tasks for src/**/*.tsx
    ✖ eslint --fix [FAILED]
    ◼ git add
  
✖ eslint --fix :


Oops! Something went wrong! :(

ESLint: 7.10.0

Error: Error while loading rule '@typescript-eslint/dot-notation': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Occurred while linting /Users/***/components/BrowserInfo/Index.tsx
    at Object.getParserServices (/Users/fugang/workspace/xinao/channel-desk/node_modules/_@[email protected]@@typescript-eslint/experimental-utils/dist/eslint-utils/getParserServices.js:26:15)

In package lint-staged

What happend?

"lint-staged": {
    "src/**/*.tsx": [
      "eslint --fix -c .eslintrc.js",
      "git add"
    ]
  },
like image 701
leofu Avatar asked Sep 29 '20 09:09

leofu


People also ask

How do I turn off Eslint dot notation?

Set the allowKeywords option to false (default is true ) to follow ECMAScript version 3 compatible style, avoiding dot notation for reserved word properties.

What is a dot notation in TypeScript?

The question mark dot (?.) syntax is called optional chaining in TypeScript and is like using dot notation to access a nested property of an object, but instead of causing an error if the reference is nullish, it short-circuits returning undefined .


1 Answers

You have to add the following config to your .eslint.json file

{
    "parserOptions": {
        ...
        "project": ["path/to/your/tsconfig/file"]
        ...
    },
}
like image 138
Vladimir Jovanović Avatar answered Oct 21 '22 09:10

Vladimir Jovanović