- in the root folder run
yarn add ./estlin-rules - configure the
.eslintrcfile - that's it
- cd into eslint-rules
- run
yarn link - cd into project where you want to use the custom rule
- run
yarn link eslint-plugin-rules(this name can be found in the package.json file of the eslint)
In your .eslintrc file, add the custom rule like this:
{
"plugins": ["rules"],
"rules": {
"rules/my-rule-name": "warn"
}
}You should now see this local package in the node_modules folder of the project you linked it to.
- remove the local package
yarn remove eslint-plugin-rules - edit the rules
- run
yarn add ./estlin-rules
- cd into eslint-rules
- edit your rule
- run tsc compiler
tsc testRule.ts
- remove the local package
yarn remove eslint-plugin-rules - remove the rule from the
.eslintrcfile - that's it
- cd into project where you want to remove the custom rule
- run
yarn unlink eslint-plugin-rules - cd into eslint-rules
- run
yarn unlink - remove the rule from the
.eslintrcfile
- Advantages
- You can easily update the rule by running
yarn add ./estlin-rules - You can easily remove the rule by running
yarn remove eslint-plugin-rules
- You can easily update the rule by running
- Disadvantages
- You have to run
yarn add ./estlin-rulesevery time you want to use the rule in a new project - You have to run
yarn remove eslint-plugin-rulesevery time you want to remove the rule from a project
- You have to run
- Advantages
- Fast development cycle since you can edit the rule and by being them linked, the changes will be reflected immediately
- You can easily remove the rule by running
yarn unlink eslint-plugin-rules
- Disadvantages
- Potencial dependency issues since the linking package might have dependencies that collied with the ones in your project
- Possible inconsistencies across development environments
- Need to be
unlinkbefore production, otherwise unexpected behaviours might happen, specially if the rule is not production ready - Potencial dependency mismatches might cause issues since they aren't cully controlled through the normal package installation process
- Notes
- Use when actively developing a package and need to test it across multiple projects, or you want to debug it without constantly publishing it to npm
- Don't use it in a collaborative environment, since it might cause issues with other developers who might not understand how to use yarn link