Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint parity with the Browsertrix repo #288

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/prefer-readonly": "warn",
"@typescript-eslint/class-literal-property-style": ["warn", "getters"],
"@typescript-eslint/consistent-generic-constructors": "error",
Expand All @@ -41,20 +42,27 @@ module.exports = {
// "@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/no-meaningless-void-operator": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "warn",
"@typescript-eslint/no-unnecessary-type-arguments": "warn",
"@typescript-eslint/prefer-reduce-type-parameter": "warn",
"@typescript-eslint/promise-function-async": "warn",
/* end stylistic rules */

/* start recommended rules */
"no-restricted-globals": [2, "event", "error"],
"@typescript-eslint/no-base-to-string": "warn",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/no-duplicate-type-constituents": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extra-non-null-assertion": "error",
// "@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
Expand All @@ -68,26 +76,28 @@ module.exports = {
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{ checksVoidReturn: { arguments: false } },
{ checksVoidReturn: false },
],
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
"@typescript-eslint/no-redundant-type-constituents": "warn",
"@typescript-eslint/no-this-alias": "warn",
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
// "@typescript-eslint/no-unsafe-argument": "warn",
/* TODO eventually turn all these on */
"@typescript-eslint/no-unsafe-argument": "warn",
// "@typescript-eslint/no-unsafe-assignment": "warn",
// "@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
"@typescript-eslint/no-unsafe-enum-comparison": "warn",
// "@typescript-eslint/no-unsafe-member-access": "warn",
// "@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/prefer-as-const": "warn",
"require-await": "off",
"@typescript-eslint/require-await": "warn",
// "@typescript-eslint/require-await": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/method-signature-style": "error",
},
reportUnusedDisableDirectives: true,
ignorePatterns: [
Expand Down
4 changes: 4 additions & 0 deletions src/appmain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ export class ReplayWebApp extends LitElement {

onStartLoad(event) {
// just redirect right away?
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.pageParams.set("source", event.detail.sourceUrl);

const url = new URL(window.location.href);
Expand Down Expand Up @@ -678,6 +680,8 @@ export class ReplayWebApp extends LitElement {
//this.initRoute();

if (event.detail.sourceUrl !== this.sourceUrl) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.pageParams.set("source", event.detail.sourceUrl);
window.location.search = this.pageParams.toString();
}
Expand Down
6 changes: 6 additions & 0 deletions src/chooser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class Chooser extends LitElement {
droppedFile: FileWithPath | null = null;

@property({ type: Boolean })
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
hasNativeFS = !!window.showOpenFilePicker && !IS_APP;

@property({ type: Object })
Expand Down Expand Up @@ -60,6 +62,8 @@ export class Chooser extends LitElement {
.flat(2);

const fileHasAllowedExtension = allowedFileExtensions.some(
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
(extension) => this.droppedFile?.name.endsWith(extension),
);

Expand All @@ -77,6 +81,8 @@ export class Chooser extends LitElement {
if (event.currentTarget.files.length === 0) {
return;
}
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.setFile(event.currentTarget.files[0]);
}

Expand Down
6 changes: 6 additions & 0 deletions src/electron-preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ async function getColl(name: string) {
await dbs[name].initing;
}

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return dbs[name];
}

async function getDB(name: string) {
const coll = await getColl(name);
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return coll.store;
}

Expand All @@ -43,6 +47,8 @@ async function getResponse(
return;
}

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const headers = Object.fromEntries(result.headers.entries());

const buffer = await result.getBuffer();
Expand Down
36 changes: 36 additions & 0 deletions src/electron-replay-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ class ElectronReplayApp {
}
});

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
app.whenReady().then(() => this.onAppReady());

// Quit when all windows are closed.
Expand All @@ -161,6 +163,8 @@ class ElectronReplayApp {
autoUpdater.logger = log;
// @ts-expect-error - TS2339 - Property 'transports' does not exist on type 'Logger'.
autoUpdater.logger.transports.file.level = "info";
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
autoUpdater.checkForUpdatesAndNotify();
}

Expand All @@ -173,12 +177,16 @@ class ElectronReplayApp {
contents.setWindowOpenHandler(({ url }) => {
// load docs in native browser for now
if (url === STATIC_PREFIX + "docs") {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
shell.openExternal("https://replayweb.page/docs/");
return { action: "deny" };
}

// load external URLs in native browser
if (!url.startsWith(STATIC_PREFIX)) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
shell.openExternal(url);
return { action: "deny" };
}
Expand All @@ -189,10 +197,14 @@ class ElectronReplayApp {

const sesh = session.defaultSession;

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/promise-function-async
sesh.protocol.interceptStreamProtocol("http", (request, callback) =>
this.doIntercept(request, callback),
);

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/promise-function-async
protocol.registerStreamProtocol(FILE_PROTO, (request, callback) =>
this.doHandleFile(request, callback),
);
Expand All @@ -211,9 +223,13 @@ class ElectronReplayApp {
return;
}

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const filename = url.fileURLToPath(request.url.replace(FILE_PROTO, "file"));

const headers = { "Content-Type": "application/octet-stream" };
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const reqHeaders = new Headers(request.headers);

if (filename) {
Expand Down Expand Up @@ -283,6 +299,8 @@ class ElectronReplayApp {
filename = "docs/index.html";
}

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
let ext = path.extname(filename);
if (!ext) {
ext = ".html";
Expand All @@ -292,6 +310,8 @@ class ElectronReplayApp {
const mimeType = mime.contentType(ext);

if (mimeType) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const fullPath = path.join(this.staticContentPath, filename);

console.log("fullPath: " + fullPath);
Expand Down Expand Up @@ -333,6 +353,8 @@ class ElectronReplayApp {
let response;

try {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
response = await fetch(url, { method, headers, body });
} catch (e) {
console.warn("fetch failed for: " + url);
Expand All @@ -342,6 +364,8 @@ class ElectronReplayApp {
const data = method === "HEAD" ? null : response.body;
const statusCode = response.status;

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
headers = Object.fromEntries(response.headers.entries());
callback({ statusCode, headers, data });
}
Expand Down Expand Up @@ -379,6 +403,8 @@ class ElectronReplayApp {
console.log("got response for: " + url);
}

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
headers = new Headers(headers);
const date = new Date();

Expand All @@ -399,11 +425,15 @@ class ElectronReplayApp {
useBaseRules: true,
});

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
request.headers = new Headers(request.headers);

try {
response = await rewriter.rewrite(response, request);

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
headers = Object.fromEntries(response.headers.entries());

let data = await response.getBuffer();
Expand Down Expand Up @@ -481,6 +511,8 @@ class ElectronReplayApp {
theWindow.maximize();
});

// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
theWindow.loadURL(STATIC_PREFIX + this.mainWindowUrl + sourceString);
if (process.env.NODE_ENV === "development") {
theWindow.webContents.openDevTools();
Expand Down Expand Up @@ -513,10 +545,14 @@ class ElectronReplayApp {
const openTS = argv.ts || argv.timestamp;

if (openUrl) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
urlParams.set("url", openUrl);
}

if (openTS) {
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
urlParams.set("ts", openTS);
}

Expand Down
24 changes: 14 additions & 10 deletions src/embed-receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,20 @@ export class RWPEmbedReceipt extends LitElement {
class="has-text-black"
target="_blank"
href="https://github.com/webrecorder/replayweb.page"
>${this.appLogo
? html`
<fa-icon
class="menu-logo mr-1"
size="1.0rem"
aria-hidden="true"
.svg=${this.appLogo}
></fa-icon>
`
: nothing}
>${
// TODO: Fix this the next time the file is edited.
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
this.appLogo
? html`
<fa-icon
class="menu-logo mr-1"
size="1.0rem"
aria-hidden="true"
.svg=${this.appLogo}
></fa-icon>
`
: nothing
}
Powered by ReplayWeb.page
</a>
</span>
Expand Down
Loading
Loading