From f7447ce36054c8f9e34751c010ad16565b0c4dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Thu, 26 Oct 2023 12:07:05 +0200 Subject: [PATCH 1/2] Added eslint-plugin-prefer-arrow-functions --- .eslintrc.json | 12 ++++++++++-- package-lock.json | 10 ++++++++++ package.json | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index c5a20e80c..bf3783da3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -10,6 +10,7 @@ "plugins": [ "compat", "deprecation", + "prefer-arrow-functions", "simple-import-sort", "@typescript-eslint" ], @@ -20,13 +21,20 @@ "plugin:@typescript-eslint/stylistic-type-checked" ], "rules": { + "arrow-body-style": ["error", "as-needed"], "camelcase": "error", + "no-warning-comments": "warn", + "strict": ["error", "never"], "compat/compat": "warn", "deprecation/deprecation": "warn", - "no-warning-comments": "warn", + "prefer-arrow-functions/prefer-arrow-functions": [ + "error", + { + "allowNamedFunctions": true + } + ], "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", - "strict": ["error", "never"], "@typescript-eslint/array-type": ["error", {"default": "generic"}], "@typescript-eslint/consistent-type-exports": "error", "@typescript-eslint/consistent-type-imports": "error", diff --git a/package-lock.json b/package-lock.json index 7f08d31b1..ff7d322b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,7 @@ "eslint": "^8.52.0", "eslint-plugin-compat": "^4.2.0", "eslint-plugin-deprecation": "^2.0.0", + "eslint-plugin-prefer-arrow-functions": "^3.2.4", "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-simple-import-sort": "^10.0.0", "gulp": "^4.0.2", @@ -8333,6 +8334,15 @@ } } }, + "node_modules/eslint-plugin-prefer-arrow-functions": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prefer-arrow-functions/-/eslint-plugin-prefer-arrow-functions-3.2.4.tgz", + "integrity": "sha512-HbPmlbO/iYQeVs2fuShNkGVJDfVfgSd84Vzxv+xlh+nIVoSsZvTj6yOqszw4mtG9JbiqMShVWqbVeoVsejE59w==", + "dev": true, + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-plugin-prettier": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.1.tgz", diff --git a/package.json b/package.json index b433cfae1..087a89be8 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "eslint": "^8.52.0", "eslint-plugin-compat": "^4.2.0", "eslint-plugin-deprecation": "^2.0.0", + "eslint-plugin-prefer-arrow-functions": "^3.2.4", "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-simple-import-sort": "^10.0.0", "gulp": "^4.0.2", From dcba1957e27617682a8065e62643ecc95e03ec1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Thu, 26 Oct 2023 12:14:08 +0200 Subject: [PATCH 2/2] Using arrow functions --- gulpfile.js | 110 +++++++++--------- src/ts/admin/root_selection.ts | 2 +- src/ts/admin/tinymce.ts | 4 +- .../frontend/shortcode/ShortcodeRegistry.ts | 4 +- 4 files changed, 57 insertions(+), 63 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index ed0910ea5..b8803fc79 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,21 +11,21 @@ const replace = require('gulp-replace'); const shell = require('gulp-shell'); const webpack = require('webpack-stream'); -gulp.task('build:css:admin', function () { - return gulp +gulp.task('build:css:admin', () => + gulp .src(['src/css/admin/*.css']) .pipe(cleanCSS()) .pipe(rename({ suffix: '.min' })) - .pipe(gulp.dest('dist/admin/css/')); -}); + .pipe(gulp.dest('dist/admin/css/')) +); -gulp.task('build:css:frontend', function () { - return gulp +gulp.task('build:css:frontend', () => + gulp .src(['src/css/frontend/*.css']) .pipe(cleanCSS()) .pipe(rename({ suffix: '.min' })) - .pipe(gulp.dest('dist/frontend/css/')); -}); + .pipe(gulp.dest('dist/frontend/css/')) +); gulp.task('build:css', gulp.parallel('build:css:admin', 'build:css:frontend')); @@ -41,8 +41,8 @@ gulp.task( 'composer dump-autoload --no-dev' + (process.env.NODE_ENV === 'production' ? ' -o' : '') ), - function () { - return merge( + () => + merge( gulp.src([ 'vendor/composer/autoload_classmap.php', 'vendor/composer/autoload_files.php', @@ -63,8 +63,7 @@ gulp.task( "'Sgdg\\\\Vendor\\\\$1\\\\' => \n" ) ) - ).pipe(gulp.dest('dist/vendor/composer/')); - }, + ).pipe(gulp.dest('dist/vendor/composer/')), shell.task('composer dump-autoload') ) ); @@ -74,17 +73,17 @@ gulp.task( gulp.series('build:deps:composer:scoper', 'build:deps:composer:autoloader') ); -gulp.task('build:deps:npm:imagelightbox', function () { - return gulp +gulp.task('build:deps:npm:imagelightbox', () => + gulp .src('node_modules/imagelightbox/dist/imagelightbox.min.*') - .pipe(gulp.dest('dist/bundled/')); -}); + .pipe(gulp.dest('dist/bundled/')) +); -gulp.task('build:deps:npm:imagesloaded', function () { - return gulp +gulp.task('build:deps:npm:imagesloaded', () => + gulp .src('node_modules/imagesloaded/imagesloaded.pkgd.min.js') - .pipe(gulp.dest('dist/bundled/')); -}); + .pipe(gulp.dest('dist/bundled/')) +); gulp.task( 'build:deps:npm:justified-layout', @@ -95,13 +94,12 @@ gulp.task( shell.task(['npm run build'], { cwd: 'node_modules/justified-layout', }), - function () { - return gulp + () => + gulp .src( 'node_modules/justified-layout/dist/justified-layout.min.*' ) - .pipe(gulp.dest('dist/bundled/')); - } + .pipe(gulp.dest('dist/bundled/')) ) ); @@ -116,53 +114,49 @@ gulp.task( gulp.task('build:deps', gulp.parallel('build:deps:composer', 'build:deps:npm')); -gulp.task('build:js:admin', function () { - return gulp +gulp.task('build:js:admin', () => + gulp .src(['src/ts/admin/root_selection.ts', 'src/ts/admin/tinymce.ts']) .pipe(named((file) => file.stem + '.min')) .pipe(webpack(require('./webpack.config.js'))) .pipe(inject.prepend('jQuery( function( $ ) {\n')) .pipe(inject.append('} );\n')) - .pipe(gulp.dest('dist/admin/js/')); -}); + .pipe(gulp.dest('dist/admin/js/')) +); -gulp.task('build:js:frontend', function () { - return gulp +gulp.task('build:js:frontend', () => + gulp .src(['src/ts/frontend/block.ts', 'src/ts/frontend/shortcode.ts']) .pipe(named((file) => file.stem + '.min')) .pipe(webpack(require('./webpack.config.js'))) .pipe(inject.prepend('jQuery( function( $ ) {\n')) .pipe(inject.append('} );\n')) - .pipe(gulp.dest('dist/frontend/js/')); -}); + .pipe(gulp.dest('dist/frontend/js/')) +); gulp.task('build:js', gulp.parallel('build:js:admin', 'build:js:frontend')); -gulp.task('build:php:admin', function () { - return gulp.src(['src/php/admin/**/*.php']).pipe(gulp.dest('dist/admin/')); -}); +gulp.task('build:php:admin', () => + gulp.src(['src/php/admin/**/*.php']).pipe(gulp.dest('dist/admin/')) +); -gulp.task('build:php:base', function () { - return gulp.src(['src/php/*.php']).pipe(gulp.dest('dist/')); -}); +gulp.task('build:php:base', () => + gulp.src(['src/php/*.php']).pipe(gulp.dest('dist/')) +); -gulp.task('build:php:exceptions', function () { - return gulp +gulp.task('build:php:exceptions', () => + gulp .src(['src/php/exceptions/**/*.php']) - .pipe(gulp.dest('dist/exceptions/')); -}); + .pipe(gulp.dest('dist/exceptions/')) +); -gulp.task('build:php:frontend', function () { - return gulp - .src(['src/php/frontend/**/*.php']) - .pipe(gulp.dest('dist/frontend/')); -}); +gulp.task('build:php:frontend', () => + gulp.src(['src/php/frontend/**/*.php']).pipe(gulp.dest('dist/frontend/')) +); -gulp.task('build:php:helpers', function () { - return gulp - .src(['src/php/helpers/**/*.php']) - .pipe(gulp.dest('dist/helpers/')); -}); +gulp.task('build:php:helpers', () => + gulp.src(['src/php/helpers/**/*.php']).pipe(gulp.dest('dist/helpers/')) +); gulp.task( 'build:php', @@ -175,13 +169,13 @@ gulp.task( ) ); -gulp.task('build:png', function () { - return gulp.src(['src/png/icon.png']).pipe(gulp.dest('dist/admin/')); -}); +gulp.task('build:png', () => + gulp.src(['src/png/icon.png']).pipe(gulp.dest('dist/admin/')) +); -gulp.task('build:txt', function () { - return gulp.src(['src/txt/*.txt']).pipe(gulp.dest('dist/')); -}); +gulp.task('build:txt', () => + gulp.src(['src/txt/*.txt']).pipe(gulp.dest('dist/')) +); gulp.task( 'build', diff --git a/src/ts/admin/root_selection.ts b/src/ts/admin/root_selection.ts index bb18dfcc9..3ac1ea78d 100644 --- a/src/ts/admin/root_selection.ts +++ b/src/ts/admin/root_selection.ts @@ -94,7 +94,7 @@ function listGdriveDir(): void { action: 'list_gdrive_dir', path, }, - function (data: ListGdriveDirResponse) { + (data: ListGdriveDirResponse) => { if (isError(data)) { $('.sgdg_root_selection').replaceWith( printError(data, sgdgRootpathLocalize) diff --git a/src/ts/admin/tinymce.ts b/src/ts/admin/tinymce.ts index 6f1ffc53f..35e444a17 100644 --- a/src/ts/admin/tinymce.ts +++ b/src/ts/admin/tinymce.ts @@ -41,7 +41,7 @@ function tinymceHtml(): void { '' + ''; $('#sgdg-tinymce-modal').html(html); - $('#sgdg-tinymce-insert').on('click', function () { + $('#sgdg-tinymce-insert').on('click', () => { tinymceSubmit(); }); } @@ -112,7 +112,7 @@ function ajaxQuery(): void { action: 'list_gallery_dir', path, }, - function (data: ListGalleryDirResponse) { + (data: ListGalleryDirResponse) => { if (isError(data)) { $('#TB_ajaxContent').html( printError(data, sgdgTinymceLocalize) diff --git a/src/ts/frontend/shortcode/ShortcodeRegistry.ts b/src/ts/frontend/shortcode/ShortcodeRegistry.ts index d8159dc1e..220568262 100644 --- a/src/ts/frontend/shortcode/ShortcodeRegistry.ts +++ b/src/ts/frontend/shortcode/ShortcodeRegistry.ts @@ -31,7 +31,7 @@ export const ShortcodeRegistry: ShortcodeRegistry = { }, reflowAll(): void { - $.each(this.shortcodes, function (_, shortcode) { + $.each(this.shortcodes, (_, shortcode) => { shortcode.reflow(); }); }, @@ -42,7 +42,7 @@ export const ShortcodeRegistry: ShortcodeRegistry = { }, onLightboxQuit(): void { - $.each(this.shortcodes, function (_, shortcode) { + $.each(this.shortcodes, (_, shortcode) => { shortcode.onLightboxQuit(); }); },