我使用 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-eslint
和 rollup-plugin-eslint2
.前者对我有用;我没试过后者。
关于javascript - Rollup + Typescript + ESLint 错误警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65181259/