Skip to content

Commit

Permalink
🐛 修复eslint对后台脚本的支持与兼容火狐
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Nov 8, 2022
1 parent e55d23f commit 2343339
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/linter.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const linter = new Linter();

const rules = linter.getRules();

const rule = {
const config = {
parserOptions: {
ecmaVersion: "latest",
sourceType: "script",
ecmaFeatures: {},
ecmaFeatures: { globalReturn: true },
},
rules: {
"constructor-super": ["error"],
Expand Down Expand Up @@ -92,22 +92,29 @@ const severityMap = {

self.addEventListener("message", (event) => {
const { code, id } = event.data;
const errs = linter.verify(code, rule);
const markers = errs.map((err: any) => ({
code: {
value: err.ruleId,
target: rules.get(err.ruleId).meta.docs.url,
},
startLineNumber: err.line,
endLineNumber: err.endLine,
startColumn: err.column,
endColumn: err.endColumn,
message: err.message,
// 设置错误的等级,此处ESLint与monaco的存在差异,做一层映射
// @ts-ignore
severity: severityMap[err.severity],
source: "ESLint",
}));
const errs = linter.verify(code, config);
const markers = errs.map((err: any) => {
const rule = rules.get(err.ruleId);
let target = "";
if (rule) {
target = rule.meta.docs.url;
}
return {
code: {
value: err.ruleId,
target,
},
startLineNumber: err.line,
endLineNumber: err.endLine,
startColumn: err.column,
endColumn: err.endColumn,
message: err.message,
// 设置错误的等级,此处ESLint与monaco的存在差异,做一层映射
// @ts-ignore
severity: severityMap[err.severity],
source: "ESLint",
};
});
// 发回主进程
self.postMessage({ markers, id });
});

0 comments on commit 2343339

Please sign in to comment.