NestJS项目中如何解决'Delete `␍`eslintprettier/prettier'错误
解决ESLint+Prettier的'Delete
␍'错误 这个错误里的␍是回车符(CR),本质是文件换行符格式和Prettier的要求不一致导致的,结合你的配置,按以下步骤解决:
1. 修正配置文件,消除冲突
- 更新
.prettierrc,添加换行符配置,统一使用LF格式:{ "singleQuote": true, "trailingComma": "all", "endOfLine": "lf" } - 修改
.eslintrc.js,删除prettier/prettier规则里的重复配置和错误的parser设置(你用的是TypeScript项目,flow是另一种工具,这里完全没必要),让ESLint直接读取Prettier的配置文件:module.exports = { parser: '@typescript-eslint/parser', parserOptions: { project: 'tsconfig.json', tsconfigRootDir: __dirname, sourceType: 'module', }, plugins: ['@typescript-eslint/eslint-plugin'], extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', ], root: true, rules: { 'prettier/prettier': ['error'], // 只保留错误级别,配置交给.prettierrc '@typescript-eslint/interface-name-prefix': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-explicit-any': 'off', }, env: { node: true, jest: true, }, ignorePatterns: ['.eslintrc.js'], };
2. 批量修复现有文件的换行符
在项目根目录执行Prettier批量格式化命令,自动修正所有文件的换行符和格式问题:
npx prettier --write .
3. 配置编辑器,避免后续再出现问题
以VS Code为例:
- 右下角状态栏找到换行符标识(比如显示
CRLF),点击后选择LF; - 打开设置,搜索
files.eol,设置为\n,让新建文件默认使用LF格式。
内容的提问来源于stack exchange,提问作者Marz m
相关产品推荐
相关产品推荐

