相关疑难解决方法(0)

使用 Typescript 时,为什么 ESLint 尝试在自己的配置文件上运行?

.eslintignore就在旁边eslintrc.js

忽略的原因很简单:

.eslintrc.js
dist/*
node_modules/*
out-tsc/*
Run Code Online (Sandbox Code Playgroud)

但是,当我进入时,eslintrc.js我收到此错误:

Parsing error: ESLint was configured to run on `<tsconfigRootDir>/.eslintrc.js` using `parserOptions.project`: <tsconfigRootDir>/../../../../../../users/dstein/repositories/social-experiment/packages/site/tsconfig.json
However, that TSConfig does not include this file. Either:
- Change ESLint's list of included files to not include this file
- Change that TSConfig to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
See the typescript-eslint docs for more info: https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file
Run Code Online (Sandbox Code Playgroud)

不出所料,它链接到的文章说,.eslintignore如果您不想对错误所在的文件进行 lint …

typescript eslint typescript-eslint

11
推荐指数
1
解决办法
6300
查看次数

加载规则“@typescript-eslint/dot-notation”时出错

今天我运行 eslint?two 脚本

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

Run Code Online (Sandbox Code Playgroud)

当我运行时npm run eslint// 没关系 当我运行时npm run lint-staged// 它是错误的

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 …
Run Code Online (Sandbox Code Playgroud)

javascript eslint husky lint-staged

10
推荐指数
2
解决办法
9684
查看次数

在打字稿中使用 eslint 解析错误,lint 没有获取 parserOptions 配置

我不确定为什么会出现此错误

You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project"
Run Code Online (Sandbox Code Playgroud)

这是我的配置

tsconfig

{
  "compilerOptions": {
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "jsx": "react",
    "rootDir": "src",
    "baseUrl": "src",
    "paths": {
      "@/*": [
        "*"
      ]
    },
    "allowJs": true,
    "resolveJsonModule": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "src/main/test/cypress"
  ]
}
Run Code Online (Sandbox Code Playgroud)

.eslintrc.json

{
  "extends": "standard-with-typescript",
  "parserOptions": {
    "projects": "./tsconfig.json"
  },
  "rules": {
    "@typescript-eslint/consistent-type-definitons": "off", …
Run Code Online (Sandbox Code Playgroud)

typescript eslint

6
推荐指数
1
解决办法
6433
查看次数

错误:.eslintrc.js 中的 ESLint 配置无效:- 意外的顶级属性“文件”

我想指定要在 eslintrc.js 中检查哪些文件,因此我添加了文件:...

module.exports = {
  extends: [
    'react-app',
    'react-app/jest',
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
    'prettier',
  ],
  files: ['*.ts', '*.jsx', '*.ts', '*.tsx'],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: './tsconfig.json',
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 'latest',
    sourceType: 'module',
  },
  rules: {
    'testing-library/no-node-access': 'off',
  },
};
Run Code Online (Sandbox Code Playgroud)

但是当我的预提交运行时出现以下错误:

precommit: BABEL_ENV=development eslint src --ext .js,.jsx,.ts,.tsx --fix'*.ts', '*.tsx'

Error: ESLint configuration in .eslintrc.js is invalid:
    - Unexpected top-level property "files".
Run Code Online (Sandbox Code Playgroud)

javascript eslintrc

5
推荐指数
1
解决办法
7983
查看次数

尝试对 Angular 模板进行 lint 时出现 ESLint 错误

我有一个使用 eslint 和 prettier 设置的 Angular 10 应用程序,到目前为止它可以很好地处理 Typescript 文件。我现在正在尝试按照此文档整理我的组件模板文件。

但是当我运行它时,eslint . --ext .js,.ts,.component.html --fix我不断得到

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.
Run Code Online (Sandbox Code Playgroud)

我的.eslintrc.js看起来像这样(注意本overrides节中的第二个块):

module.exports = {
  extends: [
    "plugin:@angular-eslint/recommended",
    // For spec files
    "plugin:jasmine/recommended",
    // AirBnB Styleguide rules
    "airbnb-typescript/base",
    // Settings for Prettier
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended",
  ],
  plugins: [
    "prettier",
    "jasmine",
  ], …
Run Code Online (Sandbox Code Playgroud)

typescript eslint angular typescript-eslint

4
推荐指数
1
解决办法
8632
查看次数

如何使用 Create-React-App 为 sass-resources-loader 设置 Webpack?

我想用 CSS 模块 + SASS 构建一个项目。我想要一些全局样式(mixins、变量、函数等),这些样式在每个 component.module.scss 中都可用。为此,我需要将全局样式导入到每个模块样式文件中。由于我预计会有很多组件,因此我一直在寻找自动执行此操作的选项。我发现sass-resourcess-loader可能会有所帮助。

然而,由于我没有任何使用 Webpack 的经验,所以我在设置它时遇到了麻烦。

到目前为止我做了什么:

  1. 使用create-react-app创建了我的 React 应用程序
  2. 安装了node-sasssass-resources-loader
  3. 在我的项目文件夹/node_modules/react-scripts/webpack.config.js 的第595行中,我添加了

{ test: /.scss$/, use: [ { loader: "style-loader", }, { loader: "css-loader", }, { loader: "sass-loader", }, { loader: "sass -资源加载器", } ], }

抱歉,我无法以某种方式正确设置该代码片段的样式。我也尝试过选项字段:

options: {
 resources: "./src/global.scss"
}
Run Code Online (Sandbox Code Playgroud)

但没有任何效果,我的模块化 scss 文件中仍然出现未定义的变量。

我究竟做错了什么?或者有其他方法可以解决这个问题吗?

css sass reactjs webpack webpack-4

4
推荐指数
1
解决办法
6460
查看次数

'Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.' 是什么意思。IntelliJ IDE 系列中的错误?

当我打开.vue文件时,我的 IntelliJ IDEA 中出现以下错误:

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: XX\XX\CurrentFile.vue.
The file must be included in at least one of the projects provided.
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

当然,如果你教我解决方案,我会很高兴,但首先我知道它意味着什么以及为什么会出现。

我怀疑这是某种错误或不准确的错误消息。实验上已知:

  1. 有时它会出现,有时 - 不。
  2. 更新 eslint 时总是出现。
  3. 如果eslint从控制台运行某个.vue文件,eslint 将正确完成执行。所以看起来它不是 eslint 错误。

我的 Eslint 配置(YAML):

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: XX\XX\CurrentFile.vue.
The file must be included in at least …
Run Code Online (Sandbox Code Playgroud)

intellij-idea typescript eslint vue.js

1
推荐指数
1
解决办法
7306
查看次数