租房小程序前端代码
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.

115 lines
2.9 KiB

3 months ago
  1. # ESLintRC Library
  2. This repository contains the legacy ESLintRC configuration file format for ESLint. This package is not intended for use outside of the ESLint ecosystem. It is ESLint-specific and not intended for use in other programs.
  3. **Note:** This package is frozen except for critical bug fixes as ESLint moves to a new config system.
  4. ## Installation
  5. You can install the package as follows:
  6. ```
  7. npm install @eslint/eslintrc --save-dev
  8. # or
  9. yarn add @eslint/eslintrc -D
  10. ```
  11. ## Usage (ESM)
  12. The primary class in this package is `FlatCompat`, which is a utility to translate ESLintRC-style configs into flat configs. Here's how you use it inside of your `eslint.config.js` file:
  13. ```js
  14. import { FlatCompat } from "@eslint/eslintrc";
  15. import js from "@eslint/js";
  16. import path from "path";
  17. import { fileURLToPath } from "url";
  18. // mimic CommonJS variables -- not needed if using CommonJS
  19. const __filename = fileURLToPath(import.meta.url);
  20. const __dirname = path.dirname(__filename);
  21. const compat = new FlatCompat({
  22. baseDirectory: __dirname, // optional; default: process.cwd()
  23. resolvePluginsRelativeTo: __dirname, // optional
  24. recommendedConfig: js.configs.recommended, // optional
  25. allConfig: js.configs.all, // optional
  26. });
  27. export default [
  28. // mimic ESLintRC-style extends
  29. ...compat.extends("standard", "example"),
  30. // mimic environments
  31. ...compat.env({
  32. es2020: true,
  33. node: true
  34. }),
  35. // mimic plugins
  36. ...compat.plugins("airbnb", "react"),
  37. // translate an entire config
  38. ...compat.config({
  39. plugins: ["airbnb", "react"],
  40. extends: "standard",
  41. env: {
  42. es2020: true,
  43. node: true
  44. },
  45. rules: {
  46. semi: "error"
  47. }
  48. })
  49. ];
  50. ```
  51. ## Usage (CommonJS)
  52. Using `FlatCompat` in CommonJS files is similar to ESM, but you'll use `require()` and `module.exports` instead of `import` and `export`. Here's how you use it inside of your `eslint.config.js` CommonJS file:
  53. ```js
  54. const { FlatCompat } = require("@eslint/eslintrc");
  55. const js = require("@eslint/js");
  56. const compat = new FlatCompat({
  57. baseDirectory: __dirname, // optional; default: process.cwd()
  58. resolvePluginsRelativeTo: __dirname, // optional
  59. recommendedConfig: js.configs.recommended, // optional
  60. allConfig: js.configs.all, // optional
  61. });
  62. module.exports = [
  63. // mimic ESLintRC-style extends
  64. ...compat.extends("standard", "example"),
  65. // mimic environments
  66. ...compat.env({
  67. es2020: true,
  68. node: true
  69. }),
  70. // mimic plugins
  71. ...compat.plugins("airbnb", "react"),
  72. // translate an entire config
  73. ...compat.config({
  74. plugins: ["airbnb", "react"],
  75. extends: "standard",
  76. env: {
  77. es2020: true,
  78. node: true
  79. },
  80. rules: {
  81. semi: "error"
  82. }
  83. })
  84. ];
  85. ```
  86. ## License
  87. MIT License