TSLint-ESLint 规则项目教程
1. 项目的目录结构及介绍
tslint-eslint-rules/
├── src/
│ ├── rules/
│ │ ├── index.ts
│ │ └── ... (其他规则文件)
│ └── index.ts
├── tests/
│ ├── rules/
│ │ └── ... (测试文件)
│ └── index.ts
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── package.json
├── README.md
└── tsconfig.json
- src/: 包含所有规则的源代码。
- rules/: 包含各个具体的规则文件。
- index.ts: 规则的入口文件。
- tests/: 包含所有规则的测试代码。
- rules/: 包含各个规则的测试文件。
- index.ts: 测试的入口文件。
- .gitignore: Git 忽略文件配置。
- .npmignore: npm 发布时忽略的文件配置。
- .travis.yml: Travis CI 配置文件。
- LICENSE: 项目许可证。
- package.json: 项目依赖和脚本配置。
- README.md: 项目说明文档。
- tsconfig.json: TypeScript 编译配置。
2. 项目的启动文件介绍
项目的启动文件位于 src/index.ts
,该文件主要负责导出所有规则,使得其他项目可以通过引入该文件来使用这些规则。
// src/index.ts
import * as rules from './rules';
export = {
rules: rules
};
3. 项目的配置文件介绍
package.json
package.json
文件包含了项目的依赖、脚本和其他元数据。
{
"name": "tslint-eslint-rules",
"version": "5.4.0",
"description": "TSLint rules for ESLint users",
"main": "index.js",
"scripts": {
"test": "npm run build && mocha",
"build": "tsc"
},
"keywords": [
"tslint",
"eslint",
"rules"
],
"author": "Efren Aguirre",
"license": "MIT",
"devDependencies": {
"@types/chai": "^4.1.4",
"@types/mocha": "^5.2.5",
"chai": "^4.1.2",
"mocha": "^5.2.0",
"tslint": "^5.11.0",
"typescript": "^3.0.3"
}
}
tsconfig.json
tsconfig.json
文件包含了 TypeScript 编译的配置。
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
},
"include": [
"src/**/*"
]
}
通过以上配置,项目可以顺利编译和运行,同时也方便了开发者对规则的维护和扩展。