WIP:
At the moment at alpha testing - use carefully
Linting of FeatureSliced concepts by existing eslint-plugins
Rules
Get Started
-
You'll first need to install ESLint:
$ npm install -D eslint
$ yarn add -D eslint
-
Next, install @feature-sliced/eslint-config
and dependencies:
$ npm install -D @feature-sliced/eslint-config eslint-plugin-import eslint-plugin-boundaries
$ yarn add -D @feature-sliced/eslint-config eslint-plugin-import eslint-plugin-boundaries
-
Add config to the extends
section of your .eslintrc
configuration file (for recommended rules). You can omit the eslint-config
postfix:
{
"extends": ["@feature-sliced"]
}
Customization
-
You can partially use the rules
WARN: Don't use main config ("@feature-sliced"
) in customization to avoid rules conflicts.
{
"extends": [
"@feature-sliced/eslint-config/rules/import-order",
"@feature-sliced/eslint-config/rules/public-api",
"@feature-sliced/eslint-config/rules/layers-slices"
]
}
-
You can use advanced FeatureSliced-specific messages processing
# (feature-sliced/public-api)
- 'Reaching to "features/search/ui" is not allowed.'
+ 'Violated usage of modules Public API | https://git.io/Jymjf'
-
You can use warnings instead of errors for specific rules
"import/order": "warn"
"import/no-internal-modules": "warn"
"boundaries/element-types": "warn"
TypeScript
This plugin can be used also in TypeScript projects using @typescript-eslint/eslint-plugin
. Follow next steps to configure it:
-
Install dependencies:
$ npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-import-resolver-typescript
$ yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-import-resolver-typescript
-
Configure @typescript-eslint/parser
as parser and setup the eslint-import-resolver-typescript
resolver in the .eslintrc
config file:
{
"parser": "@typescript-eslint/parser",
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
}
}
See also