mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-28 08:22:49 +00:00
chore: update eslint, enable more rules and fix their findings (#39438)
Update eslint and its plugins, enable more rules and fix their findings: 1. `unicorn/no-unsafe-string-replacement` found that uploading a file whose name contains `$&` inserted a broken markdown link, because `String#replace` expands such patterns in the replacement string 2. `@typescript-eslint/require-await` removes `async` from functions that never await 3. Plugin rules not covered by a preset are now listed explicitly --------- Co-authored-by: bircni <bircni@icloud.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import {html, htmlRaw} from '../utils/html.ts';
|
||||
|
||||
const {svgOuter, svgInnerHtml: giteaFaviconInner} = svgParseOuterInner('gitea-favicon');
|
||||
const faviconViewBox = svgOuter.getAttribute('viewBox')!;
|
||||
const [, , faviconViewBoxWidth, faviconViewBoxHeight] = faviconViewBox.split(/\s+/).map(Number);
|
||||
const [faviconViewBoxWidth, faviconViewBoxHeight] = faviconViewBox.split(/\s+/).slice(2).map(Number);
|
||||
|
||||
// the status badge is rendered in the bottom-right corner, following GitHub Actions favicon proportions
|
||||
const badgeIconSize = 16;
|
||||
@@ -45,7 +45,7 @@ function buildStatusIconMarkup(status: ActionsStatus): string {
|
||||
const {name, colorClass} = getActionStatusIcon(status, 'circle-fill');
|
||||
const color = resolveTailwindTextColor(colorClass);
|
||||
const {svgInnerHtml} = svgParseOuterInner(name);
|
||||
const coloredInner = svgInnerHtml.replaceAll('currentColor', color);
|
||||
const coloredInner = svgInnerHtml.replaceAll('currentColor', () => color);
|
||||
const ring = html`<circle cx="${badgeX + badgeCenter}" cy="${badgeY + badgeCenter}" r="${badgeRingRadius}" fill="#ffffff"/>`;
|
||||
const badge = html`<g data-actions-status-name="${status}" transform="translate(${badgeX}, ${badgeY}) scale(${badgeScale})" fill="${color}" color="${color}">${htmlRaw(coloredInner)}</g>`;
|
||||
return html`${htmlRaw(ring)}${htmlRaw(badge)}`;
|
||||
|
||||
@@ -40,11 +40,11 @@ test('execPseudoSelectorCommands', () => {
|
||||
expect(ret.targets).toEqual(Array.from(document.querySelectorAll('#d1 .x')));
|
||||
});
|
||||
|
||||
test('handleFetchActionSuccessJson', async () => {
|
||||
test('handleFetchActionSuccessJson', () => {
|
||||
const navigations = captureNavigations();
|
||||
await handleFetchActionSuccessJson(document.body, {redirect: '/'});
|
||||
await handleFetchActionSuccessJson(document.body, {redirect: ''});
|
||||
await handleFetchActionSuccessJson(document.body, {});
|
||||
handleFetchActionSuccessJson(document.body, {redirect: '/'});
|
||||
handleFetchActionSuccessJson(document.body, {redirect: ''});
|
||||
handleFetchActionSuccessJson(document.body, {});
|
||||
expect(navigations.map((n) => n.type)).toEqual(['push', 'reload', 'reload']);
|
||||
});
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ function toggleLoadingIndicator(el: HTMLElement, opt: FetchActionOpts, isLoading
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleFetchActionSuccessJson(el: HTMLElement, respJson: {redirect?: unknown} | null) {
|
||||
export function handleFetchActionSuccessJson(el: HTMLElement, respJson: {redirect?: unknown} | null) {
|
||||
ignoreAreYouSure(el); // ignore the areYouSure check before reloading
|
||||
const redirect = respJson?.redirect;
|
||||
if (typeof redirect === 'string' && redirect) {
|
||||
@@ -84,7 +84,7 @@ async function handleFetchActionSuccess(el: HTMLElement, opt: FetchActionOpts, r
|
||||
const respText = await resp.text();
|
||||
const respJson = isRespJson ? JSON.parse(respText) : null;
|
||||
if (isRespJson) {
|
||||
await handleFetchActionSuccessJson(el, respJson);
|
||||
handleFetchActionSuccessJson(el, respJson);
|
||||
} else if (opt.successSync) {
|
||||
await handleFetchActionSuccessSync(el, opt.successSync, respText);
|
||||
} else {
|
||||
|
||||
@@ -74,7 +74,7 @@ export function attachSearchBox<T = unknown>(container: HTMLElement, url: string
|
||||
if (query.length < minCharacters) return hide();
|
||||
const ctrl = (fetchController = new AbortController());
|
||||
try {
|
||||
const response = await GET(url.replaceAll('{query}', urlQueryEscape(query)), {signal: ctrl.signal});
|
||||
const response = await GET(url.replaceAll('{query}', () => urlQueryEscape(query)), {signal: ctrl.signal});
|
||||
if (!response.ok) return hide();
|
||||
const results = parse(await response.json(), query);
|
||||
// only render if the fetch wasn't aborted (e.g. by hide()) and the input still matches
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import {showSuccessToast, showInfoToast, showErrorToast, showWarningToast} from './toast.ts';
|
||||
|
||||
test('showSuccessToast', async () => {
|
||||
test('showSuccessToast', () => {
|
||||
showSuccessToast('success', {duration: -1});
|
||||
expect(document.querySelector('.toastify')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('showInfoToast', async () => {
|
||||
test('showInfoToast', () => {
|
||||
showInfoToast('info', {duration: -1});
|
||||
expect(document.querySelector('.toastify')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('showWarningToast', async () => {
|
||||
test('showWarningToast', () => {
|
||||
showWarningToast('warning', {duration: -1});
|
||||
expect(document.querySelector('.toastify')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('showErrorToast', async () => {
|
||||
test('showErrorToast', () => {
|
||||
showErrorToast('error', {duration: -1});
|
||||
expect(document.querySelector('.toastify')).toBeTruthy();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user