From c7f4ca265376700b56b4d0bdd4c879dd9915d1cf Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 22 Jan 2025 08:11:51 +0100 Subject: [PATCH] Enable Typescript `noImplicitAny` (#33322) Enable `noImplicitAny` and fix all issues. --------- Co-authored-by: wxiaoguang --- tests/e2e/utils_e2e.ts | 11 ++-- tsconfig.json | 1 + web_src/js/components/DashboardRepoList.vue | 16 +++--- web_src/js/components/DiffCommitSelector.vue | 29 +++++++--- web_src/js/components/DiffFileList.vue | 14 ++--- web_src/js/components/DiffFileTree.vue | 11 ++-- web_src/js/components/DiffFileTreeItem.vue | 18 +++---- .../js/components/PullRequestMergeForm.vue | 8 +-- web_src/js/components/RepoActionView.vue | 44 ++++++++++----- .../js/components/RepoActivityTopAuthors.vue | 1 + .../js/components/RepoBranchTagSelector.vue | 4 +- web_src/js/components/RepoContributors.vue | 20 +++---- .../components/ScopedAccessTokenSelector.vue | 2 +- web_src/js/features/admin/common.ts | 2 +- web_src/js/features/citation.ts | 4 ++ web_src/js/features/common-button.ts | 18 +++---- web_src/js/features/common-fetch-action.ts | 5 +- web_src/js/features/common-form.ts | 4 +- .../js/features/comp/ComboMarkdownEditor.ts | 41 ++++++++------ web_src/js/features/comp/EditorMarkdown.ts | 8 +-- web_src/js/features/comp/EditorUpload.ts | 53 ++++++++++--------- web_src/js/features/comp/QuickSubmit.ts | 2 +- web_src/js/features/comp/SearchUserBox.ts | 2 +- web_src/js/features/comp/TextExpander.ts | 7 +-- web_src/js/features/contextpopup.ts | 4 +- web_src/js/features/copycontent.ts | 2 +- web_src/js/features/dropzone.ts | 18 ++++--- web_src/js/features/emoji.ts | 6 +-- web_src/js/features/file-fold.ts | 6 +-- web_src/js/features/heatmap.ts | 2 +- web_src/js/features/imagediff.ts | 18 +++---- web_src/js/features/install.ts | 3 +- web_src/js/features/org-team.ts | 2 +- web_src/js/features/pull-view-file.ts | 8 +-- web_src/js/features/repo-common.ts | 8 +-- web_src/js/features/repo-diff.ts | 2 +- web_src/js/features/repo-editor.ts | 2 +- web_src/js/features/repo-findfile.ts | 14 ++--- web_src/js/features/repo-home.ts | 6 +-- web_src/js/features/repo-issue-content.ts | 4 +- web_src/js/features/repo-issue-edit.ts | 14 ++--- web_src/js/features/repo-issue-list.ts | 9 ++-- .../features/repo-issue-sidebar-combolist.ts | 6 +-- web_src/js/features/repo-issue.ts | 20 +++---- web_src/js/features/repo-migrate.ts | 6 +-- web_src/js/features/repo-new.ts | 4 +- web_src/js/features/repo-settings.ts | 6 +-- web_src/js/features/repo-wiki.ts | 2 +- web_src/js/features/stopwatch.ts | 6 +-- web_src/js/features/tablesort.ts | 2 +- web_src/js/features/tribute.ts | 36 +++++-------- web_src/js/features/user-auth-webauthn.ts | 4 +- web_src/js/markup/asciicast.ts | 1 + web_src/js/markup/html2markdown.ts | 6 ++- web_src/js/modules/fomantic/dropdown.ts | 24 ++++----- web_src/js/standalone/devtest.ts | 2 +- web_src/js/svg.ts | 2 +- web_src/js/types.ts | 2 + web_src/js/utils.ts | 4 +- web_src/js/utils/dom.ts | 4 +- web_src/js/utils/image.test.ts | 2 +- web_src/js/utils/time.ts | 2 +- web_src/js/webcomponents/absolute-date.ts | 2 +- 63 files changed, 326 insertions(+), 270 deletions(-) diff --git a/tests/e2e/utils_e2e.ts b/tests/e2e/utils_e2e.ts index 14ec836600a..3e92e0d3c2d 100644 --- a/tests/e2e/utils_e2e.ts +++ b/tests/e2e/utils_e2e.ts @@ -1,12 +1,13 @@ import {expect} from '@playwright/test'; import {env} from 'node:process'; +import type {Browser, Page, WorkerInfo} from '@playwright/test'; const ARTIFACTS_PATH = `tests/e2e/test-artifacts`; const LOGIN_PASSWORD = 'password'; // log in user and store session info. This should generally be // run in test.beforeAll(), then the session can be loaded in tests. -export async function login_user(browser, workerInfo, user) { +export async function login_user(browser: Browser, workerInfo: WorkerInfo, user: string) { // Set up a new context const context = await browser.newContext(); const page = await context.newPage(); @@ -17,8 +18,8 @@ export async function login_user(browser, workerInfo, user) { expect(response?.status()).toBe(200); // Status OK // Fill out form - await page.type('input[name=user_name]', user); - await page.type('input[name=password]', LOGIN_PASSWORD); + await page.locator('input[name=user_name]').fill(user); + await page.locator('input[name=password]').fill(LOGIN_PASSWORD); await page.click('form button.ui.primary.button:visible'); await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle @@ -31,7 +32,7 @@ export async function login_user(browser, workerInfo, user) { return context; } -export async function load_logged_in_context(browser, workerInfo, user) { +export async function load_logged_in_context(browser: Browser, workerInfo: WorkerInfo, user: string) { let context; try { context = await browser.newContext({storageState: `${ARTIFACTS_PATH}/state-${user}-${workerInfo.workerIndex}.json`}); @@ -43,7 +44,7 @@ export async function load_logged_in_context(browser, workerInfo, user) { return context; } -export async function save_visual(page) { +export async function save_visual(page: Page) { // Optionally include visual testing if (env.VISUAL_TEST) { await page.waitForLoadState('networkidle'); // eslint-disable-line playwright/no-networkidle diff --git a/tsconfig.json b/tsconfig.json index c41f9646d6e..78b74a3d3c9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,7 @@ "stripInternal": true, "strict": false, "strictFunctionTypes": true, + "noImplicitAny": true, "noImplicitThis": true, "noUnusedLocals": true, "noUnusedParameters": true, diff --git a/web_src/js/components/DashboardRepoList.vue b/web_src/js/components/DashboardRepoList.vue index 40ecbba5e35..876292fc94e 100644 --- a/web_src/js/components/DashboardRepoList.vue +++ b/web_src/js/components/DashboardRepoList.vue @@ -130,12 +130,12 @@ export default defineComponent({ }, methods: { - changeTab(t) { - this.tab = t; + changeTab(tab: string) { + this.tab = tab; this.updateHistory(); }, - changeReposFilter(filter) { + changeReposFilter(filter: string) { this.reposFilter = filter; this.repos = []; this.page = 1; @@ -218,7 +218,7 @@ export default defineComponent({ this.searchRepos(); }, - changePage(page) { + changePage(page: number) { this.page = page; if (this.page > this.finalPage) { this.page = this.finalPage; @@ -256,7 +256,7 @@ export default defineComponent({ } if (searchedURL === this.searchURL) { - this.repos = json.data.map((webSearchRepo) => { + this.repos = json.data.map((webSearchRepo: any) => { return { ...webSearchRepo.repository, latest_commit_status_state: webSearchRepo.latest_commit_status?.State, // if latest_commit_status is null, it means there is no commit status @@ -264,7 +264,7 @@ export default defineComponent({ locale_latest_commit_status_state: webSearchRepo.locale_latest_commit_status, }; }); - const count = response.headers.get('X-Total-Count'); + const count = Number(response.headers.get('X-Total-Count')); if (searchedQuery === '' && searchedMode === '' && this.archivedFilter === 'both') { this.reposTotalCount = count; } @@ -275,7 +275,7 @@ export default defineComponent({ } }, - repoIcon(repo) { + repoIcon(repo: any) { if (repo.fork) { return 'octicon-repo-forked'; } else if (repo.mirror) { @@ -298,7 +298,7 @@ export default defineComponent({ return commitStatus[status].color; }, - reposFilterKeyControl(e) { + reposFilterKeyControl(e: KeyboardEvent) { switch (e.key) { case 'Enter': document.querySelector('.repo-owner-name-list li.active a')?.click(); diff --git a/web_src/js/components/DiffCommitSelector.vue b/web_src/js/components/DiffCommitSelector.vue index 840acd4b51e..16760d1cb16 100644 --- a/web_src/js/components/DiffCommitSelector.vue +++ b/web_src/js/components/DiffCommitSelector.vue @@ -4,6 +4,22 @@ import {SvgIcon} from '../svg.ts'; import {GET} from '../modules/fetch.ts'; import {generateAriaId} from '../modules/fomantic/base.ts'; +type Commit = { + id: string, + hovered: boolean, + selected: boolean, + summary: string, + committer_or_author_name: string, + time: string, + short_sha: string, +} + +type CommitListResult = { + commits: Array, + last_review_commit_sha: string, + locale: Record, +} + export default defineComponent({ components: {SvgIcon}, data: () => { @@ -16,9 +32,9 @@ export default defineComponent({ locale: { filter_changes_by_commit: el.getAttribute('data-filter_changes_by_commit'), } as Record, - commits: [], + commits: [] as Array, hoverActivated: false, - lastReviewCommitSha: null, + lastReviewCommitSha: '', uniqueIdMenu: generateAriaId(), uniqueIdShowAll: generateAriaId(), }; @@ -71,7 +87,7 @@ export default defineComponent({ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { const item = document.activeElement; // try to highlight the selected commits const commitIdx = item?.matches('.item') ? item.getAttribute('data-commit-idx') : null; - if (commitIdx) this.highlight(this.commits[commitIdx]); + if (commitIdx) this.highlight(this.commits[Number(commitIdx)]); } }, onKeyUp(event: KeyboardEvent) { @@ -87,7 +103,7 @@ export default defineComponent({ } } }, - highlight(commit) { + highlight(commit: Commit) { if (!this.hoverActivated) return; const indexSelected = this.commits.findIndex((x) => x.selected); const indexCurrentElem = this.commits.findIndex((x) => x.id === commit.id); @@ -125,10 +141,11 @@ export default defineComponent({ } }); }, + /** Load the commits to show in this dropdown */ async fetchCommits() { const resp = await GET(`${this.issueLink}/commits/list`); - const results = await resp.json(); + const results = await resp.json() as CommitListResult; this.commits.push(...results.commits.map((x) => { x.hovered = false; return x; @@ -166,7 +183,7 @@ export default defineComponent({ * the diff from beginning of PR up to the second clicked commit is * opened */ - commitClickedShift(commit) { + commitClickedShift(commit: Commit) { this.hoverActivated = !this.hoverActivated; commit.selected = true; // Second click -> determine our range and open links accordingly diff --git a/web_src/js/components/DiffFileList.vue b/web_src/js/components/DiffFileList.vue index 792a1aefac3..6570c92781b 100644 --- a/web_src/js/components/DiffFileList.vue +++ b/web_src/js/components/DiffFileList.vue @@ -18,14 +18,14 @@ function toggleFileList() { } function diffTypeToString(pType: number) { - const diffTypes = { - 1: 'add', - 2: 'modify', - 3: 'del', - 4: 'rename', - 5: 'copy', + const diffTypes: Record = { + '1': 'add', + '2': 'modify', + '3': 'del', + '4': 'rename', + '5': 'copy', }; - return diffTypes[pType]; + return diffTypes[String(pType)]; } function diffStatsWidth(adds: number, dels: number) { diff --git a/web_src/js/components/DiffFileTree.vue b/web_src/js/components/DiffFileTree.vue index 8676c4d37f6..d00d03565f2 100644 --- a/web_src/js/components/DiffFileTree.vue +++ b/web_src/js/components/DiffFileTree.vue @@ -1,5 +1,5 @@