简体   繁体   English

迁移到 ESLint

[英]Migration to ESLint

I want to migrate my angular app to ESLint instead of TSLint because of two reasons:由于两个原因,我想将我的 angular 应用程序迁移到 ESLint 而不是 TSLint:

I don't seem to find any tutorial for angular.我似乎没有找到任何角度的教程。 Is there someone who did that?有没有人这样做过? I can use ESLint but what about all TSLint remaining files/settings?我可以使用 ESLint,但是 TSLint 剩余的所有文件/设置呢?

I just want the indent option to be working, somehow.我只是想让缩进选项以某种方式工作。

"indent": {
  "options": ["spaces", 2]
}

Any recommendations?有什么建议吗? What do you guys use?你们都用什么?

I am currently migrating my angular app to eslint.我目前正在将我的 angular 应用程序迁移到 eslint。 I extend the eslint configuration by adding the packages @typescript-eslint/parser and the @†ypescript-eslint/eslint-plugin .我通过添加包@typescript-eslint/parser@†ypescript-eslint/eslint-plugin 来扩展 eslint 配置。 Currently I am still setting up the whole eslint configuration but I hope these two links already helped you.目前我仍在设置整个 eslint 配置,但我希望这两个链接已经对您有所帮助。

For the indent I added:对于缩进,我添加了:

"@typescript-eslint/indent": ["error", 4]

to the rules object.rules对象。

Try This https://stackoverflow.com/a/65552444/14764759 tslint-to-eslint-config试试这个https://stackoverflow.com/a/65552444/14764759 tslint-to-eslint-config

Code Style: Prettier Coverage: 100% TypeScript: Strict NPM version Circle CI Join the chat at https://gitter.im/tslint-to-eslint-config/community Code Style: Prettier代码风格:Prettier 覆盖率:100% TypeScript:Strict NPM 版本 Circle CI 加入聊天: https ://gitter.im/tslint-to-eslint-config/community 代码风格:Prettier

Converts your TSLint configuration to the closest reasonable ESLint equivalent.将您的 TSLint 配置转换为最接近的合理 ESLint 等效项。

TSLint is deprecated. TSLint 已弃用。 Use tslint-to-eslint-config to expedite migrating your project onto ESLint.使用 tslint-to-eslint-config 加快将您的项目迁移到 ESLint。

Consider taking a peek at the relevant documentation:考虑查看相关文档:

ESLint itself
typescript-eslint, which allows TypeScript files to be linted by ESLint

Usage用法

npx tslint-to-eslint-config npx tslint-to-eslint-config

The tslint-to-eslint-config command reads in any existing linter, TypeScript, and package configuration files, then creates an .eslintrc.js result based on them. tslint-to-eslint-config 命令读入任何现有的 linter、TypeScript 和包配置文件,然后基于它们创建 .eslintrc.js 结果。

For any TSLint rules with corresponding ESLint equivalents, those equivalents will be used in the new configuration.对于任何具有相应 ESLint 等效项的 TSLint 规则,这些等效项将在新配置中使用。 TSLint rules without ESLint equivalents will be wrapped with eslint-plugin-tslint.没有 ESLint 等效项的 TSLint 规则将用 eslint-plugin-tslint 包装。

Requires Node 10+ (LTS) and TSLint 5.18+

FAQs常见问题

We strongly advise reading docs/FAQs.md before planning your conversion from TSLint to ESLint.我们强烈建议您在计划从 TSLint 到 ESLint 的转换之前阅读 docs/FAQs.md。 CLI Flags CLI 标志

Each of these flags is optional:这些标志中的每一个都是可选的:

comments: TypeScript configuration or file glob path(s) to convert TSLint rule flags to ESLint within.
config: Path to print the generated ESLint configuration file to.
editor: Path to an editor configuration file to convert linter settings within.
eslint: Path to an ESLint configuration file to read settings from.
package: Path to a package.json file to read dependencies from.
prettier: Add eslint-config-prettier to the plugins list.
tslint: Path to a TSLint configuration file to read settings from.
typescript: Path to a TypeScript configuration file to read TypeScript compiler options from.

comments注释

npx tslint-to-eslint-config --comments npx tslint-to-eslint-config --comments

Default: none默认值:无

Indicates to convert from TSLint rule flags to ESLint inline comments.表示从 TSLint 规则标志转换为 ESLint 内联注释。 Comments such as // tslint:disable: tslint-rule-name will be converted to equivalents like // eslint-disable eslint-rule-name.诸如 // tslint:disable: tslint-rule-name 之类的注释将被转换为 // eslint-disable eslint-rule-name 之类的等效项。

