eslint-plugin-ferramentas
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

eslint-ferramentas

A bundle of useful ESLint rules.

As all these rules need configuration by default, no plugin preset is exported.

Install it by running npm install --save-dev eslint-ferramentas

Rules

Static analysis

  • Forbid importing modules relative to the root of the project with siloed-import with the power of regex.

With the rule below:

/**
 * @type {import('eslint-plugin-ferramentas').SiloedImportOptions}
 */
const siloedImportOptions = {
    directories: [
        // Forbids import of test files or
        // files from the test folder from regular files
        {
            filter: '^(.*?)(?<!\\.test)\\.ts$',
            forbid: ['^(.*?)\\.test$', '^src/test'],
        },
    ],
};

module.exports = {
    plugins: ['ferramentas'],
    rules: {
        'ferramentas/siloed-import': ['error', siloedImportOptions],
    },
};

Then importing any *.test.ts files or files from the ./src/test folder will be forbidden by ESLint.

All configuration options can be found here.

Style guide

  • Ensure relative imports (and only) appear in a specific order with relative-import-order and the power friendship of regex.

With the rule below:

/**
 * @type {import('eslint-plugin-ferramentas').RelativeImportOrderOptions}
 */
const relativeImportOrderOptions = {
    directories: ['./src/domain', './src/reducers', './src/react', './src/app', './test'],
};

module.exports = {
    plugins: ['ferramentas'],
    rules: {
        'ferramentas/relative-import-order': ['error', relativeImportOrderOptions],
    },
};

The imports seen below:

import { foo } from '../../test';
import { alpha } from '../../../reducers';
import { bar } from '../../../react';
import teta from '../../../domain';

import { createIntl, IntlShape, OnErrorFn } from '@formatjs/intl';

Will be auto-fixed to:

import teta from '../../../domain';
import { alpha } from '../../../reducers';
import { bar } from '../../../react';
import { foo } from '../../test';

import { createIntl, IntlShape, OnErrorFn } from '@formatjs/intl';

All configuration options can be found here.

Note that this rule does not attempt to order non relative imports, and does not care about their grouping, values sorting, or spacing.

Package Sidebar

Install

npm i eslint-plugin-ferramentas

Weekly Downloads

2,710

Version

1.0.1

License

ISC

Unpacked Size

34.3 kB

Total Files

27

Last publish

Collaborators

  • filipomar