@veri.co/eslint-plugin-veri
v5.1.0
Published
Custom Eslint rules not available otherwise
Downloads
50
Readme
Eslint Plugin Veri
This package also shares common ESlint rules between different Veri projects.
What to include
Include common ESlint rules like basic Javascript, React and Node related rules that can be easily shared.
What not to include
Don't include rules that are specific to a technology that is only used in a single project. For example, don't include RealmJS related rules since at the time of writing this it's only used in Veri app. Hence no reason to share them with other projects.
How to use the shared linting rules
Setup eslint in your project that is part of the monorepo.
Inside the project, run:
yarn add -D @veri.co/eslint-plugin-veri
Then in
.eslintrc
add:plugins: [ "@veri.co/veri" ]
To use presets, you also have to extend it:
extends: [ "plugin:@veri.co/veri/node", "plugin:@veri.co/veri/react", "plugin:@veri.co/veri/react_native" ]
Finally install required peer dependencies.
Node
yarn add -D eslint-plugin-jsx-falsy eslint-plugin-prettier eslint-plugin-simple-import-sort prettier eslint-plugin-node @waltari/eslint-plugin-ban-falsy-enum-values
React
yarn add -D eslint-plugin-react eslint-plugin-react-hooks
React Native
yarn add -D @react-native/eslint-config @react-native/eslint-plugin eslint-plugin-react-native
How to develop locally
In
eslint-plugin-veri
folder run:yarn link
Then in the projects folder you want to link it to e.g. app run:
yarn link "@veri.co/eslint-plugin-veri"
Now you can star making changes to config files which are under
src/
After you have done changes, build the configs
yarn build
Now all the changes you make to eslint-plugin-veri are "copied" into the projects node_modules. Remember you still have to add "veri" to the plugins array in your .eslintrc file.
Note: You have to run yarn build every time you make some changes.
How to publish to npm
- Update package version number in package.json
npm publish
Useful resources
Working with Abstract Syntax tree (AST)
Some useful resources are: https://astexplorer.net/ https://typescript-eslint.io/play/#ts=4.6.2&sourceType=module&showAST=es
In astexplorer you can even develop code for your rules and see in real time if they work with the AST. You can also add your own code and also see the resulting AST. Highly recommended to check it out if you start working with eslint rules.
In astexplorer try setting "ESLint v8" for Transform and "Typescript" for syntax. One difference between eslint-plugin-veri is that the rule listeners need to be "TSInterfaceDeclaration" instead of "InterfaceDeclaration" like in astexplorer in order to work. So make sure to append that "TS" prefix when working on eslint-plugin-veri on your computer, even though its not needed in astexplorer.