If passed without arguments, respects the excludes, files, and includes in your TypeScript configuration.如果不带参数传递,则尊重 TypeScript 配置中的排除、文件和包含。

If passed a single file path ending with .json, that is treated as a TypeScript configuration file describing with files to convert.如果传递以 .json 结尾的单个文件路径,则将其视为描述要转换的文件的 TypeScript 配置文件。

npx tslint-to-eslint-config --comments tsconfig.json npx tslint-to-eslint-config --comments tsconfig.json

If passed any other arguments, those are treated as glob paths for file paths to convert:如果传递了任何其他参数,则这些参数将被视为要转换的文件路径的全局路径:

npx tslint-to-eslint-config --comments 'src/**/*.ts' npx tslint-to-eslint-config --comments 'src/**/*.ts'

config配置

npx tslint-to-eslint-config --config .eslintrc.json npx tslint-to-eslint-config --config .eslintrc.json

Default: .eslintrc.js默认值:.eslintrc.js

Path to print the generated ESLint configuration file to.将生成的 ESLint 配置文件打印到的路径。

The file extension of this path will be used to determine the format of the created file:此路径的文件扩展名将用于确定创建的文件的格式:

.js file paths will be written module.exports = ... JavaScript
Other file paths will default to JSON

editor编辑

npx tslint-to-eslint-config --editor ./path/to/.vscode/settings.json npx tslint-to-eslint-config --editor ./path/to/.vscode/settings.json

Default: .vscode/settings.json默认值:.vscode/settings.json

Path to an editor configuration file to convert settings settings within.用于在其中转换设置设置的编辑器配置文件的路径。 Any VS Code style editor settings for TSLint will be converted to their ESLint equivalents. TSLint 的任何 VS Code 样式编辑器设置都将转换为其等效的 ESLint。 eslint eslint

npx tslint-to-eslint-config --eslint ./path/to/eslintrc.js npx tslint-to-eslint-config --eslint ./path/to/eslintrc.js

Default: --config's value默认值:--config 的值

Path to an ESLint configuration file to read settings from.要从中读取设置的 ESLint 配置文件的路径。 The generated ESLint configuration file will include any settings imported from this file.生成的 ESLint 配置文件将包含从此文件导入的任何设置。 package包裹

npx tslint-to-eslint-config --package ./path/to/package.json npx tslint-to-eslint-config --package ./path/to/package.json

Default: package.json默认值:package.json

Path to a package.json file to read dependencies from.要从中读取依赖项的 package.json 文件的路径。 This will help inform the generated ESLint configuration file's env settings.这将有助于通知生成的 ESLint 配置文件的 env 设置。 prettier更漂亮

npx tslint-to-eslint-config --prettier npx tslint-to-eslint-config --prettier

Default: false默认值:假

Add eslint-config-prettier to the list of ESLint plugins.将 eslint-config-prettier 添加到 ESLint 插件列表中。 We highly recommend you use Prettier for code formatting.我们强烈建议您使用 Prettier 进行代码格式化。

When --prettier isn't enabled:当 --prettier 未启用时:

If the output configuration already doesn't enable any formatting rules, it'll extend from eslint-config-prettier.
Otherwise, a CLI message will suggest running with --prettier.

tslint特林特

npx tslint-to-eslint-config --tslint ./path/to/tslint.json npx tslint-to-eslint-config --tslint ./path/to/tslint.json

Default: tslint.json默认值:tslint.json

Path to a TSLint configuration file to read settings from.要从中读取设置的 TSLint 配置文件的路径。 This file is piped into TSLint's --print-config to generate the list of rules to enable in the generated ESLint configuration file.此文件通过管道传输到 TSLint 的 --print-config 以生成要在生成的 ESLint 配置文件中启用的规则列表。 typescript打字稿

npx tslint-to-eslint-config --typescript ./path/to/tsconfig.json npx tslint-to-eslint-config --typescript ./path/to/tsconfig.json

Default: tsconfig.json默认值:tsconfig.json

Path to a TypeScript configuration file to read TypeScript compiler options from.要从中读取 TypeScript 编译器选项的 TypeScript 配置文件的路径。 This will help inform the generated ESLint configuration file's env settings.这将有助于通知生成的 ESLint 配置文件的 env 设置。 Node API节点API

You can use tslint-to-eslint-config programmatically via its exported functions.您可以通过其导出的函数以编程方式使用 tslint-to-eslint-config。 See docs/API for details.有关详细信息,请参阅文档/API。

import { convertLintConfig } from "tslint-to-eslint-config"; import { convertLintConfig } from "tslint-to-eslint-config";

const result = await convertLintConfig(); const 结果 = 等待 convertLintConfig();

Development发展

See the general development docs.请参阅一般开发文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM