Skip to content

Commit

Permalink
Merge pull request #1074 from skaut/prefer-arrow
Browse files Browse the repository at this point in the history
Prefering arrow functions
  • Loading branch information
marekdedic authored Oct 24, 2023
2 parents b08d7ce + 5224c42 commit 7dc79f7
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 89 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"plugins": [
"compat",
"deprecation",
"prefer-arrow-functions",
"@typescript-eslint",
"simple-import-sort"
],
Expand All @@ -20,13 +21,20 @@
"plugin:@typescript-eslint/stylistic-type-checked"
],
"rules": {
"arrow-body-style": ["error", "as-needed"],
"camelcase": ["error", {"allow": ["wordpress__customize"]}],
"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",
Expand Down
143 changes: 73 additions & 70 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const terser = require('gulp-terser');
const ts = require('gulp-typescript');
const wpPot = require('gulp-wp-pot');

gulp.task('build:css:main', function () {
return gulp
gulp.task('build:css:main', () =>
gulp
.src([
'src/css/style.css',
'src/css/frontend/blog.css',
Expand All @@ -26,48 +26,48 @@ gulp.task('build:css:main', function () {
])
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(concat('style.css'))
.pipe(gulp.dest('dist/'));
});
.pipe(gulp.dest('dist/'))
);

gulp.task('build:css:admin', function () {
return gulp
gulp.task('build:css:admin', () =>
gulp
.src('src/css/admin/**/*.css')
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/admin/css/'));
});
.pipe(gulp.dest('dist/admin/css/'))
);

gulp.task('build:css', gulp.parallel('build:css:main', 'build:css:admin'));

gulp.task('build:deps:npm:dripicons', function () {
return gulp
gulp.task('build:deps:npm:dripicons', () =>
gulp
.src(
[
'node_modules/dripicons/webfont/webfont.css',
'node_modules/dripicons/webfont/fonts/*',
],
{ base: 'node_modules/dripicons/webfont' }
)
.pipe(gulp.dest('dist/frontend/dripicons'));
});
.pipe(gulp.dest('dist/frontend/dripicons'))
);

gulp.task('build:deps:npm', gulp.parallel('build:deps:npm:dripicons'));

gulp.task('build:deps', gulp.parallel('build:deps:npm'));

gulp.task('build:jpg:screenshot', function () {
return gulp.src('src/jpg/screenshot.jpg').pipe(gulp.dest('dist/'));
});
gulp.task('build:jpg:screenshot', () =>
gulp.src('src/jpg/screenshot.jpg').pipe(gulp.dest('dist/'))
);

gulp.task('build:jpg:frontend', function () {
return gulp
gulp.task('build:jpg:frontend', () =>
gulp
.src('src/jpg/frontend/**/*.jpg')
.pipe(gulp.dest('dist/frontend/images/'));
});
.pipe(gulp.dest('dist/frontend/images/'))
);

gulp.task('build:jpg:admin', function () {
return gulp.src('src/jpg/admin/**/*.jpg').pipe(gulp.dest('dist/admin/'));
});
gulp.task('build:jpg:admin', () =>
gulp.src('src/jpg/admin/**/*.jpg').pipe(gulp.dest('dist/admin/'))
);

gulp.task(
'build:jpg',
Expand All @@ -94,8 +94,8 @@ function bundle(name, sources, part, jQuery = false) {
.pipe(gulp.dest('dist/' + part + '/js/'));
}

gulp.task('build:js', function () {
return merge(
gulp.task('build:js', () =>
merge(
bundle(
'preset_customize_control',
['src/ts/admin/preset_customize_control.ts'],
Expand All @@ -122,55 +122,53 @@ gulp.task('build:js', function () {
true
),
bundle('blog', ['src/ts/frontend/blog.ts'], 'frontend', true)
);
});
)
);

gulp.task('build:mo', function () {
return gulp
gulp.task('build:mo', () =>
gulp
.src('src/languages/*.po')
.pipe(potomo({ verbose: false }))
.pipe(
rename(function (path) {
rename((path) => {
path.basename = path.basename.substring(
path.basename.lastIndexOf('-') + 1
);
})
)
.pipe(gulp.dest('dist/languages/'));
});
.pipe(gulp.dest('dist/languages/'))
);

gulp.task('build:php:root', function () {
return gulp.src('src/php/*.php').pipe(gulp.dest('dist/'));
});
gulp.task('build:php:root', () =>
gulp.src('src/php/*.php').pipe(gulp.dest('dist/'))
);

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: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',
gulp.parallel('build:php:root', 'build:php:admin', 'build:php:frontend')
);

gulp.task('build:png:frontend', function () {
return gulp
gulp.task('build:png:frontend', () =>
gulp
.src('src/png/frontend/**/*.png')
.pipe(gulp.dest('dist/frontend/images/'));
});
.pipe(gulp.dest('dist/frontend/images/'))
);

gulp.task('build:png', gulp.parallel('build:png:frontend'));

gulp.task('build:txt', function () {
return gulp
gulp.task('build:txt', () =>
gulp
.src(['src/txt/license.txt', 'src/txt/readme.txt'])
.pipe(gulp.dest('dist/'));
});
.pipe(gulp.dest('dist/'))
);

gulp.task(
'build',
Expand All @@ -188,29 +186,34 @@ gulp.task(

gulp.task(
'update-translations:generate-pot',
gulp.series(function () {
return gulp
.src('src/php/**/*.php')
.pipe(
wpPot({
bugReport: 'https://github.com/skaut/crdm-modern/issues',
domain: 'crdm-modern',
package: 'crdm-modern',
relativeTo: 'src/php',
includePOTCreationDate: false,
})
)
.pipe(gulp.dest('src/languages/crdm-modern.pot'));
}, shell.task('msgmerge -U src/languages/crdm-modern.pot src/languages/crdm-modern.pot'))
);

gulp.task('update-translations:update-po', function () {
return gulp
gulp.series(
() =>
gulp
.src('src/php/**/*.php')
.pipe(
wpPot({
bugReport:
'https://github.com/skaut/crdm-modern/issues',
domain: 'crdm-modern',
package: 'crdm-modern',
relativeTo: 'src/php',
includePOTCreationDate: false,
})
)
.pipe(gulp.dest('src/languages/crdm-modern.pot')),
shell.task(
'msgmerge -U src/languages/crdm-modern.pot src/languages/crdm-modern.pot'
)
)
);

gulp.task('update-translations:update-po', () =>
gulp
.src('src/languages/*.po', { read: false })
.pipe(
shell('msgmerge -U <%= file.path %> src/languages/crdm-modern.pot')
);
});
)
);

gulp.task(
'update-translations',
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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-simple-import-sort": "^10.0.0",
"gulp": "^4.0.2",
"gulp-clean-css": "^4.3.0",
Expand Down
16 changes: 8 additions & 8 deletions src/ts/admin/liveReload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function setCSSInHead(
mediaBegin +
target.selector +
' {\n' +
$.map(target.properties, function (property) {
$.map(target.properties, (property) => {
let computedValue = value;
if (property.computed) {
let additionalValues: Array<string> = [];
Expand Down Expand Up @@ -75,10 +75,10 @@ function liveReload(
targets: Array<LiveReloadTarget>,
fallbacks?: Array<string>
): void {
void wp.customize(setting, function (value) {
value.bind(function (newValue: string) {
void wp.customize(setting, (value) => {
value.bind((newValue: string) => {
if (!newValue && fallbacks) {
$.each(fallbacks, function (_, fallback) {
$.each(fallbacks, (_, fallback) => {
const fallbackValue = String(wp.customize(fallback).get());
if (fallbackValue) {
newValue = fallbackValue;
Expand All @@ -87,15 +87,15 @@ function liveReload(
return true;
});
}
$.each(targets, function (_, target) {
$.each(targets, (_, target) => {
setCSSInHead(setting, target, newValue);
});
});
});
if (fallbacks) {
for (let i = 0; i < fallbacks.length; i++) {
void wp.customize(fallbacks[i], function (value) {
value.bind(function (newValue: string) {
void wp.customize(fallbacks[i], (value) => {
value.bind((newValue: string) => {
if (wp.customize(setting).get() !== undefined) {
return;
}
Expand All @@ -104,7 +104,7 @@ function liveReload(
return;
}
}
$.each(targets, function (_, target) {
$.each(targets, (_, target) => {
setCSSInHead(setting, target, newValue);
});
});
Expand Down
10 changes: 5 additions & 5 deletions src/ts/admin/preset_customize_control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ function applyPreset(control: wordpress__customize.Control): void {
}

const preset = crdmModernPresetCustomizeControlLocalize[chosen];
$.each(preset, function (key, value) {
$.each(preset, (key, value) => {
if (isAssoc(value)) {
$.each(value, function (innerKey, innerValue) {
$.each(value, (innerKey, innerValue) => {
const innerSetting = wp.customize(key + '[' + innerKey + ']');
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/strict-boolean-expressions
if (!innerSetting) {
Expand All @@ -37,14 +37,14 @@ function applyPreset(control: wordpress__customize.Control): void {
$('.generatepress-font-variant select').trigger('change');
}

void wp.customize.control('crdm_modern_preset', function (control) {
void wp.customize.control('crdm_modern_preset', (control) => {
control.container
.find('input[name=crdm_modern_preset]')
.on('change', function () {
.on('change', () => {
control.container.find('.button').prop('disabled', false);
});

control.container.find('.button').on('click', function () {
control.container.find('.button').on('click', () => {
applyPreset(control);
});
});
4 changes: 2 additions & 2 deletions src/ts/admin/preset_on_activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ function onActivation(): void {
'#TB_inline?inlineId=crdm-modern-preset-on-activation-modal'
);

$('input[name=crdm-modern-preset-on-activation]').on('change', function () {
$('input[name=crdm-modern-preset-on-activation]').on('change', () => {
const applyButton = $('#crdm-modern-preset-on-activation-apply');
applyButton.removeAttr('disabled');
applyButton.on('click', applyCallback);
});
$('#crdm-modern-preset-on-activation-skip').on('click', function () {
$('#crdm-modern-preset-on-activation-skip').on('click', () => {
tb_remove();
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/ts/frontend/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function addExcerptClickability(): void {
return;
}
const articles = $('.site-main article .inside-article');
articles.each(function (_, article) {
articles.each((_, article) => {
const href = $(article).find('.entry-title a').attr('href') ?? '';
$(article).on('click', function () {
$(article).on('click', () => {
window.location.href = href;
});
});
Expand Down

0 comments on commit 7dc79f7

Please sign in to comment.