Fehler beim Laden der Regel „@typescript-eslint/dot-notation“

Lesezeit: 2 Minuten

leofus Benutzeravatar
Leofu

Heute führe ich eslint,two script aus

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

Wenn ich renne npm run eslint // Es ist in Ordnung, wenn ich renne npm run lint-staged // es ist falsch

Ergebnis von lint-staged;

> 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)

Im Paket fusselfrei

Was ist passiert?

"lint-staged": {
    "src/**/*.tsx": [
      "eslint --fix -c .eslintrc.js",
      "git add"
    ]
  },

Sie müssen die folgende Konfiguration zu Ihrer .eslint.json-Datei hinzufügen

{
    "parserOptions": {
        ...
        "project": ["path/to/your/tsconfig/file"]
        ...
    },
}

  • Vielen Dank @Vladimir Jovanović. In meinem Projekt habe ich Folgendes hinzugefügt, da „tsconfig.json“ und „.eslintrc.json“ auf derselben Ebene sind. „parserOptions“: { „Projekt“: [“tsconfig.json”] }

    – Ramya Velivala

    8. April 2021 um 3:14


  • @RamyaVelivala, hast du dein Problem jemals herausgefunden? Ich erlebe das Gleiche

    – bgmaster

    28. Mai 2021 um 15:52 Uhr

  • Diese Antwort sah vielversprechend aus und löste diesen Fehler, führte jedoch zu diesem neuen Eslint-Fehler oben im .eslintrc.js Datei selbst: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js. The file must be included in at least one of the projects provided. stackoverflow.com/q/58510287/470749 scheint verwandt zu sein, aber ich habe keine dieser Antworten zum Laufen gebracht.

    – Ryan

    24. Januar 2022 um 21:19 Uhr

  • Dies sollte Ihre Datei „.eslintrc.js“ sein, die Antwort gilt jedoch weiterhin.

    – Tim

    4. Februar 2022 um 2:52

  • Es ist sehr interessant, dass die offizielle Website sagt, man solle hinzufügen, was nicht funktioniert. Aber diese Lösung funktioniert.

    – Damdafayton

    12. August 2022 um 16:57 Uhr

Für den Fall, dass es jemand hier draußen nutzt .eslintrc.yml Sie können Folgendes verwenden, um das obige Problem zu beheben

extends:
  - airbnb-typescript
parserOptions:
  project:
    - tsconfig.json

PS: tsconfig.json sich im Stammordner befindet, ändern Sie es entsprechend Ihrem Speicherort, falls es sich nicht im Stammordner befindet.

1453990cookie-checkFehler beim Laden der Regel „@typescript-eslint/dot-notation“

This website is using cookies to improve the user-friendliness. You agree by using the website further.

Privacy policy