Shopgate Eslint Configuration
Shopgate's reasonable approach to JavaScript.
This configuration is an extension of the airbnb codestyle which is
available here.
Installation
npm i @shopgate/eslint-config --save-dev
Usage
Add the following to the .eslintrc in your project:
{
"extends": "@shopgate/eslint-config",
...
}
Rules
General
No code should be left commented out.
⬆ back to top
Comma dangle
Dangling commas are required for objects with multiple items or properties. This applies
to Array, Object, Import and Export.
const myObject = {
a: 1,
b: 2
};
const myObject = {
a: 1,
b: 2,
};
import { var1, var2, var3 } from 'Variables';
import {
var1,
var2,
var3,
} from 'Variables';
⬆ back to top
Multiple empty lines
There should not be multiple empty lines between code blocks.
const a = 1;
const b = 1;
while (...) {
...
}
const a = 1;
const b = 2;
while (...) {
...
}
⬆ back to top
All comments should beging with a capital letter. This makes comments more readable and forces more care when constructing comments.
⬆ back to top
Functions
Point free
A function should not simply call another function.
const funcA = (params) {
...
};
const funcB = (params) {
funcA(params);
};
⬆ back to top
Objects
Single line objects
If an object is defined with multiple properties then each property should occupy a new line.
const x = { a: 1, b: 2, c: 3 };
const w = { a: 1 };
const x = {
a: 1,
b: 2,
c: 3,
};
⬆ back to top
Documentation
JSDoc requirement
Every Function, Class, Method and Arrow Function definition should include a
valid JSDoc specification.
const funcA = (param1, param2) {
...
};
const funcB = (param1, param2) {
...
};
const funcC = (param1, param2) {
...
};
⬆ back to top
React
Prop Types
Proptypes should be sorted by type (required or not) and alphabetically.
static propTypes = {
width: PropTypes.string.isRequired,
color: PropTypes.string,
height: PropTypes.string.isRequired,
};
static propTypes = {
height: PropTypes.string.isRequired,
width: PropTypes.string.isRequired,
color: PropTypes.string,
};
⬆ back to top