lisk-desktop icon indicating copy to clipboard operation
lisk-desktop copied to clipboard

Add prettier

Open ManuGowda opened this issue 1 year ago • 1 comments

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/

ManuGowda avatar Jul 19 '22 10:07 ManuGowda

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

.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,
  },
}

pre commit hooks - documents

package.json


  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged"
    }
  },

soroushm avatar Jul 19 '22 18:07 soroushm