Skip to content

Commit 4b21a6c

Browse files
authored
Enable Typescript noImplicitThis (#33250)
- Enable https://www.typescriptlang.org/tsconfig/#noImplicitThis - Wrap Vue Template-Syntax SFCs in [`defineComponent`](https://vuejs.org/api/general#definecomponent) which makes type inference and linter work better - Move `createApp` calls outside the SFCs into separate files - Use [`PropType`](https://vuejs.org/api/utility-types#proptype-t) where appropriate - Some top-level component properties changed order as dictated by the linter - Fix all tsc and lint issues that popped up during these refactors
1 parent b15d01b commit 4b21a6c

29 files changed

+209
-190
lines changed

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"stripInternal": true,
2424
"strict": false,
2525
"strictFunctionTypes": true,
26+
"noImplicitThis": true,
2627
"noUnusedLocals": true,
2728
"noUnusedParameters": true,
2829
"noPropertyAccessFromIndexSignature": false,

web_src/js/components/DashboardRepoList.vue

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import {createApp, nextTick} from 'vue';
2+
import {nextTick, defineComponent} from 'vue';
33
import {SvgIcon} from '../svg.ts';
44
import {GET} from '../modules/fetch.ts';
55
import {fomanticQuery} from '../modules/fomantic/base.ts';
@@ -24,7 +24,7 @@ const commitStatus: CommitStatusMap = {
2424
warning: {name: 'gitea-exclamation', color: 'yellow'},
2525
};
2626
27-
const sfc = {
27+
export default defineComponent({
2828
components: {SvgIcon},
2929
data() {
3030
const params = new URLSearchParams(window.location.search);
@@ -335,16 +335,8 @@ const sfc = {
335335
}
336336
},
337337
},
338-
};
339-
340-
export function initDashboardRepoList() {
341-
const el = document.querySelector('#dashboard-repo-list');
342-
if (el) {
343-
createApp(sfc).mount(el);
344-
}
345-
}
338+
});
346339
347-
export default sfc; // activate the IDE's Vue plugin
348340
</script>
349341
<template>
350342
<div>

