hypertrons / hypertrons-crx

A browser extension for insights into GitHub, Gitee projects and developers.
https://hypercrx.cn
Apache License 2.0
354 stars 103 forks source link

[enhancement] Add ESLint and Prettier to project. #19

Closed heming6666 closed 4 years ago

heming6666 commented 4 years ago

In order to keep the code style in a good shape and format the code automatically, it's recommend to use ESLint and Prettier in our project.

frank-zsy commented 4 years ago

If we develop the project with TypeScript, should we use ESLint or TSLint? Although I realize that lots of Typescript project are using ESLint.

heming6666 commented 4 years ago

I think both are good for our projerct. But ESLint is recommended because the team behind TSLint have decided that they would no longer support it. Refer to https://palantir.github.io/tslint/

heming6666 commented 4 years ago

ESLint & Prettier

We use umi-fabric which provides some presets for eslint , stylelint and prettier. All open rules are meaningful for improving code quality.

Here's the ESLint configuration:

# .eslintrc.js
module.exports = {
  extends: [require.resolve('@umijs/fabric/dist/eslint')],
};
# .prettierrc.js
const fabric = require('@umijs/fabric');
module.exports = {
  ...fabric.prettier,
};

In addition, use Husky to do the lint check before commit:

  "scripts": {
    "lint": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:prettier",
    "lint:prettier": "prettier --check \"**/**.{js,jsx,tsx,ts,less,md,json}\" --end-of-line auto",
    "prettier": "prettier --write \"**/**.{js,jsx,tsx,ts,less,md,json}\""
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run lint"
    }
  },
heming6666 commented 4 years ago

Close by pr #21 .