rules配置

use the “customSyntax” option

Error: The “syntax” option is no longer available. You should install an appropriate syntax, e.g. postcss-scss, and use the “customSyntax” option
https://stylelint.io/developer-guide/syntaxes/
大概意思:“syntax”选项不可用。应该安装适当的语法,例如 postsss-scss,并使用“customSyntax”选项

error Delete ·· prettier/prettier

https://github.com/prettier/eslint-plugin-prettier/issues/219
rules,设置 prettier/prettier
image.png

  1. {
  2. "rules": {
  3. "singleQuote": 0,
  4. "no-trailing-spaces": 0,
  5. "@typescript-eslint/ban-tslint-comment": "off",
  6. "prettier/prettier": ["error", {"endOfLine": "auto"}]
  7. }
  8. }

linebreak-style

ESLint: Expected linebreaks to be 'LF' but found 'CRLF'.(linebreak-style)
使用不同的编辑器、VCS应用程序和操作系统时,使用的换行操作不一样,造成了这种报错
检查.eslinttrc.js是否有配置:eslint linebreak-style: [“error”, “unix”]

  1. module.exports = {
  2. rules: {
  3. "linebreak-style": [0,"error", "windows"],
  4. 'jsx-a11y/anchor-is-valid': 0,
  5. 'jsx-a11y/media-has-caption': 0,
  6. },
  7. };

代码规范

Identifier * is not in camel case

组件命名不能用小驼峰

no-plusplus

ESLint: Unary operator ‘’ used. (no-plusplus)
原因:ESLint没有操作符,

  • 不要在代码中,++, —,用 +=,或 state = state + 1
  • 修改为 +=,或 + 1 ```jsx for (let i = 0; i < arr.length; i += 1) { let item = arr[i].uid }

state.count ++; 改成 state.count += 1;

  1. <a name="enNZE"></a>
  2. ### Missing radix parameter. (radix),进制错误
  3. ```jsx
  4. parseInt(this.state.adminId,10),或
  5. Number(this.state.adminId)

react相关规范

React’ must be in scope

‘React’ must be in scope when using JSX react/react-in-jsx-scope?
原因:Note the uppercase R for React,没有引入 React
https://www.akashmittal.com/react-must-in-scope-when-using-jsx

  • 因为没有引入React的原因,在最顶端加上
  • 小写 react 也会报这个错误,改成 React
    1. import React, { useEffect, useState } from 'react';

react/destructuring-assignment

Unexpected console statement (no-console)’
原因:不能用 console.log,解决: 用 window.console.log

  1. 'camelcase': [0, {properties: 'always'}]