umijs / umi

A framework in react community ✨
https://umijs.org
MIT License
15.06k stars 2.64k forks source link

[Bug] umi3.x eslint 如何开启,如何配置,有没有详细的文档 #7037

Closed wenhua-lee closed 2 years ago

wenhua-lee commented 2 years ago

umi3.x 如何开启eslint检查

1. umi3.x 项目生成后,发现没有eslint检查,于是在官网找到`修改eslint配置`一栏,如下图所示:

Snipaste_2021-07-21_16-51-21 Snipaste_2021-07-21_16-53-17 Snipaste_2021-07-21_17-00-19

2. 按照说明配置以后发现无效,该生效的地方没效果,不该生效的地方一片红,按照vscode的提示,一一进行了修复,(难道eslint的规则都需要一条一条的自己加上去???),如下图所示:

Snipaste_2021-07-21_17-03-38 Snipaste_2021-07-21_17-04-54 Snipaste_2021-07-21_17-07-16

3. 并且安装`@umijs/fabric`插件以后,less文件格式化也不生效了……,我想知道这个依赖包到底是干嘛的,需要的东西一样也没拿到,不需要的东西,全都有了……

Snipaste_2021-07-21_17-09-38 Snipaste_2021-07-21_17-10-07

  1. 有没有解决的朋友,给个解决办法吧

环境说明

umi@3.5.13 windows10 @umijs/fabric": "^2.6.2"

搭建项目日期:2021/7/21

xiefengnian commented 2 years ago

cc @chenshuai2144

Dunqing commented 2 years ago

手动运行eslint检查看看有用吗

xlei1123 commented 2 years ago

+1

chenglianjie commented 2 years ago

我也遇到了这个问题 哈哈哈 如果我解决了 我再来给你留言

chenxiaoyao6228 commented 2 years ago

注意eslint-loader已经废弃,换eslint-webpack-plugin

config.local.js

const ESLintPlugin = require('eslint-webpack-plugin');

const config = {
  chainWebpack: (config: any) => {
    config
      .plugin('eslint')
      .use(ESLintPlugin, [
        {
          extensions: ['js', 'jsx', 'ts', 'tsx', 'less'], // 不再使用use
          fix: true,
          emitError: true,
          emitWarning: true,
        },
      ])
      .end();
  },
};

export default config;
fy996icu commented 2 years ago

我加了两个插件就对了: eslint-plugin-prettier@umijs/fabric

然后把 .eslintrc.js 改成了下面这样:

module.exports = {
  extends: [require.resolve('@umijs/fabric/dist/eslint')],
  globals: {
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true,
    page: true,
    REACT_APP_ENV: true,
  },
  plugins: ['prettier'],
  rules: {
    'prettier/prettier': 'error',
  },
};

代码检测、保存自动格式化都起作用了,具体原因不晓得为啥

seveneElevenup commented 1 year ago

我加了两个插件就对了: eslint-plugin-prettier@umijs/fabric

然后把 .eslintrc.js 改成了下面这样:

module.exports = {
  extends: [require.resolve('@umijs/fabric/dist/eslint')],
  globals: {
    ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: true,
    page: true,
    REACT_APP_ENV: true,
  },
  plugins: ['prettier'],
  rules: {
    'prettier/prettier': 'error',
  },
};

代码检测、保存自动格式化都起作用了,具体原因不晓得为啥

麻了,搞了一下午还是不生效

wangchaoHeart commented 2 months ago

注意eslint-loader已经废弃,换eslint-webpack-plugin

config.local.js

const ESLintPlugin = require('eslint-webpack-plugin');

const config = {
  chainWebpack: (config: any) => {
    config
      .plugin('eslint')
      .use(ESLintPlugin, [
        {
          extensions: ['js', 'jsx', 'ts', 'tsx', 'less'], // 不再使用use
          fix: true,
          emitError: true,
          emitWarning: true,
        },
      ])
      .end();
  },
};

export default config;

我用的v4版本 就是此方法解决的