This is a repo where I play around with TSLint custom rules. The rules are in the
tslint directory. Here's the list so far:
- `noBadWordsRule.ts uses the bad-words NPM module to forbid bad words in comments. Also provides options for custom list of bad words.
deMorgansRule.tsuses the TypeScript AST to "optimize" files by removing unnecessary exclamation marks through DeMorgan's Law. Please don't use it for real, it was for learning.
- Custom rules docs: https://palantir.github.io/tslint/develop/custom-rules/
- Your linter can work with Abstract Syntax Trees (AST), which is a computer-readable representation of the file your linter is targetting.
RuleWalkersubclasses can be used to "walk" along the AST using something called the Visitor Pattern. It's a complicated pattern but you can think of it as a depth-first search of the AST with callbacks for each tree node.
- Explore the TypeScript AST.
- All the AST hooks.
- Using the TypeScript compiler API.
- TSLint core rules and accompanying source code.
How do I work on this?
git clone https://github.com/ashfurrow/tslint-playground.git cd tslint-playground yarn install
src/index.ts has offenses in it, you can fix them with the rules using
yarn lint --fix src/index.ts (prefix that with a
git checkout src/index.ts for a fast reset-debug cycle).