使用量
安装
npm install --save-dev eslint typescript @apify/eslint-config-ts @typescript-eslint/eslint-plugin @typescript-eslint/parser
使用反应
要使用状态、儿童等反应类型安装:
npm i --save-dev @types/react
编辑 .eslintrc
添加(或替换) @apify/eslint-config 软件包)
{
"extends": "@apify/eslint-config-ts"
}
注: https://eslint.org/docs/developer-guide/shareable-configs 页面存档备份,存于互联网档案馆:
在使用范围化模块时,不可能省略eslint-config-前缀. 这样做将导致一揽子命名冲突,从而导致在大多数情况下解决错误。 例如,一个名为@scope/eslint-config-myconfig vs @scope/my-config的软件包,因为两者都是有效的可扩展软件包名称,所以配置应当指定为:
{
"extends": "@scope/eslint-config-myconfig"
}
创建 tsconfig.json
创建 tsconfig.json 在工程根中的文件并添加:
{}
所有选项列表 https://www.typescriptlang.org/tsconfig 互联网档案馆的存檔,存档日期2013-12-02
示例最小设置( 在网络上使用)
{
"compilerOptions": {
"skipLibCheck": true,
"esModuleInterop": true,
"jsx": "preserve",
"noUnusedLocals": true,
"noUnusedParameters": true
},
"exclude": [
"node_modules",
],
"include": [
"**/*.ts",
"**/*.tsx"
]
}
skipLibCheck数字 :
跳过第3个政党库声明文件的打字检查( extension. d. ts),因为它们可能有不同的 tsconfig
esModuleInterop数字 :
允许将“ 从反应中导入反应” 改为“ 从反应中导入 * ”
jsx数字 :
允许使用 JSX 标记
noUnusedLocals数字 :
未使用的变量出错
noUnusedParameters数字 :
未使用的函数参数出错
编辑 lint npm 脚本
编辑 lint npm 脚本以包含.ts,.tsx 文件并运行打字符验证
"eslint --ext .js,.jsx,.ts,.tsx ; tsc --noemit"