javascript - Rollup + Typescript + ESLint 错误警告

标签 javascript typescript eslint rollupjs

我使用 Rollup 创建了一个项目,它使用 Typescript 和 ESLint 以及 typescript-eslint 插件,似乎 ESLint 是在编译后的代码上执行的。

这是我的 Rollup 配置:

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'],
      })
    ]
  }
}

这是我的 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;
}

这就是 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

可以看到,行号和错误都是错误的,好像是使用生成的js文件而不是ts源。这里有什么问题?

最佳答案

“官方”版本 @rollup/plugin-eslint 似乎已经过时,并且使用了旧版本的 eslint。有两个更新的替代方案:@rbnlffl/rollup-plugin-eslintrollup-plugin-eslint2 .前者对我有用;我没试过后者。

关于javascript - Rollup + Typescript + ESLint 错误警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65181259/

相关文章:

javascript - 在 jquery 中将 ajax 数据强制评估为 XML

typescript - TypeScript 中的类型化枚举实例

reactjs - 创建 react 应用程序-没有 typescript ,得到了错误: Failed to load parser '@typescript-eslint/parser'

ecmascript-6 - 如何仅针对 ForOfStatement 关闭 ESLint 的无限制语法规则?

javascript - 如何在 setInterval 循环中设置延迟?

javascript - noUiSlider 链接错误

angular - 如何在 Ionic 2 项目上运行 Sonar 扫描仪

typescript - 检查函数的参数是否是类型参数中正确类型的键

visual-studio-code - VSCode中的ESLint无法在保存时修复

javascript - Vue.js 使用全局列表