Skip to content

Commit 1d8fea5

Browse files
committed
build: enabled strict rules for ESLint
1 parent f2c220b commit 1d8fea5

File tree

13 files changed

+132
-40
lines changed

13 files changed

+132
-40
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ const ignoresConfig = globalIgnores([
1616

1717
export default defineConfig([
1818
{
19-
extends: [ignoresConfig, eslint.configs.recommended, tseslint.configs.recommended],
19+
extends: [ignoresConfig, eslint.configs.recommended, tseslint.configs.strict],
2020
},
2121
]);

phpmyfaq/admin/assets/src/configuration/forms.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ export const handleFormTranslations = (): void => {
142142
if (typeof response.success === 'string') {
143143
pushNotification(response.success);
144144
document.getElementById('item_' + lang)?.remove();
145-
const option = document.createElement('option') as HTMLOptionElement;
146-
option.innerText = element.getAttribute('data-pmf-langname')!;
147-
document.getElementById('languageSelect')?.appendChild(option);
145+
const langName = element.getAttribute('data-pmf-langname');
146+
if (langName) {
147+
const option = document.createElement('option') as HTMLOptionElement;
148+
option.innerText = langName;
149+
document.getElementById('languageSelect')?.appendChild(option);
150+
}
148151
} else {
149152
console.error(response.error);
150153
}

phpmyfaq/admin/assets/src/configuration/upgrade.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ export const handleCheckForUpdates = (): void => {
185185
downloadButton.disabled = true;
186186
}
187187

188-
result.replaceWith(addElement('p', { innerText: response.message! }));
188+
if (response.message) {
189+
result.replaceWith(addElement('p', { innerText: response.message }));
190+
}
189191
spinner.classList.add('d-none');
190192
checkUpdateButton.disabled = true;
191193
}
@@ -215,10 +217,14 @@ export const handleCheckForUpdates = (): void => {
215217
const spinner = document.getElementById('spinner-download-new-version') as HTMLElement;
216218
spinner.classList.remove('d-none');
217219

218-
if (releaseEnvironment!.innerText.toLowerCase() === 'nightly') {
220+
if (releaseEnvironment && releaseEnvironment.innerText.toLowerCase() === 'nightly') {
219221
version = 'nightly';
222+
} else if (versionLastChecked) {
223+
version = versionLastChecked.innerText;
220224
} else {
221-
version = versionLastChecked!.innerText;
225+
console.error('Version information not found');
226+
spinner.classList.add('d-none');
227+
return;
222228
}
223229

224230
try {
@@ -229,15 +235,17 @@ export const handleCheckForUpdates = (): void => {
229235

230236
if (response.success) {
231237
card.classList.add('text-bg-success');
232-
divExtractPackage!.classList.remove('d-none');
233-
result.replaceWith(addElement('p', { innerText: response.success! }));
238+
if (divExtractPackage) {
239+
divExtractPackage.classList.remove('d-none');
240+
}
241+
result.replaceWith(addElement('p', { innerText: response.success }));
234242
spinner.classList.add('d-none');
235243
downloadButton.disabled = true;
236244
}
237245

238246
if (response.error) {
239247
card.classList.add('text-bg-danger');
240-
result.replaceWith(addElement('p', { innerText: response.error! }));
248+
result.replaceWith(addElement('p', { innerText: response.error }));
241249
spinner.classList.add('d-none');
242250
}
243251
} catch (error) {
@@ -264,8 +272,12 @@ export const handleCheckForUpdates = (): void => {
264272

265273
if (result) {
266274
card.classList.add('text-bg-success');
267-
divInstallPackage!.classList.remove('d-none');
268-
result.replaceWith(addElement('p', { innerText: response.message! }));
275+
if (divInstallPackage) {
276+
divInstallPackage.classList.remove('d-none');
277+
}
278+
if (response.message) {
279+
result.replaceWith(addElement('p', { innerText: response.message }));
280+
}
269281
spinner.classList.add('d-none');
270282
extractButton.disabled = true;
271283
}

phpmyfaq/admin/assets/src/content/attachment-upload.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,18 @@ export const handleAttachmentUploads = (): void => {
2626
const fileSize = document.getElementById('filesize') as HTMLElement;
2727
const fileList = document.querySelector('.pmf-attachment-upload-files') as HTMLElement;
2828

29+
if (!files || files.length === 0) {
30+
return;
31+
}
32+
2933
fileList.classList.remove('invisible');
3034

3135
let bytes: number = 0;
32-
const numFiles: number = files?.length || 0;
36+
const numFiles: number = files.length;
3337
const fileItems: HTMLElement[] = [];
3438
for (let fileId: number = 0; fileId < numFiles; fileId++) {
35-
bytes += files![fileId].size;
36-
fileItems.push(addElement('li', { innerText: files![fileId].name }));
39+
bytes += files[fileId].size;
40+
fileItems.push(addElement('li', { innerText: files[fileId].name }));
3741
}
3842

3943
let output: string = bytes + ' bytes';

phpmyfaq/admin/assets/src/content/tags.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ export const handleTags = (): void => {
8080
event.preventDefault();
8181

8282
const input = document.querySelector('input:focus') as HTMLInputElement;
83-
const tagId = input.getAttribute('id')!.replace('tag-id-', '');
83+
const inputId = input.getAttribute('id');
84+
85+
if (!inputId) {
86+
console.error('Missing id attribute on input element');
87+
return;
88+
}
89+
90+
const tagId = inputId.replace('tag-id-', '');
8491
const tag = input.value;
8592
const csrf = (document.querySelector('input[name=pmf-csrf-token]') as HTMLInputElement).value;
8693

phpmyfaq/admin/assets/src/dashboard.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ export const renderVisitorCharts = async (): Promise<void> => {
170170
const visits: { date: string; number: number }[] = await response.json();
171171

172172
visits.forEach((visit) => {
173-
visitorChart.data.labels!.push(visit.date);
173+
if (visitorChart.data.labels) {
174+
visitorChart.data.labels.push(visit.date);
175+
}
174176
(visitorChart.data.datasets[0].data as number[]).push(visit.number);
175177
});
176178

@@ -259,13 +261,14 @@ export const renderTopTenCharts = async (): Promise<void> => {
259261
const c = getThemeColors();
260262
if (!doughnutChart.options.plugins) doughnutChart.options.plugins = {};
261263
doughnutChart.options.plugins.legend = { display: false, labels: { color: c.bodyColor } };
262-
doughnutChart.options.scales!.x = {
264+
if (!doughnutChart.options.scales) doughnutChart.options.scales = {};
265+
doughnutChart.options.scales.x = {
263266
display: true,
264267
title: { display: false, color: c.bodyColor },
265268
ticks: { display: false, color: c.bodyColor },
266269
grid: { color: c.gridColor },
267270
};
268-
doughnutChart.options.scales!.y = {
271+
doughnutChart.options.scales.y = {
269272
display: true,
270273
title: { display: false, color: c.bodyColor },
271274
ticks: { color: c.bodyColor },
@@ -306,7 +309,9 @@ export const renderTopTenCharts = async (): Promise<void> => {
306309
const topTen: { question: string; visits: number }[] = await response.json();
307310

308311
topTen.forEach((faq: { question: string; visits: number }): void => {
309-
doughnutChart.data.labels!.push(faq.question);
312+
if (doughnutChart.data.labels) {
313+
doughnutChart.data.labels.push(faq.question);
314+
}
310315
(doughnutChart.data.datasets[0].data as number[]).push(faq.visits);
311316
colors.push(dynamicColors());
312317
});

phpmyfaq/admin/assets/src/statistics/admin-log.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ export const handleDeleteAdminLog = (): void => {
2424
buttonDeleteAdminLog.addEventListener('click', async (event: Event): Promise<void> => {
2525
event.preventDefault();
2626
const target = event.target as HTMLElement;
27-
const csrf = target.getAttribute('data-pmf-csrf')!;
27+
const csrf = target.getAttribute('data-pmf-csrf');
28+
29+
if (!csrf) {
30+
pushErrorNotification('Missing CSRF token');
31+
return;
32+
}
33+
2834
const response = (await deleteAdminLog(csrf)) as Response;
2935

3036
if (response.success) {
3137
pushNotification(response.success);
32-
} else {
38+
} else if (response.error) {
3339
pushErrorNotification(response.error);
3440
}
3541
});

phpmyfaq/admin/assets/src/statistics/ratings.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ export const handleClearRatings = (): void => {
2424
buttonClearRatings.addEventListener('click', async (event: Event): Promise<void> => {
2525
event.preventDefault();
2626
const target = event.target as HTMLElement;
27-
const csrf = target.getAttribute('data-pmf-csrf')!;
27+
const csrf = target.getAttribute('data-pmf-csrf');
28+
29+
if (!csrf) {
30+
pushErrorNotification('Missing CSRF token');
31+
return;
32+
}
33+
2834
const response = (await clearRatings(csrf)) as Response;
2935

3036
if (response.success) {
3137
pushNotification(response.success);
32-
} else {
38+
} else if (response.error) {
3339
pushErrorNotification(response.error);
3440
}
3541
});

phpmyfaq/admin/assets/src/statistics/search.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ export const handleTruncateSearchTerms = (): void => {
2727
event.preventDefault();
2828

2929
const target = event.target as HTMLElement;
30-
const csrf = target.getAttribute('data-pmf-csrf-token')!;
30+
const csrf = target.getAttribute('data-pmf-csrf-token');
31+
32+
if (!csrf) {
33+
pushErrorNotification('Missing CSRF token');
34+
return;
35+
}
3136

3237
if (confirm('Are you sure?')) {
3338
const response = (await truncateSearchTerms(csrf)) as Response;
@@ -36,7 +41,7 @@ export const handleTruncateSearchTerms = (): void => {
3641
const tableToDelete = document.getElementById('pmf-table-search-terms') as HTMLElement;
3742
tableToDelete.remove();
3843
pushNotification(response.success);
39-
} else {
44+
} else if (response.error) {
4045
pushErrorNotification(response.error);
4146
}
4247
}

phpmyfaq/admin/assets/src/statistics/sessions.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ export const handleSessions = (): void => {
8181
const jsonResponse = await response.json();
8282
pushErrorNotification(jsonResponse.error);
8383
}
84-
} catch (error) {
85-
console.error(error.message);
84+
} catch (error: unknown) {
85+
const errorMessage = error instanceof Error ? error.message : 'An error occurred during export';
86+
console.error(errorMessage);
87+
pushErrorNotification(errorMessage);
8688
}
8789
});
8890
}
@@ -95,12 +97,23 @@ export const handleClearVisits = (): void => {
9597
buttonClearVisits.addEventListener('click', async (event: Event): Promise<void> => {
9698
event.preventDefault();
9799
const target = event.target as HTMLElement;
98-
const csrf = target.getAttribute('data-pmf-csrf')!;
100+
const csrf = target.getAttribute('data-pmf-csrf');
101+
102+
if (!csrf) {
103+
pushErrorNotification('Missing CSRF token');
104+
return;
105+
}
106+
99107
const response = await clearVisits(csrf);
100108

109+
if (!response) {
110+
pushErrorNotification('No response received');
111+
return;
112+
}
113+
101114
if (response.success) {
102115
pushNotification(response.success);
103-
} else {
116+
} else if (response.error) {
104117
pushErrorNotification(response.error);
105118
}
106119
});
@@ -117,9 +130,14 @@ export const handleDeleteSessions = (): void => {
117130
const month = (document.getElementById('month') as HTMLInputElement).value;
118131
const response = await deleteSessions(csrf, month);
119132

133+
if (!response) {
134+
pushErrorNotification('No response received');
135+
return;
136+
}
137+
120138
if (response.success) {
121139
pushNotification(response.success);
122-
} else {
140+
} else if (response.error) {
123141
pushErrorNotification(response.error);
124142
}
125143
});

0 commit comments

Comments
 (0)