A collection of TypeScript & Angular lint rules for Terminus frontend codebases.
For ESLint configuration, see: https://github.com/GetTerminus/eslint-config-frontend
Table of Contents
$ yarn add tslint @terminus/tslint-config-frontend -D
There are 3 rulesets defined for TSLint:
- CI: This is the default ruleset. This is meant to be used during your CI builds so it throws hard errors when issues are found.
- Development: This enforces all the same rules as the CI ruleset but infractions are reported as warnings rather than errors.
- Testing: This ruleset extends the development ruleset and then further disables certain tests that make writing spec
files less arduous (
no-non-null-assertion, component naming requirements, etc).
You will need to set up separate configs and scripts for each ruleset: ci, development and testing. Creating a custom script call for
each within your package.json will allow for easy composability of commands once all linters are set up.
Create a TSLint config file at the root level named tslint.ci.json and extend the base ruleset:
{
"extends": "@terminus/tslint-config-frontend"
}Linting during the CI process is the most strict and will fail if any issues are found. The only way a linting issue makes it to CI is because someone didn't lint before commiting.
- The
--projectflag reference should point to the primary apptsconfigfile. - The
--configflag reference should point to the citslintfile.
{
"name": "My Project",
"scripts": {
"lint:tslint:ci": "npx tslint --project ./src/tsconfig.app.json --config ./tslint.ci.json"
}
}This ruleset extends the ci ruleset but softens the rules to turn many stylistic issues into warnings in order to not impede development.
Create a TSLint config file at the root level named tslint.json and extend the development ruleset:
{
"extends": "@terminus/tslint-config-frontend/development"
}NOTE: When adjusting a TSLint rule, the entire rule must be defined again.
{
"extends": "@terminus/tslint-config-frontend/development",
"rules": {
"component-selector": [
true,
"element",
"foo",
"kebab-case"
],
"directive-selector": [
true,
"attribute",
"foo",
"camelCase"
],
"pipe-prefix": [
true,
"foo"
]
}
}After the --project flag, the reference should point to your primary app tsconfig file.
{
"name": "My Project",
"scripts": {
"lint:tslint": "npx tslint --project ./src/tsconfig.app.json"
}
}Create a TSLint config file at the root level named tslint.spec.json and extend the testing ruleset:
{
"extends": "@terminus/tslint-config-frontend/testing"
}- The
--projectflag reference should point to the spectsconfigfile. - The
--configflag reference should point to the spectslintfile.
{
"name": "My Project",
"scripts": {
"lint:tslint:spec": "npx tslint --project ./src/tsconfig.spec.json --config ./tslint.spec.json"
}
}Each rule is accompanied by a comment outlining the reasoning behind the decision to include the rule.
For most rules, see ci.js.