Skip to content

Commit 5791a73

Browse files
authored
Convert frontend code to typescript (go-gitea#31559)
None of the frontend js/ts files was touched besides these two commands (edit: no longer true, I touched one file in go-gitea@61105d0 because of a deprecation that was not showing before the rename). `tsc` currently reports 778 errors, so I have disabled it in CI as planned. Everything appears to work fine.
1 parent 5115c27 commit 5791a73

File tree

168 files changed

+563
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+563
-387
lines changed

.eslintrc.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ overrides:
5858
worker: true
5959
rules:
6060
no-restricted-globals: [2, addEventListener, blur, close, closed, confirm, defaultStatus, defaultstatus, error, event, external, find, focus, frameElement, frames, history, innerHeight, innerWidth, isFinite, isNaN, length, locationbar, menubar, moveBy, moveTo, name, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, print, removeEventListener, resizeBy, resizeTo, screen, screenLeft, screenTop, screenX, screenY, scroll, scrollbars, scrollBy, scrollTo, scrollX, scrollY, status, statusbar, stop, toolbar, top]
61-
- files: ["*.config.*"]
61+
- files: ["*.config.*", "**/*.d.ts"]
6262
rules:
6363
i/no-unused-modules: [0]
64-
- files: ["**/*.test.*", "web_src/js/test/setup.js"]
64+
- files: ["**/*.test.*", "web_src/js/test/setup.ts"]
6565
env:
6666
vitest-globals/env: true
6767
rules:
@@ -114,7 +114,7 @@ overrides:
114114
vitest/valid-describe-callback: [2]
115115
vitest/valid-expect: [2]
116116
vitest/valid-title: [2]
117-
- files: ["web_src/js/modules/fetch.js", "web_src/js/standalone/**/*"]
117+
- files: ["web_src/js/modules/fetch.ts", "web_src/js/standalone/**/*"]
118118
rules:
119119
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression]
120120
- files: ["**/*.vue"]
@@ -467,7 +467,7 @@ rules:
467467
no-dupe-else-if: [2]
468468
no-dupe-keys: [2]
469469
no-duplicate-case: [2]
470-
no-duplicate-imports: [2]
470+
no-duplicate-imports: [0]
471471
no-else-return: [2]
472472
no-empty-character-class: [2]
473473
no-empty-function: [0]
@@ -619,7 +619,7 @@ rules:
619619
no-restricted-exports: [0]
620620
no-restricted-globals: [2, addEventListener, blur, close, closed, confirm, defaultStatus, defaultstatus, error, event, external, find, focus, frameElement, frames, history, innerHeight, innerWidth, isFinite, isNaN, length, location, locationbar, menubar, moveBy, moveTo, name, onblur, onerror, onfocus, onload, onresize, onunload, open, opener, opera, outerHeight, outerWidth, pageXOffset, pageYOffset, parent, print, removeEventListener, resizeBy, resizeTo, screen, screenLeft, screenTop, screenX, screenY, scroll, scrollbars, scrollBy, scrollTo, scrollX, scrollY, self, status, statusbar, stop, toolbar, top, __dirname, __filename]
621621
no-restricted-imports: [0]
622-
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression, {selector: "CallExpression[callee.name='fetch']", message: "use modules/fetch.js instead"}]
622+
no-restricted-syntax: [2, WithStatement, ForInStatement, LabeledStatement, SequenceExpression, {selector: "CallExpression[callee.name='fetch']", message: "use modules/fetch.ts instead"}]
623623
no-return-assign: [0]
624624
no-script-url: [2]
625625
no-self-assign: [2, {props: true}]

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMAN
144144
GO_DIRS := build cmd models modules routers services tests
145145
WEB_DIRS := web_src/js web_src/css
146146

