1.3.0 • Published 19 days ago
@profi.co/eslint-plugin v1.3.0
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:
lodash-imports
- 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";
grouped-imports
Automatically group import statements according to our style guide: https://github.com/profico/react-boilerplate/blob/master/style-guide.md
Include comments as part of import statements
- Sort each import group alphabetically
dto-decorators
// Bad
@IsString()
@ApiProperty()
public classProperty: string;
// Good
@ApiProperty()
@IsString()
public classProperty: string;
ordered-controller-params
// 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();
}