web_src/js/components/DiffCommitSelector.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script lang="ts">
2+
import {defineComponent} from 'vue';
23
import {SvgIcon} from '../svg.ts';
34
import {GET} from '../modules/fetch.ts';
45
import {generateAriaId} from '../modules/fomantic/base.ts';
56
6-
export default {
7+
export default defineComponent({
78
components: {SvgIcon},
89
data: () => {
910
const el = document.querySelector('#diff-commit-select');
@@ -55,11 +56,11 @@ export default {
5556
switch (event.key) {
5657
case 'ArrowDown': // select next element
5758
event.preventDefault();
58-
this.focusElem(item.nextElementSibling, item);
59+
this.focusElem(item.nextElementSibling as HTMLElement, item);
5960
break;
6061
case 'ArrowUp': // select previous element
6162
event.preventDefault();
62-
this.focusElem(item.previousElementSibling, item);
63+
this.focusElem(item.previousElementSibling as HTMLElement, item);
6364
break;
6465
case 'Escape': // close menu
6566
event.preventDefault();
@@ -118,9 +119,9 @@ export default {
118119
// set correct tabindex to allow easier navigation
119120
this.$nextTick(() => {
120121
if (this.menuVisible) {
121-
this.focusElem(this.$refs.showAllChanges, this.$refs.expandBtn);
122+
this.focusElem(this.$refs.showAllChanges as HTMLElement, this.$refs.expandBtn as HTMLElement);
122123
} else {
123-
this.focusElem(this.$refs.expandBtn, this.$refs.showAllChanges);
124+
this.focusElem(this.$refs.expandBtn as HTMLElement, this.$refs.showAllChanges as HTMLElement);
124125
}
125126
});
126127
},
@@ -188,7 +189,7 @@ export default {
188189
}
189190
},
190191
},
191-
};
192+
});
192193
</script>
193194
<template>
194195
<div class="ui scrolling dropdown custom diff-commit-selector">

web_src/js/components/DiffFileList.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function toggleFileList() {
1717
store.fileListIsVisible = !store.fileListIsVisible;
1818
}
1919
20-
function diffTypeToString(pType) {
20+
function diffTypeToString(pType: number) {
2121
const diffTypes = {
2222
1: 'add',
2323
2: 'modify',
@@ -28,7 +28,7 @@ function diffTypeToString(pType) {
2828
return diffTypes[pType];
2929
}
3030
31-
function diffStatsWidth(adds, dels) {
31+
function diffStatsWidth(adds: number, dels: number) {
3232
return `${adds / (adds + dels) * 100}%`;
3333
}
3434

web_src/js/components/DiffFileTree.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const fileTree = computed(() => {
6060
parent = newParent;
6161
}
6262
}
63-
const mergeChildIfOnlyOneDir = (entries) => {
63+
const mergeChildIfOnlyOneDir = (entries: Array<Record<string, any>>) => {
6464
for (const entry of entries) {
6565
if (entry.children) {
6666
mergeChildIfOnlyOneDir(entry.children);
@@ -110,13 +110,13 @@ function toggleVisibility() {
110110
updateVisibility(!store.fileTreeIsVisible);
111111
}
112112
113-
function updateVisibility(visible) {
113+
function updateVisibility(visible: boolean) {
114114
store.fileTreeIsVisible = visible;
115115
localStorage.setItem(LOCAL_STORAGE_KEY, store.fileTreeIsVisible);
116116
updateState(store.fileTreeIsVisible);
117117
}
118118
119-
function updateState(visible) {
119+
function updateState(visible: boolean) {
120120
const btn = document.querySelector('.diff-toggle-file-tree-button');
121121
const [toShow, toHide] = btn.querySelectorAll('.icon');
122122
const tree = document.querySelector('#diff-file-tree');

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defineProps<{
2525
const store = diffTreeStore();
2626
const collapsed = ref(false);
2727
28-
function getIconForDiffType(pType) {
28+
function getIconForDiffType(pType: number) {
2929
const diffTypes = {
3030
1: {name: 'octicon-diff-added', classes: ['text', 'green']},
3131
2: {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
@@ -36,7 +36,7 @@ function getIconForDiffType(pType) {
3636
return diffTypes[pType];
3737
}
3838
39-
function fileIcon(file) {
39+
function fileIcon(file: File) {
4040
if (file.IsSubmodule) {
4141
return 'octicon-file-submodule';
4242
}

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function toggleActionForm(show: boolean) {
6868
mergeMessageFieldValue.value = mergeStyleDetail.value.mergeMessageFieldText;
6969
}
7070
71-
function switchMergeStyle(name, autoMerge = false) {
71+
function switchMergeStyle(name: string, autoMerge = false) {
7272
mergeStyle.value = name;
7373
autoMergeWhenSucceed.value = autoMerge;
7474
}

web_src/js/components/RepoActionView.vue

Lines changed: 36 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts">
22
import {SvgIcon} from '../svg.ts';
33
import ActionRunStatus from './ActionRunStatus.vue';
4-
import {createApp} from 'vue';
4+
import {defineComponent, type PropType} from 'vue';
55
import {createElementFromAttrs, toggleElem} from '../utils/dom.ts';
66
import {formatDatetime} from '../utils/time.ts';
77
import {renderAnsi} from '../render/ansi.ts';
@@ -38,7 +38,7 @@ function parseLineCommand(line: LogLine): LogLineCommand | null {
3838
return null;
3939
}
4040
41-
function isLogElementInViewport(el: HTMLElement): boolean {
41+
function isLogElementInViewport(el: Element): boolean {
4242
const rect = el.getBoundingClientRect();
4343
return rect.top >= 0 && rect.bottom <= window.innerHeight; // only check height but not width
4444
}
@@ -57,25 +57,28 @@ function getLocaleStorageOptions(): LocaleStorageOptions {
5757
return {autoScroll: true, expandRunning: false};
5858
}
5959
60-
const sfc = {
60+
export default defineComponent({
6161
name: 'RepoActionView',
6262
components: {
6363
SvgIcon,
6464
ActionRunStatus,
6565
},
6666
props: {
67-
runIndex: String,
68-
jobIndex: String,
69-
actionsURL: String,
70-
locale: Object,
71-
},
72-
73-
watch: {
74-
optionAlwaysAutoScroll() {
75-
this.saveLocaleStorageOptions();
67+
runIndex: {
68+
type: String,
69+
default: '',
7670
},
77-
optionAlwaysExpandRunning() {
78-
this.saveLocaleStorageOptions();
71+
jobIndex: {
72+
type: String,
73+
default: '',
74+
},
75+
actionsURL: {
76+
type: String,
77+
default: '',
78+
},
79+
locale: {
80+
type: Object as PropType<Record<string, string>>,
81+
default: null,
7982
},
8083
},
8184
@@ -102,10 +105,11 @@ const sfc = {
102105
link: '',
103106
title: '',
104107
titleHTML: '',
105-
status: '',
108+
status: 'unknown' as RunStatus,
106109
canCancel: false,
107110
canApprove: false,
108111
canRerun: false,
112+
canDeleteArtifact: false,
109113
done: false,
110114
workflowID: '',
111115
workflowLink: '',
@@ -131,6 +135,7 @@ const sfc = {
131135
branch: {
132136
name: '',
133137
link: '',
138+
isDeleted: false,
134139
},
135140
},
136141
},
@@ -148,7 +153,16 @@ const sfc = {
148153
};
149154
},
150155
151-
async mounted() {
156+
watch: {
157+
optionAlwaysAutoScroll() {
158+
this.saveLocaleStorageOptions();
159+
},
160+
optionAlwaysExpandRunning() {
161+
this.saveLocaleStorageOptions();
162+
},
163+
},
164+
165+
async mounted() { // eslint-disable-line @typescript-eslint/no-misused-promises
152166
// load job data and then auto-reload periodically
153167
// need to await first loadJob so this.currentJobStepsStates is initialized and can be used in hashChangeListener
154168
await this.loadJob();
@@ -186,6 +200,7 @@ const sfc = {
186200
// get the active logs container element, either the `job-step-logs` or the `job-log-list` in the `job-log-group`
187201
getActiveLogsContainer(stepIndex: number): HTMLElement {
188202
const el = this.getJobStepLogsContainer(stepIndex);
203+
// @ts-expect-error - _stepLogsActiveContainer is a custom property
189204
return el._stepLogsActiveContainer ?? el;
190205
},
191206
// begin a log group
@@ -263,7 +278,7 @@ const sfc = {
263278
const el = this.getJobStepLogsContainer(stepIndex);
264279
// if the logs container is empty, then auto-scroll if the step is expanded
265280
if (!el.lastChild) return this.currentJobStepsStates[stepIndex].expanded;
266-
return isLogElementInViewport(el.lastChild);
281+
return isLogElementInViewport(el.lastChild as Element);
267282
},
268283
269284
appendLogs(stepIndex: number, startTime: number, logLines: LogLine[]) {
@@ -380,7 +395,7 @@ const sfc = {
380395
381396
toggleTimeDisplay(type: string) {
382397
this.timeVisible[`log-time-${type}`] = !this.timeVisible[`log-time-${type}`];
383-
for (const el of this.$refs.steps.querySelectorAll(`.log-time-${type}`)) {
398+
for (const el of (this.$refs.steps as HTMLElement).querySelectorAll(`.log-time-${type}`)) {
384399
toggleElem(el, this.timeVisible[`log-time-${type}`]);
385400
}
386401
},
@@ -414,59 +429,12 @@ const sfc = {
414429
// so logline can be selected by querySelector
415430
await this.loadJob();
416431
}
417-
const logLine = this.$refs.steps.querySelector(selectedLogStep);
432+
const logLine = (this.$refs.steps as HTMLElement).querySelector(selectedLogStep);
418433
if (!logLine) return;
419-
logLine.querySelector('.line-num').click();
434+
logLine.querySelector<HTMLAnchorElement>('.line-num').click();
420435
},
421436
},
422-
};
423-
424-
export default sfc;
425-
426-
export function initRepositoryActionView() {
427-
const el = document.querySelector('#repo-action-view');
428-
if (!el) return;
429-
430-
// TODO: the parent element's full height doesn't work well now,
431-
// but we can not pollute the global style at the moment, only fix the height problem for pages with this component
432-
const parentFullHeight = document.querySelector<HTMLElement>('body > div.full.height');
433-
if (parentFullHeight) parentFullHeight.style.paddingBottom = '0';
434-
435-
const view = createApp(sfc, {
436-
runIndex: el.getAttribute('data-run-index'),
437-
jobIndex: el.getAttribute('data-job-index'),
438-
actionsURL: el.getAttribute('data-actions-url'),
439-
locale: {
440-
approve: el.getAttribute('data-locale-approve'),
441-
cancel: el.getAttribute('data-locale-cancel'),
442-
rerun: el.getAttribute('data-locale-rerun'),
443-
rerun_all: el.getAttribute('data-locale-rerun-all'),
444-
scheduled: el.getAttribute('data-locale-runs-scheduled'),
445-
commit: el.getAttribute('data-locale-runs-commit'),
446-
pushedBy: el.getAttribute('data-locale-runs-pushed-by'),
447-
artifactsTitle: el.getAttribute('data-locale-artifacts-title'),
448-
areYouSure: el.getAttribute('data-locale-are-you-sure'),
449-
confirmDeleteArtifact: el.getAttribute('data-locale-confirm-delete-artifact'),
450-
showTimeStamps: el.getAttribute('data-locale-show-timestamps'),
451-
showLogSeconds: el.getAttribute('data-locale-show-log-seconds'),
452-
showFullScreen: el.getAttribute('data-locale-show-full-screen'),
453-
downloadLogs: el.getAttribute('data-locale-download-logs'),
454-
status: {
455-
unknown: el.getAttribute('data-locale-status-unknown'),
456-
waiting: el.getAttribute('data-locale-status-waiting'),
457-
running: el.getAttribute('data-locale-status-running'),
458-
success: el.getAttribute('data-locale-status-success'),
459-
failure: el.getAttribute('data-locale-status-failure'),
460-
cancelled: el.getAttribute('data-locale-status-cancelled'),
461-
skipped: el.getAttribute('data-locale-status-skipped'),
462-
blocked: el.getAttribute('data-locale-status-blocked'),
463-
},
464-
logsAlwaysAutoScroll: el.getAttribute('data-locale-logs-always-auto-scroll'),
465-
logsAlwaysExpandRunning: el.getAttribute('data-locale-logs-always-expand-running'),
466-
},
467-
});
468-
view.mount(el);
469-
}
437+
});
470438
</script>
471439
<template>
472440
<div class="ui container action-view-container">

web_src/js/components/RepoActivityTopAuthors.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ const colors = ref({
88
textAltColor: 'white',
99
});
1010
11-
// possible keys:
12-
// * avatar_link: (...)
13-
// * commits: (...)
14-
// * home_link: (...)
15-
// * login: (...)
16-
// * name: (...)
17-
const activityTopAuthors = window.config.pageData.repoActivityTopAuthors || [];
11+
type ActivityAuthorData = {
12+
avatar_link: string;
13+
commits: number;
14+
home_link: string;
15+
login: string;
16+
name: string;
17+
}
18+
19+
const activityTopAuthors: Array<ActivityAuthorData> = window.config.pageData.repoActivityTopAuthors || [];
1820
1921
const graphPoints = computed(() => {
2022
return activityTopAuthors.map((item) => {
@@ -26,7 +28,7 @@ const graphPoints = computed(() => {
2628
});
2729
2830
const graphAuthors = computed(() => {
29-
return activityTopAuthors.map((item, idx) => {
31+
return activityTopAuthors.map((item, idx: number) => {
3032
return {
3133
position: idx + 1,
3234
...item,

0 commit comments

Comments
 (0)