Tips: Install the ESLint plugin and extension before configuring
The configuration file can be a JS file or a JSON file with different syntax. Do not blindly copy other configuration items, depending on what is installed in your project and whether it is needed.
1. SLint supports configuration files in several formats
2. Numerical representation of ESLint
“Off” or 0 – Turns off the rule
“Warn” or 1 – turn on the rule, using warning level errors: WARN (will not cause the program to exit) “error” or 2 – turn on the rule, using error level errors: error (when triggered, the program will exit)
Refer to my configuration:
module.exports = { env: { browser: true, es6: true, node: true, }, extends: ["eslint:recommended", "plugin: recommended"], // Install react plugins: ["react", "prettier"], // add plugins here. globals: { Atomics: "readonly", SharedArrayBuffer: "readonly", }, // parser: "@typescript-eslint/parser", parserOptions: { ecmaVersion: "latest", sourceType: "module", ecmaFeatures: { jsx: true, }, }, rules: { "javascript.validate.enable": "warn", "react/jsx-uses-react": "Error ", // Disallow the definition of unused variables "no-unused-vars": [2, {vars: "all", // The variable definition must be used args: "None ", // does not inspect the ignoreRestSiblings: true for the function parameter, // ignores the remaining child items fn(...args), {a, b,...coords} caughtErrors: },], // suppress errors for missing 'import React' in files "React /react-in-jsx-scope": "off", // allow jsx syntax in js files (for next.js project) "react/jsx-filename-extension": [1, { extensions: [".js", ".jsx"] }], //should add ".ts" if typescript project "react/prop-types": "off", }, }; /** "off" or 0 - turn off the rule "WARN" or 1 - turn on the rule, using warning level errors: WARN (will not cause the program to exit) "error" or 2 - turn on the rule, using error level errors: error (when triggered, the program will exit) */Copy the code
3. Links
(1)ESLint website, for details, see Configuration. You can search here, as shown:If you don’t understand it, you can discuss it in the comments section.
(2) About the problems I had with the ESLint configuration.