项目作者: blvdgroup

项目描述 :
An ESLint config that conforms to the blvd JavaScript/TypeScript styleguide.
高级语言: JavaScript
项目地址: git://github.com/blvdgroup/eslint-config-blvd.git
创建时间: 2019-01-20T06:06:59Z
项目社区:https://github.com/blvdgroup/eslint-config-blvd

开源协议:Apache License 2.0

下载


eslint-config-blvd

✨ An ESLint config that conforms to the blvd JavaScript/TypeScript styleguide.

Installation

Install eslint and eslint-config-blvd using yarn:

  1. yarn add --dev eslint eslint-config-blvd

or, for npm:

  1. npm install --save-dev eslint eslint-config-blvd

Usage

In your .eslintrc file, extend eslint-config-blvd.

  1. {
  2. "extends": "eslint-config-blvd"
  3. }

React rules

For React projects, extend eslint-config-blvd/react.

  1. {
  2. "extends": ["eslint-config-blvd/react"]
  3. }

Using TypeScript

To use eslint-config-blvd with TypeScript, you need to do a little additional setup to make eslint-plugin-import play well with TypeScript. First, install eslint-import-resolver-typescript.

  1. # yarn
  2. yarn add --dev eslint-import-resolver-typescript

Then, on your .eslintrc:

  1. module.exports = {
  2. // other configuration are omitted for brevity
  3. settings: {
  4. 'import/resolver': {
  5. typescript: {} // this loads <rootdir>/tsconfig.json to eslint
  6. }
  7. }
  8. }

Prettier

Prettier is an automated code formatter for JavaScript, TypeScript, and other languages.

This eslint config works alongside Prettier, too. To use it, install Prettier as well as eslint-config-prettier to your project.

  1. yarn add --dev prettier eslint-config-prettier eslint-plugin-prettier

Create a .prettierrc file. Then add the following configs. This should make Prettier automatically format your code based
on the blvd guidelines.

  1. {
  2. "semi": false,
  3. "tabWidth": 2,
  4. "printWidth": 140,
  5. "singleQuote": true,
  6. "trailingComma": "none"
  7. }

Then include eslint-config-prettier in your project. IMPORTANT: You must add prettier extends after extending the blvd config!

  1. {
  2. "extends": ["blvd", "prettier", "prettier/@typescript-eslint", "plugin:prettier/recommended"],
  3. "plugins": ["prettier"],
  4. "rules": {
  5. "prettier/prettier": "error"
  6. }
  7. }

Also include eslint-config-prettier/react for React projects.

  1. {
  2. "extends": ["blvd/react", "prettier", "prettier/@typescript-eslint", "prettier/react", "plugin:prettier/recommended"],
  3. "plugins": ["prettier"],
  4. "rules": {
  5. "prettier/prettier": "error"
  6. }
  7. }