0.9.0 • Published 2 years ago
collation v0.9.0
Code linting/manipulation tools to make your TypeScript code easier to read
Usage
Currently, collation
ships with a CLI that can be run manually or plugged into your git hooks to
run when files are changed.
npm install --save-dev collation
# Verify installation and show help menu
npx collation --help
# Run on specific file
npx collation --files button.tsx
# Run on list of files
npx collation --files button.tsx dialog.tsx
See .husky/pre-commit
for an example of usage in a git hook.
Rules
This project implements various different rules to make your code more consistent and easier to read - similar to tools like ESLint
, with the idea that all rules should be fixable without intervention.
For documentation on the available rules, see Rules
Notes
- This package does not do any additional formatting/processing on the code that's emitted from the TS compiler. For example, multi-line props for a component may be lifted up to a single line once they are alphabetized with
alphabetize-jsx-props
. It is recommended that you use a tool likeprettier
after your code has been transformed fromcollation
.
Adding a new rule
When adding a new rule, there are a few places that need to be updated:
- The rule name must be added to
rule-name.ts
- The function that should accept a
SourceFile
should be created atsrc/rules/<rule-name>.ts
- The function should have a test file next to its implementation, i.e.
src/rules/<rule-name>.test.ts
- The function needs to be mapped to its rule name in
src/constants/rule-map.ts
A small CLI has been created for internally scaffolding out these changes given a rule name:
npm run internal-codegen -- --name new-rule-name