Skip to content

Commit f4d7701

Browse files
authored
Change function description comments to tsdoc style (go-gitea#35185)
1. change function comments to the minimal [tsdoc](https://tsdoc.org/) style. This has the benefit of making editors show the doc string in tooltips when the function is hovered: <img width="521" height="110" alt="image" src="https://github.com/user-attachments/assets/b966f4f1-8239-433a-a456-5bd5c05d69ef" /> 2. disable eslint `multiline-comment-style` as it conflicts with tsdoc. --------- Signed-off-by: silverwind <[email protected]>
1 parent 84d31bc commit f4d7701

File tree

9 files changed

+36
-36
lines changed

9 files changed

+36
-36
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ module.exports = {
484484
'max-nested-callbacks': [0],
485485
'max-params': [0],
486486
'max-statements': [0],
487-
'multiline-comment-style': [2, 'separate-lines'],
487+
'multiline-comment-style': [0],
488488
'new-cap': [0],
489489
'no-alert': [0],
490490
'no-array-constructor': [0], // handled by @typescript-eslint/no-array-constructor

web_src/js/modules/toast.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ToastOpts = {
4242

4343
type ToastifyElement = HTMLElement & {_giteaToastifyInstance?: Toast };
4444

45-
// See https://github.com/apvarun/toastify-js#api for options
45+
/** See https://github.com/apvarun/toastify-js#api for options */
4646
function showToast(message: string, level: Intent, {gravity, position, duration, useHtmlBody, preventDuplicates = true, ...other}: ToastOpts = {}): Toast {
4747
const body = useHtmlBody ? message : htmlEscape(message);
4848
const parent = document.querySelector('.ui.dimmer.active') ?? document.body;

web_src/js/render/plugins/3d-viewer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {extname} from '../../utils.ts';
33

44
// support common 3D model file formats, use online-3d-viewer library for rendering
55

6-
// eslint-disable-next-line multiline-comment-style
76
/* a simple text STL file example:
87
solid SimpleTriangle
98
facet normal 0 0 1

web_src/js/utils.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@ import {decode, encode} from 'uint8-to-base64';
22
import type {IssuePageInfo, IssuePathInfo, RepoOwnerPathInfo} from './types.ts';
33
import {toggleElemClass, toggleElem} from './utils/dom.ts';
44

5-
// transform /path/to/file.ext to /path/to
5+
/** transform /path/to/file.ext to /path/to */
66
export function dirname(path: string): string {
77
const lastSlashIndex = path.lastIndexOf('/');
88
return lastSlashIndex < 0 ? '' : path.substring(0, lastSlashIndex);
99
}
1010

11-
// transform /path/to/file.ext to file.ext
11+
/** transform /path/to/file.ext to file.ext */
1212
export function basename(path: string): string {
1313
const lastSlashIndex = path.lastIndexOf('/');
1414
return lastSlashIndex < 0 ? path : path.substring(lastSlashIndex + 1);
1515
}
1616

17-
// transform /path/to/file.ext to .ext
17+
/** transform /path/to/file.ext to .ext */
1818
export function extname(path: string): string {
1919
const lastSlashIndex = path.lastIndexOf('/');
2020
const lastPointIndex = path.lastIndexOf('.');
2121
if (lastSlashIndex > lastPointIndex) return '';
2222
return lastPointIndex < 0 ? '' : path.substring(lastPointIndex);
2323
}
2424

25-
// test whether a variable is an object
25+
/** test whether a variable is an object */
2626
export function isObject(obj: any): boolean {
2727
return Object.prototype.toString.call(obj) === '[object Object]';
2828
}
2929

30-
// returns whether a dark theme is enabled
30+
/** returns whether a dark theme is enabled */
3131
export function isDarkTheme(): boolean {
3232
const style = window.getComputedStyle(document.documentElement);
3333
return style.getPropertyValue('--is-dark-theme').trim().toLowerCase() === 'true';
3434
}
3535

36-
// strip <tags> from a string
36+
/** strip <tags> from a string */
3737
export function stripTags(text: string): string {
3838
return text.replace(/<[^>]*>?/g, '');
3939
}
@@ -62,27 +62,27 @@ export function parseIssuePageInfo(): IssuePageInfo {
6262
};
6363
}
6464

65-
// parse a URL, either relative '/path' or absolute 'https://localhost/path'
65+
/** parse a URL, either relative '/path' or absolute 'https://localhost/path' */
6666
export function parseUrl(str: string): URL {
6767
return new URL(str, str.startsWith('http') ? undefined : window.location.origin);
6868
}
6969

70-
// return current locale chosen by user
70+
/** return current locale chosen by user */
7171
export function getCurrentLocale(): string {
7272
return document.documentElement.lang;
7373
}
7474

75-
// given a month (0-11), returns it in the documents language
75+
/** given a month (0-11), returns it in the documents language */
7676
export function translateMonth(month: number) {
7777
return new Date(Date.UTC(2022, month, 12)).toLocaleString(getCurrentLocale(), {month: 'short', timeZone: 'UTC'});
7878
}
7979

80-
// given a weekday (0-6, Sunday to Saturday), returns it in the documents language
80+
/** given a weekday (0-6, Sunday to Saturday), returns it in the documents language */
8181
export function translateDay(day: number) {
8282
return new Date(Date.UTC(2022, 7, day)).toLocaleString(getCurrentLocale(), {weekday: 'short', timeZone: 'UTC'});
8383
}
8484

85-
// convert a Blob to a DataURI
85+
/** convert a Blob to a DataURI */
8686
export function blobToDataURI(blob: Blob): Promise<string> {
8787
return new Promise((resolve, reject) => {
8888
try {
@@ -100,7 +100,7 @@ export function blobToDataURI(blob: Blob): Promise<string> {
100100
});
101101
}
102102

103-
// convert image Blob to another mime-type format.
103+
/** convert image Blob to another mime-type format. */
104104
export function convertImage(blob: Blob, mime: string): Promise<Blob> {
105105
return new Promise(async (resolve, reject) => {
106106
try {
@@ -143,15 +143,15 @@ export function toAbsoluteUrl(url: string): string {
143143
return `${window.location.origin}${url}`;
144144
}
145145

146-
// Encode an Uint8Array into a URLEncoded base64 string.
146+
/** Encode an Uint8Array into a URLEncoded base64 string. */
147147
export function encodeURLEncodedBase64(uint8Array: Uint8Array): string {
148148
return encode(uint8Array)
149149
.replace(/\+/g, '-')
150150
.replace(/\//g, '_')
151151
.replace(/=/g, '');
152152
}
153153

154-
// Decode a URLEncoded base64 to an Uint8Array.
154+
/** Decode a URLEncoded base64 to an Uint8Array. */
155155
export function decodeURLEncodedBase64(base64url: string): Uint8Array {
156156
return decode(base64url
157157
.replace(/_/g, '/')

web_src/js/utils/color.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import tinycolor from 'tinycolor2';
22
import type {ColorInput} from 'tinycolor2';
33

4-
// Returns relative luminance for a SRGB color - https://en.wikipedia.org/wiki/Relative_luminance
4+
/** Returns relative luminance for a SRGB color - https://en.wikipedia.org/wiki/Relative_luminance */
55
// Keep this in sync with modules/util/color.go
66
function getRelativeLuminance(color: ColorInput): number {
77
const {r, g, b} = tinycolor(color).toRgb();
@@ -12,8 +12,9 @@ function useLightText(backgroundColor: ColorInput): boolean {
1212
return getRelativeLuminance(backgroundColor) < 0.453;
1313
}
1414

15-
// Given a background color, returns a black or white foreground color that the highest
16-
// contrast ratio. In the future, the APCA contrast function, or CSS `contrast-color` will be better.
15+
/** Given a background color, returns a black or white foreground color that the highest
16+
* contrast ratio. */
17+
// In the future, the APCA contrast function, or CSS `contrast-color` will be better.
1718
// https://github.com/color-js/color.js/blob/eb7b53f7a13bb716ec8b28c7a56f052cd599acd9/src/contrast/APCA.js#L42
1819
export function contrastColor(backgroundColor: ColorInput): string {
1920
return useLightText(backgroundColor) ? '#fff' : '#000';

web_src/js/utils/dom.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function queryElemSiblings<T extends Element>(el: Element, selector = '*'
7171
}), fn);
7272
}
7373

74-
// it works like jQuery.children: only the direct children are selected
74+
/** it works like jQuery.children: only the direct children are selected */
7575
export function queryElemChildren<T extends Element>(parent: Element | ParentNode, selector = '*', fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
7676
if (isInFrontendUnitTest()) {
7777
// https://github.com/capricorn86/happy-dom/issues/1620 : ":scope" doesn't work
@@ -81,7 +81,7 @@ export function queryElemChildren<T extends Element>(parent: Element | ParentNod
8181
return applyElemsCallback<T>(parent.querySelectorAll(`:scope > ${selector}`), fn);
8282
}
8383

84-
// it works like parent.querySelectorAll: all descendants are selected
84+
/** it works like parent.querySelectorAll: all descendants are selected */
8585
// in the future, all "queryElems(document, ...)" should be refactored to use a more specific parent if the targets are not for page-level components.
8686
export function queryElems<T extends HTMLElement>(parent: Element | ParentNode, selector: string, fn?: ElementsCallback<T>): ArrayLikeIterable<T> {
8787
return applyElemsCallback<T>(parent.querySelectorAll(selector), fn);
@@ -95,8 +95,8 @@ export function onDomReady(cb: () => Promisable<void>) {
9595
}
9696
}
9797

98-
// checks whether an element is owned by the current document, and whether it is a document fragment or element node
99-
// if it is, it means it is a "normal" element managed by us, which can be modified safely.
98+
/** checks whether an element is owned by the current document, and whether it is a document fragment or element node
99+
* if it is, it means it is a "normal" element managed by us, which can be modified safely. */
100100
export function isDocumentFragmentOrElementNode(el: Node) {
101101
try {
102102
return el.ownerDocument === document && el.nodeType === Node.ELEMENT_NODE || el.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
@@ -106,8 +106,8 @@ export function isDocumentFragmentOrElementNode(el: Node) {
106106
}
107107
}
108108

109-
// autosize a textarea to fit content. Based on
110-
// https://github.com/github/textarea-autosize
109+
/** autosize a textarea to fit content. */
110+
// Based on https://github.com/github/textarea-autosize
111111
// ---------------------------------------------------------------------
112112
// Copyright (c) 2018 GitHub, Inc.
113113
//
@@ -246,8 +246,8 @@ export function onInputDebounce(fn: () => Promisable<any>) {
246246

247247
type LoadableElement = HTMLEmbedElement | HTMLIFrameElement | HTMLImageElement | HTMLScriptElement | HTMLTrackElement;
248248

249-
// Set the `src` attribute on an element and returns a promise that resolves once the element
250-
// has loaded or errored.
249+
/** Set the `src` attribute on an element and returns a promise that resolves once the element
250+
* has loaded or errored. */
251251
export function loadElem(el: LoadableElement, src: string) {
252252
return new Promise((resolve) => {
253253
el.addEventListener('load', () => resolve(true), {once: true});
@@ -286,7 +286,7 @@ export function isElemVisible(el: HTMLElement): boolean {
286286
return !el.classList.contains('tw-hidden') && (el.offsetWidth || el.offsetHeight || el.getClientRects().length) && el.style.display !== 'none';
287287
}
288288

289-
// replace selected text in a textarea while preserving editor history, e.g. CTRL-Z works after this
289+
/** replace selected text in a textarea while preserving editor history, e.g. CTRL-Z works after this */
290290
export function replaceTextareaSelection(textarea: HTMLTextAreaElement, text: string) {
291291
const before = textarea.value.slice(0, textarea.selectionStart ?? undefined);
292292
const after = textarea.value.slice(textarea.selectionEnd ?? undefined);
@@ -368,7 +368,7 @@ export function addDelegatedEventListener<T extends HTMLElement, E extends Event
368368
}, options);
369369
}
370370

371-
// Returns whether a click event is a left-click without any modifiers held
371+
/** Returns whether a click event is a left-click without any modifiers held */
372372
export function isPlainClick(e: MouseEvent) {
373373
return e.button === 0 && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
374374
}

web_src/js/utils/image.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ type ImageInfo = {
2929
dppx?: number,
3030
}
3131

32-
// decode a image and try to obtain width and dppx. It will never throw but instead
33-
// return default values.
32+
/** decode a image and try to obtain width and dppx. It will never throw but instead
33+
* return default values. */
3434
export async function imageInfo(blob: Blob): Promise<ImageInfo> {
3535
let width = 0, dppx = 1; // dppx: 1 dot per pixel for non-HiDPI screens
3636

web_src/js/utils/time.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export function fillEmptyStartDaysWithZeroes(startDays: number[], data: DayDataO
6565

6666
let dateFormat: Intl.DateTimeFormat;
6767

68-
// format a Date object to document's locale, but with 24h format from user's current locale because this
69-
// option is a personal preference of the user, not something that the document's locale should dictate.
68+
/** Format a Date object to document's locale, but with 24h format from user's current locale because this
69+
* option is a personal preference of the user, not something that the document's locale should dictate. */
7070
export function formatDatetime(date: Date | number): string {
7171
if (!dateFormat) {
7272
// TODO: replace `hour12` with `Intl.Locale.prototype.getHourCycles` once there is broad browser support

web_src/js/utils/url.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export function isUrl(url: string): boolean {
1414
}
1515
}
1616

17-
// Convert an absolute or relative URL to an absolute URL with the current origin. It only
18-
// processes absolute HTTP/HTTPS URLs or relative URLs like '/xxx' or '//host/xxx'.
17+
/** Convert an absolute or relative URL to an absolute URL with the current origin. It only
18+
* processes absolute HTTP/HTTPS URLs or relative URLs like '/xxx' or '//host/xxx'. */
1919
export function toOriginUrl(urlStr: string) {
2020
try {
2121
if (urlStr.startsWith('http://') || urlStr.startsWith('https://') || urlStr.startsWith('/')) {

0 commit comments

Comments
 (0)