租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.7 KiB

3 months ago
  1. # eslint-config-airbnb
  2. [![npm version](https://badge.fury.io/js/eslint-config-airbnb.svg)](https://badge.fury.io/js/eslint-config-airbnb)
  3. This package provides Airbnb's .eslintrc as an extensible shared config.
  4. ## Usage
  5. We export three ESLint configurations for your usage.
  6. ### eslint-config-airbnb
  7. Our default export contains most of our ESLint rules, including ECMAScript 6+ and React. It requires `eslint`, `eslint-plugin-import`, `eslint-plugin-react`, `eslint-plugin-react-hooks`, and `eslint-plugin-jsx-a11y`. Note that it does not enable our React Hooks rules. To enable those, see the [`eslint-config-airbnb/hooks` section](#eslint-config-airbnbhooks).
  8. If you don't need React, see [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
  9. 1. Install the correct versions of each package, which are listed by the command:
  10. ```sh
  11. npm info "eslint-config-airbnb@latest" peerDependencies
  12. ```
  13. If using **npm 5+**, use this shortcut
  14. ```sh
  15. npx install-peerdeps --dev eslint-config-airbnb
  16. ```
  17. If using **yarn**, you can also use the shortcut described above if you have npm 5+ installed on your machine, as the command will detect that you are using yarn and will act accordingly.
  18. Otherwise, run `npm info "eslint-config-airbnb@latest" peerDependencies` to list the peer dependencies and versions, then run `yarn add --dev <dependency>@<version>` for each listed peer dependency.
  19. If using **npm < 5**, Linux/OSX users can run
  20. ```sh
  21. (
  22. export PKG=eslint-config-airbnb;
  23. npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
  24. )
  25. ```
  26. Which produces and runs a command like:
  27. ```sh
  28. npm install --save-dev eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# eslint-plugin-react-hooks@^#.#.#
  29. ```
  30. If using **npm < 5**, Windows users can either install all the peer dependencies manually, or use the [install-peerdeps](https://github.com/nathanhleung/install-peerdeps) cli tool.
  31. ```sh
  32. npm install -g install-peerdeps
  33. install-peerdeps --dev eslint-config-airbnb
  34. ```
  35. The cli will produce and run a command like:
  36. ```sh
  37. npm install --save-dev eslint-config-airbnb eslint@^#.#.# eslint-plugin-jsx-a11y@^#.#.# eslint-plugin-import@^#.#.# eslint-plugin-react@^#.#.# eslint-plugin-react-hooks@^#.#.#
  38. ```
  39. 2. Add `"extends": "airbnb"` to your `.eslintrc`
  40. ### eslint-config-airbnb/hooks
  41. This entry point enables the linting rules for React hooks (requires v16.8+). To use, add `"extends": ["airbnb", "airbnb/hooks"]` to your `.eslintrc`.
  42. ### eslint-config-airbnb/whitespace
  43. This entry point only errors on whitespace rules and sets all other rules to warnings. View the list of whitespace rules [here](https://github.com/airbnb/javascript/blob/master/packages/eslint-config-airbnb/whitespace.js).
  44. ### eslint-config-airbnb/base
  45. This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
  46. ### eslint-config-airbnb/legacy
  47. This entry point is deprecated. See [eslint-config-airbnb-base](https://npmjs.com/eslint-config-airbnb-base).
  48. See [Airbnb's JavaScript styleguide](https://github.com/airbnb/javascript) and
  49. the [ESlint config docs](https://eslint.org/docs/user-guide/configuring#extending-configuration-files)
  50. for more information.
  51. ## Improving this config
  52. Consider adding test cases if you're making complicated rules changes, like anything involving regexes. Perhaps in a distant future, we could use literate programming to structure our README as test cases for our .eslintrc?
  53. You can run tests with `npm test`.
  54. You can make sure this module lints with itself using `npm run lint`.