如果你 Vibe Coding TS,我推荐你开这些 ESLint Rule,可以显著改善代码质量:
有一些规则可能会给人类多找很多麻烦,但是 AI 犯蠢你看不到和你多写两行相比,前者的严重性更大一些……
以及,我推荐你同时在流水线开 similarity-ts,可以进一步减少你的 LLM 瞎搞轮子的情况……
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'no-restricted-syntax': [
'error',
{
selector: 'TSAsExpression[typeAnnotation.type="TSAnyKeyword"]',
message: 'Do not use "as any" assertions.'
},
{
selector: 'TSAsExpression[typeAnnotation.type="TSUnknownKeyword"]',
message: 'Do not use "as unknown" assertions.'
},
{
selector: 'TSTypeAssertion[typeAnnotation.type="TSAnyKeyword"]',
message: 'Do not use "<any>" type assertions.'
},
{
selector: 'TSTypeAssertion[typeAnnotation.type="TSUnknownKeyword"]',
message: 'Do not use "<unknown>" type assertions.'
},
{
selector: 'TSTypeAnnotation > TSTypeLiteral',
message: 'Do not use inline object type literals. Extract to a named type or interface.'
},
{
selector: 'TSTypeParameterInstantiation > TSTypeLiteral',
message:
'Do not use inline object type literals in type arguments. Extract to a named type or interface.'
},
{
selector: 'TSTypeAnnotation > TSFunctionType',
message: 'Do not use inline function type literals. Extract to a named type.'
},
{
selector: 'TSTypeParameterInstantiation > TSFunctionType',
message:
'Do not use inline function type literals in type arguments. Extract to a named type.'
},
{
selector: 'TSTypeAnnotation > TSTupleType',
message: 'Do not use inline tuple types. Extract to a named type.'
},
{
selector: 'TSTypeParameterInstantiation > TSTupleType',
message: 'Do not use inline tuple types in type arguments. Extract to a named type.'
}
]
}有一些规则可能会给人类多找很多麻烦,但是 AI 犯蠢你看不到和你多写两行相比,前者的严重性更大一些……
以及,我推荐你同时在流水线开 similarity-ts,可以进一步减少你的 LLM 瞎搞轮子的情况……