eslint-plugin-ferramentas
This package contains 3 ESLint rules.
As all these rules need configuration by default, no plugin preset is exported.
Install it by running npm install --save-dev eslint-plugin-ferramentas
Rules
import-spaces
Enforces consistency of spacing between relative imports according to the folder each imports reference.
Imports are grouped as defined in the configuration, spaces are only allowed between the groups.
Non relative imports, and relative imports without a specified group will be considered to be each in their own group, thus having spaces between them as well.
Configuration
To configure the rule on .eslintrc.js, simply add:
/** @type {import('eslint-plugin-ferramentas').Options['import-spaces']} */
const options = {
groups: ['^foo.*
Possible errors examples
🔧 Automatic fixes available
There should be no empty lines in a import group
There should be one empty line between import groups
Fixes
When configured with:
{
"groups": ["^foo.*$", "^bar.*$"]
}
Will change:
import { DomainType } from 'static';
import { FooA } from './foo/a';
import { FooB } from './foo/b';
import { Bar } from './bar';
import { Other } from './other';
To:
import { DomainType } from 'static';
import { FooA } from './foo/a';
import { FooB } from './foo/b';
import { Bar } from './bar';
import { Other } from './other';
relative-import-order
Ensure relative imports appear in a specific order as set on the configuration.
The paths must be set with root paths and not from the perspective of the files where the import actually happens.
Configuration
To configure the rule on .eslintrc.js, simply add:
/** @type {import('eslint-plugin-ferramentas').Options['relative-import-order']} */
const options = {
sort: [
{
type: 'group',
groups: ['src/utils', 'src/domain', 'src/react'],
},
{
type: 'depth',
},
{
type: 'name',
},
],
};
module.exports = { rules: { 'ferramentas/relative-import-order': ['error', options] } };
Possible errors examples
🔧 Automatic fixes available
The path './foo/bar' is not listed.
All imported paths need to be included, either in the groups (so they are sorted) or ignored
Imports from './foo' should be above the import from './bar'
Fixes
When configured with:
{
"sort": [
{
"type": "group",
"groups": ["top-library", "bottom-library"]
},
{
"type": "depth"
},
{
"type": "name"
}
]
}
Will change (while on the file ./bottom-library/ExampleImporter.tsx):
import { Label } from '../bottom-library';
import { isBufferValid } from '../top-library';
import { SpanishInquisition } from '../non-listed/import-path';
To:
import { isBufferValid } from '../top-library';
import { Label } from '../bottom-library';
import { SpanishInquisition } from '../non-listed/import-path';
siloed-relative-import
Prevents importing of files in specific folders from other specified locations of the codebase through regex.
Configuration
To configure the rule on .eslintrc.js, simply add:
/** @type {import('eslint-plugin-ferramentas').Options['siloed-relative-import']} */
const options = {
directories: [
{
filter: '^src/react',
forbid: ['^src/http'],
},
],
};
module.exports = { rules: { 'ferramentas/siloed-relative-import': ['error', options] } };
Possible errors examples
Importing of './foo' is forbidden on './moo'
, '^bar.*
Possible errors examples
__INLINE_CODE_2__
There should be no empty lines in a import group
There should be one empty line between import groups
Fixes
When configured with:
__CODE_BLOCK_1__
Will change:
__CODE_BLOCK_2__
To:
__CODE_BLOCK_3__
relative-import-order
Ensure relative imports appear in a specific order as set on the configuration.
The paths must be set with root paths and not from the perspective of the files where the import actually happens.
Configuration
To configure the rule on __INLINE_CODE_3__, simply add:
__CODE_BLOCK_4__
Possible errors examples
__INLINE_CODE_4__
The path './foo/bar' is not listed.
All imported paths need to be included, either in the groups (so they are sorted) or ignored
Imports from './foo' should be above the import from './bar'
Fixes
When configured with:
__CODE_BLOCK_5__
Will change (while on the file __INLINE_CODE_5__):
__CODE_BLOCK_6__
To:
__CODE_BLOCK_7__
siloed-relative-import
Prevents importing of files in specific folders from other specified locations of the codebase through regex.
Configuration
To configure the rule on __INLINE_CODE_6__, simply add:
__CODE_BLOCK_8__
Possible errors examples
Importing of './foo' is forbidden on './moo'
],
};
module.exports = { rules: { 'ferramentas/import-spaces': ['error', options] } };
Possible errors examples
__INLINE_CODE_2__
There should be no empty lines in a import group
There should be one empty line between import groups
Fixes
When configured with:
__CODE_BLOCK_1__Will change:
__CODE_BLOCK_2__To:
__CODE_BLOCK_3__relative-import-order
Ensure relative imports appear in a specific order as set on the configuration.
The paths must be set with root paths and not from the perspective of the files where the import actually happens.
Configuration
To configure the rule on __INLINE_CODE_3__, simply add:
__CODE_BLOCK_4__Possible errors examples
__INLINE_CODE_4__
The path './foo/bar' is not listed. All imported paths need to be included, either in the groups (so they are sorted) or ignored
Imports from './foo' should be above the import from './bar'
Fixes
When configured with:
__CODE_BLOCK_5__Will change (while on the file __INLINE_CODE_5__):
__CODE_BLOCK_6__To:
__CODE_BLOCK_7__siloed-relative-import
Prevents importing of files in specific folders from other specified locations of the codebase through regex.
Configuration
To configure the rule on __INLINE_CODE_6__, simply add:
__CODE_BLOCK_8__Possible errors examples
Importing of './foo' is forbidden on './moo'