Skip to content

profico/eslint-plugin-profico

Repository files navigation

ESLint plugin by Profico

This plugin is used to enforce some ESLint rules Profico developers use on a day-to-day basis.

Installation

Install @profi.co/eslint-plugin with npm:

npm install --save-dev @profi.co/eslint-plugin

or with yarn:

yarn add --dev @profi.co/eslint-plugin

Usage

To use the recommended rules, add our plugin to your .eslintrc file:

{
  "extends": ["plugin:@profi.co/recommended"]
}

// or configure manually:
{
  "plugins": ["@profi.co"],
  "rules": {
    "@profi.co/lodash-imports": ["error"],
    "@profi.co/grouped-imports": ["error"],
    "@profi.co/dto-decorators": ["error"],
    "@profi.co/ordered-controllers-params": ["error"]
  }
}

The following checklist shows what we have implemented and what we plan on implementing in the near future:

  • Default import lodash modules instead of importing the whole library or parts of it:
// Bad
import _ from "lodash"; // Not fixable
import { get, pick } from "lodash"; // Fixable

// Good
import get from "lodash/get";
import pick from "lodash/pick";
// Bad
@IsString()
@ApiProperty()
public classProperty: string;

// Good
@ApiProperty()
@IsString()
public classProperty: string;
// Bad
public findAll(
  @Req() req: ProficoRequest,
  @Query() queryParams: QueryParams,
  @Custom2() customParam2: CustomParam,
  @Custom1() customParam1: CustomParam,
) {
  return this.service.find();
}

// Good
public findAll(
  @Query() queryParams: QueryParams,
  @Req() req: ProficoRequest,
  @Custom1() customParam1: CustomParam,
  @Custom2() customParam2: CustomParam,
) {
  return this.service.find();
}

Also take a look at our own ESLint config: https://github.com/profico/eslint-config-profico