首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用parserOptions和exclude

使用parserOptions和exclude
EN

Stack Overflow用户
提问于 2020-03-15 22:54:17
回答 1查看 617关注 0票数 2

我想将@typescript-eslint/no-floating-promises添加到我的ESLint规则中,并且遇到了困难。

这需要parserOptions

这是我的.eslintrc.js:

代码语言:javascript
复制
module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaVersion: 2017,
    project: './tsconfig.json'
  },
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'prettier'
  ],
  rules: {
    '@typescript-eslint/no-floating-promises': ['error'],
    '@typescript-eslint/no-explicit-any': 'off'
  }
};

我的tsconfig.json:

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["ES2017"],
    "module": "commonjs",
    "declaration": true,
    "outDir": "lib",
    "removeComments": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["src/**/*.spec.ts"]
}

抓到的是exclude。我不希望我的测试(规范)被编译到outDir中。但是,当我运行ESLint时,这会导致以下错误:

错误解析错误:"parserOptions.project“已设置为@parserOptions.project/解析器。该文件与项目配置不匹配: src/index.spec.ts。该文件必须至少包含在所提供的一个项目中。

(脚本为"lint": "eslint \"src/**/*.ts\"" )

do想给我的测试涂上棉线。

在我添加parserOptions之前,一切都很好--我需要这一点来执行no-floating-promises规则。

打字稿-回避常见问题说:

要解决这个问题,只需确保tsconfig中的include选项包含每个要链接的文件。

问题是我正在创建一个库,我不想发布测试文件。

如何在仍在林立所有文件的同时,只构建要发布到一个目录的文件?(我希望使构建尽可能简单。)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-16 05:37:00

我在我的项目中使用了两个tsconfig.json

tsconfig.json

代码语言:javascript
复制
{
  "compilerOptions": {
    "target": "ES2017",
    "lib": ["ES2017"],
    "module": "commonjs",
    "declaration": true,
    "outDir": "lib",
    "removeComments": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"]
}

tsconfig.build.json

代码语言:javascript
复制
{
    "extends": "./tsconfig.json",
    "exclude": ["src/**/*.spec.ts"]
}

要构建该项目,请运行tsc -p tsconfig.build.json

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60698487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档