The simple steps of contributing to any GitHub project are as follows:
- Fork the repository(https://github.com/kata-ai/tslint-config-kata/fork)
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push -u origin my-new-feature
- Create a Pull Request!
To keep your fork of in sync with this repository, follow this guide.
- Git
- Node.js (8.0.0+)
- Yarn
- Text Editor with EditorConfig & Prettier support. (We recommend Visual Studio Code)
Install dependencies using Yarn.
$ yarn
To start incremental build, run:
$ yarn start
After updating, test the changes against the code by building it:
$ yarn build
To build the package for publishing, run:
$ yarn publish
Just like ESLint, the TSLint config can either be written in JSON format, or plain JS format. In this case, we use the latter, but compiled from TypeScript.
The main entry point for our config is the .js
files located at the root. Note that we separated the configurations into two:
./index.js
- Base config that overrides the default TSLint config../react.js
- Overrides to React-specific rules provided bytslint-react
.
The entry files are written in the following format:
// ./index.js
// Point to the built index file, and specifically choose the config to use.
module.exports = require('./build/index').baseConfig;
Next comes the configuration file. This file is formatted the same as a regular tslint.json
file, only in JavaScript. For an example on how to write rules in this format, see this example config.
It is very important to use a separate named export in this very file for creating additional configs.
// ./src/index.ts
import react from './config/react';
import base from './config/base';
export const baseConfig = {
rulesDirectory: [
// ...the custom rules we import
],
extends: [
// ...the configs/rulesets we extend
],
rules: {
...base.rules,
...react.rules
// ...add extra config sets below
}
};
export const otherConfig = {
// ...another config path using different configs
};
Further reading: The TSLint documentation on shareable configurations.
Any additional custom TSLint rules must be added inside the ./src/rules
directory. Please follow the TSLint documentation on adding custom rules. Make sure to follow these conventions:
- Rule identifiers are always kebab-cased.
- Rule files are always camel-cased (
camelCasedRule.ts
). - Rule files must contain the suffix
Rule
. - The exported class must always be named
Rule
and extend fromLint.Rules.AbstractRule
.
To load these custom rules into TSLint, make sure to add said folder to the rulesDirectory
config.
// ./src/base.ts
module.exports = {
rulesDirectory: ['./rules', ...otherRules],
...otherConfigs
};