Skip to content

Commit

Permalink
fix(textchecker-element): remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Aug 2, 2020
1 parent 6625de3 commit 040724d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/textchecker-element/src/text-checker-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TextCheckerElement extends HTMLElement {
// non-visible = drop from `rectItems`
const annotationItemsByDescendingOrder = annotationItems.slice().reverse();
let stopSearchAboveIsNotVisible = false;
const rectItems = annotationItemsByDescendingOrder.flatMap((annotation, index) => {
const rectItems = annotationItemsByDescendingOrder.flatMap((annotation) => {
// already the annotation is not visible, skip it
if (stopSearchAboveIsNotVisible) {
return [];
Expand Down
23 changes: 19 additions & 4 deletions packages/webextension/app/scripts/background/textlint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,40 @@ export const createTextlintWorker = (defaultWorkerUrl: string | URL = "download/
} as TextlintWorkerCommandFix);
});
};
const log = (...args: any[]) => {
console.log("[Background]", ...args);
};
return {
createLintEngine({ ext }: { ext: string }) {
const lintEngine: LintEngineAPI = {
lintText: ({ text }) => lintText({ text, ext }),
lintText: ({ text }) =>
lintText({ text, ext }).then((result) => {
log("lintText", result);
return result;
}),
fixText: async ({ text, message }): Promise<{ output: string }> => {
if (!message.fix || !message.fix.range) {
return { output: text };
}
// replace fix.range[0, 1] with fix.text
return {
const result = {
output:
text.slice(0, message.fix.range[0]) + message.fix.text + text.slice(message.fix.range[1])
};
log("fixText", result);
return result;
},
fixAll({ text }: { text: string }): Promise<TextlintFixResult> {
return fixText({ text, ext });
return fixText({ text, ext }).then((result) => {
log("fixAll", result);
return result;
});
},
fixRule({ text, message }: { text: string; message: TextlintMessage }): Promise<TextlintFixResult> {
return fixText({ text, message, ext });
return fixText({ text, message, ext }).then((result) => {
log("fixRule", result);
return result;
});
}
};
return lintEngine;
Expand Down
6 changes: 4 additions & 2 deletions packages/webextension/app/scripts/contentScript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-ignore - replace webcomponent to shim
import "@webcomponents/custom-elements";
// Load webcomponents polyfill for Chrome Extension
if (window.customElements === null || window.customElements === undefined) {
require("@webcomponents/custom-elements");
}
import { browser } from "webextension-polyfill-ts";
import { attachToTextArea, LintEngineAPI } from "textchecker-element";
import { createEndpoint } from "comlink-extension";
Expand Down
2 changes: 1 addition & 1 deletion packages/webextension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"outDir": "./lib/",
"target": "ES2015",
"sourceMap": true,
"declaration": true,
"declaration": false,
"jsx": "preserve",
"lib": [
"esnext",
Expand Down

0 comments on commit 040724d

Please sign in to comment.