项目作者: j0hnm4r5

项目描述 :
An ESLint config built for Vanilla JS, React, and/or Typescript, based on Airbnb + Unicorn + Prettier.
高级语言: JavaScript
项目地址: git://github.com/j0hnm4r5/eslint-config.git
创建时间: 2019-10-14T20:36:33Z
项目社区:https://github.com/j0hnm4r5/eslint-config

开源协议:

下载


@j0hnm4r5/eslint-config

GitHub Release
@j0hnm4r5/eslint-config?style=flat" alt="NPM Downloads">
GitHub Build

About

This ESLint config is built on top of Airbnb’s config and Unicorn. It includes Prettier to automatically format code.

Instructions

  1. Install eslint and this config in your project with yarn add -D eslint @j0hnm4r5/eslint-config

  2. In your .eslintrc file, add one of the following to the extends array:

Vanilla (default): "@j0hnm4r5/eslint-config"
TypeScript without React : "@j0hnm4r5/eslint-config/configs/ts"
React: "@j0hnm4r5/eslint-config/configs/react"
TypeScript with React: "@j0hnm4r5/eslint-config/configs/ts-react"

That’s it! All of the extended configs, Prettier, and some extra rule changes should just work out of the box.


Example Usage

This should change depending on the project, but here’s what I like to use as a baseline:

.eslintrc

  1. // .eslintrc
  2. {
  3. "env": {
  4. "node": true,
  5. "browser": true,
  6. "es2020": true,
  7. },
  8. "extends": [
  9. "@j0hnm4r5/eslint-config"
  10. ],
  11. }

Typescript

If you’re using TypeScript, add this to your .eslintrc too:

  1. // inside .eslintrc root object
  2. "parserOptions": {
  3. "project": "./tsconfig.json"
  4. }

As well as a tsconfig.json file at the root of the project:

Node

  1. // tsconfig.json
  2. {
  3. "compilerOptions": {
  4. "lib": ["es2020"],
  5. "module": "commonjs",
  6. "target": "es2020",
  7. "sourceMap": true,
  8. "strict": true,
  9. "esModuleInterop": true,
  10. "skipLibCheck": true,
  11. "forceConsistentCasingInFileNames": true
  12. },
  13. "exclude": [
  14. "node_modules"
  15. ]
  16. }

Browser

  1. // tsconfig.json
  2. {
  3. "compilerOptions": {
  4. "lib": ["es2020", "dom"],
  5. "module": "commonjs",
  6. "target": "es6",
  7. "jsx": "react",
  8. "sourceMap": true,
  9. "strict": true,
  10. "esModuleInterop": true,
  11. "skipLibCheck": true,
  12. "forceConsistentCasingInFileNames": true
  13. },
  14. "exclude": [
  15. "node_modules"
  16. ]
  17. }

Prettier

And don’t forget your Prettier configs! Here’s what I use:

.prettierrc

  1. // .prettierrc
  2. {
  3. "printWidth": 62, // perfect size for my vscode window
  4. "tabWidth": 2,
  5. "useTabs": true,
  6. "semicolons": true,
  7. "singleQuote": false,
  8. "quoteProps": "consistent",
  9. "jsxSingleQuote": false,
  10. "trailingComma": "es5",
  11. "bracketSpacing": true,
  12. "jsxBracketSameLine": false,
  13. "arrowParens": "always"
  14. }

.prettierignore

  1. # .prettierignore
  2. package.json
  3. package-lock.json
  4. yarn.lock
  5. node_modules
  6. public
  7. .cache