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

Enable Typescript noImplicitAny #33322

Merged
merged 16 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 12 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
11 changes: 6 additions & 5 deletions tests/e2e/utils_e2e.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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
Expand All @@ -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`});
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"stripInternal": true,
"strict": false,
"strictFunctionTypes": true,
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down
16 changes: 8 additions & 8 deletions web_src/js/components/DashboardRepoList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -256,15 +256,15 @@ 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
latest_commit_status_state_link: webSearchRepo.latest_commit_status?.TargetURL,
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;
}
Expand All @@ -275,7 +275,7 @@ export default defineComponent({
}
},

repoIcon(repo) {
repoIcon(repo: any) {
if (repo.fork) {
return 'octicon-repo-forked';
} else if (repo.mirror) {
Expand All @@ -298,7 +298,7 @@ export default defineComponent({
return commitStatus[status].color;
},

reposFilterKeyControl(e) {
reposFilterKeyControl(e: KeyboardEvent) {
switch (e.key) {
case 'Enter':
document.querySelector<HTMLAnchorElement>('.repo-owner-name-list li.active a')?.click();
Expand Down
29 changes: 23 additions & 6 deletions web_src/js/components/DiffCommitSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<Commit>,
last_review_commit_sha: string,
locale: Record<string, string>,
}

export default defineComponent({
components: {SvgIcon},
data: () => {
Expand All @@ -16,9 +32,9 @@ export default defineComponent({
locale: {
filter_changes_by_commit: el.getAttribute('data-filter_changes_by_commit'),
} as Record<string, string>,
commits: [],
commits: [] as Array<Commit>,
hoverActivated: false,
lastReviewCommitSha: null,
lastReviewCommitSha: '',
uniqueIdMenu: generateAriaId(),
uniqueIdShowAll: generateAriaId(),
};
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions web_src/js/components/DiffFileList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = {
'1': 'add',
'2': 'modify',
'3': 'del',
'4': 'rename',
'5': 'copy',
};
return diffTypes[pType];
return diffTypes[String(pType)];
}

function diffStatsWidth(adds: number, dels: number) {
Expand Down
11 changes: 3 additions & 8 deletions web_src/js/components/DiffFileTree.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import DiffFileTreeItem from './DiffFileTreeItem.vue';
import DiffFileTreeItem, {type Item} from './DiffFileTreeItem.vue';
import {loadMoreFiles} from '../features/repo-diff.ts';
import {toggleElem} from '../utils/dom.ts';
import {diffTreeStore} from '../modules/stores.ts';
Expand All @@ -11,7 +11,7 @@ const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
const store = diffTreeStore();

const fileTree = computed(() => {
const result = [];
const result: Array<Item> = [];
for (const file of store.files) {
// Split file into directories
const splits = file.Name.split('/');
Expand All @@ -24,15 +24,10 @@ const fileTree = computed(() => {
if (index === splits.length) {
isFile = true;
}
let newParent = {
let newParent: Item = {
name: split,
children: [],
isFile,
} as {
name: string,
children: any[],
isFile: boolean,
file?: any,
};

if (isFile === true) {
Expand Down
18 changes: 9 additions & 9 deletions web_src/js/components/DiffFileTreeItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import {SvgIcon} from '../svg.ts';
import {SvgIcon, type SvgName} from '../svg.ts';
import {diffTreeStore} from '../modules/stores.ts';
import {ref} from 'vue';

Expand All @@ -11,7 +11,7 @@ type File = {
IsSubmodule: boolean;
}

type Item = {
export type Item = {
name: string;
isFile: boolean;
file?: File;
Expand All @@ -26,14 +26,14 @@ const store = diffTreeStore();
const collapsed = ref(false);

function getIconForDiffType(pType: number) {
const diffTypes = {
1: {name: 'octicon-diff-added', classes: ['text', 'green']},
2: {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
3: {name: 'octicon-diff-removed', classes: ['text', 'red']},
4: {name: 'octicon-diff-renamed', classes: ['text', 'teal']},
5: {name: 'octicon-diff-renamed', classes: ['text', 'green']}, // there is no octicon for copied, so renamed should be ok
const diffTypes: Record<string, {name: SvgName, classes: Array<string>}> = {
'1': {name: 'octicon-diff-added', classes: ['text', 'green']},
'2': {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
'3': {name: 'octicon-diff-removed', classes: ['text', 'red']},
'4': {name: 'octicon-diff-renamed', classes: ['text', 'teal']},
'5': {name: 'octicon-diff-renamed', classes: ['text', 'green']}, // there is no octicon for copied, so renamed should be ok
};
return diffTypes[pType];
return diffTypes[String(pType)];
}

function fileIcon(file: File) {
Expand Down
8 changes: 4 additions & 4 deletions web_src/js/components/PullRequestMergeForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ const forceMerge = computed(() => {
});

watch(mergeStyle, (val) => {
mergeStyleDetail.value = mergeForm.value.mergeStyles.find((e) => e.name === val);
mergeStyleDetail.value = mergeForm.value.mergeStyles.find((e: any) => e.name === val);
for (const elem of document.querySelectorAll('[data-pull-merge-style]')) {
toggleElem(elem, elem.getAttribute('data-pull-merge-style') === val);
}
});

onMounted(() => {
mergeStyleAllowedCount.value = mergeForm.value.mergeStyles.reduce((v, msd) => v + (msd.allowed ? 1 : 0), 0);
mergeStyleAllowedCount.value = mergeForm.value.mergeStyles.reduce((v: any, msd: any) => v + (msd.allowed ? 1 : 0), 0);

let mergeStyle = mergeForm.value.mergeStyles.find((e) => e.allowed && e.name === mergeForm.value.defaultMergeStyle)?.name;
if (!mergeStyle) mergeStyle = mergeForm.value.mergeStyles.find((e) => e.allowed)?.name;
let mergeStyle = mergeForm.value.mergeStyles.find((e: any) => e.allowed && e.name === mergeForm.value.defaultMergeStyle)?.name;
if (!mergeStyle) mergeStyle = mergeForm.value.mergeStyles.find((e: any) => e.allowed)?.name;
switchMergeStyle(mergeStyle, !mergeForm.value.canMergeNow);

document.addEventListener('mouseup', hideMergeStyleMenu);
Expand Down
Loading
Loading