This plugin is used to enforce some ESLint rules Profico developers use on a day-to-day basis.
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
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";
-
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
// 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