【发布时间】:2021-12-14 16:49:17
【问题描述】:
软件包版本:
eslint@7.32.0
prettier@2.4.1
eslint-plugin-prettier@4.0.0
我有以下 eslintrc,这只是 NestJS 的库存配置:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: [
'@typescript-eslint/eslint-plugin',
'filenames'
],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@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',
'filenames/match-regex': [2, "^[0-9a-z-.]+$", true]
},
};
这是更漂亮的配置:
{
"singleQuote": true,
"trailingComma": "all"
}
这是 tsconfig:
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"esModuleInterop": true,
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": ".",
"rootDir": ".",
"incremental": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strictNullChecks": true,
"noImplicitAny": true,
"strictBindCallApply": true,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitOverride": true
}
}
在我的代码中,我有一个这样的类:
@Injectable()
export class FirebaseStrategy extends PassportStrategy(
FirebaseAuthStrategy,
'firebase',
) {
constructor(private usersService: UsersService) {
super({ extractor: ExtractJwt.fromAuthHeaderAsBearerToken() });
}
override async validate(payload: FirebaseUser): Promise<User | undefined> {
return this.usersService.findByFirebaseUid(payload.uid);
}
}
这段代码运行良好,但是当我尝试 lint 时,出现以下错误:
/app/src/auth/strategy/firebase.strategy.ts
22:12 error Parsing error: Unexpected token prettier/prettier
有没有办法解决这个问题?我不希望有隐式覆盖。
【问题讨论】:
-
能否添加 .prettierrc & tsconfig.json?
-
@LongNguyen 已添加,感谢收看。
-
为什么要添加
prettier/recommended来扩展而不是插件列表? -
我什么都没做,这是nestjs默认配置:github.com/nestjs/nest/blob/master/.eslintrc.js,也是esplugin-plugin-prettier的推荐配置:github.com/prettier/eslint-plugin-prettier/blob/master/…
标签: typescript eslint prettier