Skip to content

Commit 6ca117c

Browse files
authored
Merge pull request #96 from sectsect/feature/migrate-eslint-flat-config
chore: migrate ESLint config to flat config
2 parents 8595a27 + 87fb035 commit 6ca117c

File tree

5 files changed

+60
-23
lines changed

5 files changed

+60
-23
lines changed

assets/css/options.css

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

assets/js/options.js

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

eslint.config.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
/* eslint-disable no-underscore-dangle */
33
/* eslint-disable import/no-anonymous-default-export */
44

5-
// Node.js path and URL utilities
6-
import path from 'node:path';
7-
import { fileURLToPath } from 'node:url';
8-
95
// ESLint core and compatibility utilities
106
import js from '@eslint/js';
117
import { FlatCompat } from '@eslint/eslintrc';
12-
import { fixupPluginRules } from '@eslint/compat';
8+
// import { fixupPluginRules } from '@eslint/compat';
139
import globals from 'globals';
1410

1511
// ESLint plugins for various technologies and best practices
@@ -26,15 +22,12 @@ import prettier from 'eslint-plugin-prettier';
2622
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
2723
import testingLibrary from 'eslint-plugin-testing-library';
2824
import vitest from 'eslint-plugin-vitest';
29-
import deprecationPlugin from 'eslint-plugin-deprecation';
25+
import deprecation from 'eslint-plugin-deprecation';
3026
// import nextPlugin from '@next/eslint-plugin-next';
3127
import pluginQuery from '@tanstack/eslint-plugin-query';
3228

33-
// Resolve current file and directory paths
34-
const __filename = fileURLToPath(import.meta.url);
35-
const __dirname = path.dirname(__filename);
3629
const compat = new FlatCompat({
37-
baseDirectory: __dirname,
30+
baseDirectory: import.meta.dirname, // Added in: v21.2.0, v20.11.0 @ https://nodejs.org/api/esm.html#importmetadirname
3831
recommendedConfig: js.configs.recommended,
3932
allConfig: js.configs.all,
4033
});
@@ -72,7 +65,8 @@ export default [
7265
// '@next/next': nextPlugin,
7366
'unused-imports': unusedImports,
7467
'@tanstack/query': pluginQuery,
75-
deprecation: fixupPluginRules(deprecationPlugin),
68+
// deprecation: fixupPluginRules(deprecationPlugin),
69+
deprecation,
7670
tailwindcss,
7771
tsdoc,
7872
import: _import,
@@ -118,6 +112,8 @@ export default [
118112
unnamedComponents: 'arrow-function',
119113
},
120114
],
115+
// Performance and optimization rules
116+
'react/jsx-no-useless-fragment': 'error',
121117

122118
// Accessibility rules
123119
'jsx-a11y/anchor-is-valid': 'off',
@@ -153,12 +149,16 @@ export default [
153149
},
154150
],
155151
'import/prefer-default-export': 'off',
152+
'import/no-duplicates': 'error',
156153

157154
// TypeScript rules
158155
'@typescript-eslint/comma-dangle': 'off',
159156
'@typescript-eslint/consistent-type-imports': 'error',
160157
'@typescript-eslint/no-unnecessary-condition': 'error',
158+
// '@typescript-eslint/strict-boolean-expressions': 'error',
159+
'@typescript-eslint/no-explicit-any': 'error',
161160
'@typescript-eslint/no-unused-vars': 'off',
161+
'@typescript-eslint/prefer-optional-chain': 'error',
162162

163163
// Unused imports/variables rules
164164
'unused-imports/no-unused-imports': 'error',
@@ -168,6 +168,7 @@ export default [
168168
'no-underscore-dangle': 'off',
169169
'tailwindcss/no-custom-classname': 'off',
170170
'tsdoc/syntax': 'warn',
171+
'no-console': ['warn', { allow: ['warn', 'error'] }],
171172
},
172173
},
173174

src/assets/ts/_modules/options.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,28 @@ interface WtoOptionsResponse {
1616
count: number;
1717
}
1818

19-
export const options = (): void => {
19+
/**
20+
* Handles options page interaction and settings application
21+
*
22+
* @remarks
23+
* Manages the process of applying settings with a confirmation dialog
24+
* and AJAX request handling
25+
*
26+
* @example
27+
* // Automatically initialized on options page load
28+
* options();
29+
*/
30+
export const options = () => {
2031
const { nonce, action, ajax_url: url } = window.wto_options_data;
2132

33+
/**
34+
* Prepares the UI before sending settings
35+
*
36+
* @remarks
37+
* Disables the apply button and shows a processing message
38+
*
39+
* @returns A promise that resolves when preparation is complete
40+
*/
2241
const beforeSend = () =>
2342
new Promise<string>(resolve => {
2443
jQuery('#wpbody-content form input[name=apply]').prop('disabled', true);
@@ -28,6 +47,14 @@ export const options = (): void => {
2847
resolve('resolved');
2948
});
3049

50+
/**
51+
* Performs asynchronous pre-confirmation request
52+
*
53+
* @remarks
54+
* Sends an AJAX request to apply settings with error handling
55+
*
56+
* @returns Processed response data or throws an error
57+
*/
3158
const asyncPreConfirm = async () => {
3259
await beforeSend();
3360

src/assets/ts/_modules/post.ts

+15-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ declare global {
44
}
55
}
66

7+
/**
8+
* Represents the global data structure for WordPress post operations
9+
*
10+
* @remarks
11+
* Contains essential information for AJAX synchronization and updates
12+
*/
713
interface WtoData {
814
post_id: string;
915
nonce_sync: string;
@@ -22,10 +28,15 @@ const {
2228
action_update: actionUpdate,
2329
} = window.wto_data;
2430

31+
/**
32+
* Manages post-related tag synchronization and UI interactions
33+
*
34+
* @remarks
35+
* Handles two primary functionalities:
36+
* 1. Synchronizes tags across different taxonomy boxes
37+
* 2. Enables drag-and-drop sorting of tags with AJAX updates
38+
*/
2539
export const post = () => {
26-
/*= =================================================
27-
Sync Tags to "#tagsdiv-post_tag" box
28-
================================================== */
2940
let flag = '';
3041
setTimeout(() => {
3142
const tagchecklists = document.querySelectorAll(
@@ -93,9 +104,7 @@ export const post = () => {
93104
observer.observe(tagchecklist, { childList: true, subtree: true });
94105
});
95106
}, 400);
96-
/*= =================================================
97-
jQuery UI Sortable
98-
================================================== */
107+
99108
jQuery('.wpto_meta_box_panel .inside .inner ul').sortable({
100109
update() {
101110
const postboxid = jQuery(this).closest('.postbox').attr('id') ?? '';

0 commit comments

Comments
 (0)