Skip to content

Commit

Permalink
apple eslint rules from rwp & run auto-fixers
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-sg committed Jan 25, 2024
1 parent b3be837 commit 8a8dfe9
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 145 deletions.
110 changes: 71 additions & 39 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,86 @@ module.exports = {
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:wc/recommended",
"plugin:lit/recommended",
"prettier",
"plugin:@typescript-eslint/recommended",
],
plugins: ["@typescript-eslint", "lit"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
project: ["./tsconfig.eslint.json"],
tsconfigRootDir: __dirname,
},
root: true,
rules: {
/* start stylistic rules */
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-imports": [
"error",
{
fixStyle: "inline-type-imports",
},
],
"@typescript-eslint/prefer-readonly": "warn",
"@typescript-eslint/class-literal-property-style": ["warn", "getters"],
"@typescript-eslint/consistent-generic-constructors": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/no-confusing-non-null-assertion": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/non-nullable-type-assertion-style": "warn",
"@typescript-eslint/prefer-for-of": "warn",
// "@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
/* end stylistic rules */

/* start recommended rules */
"no-restricted-globals": [2, "event", "error"],
"linebreak-style": ["error", "unix"],
"@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-extra-non-null-assertion": "error",
// "@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-for-in-array": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
},
],
"no-implied-eval": "off",
"@typescript-eslint/no-implied-eval": "error",
"no-loss-of-precision": "off",
"@typescript-eslint/no-loss-of-precision": "warn",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{ checksVoidReturn: { arguments: 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",
// "@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/prefer-as-const": "warn",
"require-await": "off",
"@typescript-eslint/require-await": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/unbound-method": "off",
},
ignorePatterns: [
"ruffle/**/*",
Expand All @@ -31,38 +98,3 @@ module.exports = {
],
reportUnusedDisableDirectives: true,
};

// module.exports = {
// "env": {
// "browser": true,
// "es6": true,
// "webextensions": true
// },
// "extends": "eslint:recommended",
// "parserOptions": {
// "ecmaVersion": 2018,
// "sourceType": "module"
// },
// "rules": {
// "no-restricted-globals": [
// 2,
// "event", "error"
// ],
// "indent": [
// "error",
// 2
// ],
// "linebreak-style": [
// "error",
// "unix"
// ],
// "quotes": [
// "error",
// "double"
// ],
// "semi": [
// "error",
// "always"
// ]
// }
// };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-lit": "^1.11.0",
"eslint-plugin-prettier": "^5.1.0",
"eslint-plugin-wc": "^2.0.4",
"generate-json-webpack-plugin": "^2.0.0",
"mini-css-extract-plugin": "^2.3.0",
"node-sass": "^8.0.0",
Expand Down
16 changes: 8 additions & 8 deletions src/electron/app-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class AppRecPopup extends RecPopup {
constructor() {
super();

// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
this.collLoader = new CollectionLoader();

//this.tabId = 0;//window.location.hash && Number(window.location.hash.slice(1));

// @ts-expect-error - TS2339 - Property 'allowCreate' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'allowCreate' does not exist on type 'AppRecPopup'.
this.allowCreate = false;

// @ts-expect-error - TS2339 - Property 'msg' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'msg' does not exist on type 'AppRecPopup'.
this.msg = null;
}

Expand All @@ -29,11 +29,11 @@ class AppRecPopup extends RecPopup {
};
}

// @ts-expect-error - TS2416 - Property 'firstUpdated' in type 'AppRecPopup' is not assignable to the same property in base type 'RecPopup'.
// @ts-expect-error - TS2416 - Property 'firstUpdated' in type 'AppRecPopup' is not assignable to the same property in base type 'RecPopup'.
firstUpdated() {
super.firstUpdated();

// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
listAllMsg(this.collLoader).then((msg) => {
this.onMessage(msg);
});
Expand All @@ -43,7 +43,7 @@ class AppRecPopup extends RecPopup {
super.updated(changedProperties);

if (changedProperties.has("msg")) {
// @ts-expect-error - TS2339 - Property 'msg' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'msg' does not exist on type 'AppRecPopup'.
this.onMessage(this.msg);
}
}
Expand All @@ -65,12 +65,12 @@ class AppRecPopup extends RecPopup {
}

async makeNewColl(message) {
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
const newColl = await this.collLoader.initNewColl({ title: message.title });

await setLocalOption("defaultCollId", newColl.name);

// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
// @ts-expect-error - TS2339 - Property 'collLoader' does not exist on type 'AppRecPopup'.
const respMsg = await listAllMsg(this.collLoader);

this.onMessage(respMsg);
Expand Down
5 changes: 2 additions & 3 deletions src/electron/electron-rec-preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ensureDefaultColl } from "../utils";

import { loader, getDB } from "replaywebpage/src/electron-preload";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ipcRenderer, contextBridge } = require("electron");

let downloadCallback;
Expand Down Expand Up @@ -65,14 +64,14 @@ ipcRenderer.on("add-page", async (event, pageInfo, collId) => {
});

// ===========================================================================
ipcRenderer.on("inc-sizes", async (event, totalSize, writtenSize, collId) => {
ipcRenderer.on("inc-sizes", (event, totalSize, writtenSize, collId) => {
if (totalSize > 0) {
loader.updateSize(collId, totalSize, writtenSize);
}
});

// ===========================================================================
ipcRenderer.on("download-progress", async (event, progress) => {
ipcRenderer.on("download-progress", (event, progress) => {
if (downloadCallback) {
downloadCallback(progress);
}
Expand Down
4 changes: 2 additions & 2 deletions src/electron/electron-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ class ElectronRecorder extends Recorder {
this.frameWC.send("stats", stats);
}
// @ts-expect-error - TS2339 - Property 'popup' does not exist on type 'ElectronRecorder'. | TS2339 - Property 'popup' does not exist on type 'ElectronRecorder'.
if (this.popup && this.popup.webContents) {
if (this.popup?.webContents) {
// @ts-expect-error - TS2339 - Property 'popup' does not exist on type 'ElectronRecorder'.
this.popup.webContents.send("popup", stats);
}
}

getFavIcon() {
// @ts-expect-error - TS2339 - Property 'favicons' does not exist on type 'ElectronRecorder'. | TS2339 - Property 'favicons' does not exist on type 'ElectronRecorder'. | TS2339 - Property 'favicons' does not exist on type 'ElectronRecorder'.
return this.favicons && this.favicons.length ? this.favicons[0] : null;
return this.favicons?.length ? this.favicons[0] : null;
}

async _doAddResource(data) {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/rec-preload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*eslint-env node */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ipcRenderer, contextBridge } = require("electron");

ipcRenderer.on("stats", (event, stats) => {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/rec-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class RecWindowUI extends LitElement {
// @ts-expect-error - TS2339 - Property 'favIconUrl' does not exist on type 'RecWindowUI'.
this.favIconUrl =
// @ts-expect-error - TS2339 - Property 'favIcons' does not exist on type 'RecWindowUI'. | TS2339 - Property 'favIcons' does not exist on type 'RecWindowUI'. | TS2339 - Property 'favIcons' does not exist on type 'RecWindowUI'.
this.favIcons && this.favIcons.length ? this.favIcons.shift() : null;
this.favIcons?.length ? this.favIcons.shift() : null;
}

onGoBack() {
Expand Down
6 changes: 2 additions & 4 deletions src/ext/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ chrome.tabs.onCreated.addListener((tab) => {
} else if (
tab.openerTabId &&
(!tab.pendingUrl || isValidUrl(tab.pendingUrl)) &&
self.recorders[tab.openerTabId] &&
// @ts-expect-error - TS2339 - Property 'running' does not exist on type 'BrowserRecorder'.
self.recorders[tab.openerTabId].running
self.recorders[tab.openerTabId]?.running
) {
// @ts-expect-error - TS2339 - Property 'collId' does not exist on type 'BrowserRecorder'.
collId = self.recorders[tab.openerTabId].collId;
Expand Down Expand Up @@ -274,7 +272,7 @@ function toggleBehaviors(tabId) {
// ===========================================================================
function isRecording(tabId) {
// @ts-expect-error - TS2339 - Property 'running' does not exist on type 'BrowserRecorder'.
return self.recorders[tabId] && self.recorders[tabId].running;
return self.recorders[tabId]?.running;
}

// ===========================================================================
Expand Down
8 changes: 4 additions & 4 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ declare const __VERSION__: string;
declare const __WEB3_STORAGE_TOKEN__: string;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const pdfjsLib: any;
declare type TODOFixMe = any;

declare const pdfjsLib: TODOFixMe;

interface Window {
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
archivewebpage?: import("./electron/electron-rec-preload").GlobalAPI;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare type TODOFixMe = any;
6 changes: 3 additions & 3 deletions src/localstorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function setLocalOption(name, value) {
// @ts-expect-error - TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'. | TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'.
if (self.chrome && self.chrome.storage) {
if (self.chrome?.storage) {
return new Promise((resolve) => {
const data = {};
data[name] = value;
Expand All @@ -19,7 +19,7 @@ export function setLocalOption(name, value) {
// ===========================================================================
export function getLocalOption(name) {
// @ts-expect-error - TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'. | TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'.
if (self.chrome && self.chrome.storage) {
if (self.chrome?.storage) {
return new Promise((resolve) => {
// @ts-expect-error - TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'.
self.chrome.storage.local.get(name, (res) => {
Expand All @@ -38,7 +38,7 @@ export function getLocalOption(name) {
// ===========================================================================
export function removeLocalOption(name) {
// @ts-expect-error - TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'. | TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'.
if (self.chrome && self.chrome.storage) {
if (self.chrome?.storage) {
return new Promise((resolve) => {
// @ts-expect-error - TS2339 - Property 'chrome' does not exist on type 'Window & typeof globalThis'.
self.chrome.storage.local.remove(name, () => {
Expand Down
10 changes: 5 additions & 5 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ class RecPopup extends LitElement {
this.behaviorState = message.behaviorState;
// @ts-expect-error - TS2339 - Property 'behaviorMsg' does not exist on type 'RecPopup'.
this.behaviorMsg =
(message.behaviorData && message.behaviorData.msg) || "Starting...";
(message.behaviorData?.msg) || "Starting...";
// @ts-expect-error - TS2339 - Property 'behaviorResults' does not exist on type 'RecPopup'.
this.behaviorResults =
message.behaviorData && message.behaviorData.state;
message.behaviorData?.state;
// @ts-expect-error - TS2339 - Property 'autorun' does not exist on type 'RecPopup'.
this.autorun = message.autorun;
if (message.pageUrl) {
Expand Down Expand Up @@ -465,7 +465,7 @@ class RecPopup extends LitElement {
Archiving:&nbsp;</b
>${
// @ts-expect-error - TS2339 - Property 'status' does not exist on type 'RecPopup'. | TS2339 - Property 'status' does not exist on type 'RecPopup'.
this.status && this.status.numPending
this.status?.numPending
? html`
<span class="status-pending"
>${
Expand Down Expand Up @@ -518,7 +518,7 @@ class RecPopup extends LitElement {
// @ts-expect-error - TS2339 - Property 'canRecord' does not exist on type 'RecPopup'.
if (!this.canRecord) {
// @ts-expect-error - TS2339 - Property 'pageUrl' does not exist on type 'RecPopup'. | TS2339 - Property 'pageUrl' does not exist on type 'RecPopup'.
if (this.pageUrl && this.pageUrl.startsWith(this.extRoot)) {
if (this.pageUrl?.startsWith(this.extRoot)) {
return html`
<p class="is-size-7">
This page is part of the extension. You can view existing archived
Expand Down Expand Up @@ -803,7 +803,7 @@ class RecPopup extends LitElement {
}
${
// @ts-expect-error - TS2339 - Property 'status' does not exist on type 'RecPopup'. | TS2339 - Property 'status' does not exist on type 'RecPopup'.
this.status && this.status.sizeTotal
this.status?.sizeTotal
? html`
<div class="view-row underline">
<div class="session-head">Archived in this tab</div>
Expand Down

0 comments on commit 8a8dfe9

Please sign in to comment.