From 933a730928bf07f24384d33c7c9e43d3ac975634 Mon Sep 17 00:00:00 2001 From: Lovelyfin00 <omokaroloveth10@gmail.com> Date: Tue, 8 Nov 2022 22:06:28 +0100 Subject: [PATCH] Removed no-prototype-builtins rule from eslintrc and fixed minor additional issues --- .eslintrc.js | 4 ---- CHANGELOG.txt | 1 + .../StreamField/blocks/StreamBlock.js | 5 +++-- .../StreamField/blocks/StructBlock.js | 3 ++- .../entrypoints/admin/expanding-formset.js | 4 ++-- .../src/entrypoints/admin/filtered-select.js | 4 ++-- .../entrypoints/contrib/table_block/table.js | 20 +++++++++---------- docs/releases/4.2.md | 1 + 8 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 07ddcba1a3..5ada2d03a7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,7 +8,6 @@ const legacyCode = { 'no-continue': 'off', 'no-else-return': 'off', 'no-plusplus': 'off', - 'no-prototype-builtins': 'off', 'no-restricted-syntax': 'off', 'no-this-before-super': 'off', }; @@ -71,12 +70,9 @@ module.exports = { files: [ 'client/src/entrypoints/admin/comments.js', 'client/src/entrypoints/admin/core.js', - 'client/src/entrypoints/admin/expanding-formset.js', - 'client/src/entrypoints/admin/filtered-select.js', 'client/src/entrypoints/admin/page-chooser.js', 'client/src/entrypoints/admin/page-editor.js', 'client/src/entrypoints/admin/telepath/widgets.js', - 'client/src/entrypoints/contrib/table_block/table.js', 'client/src/entrypoints/contrib/typed_table_block/typed_table_block.js', 'client/src/entrypoints/images/image-chooser-modal.js', 'client/src/utils/actions.ts', diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 480655a95b..db11c1262a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -22,6 +22,7 @@ Changelog * Clean up some unused utility classes and migrate `unlist` to Tailwind utility class `w-list-none` (Loveth Omokaro) * Ensure that the `rebuild_references_index` command can run without console output if called with `--verbosity 0` (Omerzahid Ali, Aman Pandey) * Add development (contributing to Wagtail) documentation notes for development on Windows (Akua Dokua Asiedu) + * Clean up linting on legacy code and add shared util `hasOwn` in TypeScript (Loveth Omokaro) * Fix: Make sure workflow timeline icons are visible in high-contrast mode (Loveth Omokaro) * Fix: Ensure authentication forms (login, password reset) have a visible border in Windows high-contrast mode (Loveth Omokaro) * Fix: Ensure visual consistency between buttons and links as buttons in Windows high-contrast mode (Albina Starykova) diff --git a/client/src/components/StreamField/blocks/StreamBlock.js b/client/src/components/StreamField/blocks/StreamBlock.js index 82d57808b9..9ba0773588 100644 --- a/client/src/components/StreamField/blocks/StreamBlock.js +++ b/client/src/components/StreamField/blocks/StreamBlock.js @@ -8,6 +8,7 @@ import { BaseInsertionControl, } from './BaseSequenceBlock'; import { escapeHtml as h } from '../../../utils/text'; +import { hasOwn } from '../../../utils/hasOwn'; /* global $ */ @@ -318,7 +319,7 @@ export class StreamBlock extends BaseSequenceBlock { // Check if there are any block types that have count limits this.disabledBlockTypes = new Set(); for (const blockType in this.blockDef.meta.blockCounts) { - if (this.blockDef.meta.blockCounts.hasOwnProperty(blockType)) { + if (hasOwn(this.blockDef.meta.blockCounts, blockType)) { const maxNum = this.getBlockMax(blockType); if (typeof maxNum === 'number') { @@ -459,7 +460,7 @@ export class StreamBlock extends BaseSequenceBlock { // Block errors for (const blockIndex in error.blockErrors) { - if (error.blockErrors.hasOwnProperty(blockIndex)) { + if (hasOwn(error.blockErrors, blockIndex)) { this.children[blockIndex].setError(error.blockErrors[blockIndex]); } } diff --git a/client/src/components/StreamField/blocks/StructBlock.js b/client/src/components/StreamField/blocks/StructBlock.js index e4af0c8564..b092ba42eb 100644 --- a/client/src/components/StreamField/blocks/StructBlock.js +++ b/client/src/components/StreamField/blocks/StructBlock.js @@ -1,6 +1,7 @@ /* global $ */ import { escapeHtml as h } from '../../../utils/text'; +import { hasOwn } from '../../../utils/hasOwn'; export class StructBlockValidationError { constructor(blockErrors) { @@ -96,7 +97,7 @@ export class StructBlock { const error = errorList[0]; for (const blockName in error.blockErrors) { - if (error.blockErrors.hasOwnProperty(blockName)) { + if (hasOwn(error.blockErrors, blockName)) { this.childBlocks[blockName].setError(error.blockErrors[blockName]); } } diff --git a/client/src/entrypoints/admin/expanding-formset.js b/client/src/entrypoints/admin/expanding-formset.js index 8d5cd43879..a4e987b211 100644 --- a/client/src/entrypoints/admin/expanding-formset.js +++ b/client/src/entrypoints/admin/expanding-formset.js @@ -7,7 +7,7 @@ function buildExpandingFormset(prefix, opts = {}) { let formCount = parseInt(totalFormsInput.val(), 10); if (opts.onInit) { - for (let i = 0; i < formCount; i++) { + for (let i = 0; i < formCount; i += 1) { opts.onInit(i); } } @@ -29,7 +29,7 @@ function buildExpandingFormset(prefix, opts = {}) { if (opts.onAdd) opts.onAdd(formCount); if (opts.onInit) opts.onInit(formCount); - formCount++; + formCount += 1; totalFormsInput.val(formCount); }); } diff --git a/client/src/entrypoints/admin/filtered-select.js b/client/src/entrypoints/admin/filtered-select.js index 3ab49a3a35..e83ebb41cb 100644 --- a/client/src/entrypoints/admin/filtered-select.js +++ b/client/src/entrypoints/admin/filtered-select.js @@ -61,7 +61,7 @@ $(() => { filteredValues = optionData; } else { filteredValues = []; - for (let i = 0; i < optionData.length; i++) { + for (let i = 0; i < optionData.length; i += 1) { if ( optionData[i].value === '' || optionData[i].filterValue.indexOf(chosenFilter) !== -1 @@ -72,7 +72,7 @@ $(() => { } let foundValue = false; - for (let i = 0; i < filteredValues.length; i++) { + for (let i = 0; i < filteredValues.length; i += 1) { const option = $('<option>'); option.attr('value', filteredValues[i].value); if (filteredValues[i].value === currentValue) foundValue = true; diff --git a/client/src/entrypoints/contrib/table_block/table.js b/client/src/entrypoints/contrib/table_block/table.js index bf9661d427..6f2dd5e060 100644 --- a/client/src/entrypoints/contrib/table_block/table.js +++ b/client/src/entrypoints/contrib/table_block/table.js @@ -3,6 +3,7 @@ /* global Handsontable */ import $ from 'jquery'; +import { hasOwn } from '../../../utils/hasOwn'; function initTable(id, tableOptions) { const containerId = id + '-handsontable-container'; @@ -54,24 +55,21 @@ function initTable(id, tableOptions) { } if (dataForForm !== null) { - if (dataForForm.hasOwnProperty('first_row_is_table_header')) { + if (hasOwn(dataForForm, 'first_row_is_table_header')) { tableHeaderCheckbox.prop( 'checked', dataForForm.first_row_is_table_header, ); } - if (dataForForm.hasOwnProperty('first_col_is_header')) { + if (hasOwn(dataForForm, 'first_col_is_header')) { colHeaderCheckbox.prop('checked', dataForForm.first_col_is_header); } - if (dataForForm.hasOwnProperty('table_caption')) { + if (hasOwn(dataForForm, 'table_caption')) { tableCaption.prop('value', dataForForm.table_caption); } } - if ( - !tableOptions.hasOwnProperty('width') || - !tableOptions.hasOwnProperty('height') - ) { + if (hasOwn(!tableOptions, 'width') || hasOwn(!tableOptions, 'height')) { // Size to parent .sequence-member-inner width if width is not given in tableOptions $(window).on('resize', () => { hot.updateSettings({ @@ -85,8 +83,8 @@ function initTable(id, tableOptions) { const getCellsClassnames = function () { const meta = hot.getCellsMeta(); const cellsClassnames = []; - for (let i = 0; i < meta.length; i++) { - if (meta[i].hasOwnProperty('className')) { + for (let i = 0; i < meta.length; i += 1) { + if (hasOwn(meta[i], 'className')) { cellsClassnames.push({ row: meta[i].row, col: meta[i].col, @@ -159,10 +157,10 @@ function initTable(id, tableOptions) { if (dataForForm !== null) { // Overrides default value from tableOptions (if given) with value from database - if (dataForForm.hasOwnProperty('data')) { + if (hasOwn(dataForForm, 'data')) { defaultOptions.data = dataForForm.data; } - if (dataForForm.hasOwnProperty('cell')) { + if (hasOwn(dataForForm, 'cell')) { defaultOptions.cell = dataForForm.cell; } } diff --git a/docs/releases/4.2.md b/docs/releases/4.2.md index 10832bc962..ea5ec385a7 100644 --- a/docs/releases/4.2.md +++ b/docs/releases/4.2.md @@ -31,6 +31,7 @@ depth: 1 * Clean up some unused utility classes and migrate `unlist` to Tailwind utility class `w-list-none` (Loveth Omokaro) * Ensure that the `rebuild_references_index` command can run without console output if called with `--verbosity 0` (Omerzahid Ali, Aman Pandey) * Add development (contributing to Wagtail) documentation notes for [development on Windows](development_on_windows) (Akua Dokua Asiedu) + * Clean up linting on legacy code and add shared util `hasOwn` in TypeScript (Loveth Omokaro) ### Bug fixes