简体   繁体   English

Rollup + Typescript + ESLint 错误警告

[英]Rollup + Typescript + ESLint wrong warning

I created a project using Rollup which use Typescript and ESLint with the typescript-eslint plugin and it seems that ESLint is executed on compiled code.我使用 Rollup 创建了一个项目,该项目使用 Typescript 和 ESLint 以及 typescript-eslint 插件,似乎 ESLint 是在编译后的代码上执行的。

Here is my Rollup config:这是我的汇总配置:

export default commandLineArgs => {
  const serving = commandLineArgs.configServe === true;

  return {
    input: 'src/main.ts',
    output: {
      file: pkg.main,
      format: 'umd',
      name: 'bot',
      sourcemap: !isProduction
    },
    plugins: [
      eslint({ include: ['src/**/*.js', 'src/**/*.ts'] }),
      nodeResolve(),
      commonjs(),
      typescript({ sourceMap: !isProduction, inlineSources: !isProduction }),
      replace({
        'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development')
      }),
      scss({
        includePaths: ['node_modules/'],
        outputStyle: isProduction ? 'compressed' : 'expanded'
      }),
      html({ include: 'src/**/*.html' }), // to allow import of html files (for templating)
      image(), // to allow import of image files
      isProduction && terser(),
      isProduction && filesize(),
      serving && serve({
        open: true,
        openPage: '/index.html',
        contentBase: ['demo', 'dist'],
      })
    ]
  }
}

Here is my main.ts:这是我的 main.ts:

import './styles/app.scss';

import ChatUI from './ui';
import Chat from './chat';

export default async function init(target: HTMLDivElement): Promise<Chat> {
  const ui = new ChatUI(target);
  const chat = new Chat(ui);

  return chat;
}

And this is what ESLint logs:这就是 ESLint 记录的内容:

.../src/main.ts
4:16  warning  Missing return type on function    @typescript-eslint/explicit-module-boundary-types
4:36  warning  Argument 'target' should be typed  @typescript-eslint/explicit-module-boundary-types

As you can see, both line numbers and errors are wrong, as if it use the generated js file rather than the ts source.可以看到,无论是行号还是错误都是错误的,好像使用的是生成的js文件而不是ts源。 What is the problem here?这里有什么问题?

It appears that the "official" version, @rollup/plugin-eslint , is outdated, and uses an old version of eslint.似乎“官方”版本@rollup/plugin-eslint已经过时,并且使用的是旧版本的 eslint。 There are two available alternatives that are more current: @rbnlffl/rollup-plugin-eslint and rollup-plugin-eslint2 .有两种更新的替代方案: @rbnlffl/rollup-plugin-eslintrollup-plugin-eslint2 The former did the trick for me;前者对我有用; I haven't tried the latter.后者我没试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM