Adhere code to Alephium UI coding style
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-alephium-ui
:
npm install eslint-plugin-alephium-ui --save-dev
Add alephium-ui
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"alephium-ui"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"alephium-ui/rule-name": 2
}
}
(2 means "error". You can also write "error"
.)
Not ok:
const Component = () => <div>Hi</div>;
const ThingStyled = styled.div`
color: red;
`;
export default Component;
Ok:
const Component = () => <div>Hi</div>;
export default Component;
const ThingStyled = styled.div`
color: red;
`;
Not ok:
interface A {
callback: Dispatch<SetStateAction<string>>;
}
Ok:
interface A {
callback: (string) => void;
}
Note these are not equivalent. The full type of Dispatch<SetStateAction<T>>
is:
(action: T | ((prevState: T) => T)) => void;
Not ok:
function a() { return 3; }
Ok:
const a = () => 3;
Not ok:
// (or let A = ... or A = ...)
const A = styled.div`
color: red;
`;
export default A;
Ok:
export default styled.div`
color: red;
`;
Not ok:
interface A {
thing: string;
className?: string;
hello: string;
}
Ok:
interface A {
thing: string;
hello: string;
className?: string;
}