代码之家  ›  专栏  ›  技术社区  ›  Ole

在eslint推荐的配置中添加忽略项?

  •  -3
  • Ole  · 技术社区  · 1 年前

    我试图添加一个 ignores 反对 typescript-eslint configuration

    我想这会奏效:

    import eslint from "@eslint/js";
    import tseslint from "typescript-eslint";
    
    export default tseslint.config(
      eslint.configs.recommended,
      ...tseslint.configs.recommended,
    ).push({
      ignores: ["build/*"]
    });
    
    

    然而,在跑步时 npx eslint . 它会产生以下错误:

    
    
    Oops! Something went wrong! :(
    
    ESLint: 8.57.0
    
    TypeError: All arguments must be objects.
        at ObjectSchema.merge (/Users/oleersoy/Github/fs-typescript-starter/node_modules/@humanwhocodes/object-schema/src/object-schema.js:234:19)
        at /Users/oleersoy/Github/fs-typescript-starter/node_modules/@humanwhocodes/config-array/api.js:935:42
        at Array.reduce (<anonymous>)
        at FlatConfigArray.getConfig (/Users/oleersoy/Github/fs-typescript-starter/node_modules/@humanwhocodes/config-array/api.js:934:39)
        at FlatConfigArray.isFileIgnored (/Users/oleersoy/Github/fs-typescript-starter/node_modules/@humanwhocodes/config-array/api.js:962:15)
        at /Users/oleersoy/Github/fs-typescript-starter/node_modules/eslint/lib/eslint/eslint-helpers.js:312:49
        at Array.reduce (<anonymous>)
        at entryFilter (/Users/oleersoy/Github/fs-typescript-starter/node_modules/eslint/lib/eslint/eslint-helpers.js:299:28)
        at Object.isAppliedFilter (/Users/oleersoy/Github/fs-typescript-starter/node_modules/@nodelib/fs.walk/out/readers/common.js:12:31)
        at AsyncReader._handleEntry (/Users/oleersoy/Github/fs-typescript-starter/node_modules/@nodelib/fs.walk/out/readers/async.js:86:20)
    

    我们应该如何扩展配置以添加 忽略 ?

    1 回复  |  直到 1 年前
        1
  •  1
  •   SAE    1 年前

    config 期望对象; push 作用于数组。 只需添加额外的规则对象:

    import eslint from "@eslint/js";
    import tseslint from "typescript-eslint";
    
    export default tseslint.config(
      eslint.configs.recommended,
      ...tseslint.configs.recommended,
      {
        ignores: ["build/*"]
      }
    );
    

    看见 here 文件。

    推荐文章