147-
ESLINT_FILES := web_src/js tools *.js tests/e2e
147+
ESLINT_FILES := web_src/js tools *.js *.ts tests/e2e
148148
STYLELINT_FILES := web_src/css web_src/js/components/*.vue
149149
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github $(filter-out CHANGELOG.md, $(wildcard *.go *.js *.md *.yml *.yaml *.toml))
150150
EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini
@@ -376,12 +376,12 @@ lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
376376
.PHONY: lint-js
377377
lint-js: node_modules
378378
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
379-
npx tsc
379+
# npx tsc
380380

381381
.PHONY: lint-js-fix
382382
lint-js-fix: node_modules
383383
npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
384-
npx tsc
384+
# npx tsc
385385

386386
.PHONY: lint-css
387387
lint-css: node_modules

package-lock.json

+157
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@
6868
"@stoplight/spectral-cli": "6.11.1",
6969
"@stylistic/eslint-plugin-js": "2.2.1",
7070
"@stylistic/stylelint-plugin": "2.1.2",
71+
"@types/dropzone": "5.7.8",
72+
"@types/jquery": "3.5.30",
73+
"@types/katex": "0.16.7",
74+
"@types/license-checker-webpack-plugin": "0.2.4",
75+
"@types/pdfobject": "2.2.5",
76+
"@types/sortablejs": "1.15.8",
77+
"@types/swagger-ui-dist": "3.30.5",
78+
"@types/throttle-debounce": "5.0.2",
79+
"@types/tinycolor2": "1.4.6",
80+
"@types/toastify-js": "1.12.3",
7181
"@typescript-eslint/eslint-plugin": "7.14.1",
7282
"@typescript-eslint/parser": "7.14.1",
7383
"@vitejs/plugin-vue": "5.0.5",

tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
"noUnusedParameters": true,
2727
"noPropertyAccessFromIndexSignature": false,
2828
"exactOptionalPropertyTypes": false,
29+
"sourceMap": true,
30+
"types": [
31+
"vitest/globals",
32+
"./types.d.ts",
33+
],
2934
}
3035
}

types.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.svg' {
2+
const value: string;
3+
export default value;
4+
}

vitest.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {stringPlugin} from 'vite-string-plugin';
44

55
export default defineConfig({
66
test: {
7-
include: ['web_src/**/*.test.js'],
8-
setupFiles: ['web_src/js/vitest.setup.js'],
7+
include: ['web_src/**/*.test.ts'],
8+
setupFiles: ['web_src/js/vitest.setup.ts'],
99
environment: 'happy-dom',
1010
testTimeout: 20000,
1111
open: false,

web_src/js/bootstrap.test.js web_src/js/bootstrap.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {showGlobalErrorMessage} from './bootstrap.js';
1+
import {showGlobalErrorMessage} from './bootstrap.ts';
22

33
test('showGlobalErrorMessage', () => {
44
document.body.innerHTML = '<div class="page-content"></div>';
File renamed without changes.

web_src/js/components/ActionRunStatus.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Please also update the template file above if this vue is modified.
33
action status accepted: success, skipped, waiting, blocked, running, failure, cancelled, unknown
44
-->
5-
<script>
6-
import {SvgIcon} from '../svg.js';
5+
<script lang="ts">
6+
import {SvgIcon} from '../svg.ts';
77

88
export default {
99
components: {SvgIcon},

web_src/js/components/ActivityHeatmap.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script>
1+
<script lang="ts">
22
// TODO: Switch to upstream after https://github.com/razorness/vue3-calendar-heatmap/pull/34 is merged
33
import {CalendarHeatmap} from '@silverwind/vue3-calendar-heatmap';
44

web_src/js/components/ContextPopup.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<script>
2-
import {SvgIcon} from '../svg.js';
3-
import {GET} from '../modules/fetch.js';
1+
<script lang="ts">
2+
import {SvgIcon} from '../svg.ts';
3+
import {GET} from '../modules/fetch.ts';
44
55
const {appSubUrl, i18n} = window.config;
66

web_src/js/components/DashboardRepoList.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<script>
1+
<script lang="ts">
22
import {createApp, nextTick} from 'vue';
33
import $ from 'jquery';
4-
import {SvgIcon} from '../svg.js';
5-
import {GET} from '../modules/fetch.js';
4+
import {SvgIcon} from '../svg.ts';
5+
import {GET} from '../modules/fetch.ts';
66
77
const {appSubUrl, assetUrlPrefix, pageData} = window.config;
88

web_src/js/components/DiffCommitSelector.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<script>
2-
import {SvgIcon} from '../svg.js';
3-
import {GET} from '../modules/fetch.js';
1+
<script lang="ts">
2+
import {SvgIcon} from '../svg.ts';
3+
import {GET} from '../modules/fetch.ts';
44
55
export default {
66
components: {SvgIcon},

web_src/js/components/DiffFileList.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<script>
2-
import {loadMoreFiles} from '../features/repo-diff.js';
3-
import {diffTreeStore} from '../modules/stores.js';
1+
<script lang="ts">
2+
import {loadMoreFiles} from '../features/repo-diff.ts';
3+
import {diffTreeStore} from '../modules/stores.ts';
44
55
export default {
66
data: () => {

web_src/js/components/DiffFileTree.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<script>
1+
<script lang="ts">
22
import DiffFileTreeItem from './DiffFileTreeItem.vue';
3-
import {loadMoreFiles} from '../features/repo-diff.js';
4-
import {toggleElem} from '../utils/dom.js';
5-
import {diffTreeStore} from '../modules/stores.js';
6-
import {setFileFolding} from '../features/file-fold.js';
3+
import {loadMoreFiles} from '../features/repo-diff.ts';
4+
import {toggleElem} from '../utils/dom.ts';
5+
import {diffTreeStore} from '../modules/stores.ts';
6+
import {setFileFolding} from '../features/file-fold.ts';
77
88
const LOCAL_STORAGE_KEY = 'diff_file_tree_visible';
99

0 commit comments

Comments
 (0)