lisk-desktop
lisk-desktop copied to clipboard
Add prettier
Description
We should apply the code formatter to maintain the standards
- Add
prettierignore
and.prettierrc.json
- Apply the format to codebase
- Configure git hooks to format for all commits
Motivation
- Maintain standards across projects
- Well formatted codebase
Additional Information
- https://prettier.io/
- Reference configuration https://github.com/LiskHQ/lisk-core/blob/development/.prettierrc.json
- External reference: https://www.aleksandrhovhannisyan.com/blog/format-code-on-save-vs-code-eslint/
here is my prefrence for the preittier
.prettierrc.js
module.exports = {
printWidth: 120,
tabWidth: 2,
semi: false,
singleQuote: true,
bracketSpacing: true,
arrowParens: 'always',
trailingComma: 'es5',
}
most the difrence is
- tabWith: 2 - default (prefer use space over tab)
- arrowParens: 'always' - default ( prefer parantes always for arrow function )
- bracketSpacing: true - default
- trailing-commas: 'es5' - default
- semi: false - custom semicolon less - read this article
.eslintrc
module.exports = {
"parser": "babel-eslint",
env: {
jest: true,
browser: true,
node: true,
es6: true,
},
settings: {
react: {
version: 'detect',
},
import/resolver : {}
},
plugins: [
'react',
'prettier',
'jsx-a11y',
'react-hooks',
],
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:prettier/recommended',
'prettier',
'prettier/react',
'prettier/standard',
],
rules: {
// overrides rules
'no-case-declarations': 'off',
'react/prop-types': 'off',
'react-hooks/rules-of-hooks': 'warn', //avoid resolve tons of issues
'react-hooks/exhaustive-deps': 'warn', //avoid resolve tons of issues
'prettier/prettier': [
'error',
{
printWidth: 120,
tabWidth: 2,
semi: false,
singleQuote: true,
bracketSpacing: true,
arrowParens: 'always',
trailingComma: 'es5',
},
],
'no-console': 0,
},
}
package.json
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
},