Enable Typescript noImplicitAny (#33322)

Enable `noImplicitAny` and fix all issues.

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind 2025-01-22 08:11:51 +01:00 committed by GitHub
parent 6fe4d1c038
commit c7f4ca2653
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
63 changed files with 326 additions and 270 deletions

View file

@ -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<HTMLAnchorElement>('.repo-owner-name-list li.active a')?.click();

View file

@ -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: () => {
@ -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(),
};
@ -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

View file

@ -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) {

View file

@ -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';
@ -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('/');
@ -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) {

View file

@ -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';
@ -11,7 +11,7 @@ type File = {
IsSubmodule: boolean;
}
type Item = {
export type Item = {
name: string;
isFile: boolean;
file?: File;
@ -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) {

View file

@ -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);

View file

@ -6,6 +6,7 @@ import {createElementFromAttrs, toggleElem} from '../utils/dom.ts';
import {formatDatetime} from '../utils/time.ts';
import {renderAnsi} from '../render/ansi.ts';
import {POST, DELETE} from '../modules/fetch.ts';
import type {IntervalId} from '../types.ts';
// see "models/actions/status.go", if it needs to be used somewhere else, move it to a shared file like "types/actions.ts"
type RunStatus = 'unknown' | 'waiting' | 'running' | 'success' | 'failure' | 'cancelled' | 'skipped' | 'blocked';
@ -24,6 +25,20 @@ type LogLineCommand = {
prefix: string,
}
type Job = {
id: number;
name: string;
status: RunStatus;
canRerun: boolean;
duration: string;
}
type Step = {
summary: string,
duration: string,
status: RunStatus,
}
function parseLineCommand(line: LogLine): LogLineCommand | null {
for (const prefix of LogLinePrefixesGroup) {
if (line.message.startsWith(prefix)) {
@ -77,7 +92,7 @@ export default defineComponent({
default: '',
},
locale: {
type: Object as PropType<Record<string, string>>,
type: Object as PropType<Record<string, any>>,
default: null,
},
},
@ -86,10 +101,10 @@ export default defineComponent({
const {autoScroll, expandRunning} = getLocaleStorageOptions();
return {
// internal state
loadingAbortController: null,
intervalID: null,
currentJobStepsStates: [],
artifacts: [],
loadingAbortController: null as AbortController | null,
intervalID: null as IntervalId | null,
currentJobStepsStates: [] as Array<Record<string, any>>,
artifacts: [] as Array<Record<string, any>>,
onHoverRerunIndex: -1,
menuVisible: false,
isFullScreen: false,
@ -122,7 +137,7 @@ export default defineComponent({
// canRerun: false,
// duration: '',
// },
],
] as Array<Job>,
commit: {
localeCommit: '',
localePushedBy: '',
@ -148,7 +163,7 @@ export default defineComponent({
// duration: '',
// status: '',
// }
],
] as Array<Step>,
},
};
},
@ -194,7 +209,7 @@ export default defineComponent({
// get the job step logs container ('.job-step-logs')
getJobStepLogsContainer(stepIndex: number): HTMLElement {
return this.$refs.logs[stepIndex];
return (this.$refs.logs as any)[stepIndex];
},
// get the active logs container element, either the `job-step-logs` or the `job-log-list` in the `job-log-group`
@ -205,7 +220,7 @@ export default defineComponent({
},
// begin a log group
beginLogGroup(stepIndex: number, startTime: number, line: LogLine, cmd: LogLineCommand) {
const el = this.$refs.logs[stepIndex];
const el = (this.$refs.logs as any)[stepIndex];
const elJobLogGroupSummary = createElementFromAttrs('summary', {class: 'job-log-group-summary'},
this.createLogLine(stepIndex, startTime, {
index: line.index,
@ -223,7 +238,7 @@ export default defineComponent({
},
// end a log group
endLogGroup(stepIndex: number, startTime: number, line: LogLine, cmd: LogLineCommand) {
const el = this.$refs.logs[stepIndex];
const el = (this.$refs.logs as any)[stepIndex];
el._stepLogsActiveContainer = null;
el.append(this.createLogLine(stepIndex, startTime, {
index: line.index,
@ -393,7 +408,7 @@ export default defineComponent({
if (this.menuVisible) this.menuVisible = false;
},
toggleTimeDisplay(type: string) {
toggleTimeDisplay(type: 'seconds' | 'stamp') {
this.timeVisible[`log-time-${type}`] = !this.timeVisible[`log-time-${type}`];
for (const el of (this.$refs.steps as HTMLElement).querySelectorAll(`.log-time-${type}`)) {
toggleElem(el, this.timeVisible[`log-time-${type}`]);
@ -422,9 +437,10 @@ export default defineComponent({
const selectedLogStep = window.location.hash;
if (!selectedLogStep) return;
const [_, step, _line] = selectedLogStep.split('-');
if (!this.currentJobStepsStates[step]) return;
if (!this.currentJobStepsStates[step].expanded && this.currentJobStepsStates[step].cursor === null) {
this.currentJobStepsStates[step].expanded = true;
const stepNum = Number(step);
if (!this.currentJobStepsStates[stepNum]) return;
if (!this.currentJobStepsStates[stepNum].expanded && this.currentJobStepsStates[stepNum].cursor === null) {
this.currentJobStepsStates[stepNum].expanded = true;
// need to await for load job if the step log is loaded for the first time
// so logline can be selected by querySelector
await this.loadJob();

View file

@ -1,4 +1,5 @@
<script lang="ts" setup>
// @ts-expect-error - module exports no types
import {VueBarGraph} from 'vue-bar-graph';
import {computed, onMounted, ref} from 'vue';

View file

@ -157,7 +157,7 @@ export default defineComponent({
// @ts-expect-error - el is unknown type
return (el && el.length) ? el[0] : null;
},
keydown(e) {
keydown(e: KeyboardEvent) {
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
e.preventDefault();
@ -181,7 +181,7 @@ export default defineComponent({
this.menuVisible = false;
}
},
handleTabSwitch(selectedTab) {
handleTabSwitch(selectedTab: SelectedTab) {
this.selectedTab = selectedTab;
this.focusSearchField();
this.loadTabItems();

View file

@ -80,10 +80,10 @@ export default defineComponent({
sortedContributors: {} as Record<string, any>,
type: 'commits',
contributorsStats: {} as Record<string, any>,
xAxisStart: null,
xAxisEnd: null,
xAxisMin: null,
xAxisMax: null,
xAxisStart: null as number | null,
xAxisEnd: null as number | null,
xAxisMin: null as number | null,
xAxisMax: null as number | null,
}),
mounted() {
this.fetchGraphData();
@ -99,7 +99,7 @@ export default defineComponent({
},
methods: {
sortContributors() {
const contributors = this.filterContributorWeeksByDateRange();
const contributors: Record<string, any> = this.filterContributorWeeksByDateRange();
const criteria = `total_${this.type}`;
this.sortedContributors = Object.values(contributors)
.filter((contributor) => contributor[criteria] !== 0)
@ -158,7 +158,7 @@ export default defineComponent({
},
filterContributorWeeksByDateRange() {
const filteredData = {};
const filteredData: Record<string, any> = {};
const data = this.contributorsStats;
for (const key of Object.keys(data)) {
const user = data[key];
@ -196,7 +196,7 @@ export default defineComponent({
// Normally, chartjs handles this automatically, but it will resize the graph when you
// zoom, pan etc. I think resizing the graph makes it harder to compare things visually.
const maxValue = Math.max(
...this.totalStats.weeks.map((o) => o[this.type]),
...this.totalStats.weeks.map((o: Record<string, any>) => o[this.type]),
);
const [coefficient, exp] = maxValue.toExponential().split('e').map(Number);
if (coefficient % 1 === 0) return maxValue;
@ -208,7 +208,7 @@ export default defineComponent({
// for contributors' graph. If I let chartjs do this for me, it will choose different
// maxY value for each contributors' graph which again makes it harder to compare.
const maxValue = Math.max(
...this.sortedContributors.map((c) => c.max_contribution_type),
...this.sortedContributors.map((c: Record<string, any>) => c.max_contribution_type),
);
const [coefficient, exp] = maxValue.toExponential().split('e').map(Number);
if (coefficient % 1 === 0) return maxValue;
@ -232,8 +232,8 @@ export default defineComponent({
},
updateOtherCharts({chart}: {chart: Chart}, reset: boolean = false) {
const minVal = chart.options.scales.x.min;
const maxVal = chart.options.scales.x.max;
const minVal = Number(chart.options.scales.x.min);
const maxVal = Number(chart.options.scales.x.max);
if (reset) {
this.xAxisMin = this.xAxisStart;
this.xAxisMax = this.xAxisEnd;

View file

@ -35,7 +35,7 @@ onUnmounted(() => {
document.querySelector('#scoped-access-submit').removeEventListener('click', onClickSubmit);
});
function onClickSubmit(e) {
function onClickSubmit(e: Event) {
e.preventDefault();
const warningEl = document.querySelector('#scoped-access-warning');