Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Require approval for new Web lint suppressions

Manav Rathi30ce55c52721
diff --git a/.github/checks/change-approval/changes.mjs b/.github/checks/change-approval/changes.mjs
index 1752b47427..674cfc232e 100644
--- a/.github/checks/change-approval/changes.mjs
+++ b/.github/checks/change-approval/changes.mjs
@@ -97,6 +97,26 @@ export function readChanges(base, local) {
.filter(Boolean),
readBefore,
readAfter,
+ readAddedLines: (path) => {
+ if (!sizes.has(path)) return "";
+ if (!pathsBefore.has(path)) return readAfter(path);
+ return git(
+ "--literal-pathspecs",
+ "diff",
+ "--no-ext-diff",
+ "--no-textconv",
+ "--unified=0",
+ "--output-indicator-new=>",
+ mergeBase,
+ ...(local ? [] : ["HEAD"]),
+ "--",
+ path,
+ )
+ .split("\n")
+ .filter((line) => line.startsWith(">"))
+ .map((line) => line.slice(1))
+ .join("\n");
+ },
readVersions: (path) => ({
before: pathsBefore.has(path) ? readBefore(path) : "",
after: sizes.has(path) ? readAfter(path) : "",
diff --git a/.github/checks/change-approval/check.mjs b/.github/checks/change-approval/check.mjs
index 5496048ccd..ce4e607aa4 100644
--- a/.github/checks/change-approval/check.mjs
+++ b/.github/checks/change-approval/check.mjs
@@ -3,6 +3,7 @@ import { checkDependencies } from "./dependencies.mjs";
import { checkFiles } from "./files.mjs";
import { writeReport } from "./report.mjs";
import { checkRust } from "./rust.mjs";
+import { checkWeb } from "./web.mjs";
const [base = "origin/main"] = process.argv.slice(2);
const changes = readChanges(base, !process.env.GITHUB_OUTPUT);
@@ -11,4 +12,5 @@ writeReport({
files: checkFiles(changes),
dependencies: checkDependencies(changes),
rust: checkRust(changes),
+ web: checkWeb(changes),
});
diff --git a/.github/checks/change-approval/report.mjs b/.github/checks/change-approval/report.mjs
index bad12821f7..74de32c281 100644
--- a/.github/checks/change-approval/report.mjs
+++ b/.github/checks/change-approval/report.mjs
@@ -4,6 +4,7 @@ export function writeReport({
files: { binaries, large, guardrails, configs },
dependencies,
rust,
+ web,
}) {
const categories = [
{
@@ -43,6 +44,11 @@ export function writeReport({
plural: "Rust lint policy files",
count: rust.length,
},
+ {
+ singular: "Web lint policy file",
+ plural: "Web lint policy files",
+ count: web.length,
+ },
].filter(({ count }) => count);
const summary = categories
.map(
@@ -78,6 +84,8 @@ export function writeReport({
sections.push(
`## Rust lint declarations and files containing unsafe\n\n${list(rust.map(code))}`,
);
+ if (web.length)
+ sections.push(`## Web lint directives\n\n${list(web.map(code))}`);
const detail = sections.join("\n\n");
const { GITHUB_OUTPUT, GITHUB_STEP_SUMMARY } = process.env;
diff --git a/.github/checks/change-approval/test.mjs b/.github/checks/change-approval/test.mjs
index f04b9b566a..3e8620cff8 100644
--- a/.github/checks/change-approval/test.mjs
+++ b/.github/checks/change-approval/test.mjs
@@ -975,6 +975,56 @@ fn helper() {}
);
});
+test("ESLint directives in added lines need approval", (t) => {
+ const body = "first();\n";
+ for (const directive of [
+ "// eslint-disable-next-line no-console\n",
+ "/* eslint-disable no-console */\n",
+ '/* eslint "no-console": "off" */\n',
+ 'const example = "eslint-disable-next-line no-console";\n',
+ ])
+ assert.match(
+ scan(
+ t,
+ { "web/example.ts": body },
+ { "web/example.ts": directive + body },
+ ),
+ /^1 Web lint policy file\n/,
+ );
+ assert.match(
+ scan(
+ t,
+ {
+ "web/example.ts":
+ "// eslint-disable-next-line no-console\n" + body,
+ },
+ {
+ "web/example.ts":
+ "// eslint-disable-next-line no-alert\n" + body,
+ },
+ ),
+ /^1 Web lint policy file\n/,
+ );
+});
+
+test("unchanged and removed ESLint directives need no approval", (t) => {
+ const before = "// eslint-disable-next-line no-console\nfirst();\n";
+ for (const after of [before.replace("first", "second"), "first();\n", null])
+ assert.equal(
+ scan(t, { "web/example.ts": before }, { "web/example.ts": after }),
+ "",
+ );
+});
+
+test("new Web directives are checked in uncommitted and untracked files", (t) => {
+ const source = "// eslint-disable-next-line no-console\nfirst();\n";
+ for (const base of [{}, { "web/example.ts": "first();\n" }])
+ assert.match(
+ scan(t, base, { "web/example.ts": source }, { commit: false }),
+ /^1 Web lint policy file\n/,
+ );
+});
+
test("checks started in a subdirectory inspect repository-wide changes", (t) => {
const summary =
"1 binary file, 1 new dependency\n\n## Binary files\n\n- `new.bin` (16 bytes)\n\n## New dependencies\n\n`rust/Cargo.lock`\n\n- b 2.0.0\n";
@@ -1021,13 +1071,18 @@ test("workflow scans PR changes with the complete checker from main", (t) => {
{
[`${checkerDir}/additional-rule.mjs`]:
"export function checkRust() { return []; }",
+ [`${checkerDir}/web.mjs`]:
+ 'throw new Error("loaded an untrusted rule");',
"src/lib.rs": "pub unsafe fn call() {}",
+ "web/example.ts":
+ "// eslint-disable-next-line no-console\nfirst();\n",
},
{ ci: true, workflow: true },
);
assert.equal(
output,
- 'categories=["guardrail files","Rust lint policy files"]\n',
+ 'categories=["guardrail files","Rust lint policy files","Web lint policy files"]\n',
);
assert.match(summary, /- `src\/lib.rs`/);
+ assert.match(summary, /- `web\/example.ts`/);
});
diff --git a/.github/checks/change-approval/web.mjs b/.github/checks/change-approval/web.mjs
new file mode 100644
index 0000000000..d605307a20
--- /dev/null
+++ b/.github/checks/change-approval/web.mjs
@@ -0,0 +1,9 @@
+export function checkWeb({ files, readAddedLines }) {
+ return files
+ .filter(
+ ({ path, binary, deleted }) =>
+ !binary && !deleted && /^web\/.*\.[cm]?[jt]sx?$/.test(path),
+ )
+ .filter(({ path }) => /\beslint(?:[-\s]|$)/m.test(readAddedLines(path)))
+ .map(({ path }) => path);
+}
diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.ts
index 15d63aa0c8..463e4c4948 100644
--- a/web/apps/photos/src/services/upload-manager.ts
+++ b/web/apps/photos/src/services/upload-manager.ts
@@ -161,9 +161,7 @@ export type UploadItemWithCollection = UploadAsset & {
};
class UIService {
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- private progressUpdater: ProgressUpdater;
+ private progressUpdater!: ProgressUpdater;
private uploadPhase: UploadPhase = "preparing";
private filenames = new Map<number, string>();
diff --git a/web/packages/build-config/eslintrc-base.mjs b/web/packages/build-config/eslintrc-base.mjs
index 11799ae96b..8dff02fdc0 100644
--- a/web/packages/build-config/eslintrc-base.mjs
+++ b/web/packages/build-config/eslintrc-base.mjs
@@ -14,6 +14,15 @@ export default tseslint.config(
{ ignores: ["eslint.config.mjs"] },
{
rules: {
+ "@typescript-eslint/ban-ts-comment": [
+ "error",
+ {
+ "ts-ignore": true,
+ "ts-expect-error": true,
+ "ts-nocheck": true,
+ "ts-check": false,
+ },
+ ],
"@typescript-eslint/no-import-type-side-effects": "error",
"@typescript-eslint/restrict-template-expressions": [
"error",
diff --git a/web/packages/new/photos/components/ImageEditorOverlay.tsx b/web/packages/new/photos/components/ImageEditorOverlay.tsx
index 03e104df58..4d78e3ecd2 100644
--- a/web/packages/new/photos/components/ImageEditorOverlay.tsx
+++ b/web/packages/new/photos/components/ImageEditorOverlay.tsx
@@ -737,11 +737,10 @@ const canvasToFile = async (
break;
}
- const blob = await new Promise<Blob>((resolve) =>
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
+ const blob = await new Promise<Blob | null>((resolve) =>
canvas.toBlob(resolve, mimeType),
);
+ if (!blob) throw new Error("Failed to encode edited image");
const [originalName] = nameAndExtension(originalFileName);
const fileName = `${originalName}-edited.${extension}`;