kopia lustrzana https://github.com/wagtail/wagtail
Eslint - Removed legacyCode rules
- Fix any issues in files being ignored - Fixed linting errors where appropriate - Include some rules being ignored in the src/components folder - Closes #8731pull/9876/head
rodzic
0513a78fb5
commit
554311752b
22
.eslintrc.js
22
.eslintrc.js
|
@ -1,12 +1,3 @@
|
||||||
// Rules which have been enforced in configuration upgrades and flag issues in existing code.
|
|
||||||
// We need to consider whether to disable those rules permanently, or fix the issues.
|
|
||||||
const legacyCode = {
|
|
||||||
'default-param-last': 'off',
|
|
||||||
'no-continue': 'off',
|
|
||||||
'no-else-return': 'off',
|
|
||||||
'no-restricted-syntax': 'off',
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
extends: [
|
extends: [
|
||||||
'@wagtail/eslint-config-wagtail',
|
'@wagtail/eslint-config-wagtail',
|
||||||
|
@ -63,26 +54,15 @@ module.exports = {
|
||||||
'import/resolver': { node: { extensions: ['.js', '.ts', '.tsx'] } },
|
'import/resolver': { node: { extensions: ['.js', '.ts', '.tsx'] } },
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
// Legacy Code - remove from `files` when adopting desired rules in new code progressively
|
|
||||||
{
|
|
||||||
files: [
|
|
||||||
'client/src/entrypoints/admin/core.js',
|
|
||||||
'client/src/entrypoints/admin/page-editor.js',
|
|
||||||
'client/src/entrypoints/admin/telepath/widgets.js',
|
|
||||||
'client/src/entrypoints/contrib/typed_table_block/typed_table_block.js',
|
|
||||||
'client/src/utils/version.js',
|
|
||||||
],
|
|
||||||
rules: legacyCode,
|
|
||||||
},
|
|
||||||
// Rules that we are ignoring currently due to legacy code in React components only
|
// Rules that we are ignoring currently due to legacy code in React components only
|
||||||
{
|
{
|
||||||
files: ['client/src/components/**'],
|
files: ['client/src/components/**'],
|
||||||
rules: {
|
rules: {
|
||||||
...legacyCode,
|
|
||||||
'jsx-a11y/click-events-have-key-events': 'off',
|
'jsx-a11y/click-events-have-key-events': 'off',
|
||||||
'jsx-a11y/interactive-supports-focus': 'off',
|
'jsx-a11y/interactive-supports-focus': 'off',
|
||||||
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
'jsx-a11y/no-noninteractive-element-interactions': 'off',
|
||||||
'jsx-a11y/role-supports-aria-props': 'off',
|
'jsx-a11y/role-supports-aria-props': 'off',
|
||||||
|
'no-restricted-syntax': 'off',
|
||||||
'react-hooks/exhaustive-deps': 'off',
|
'react-hooks/exhaustive-deps': 'off',
|
||||||
'react-hooks/rules-of-hooks': 'off',
|
'react-hooks/rules-of-hooks': 'off',
|
||||||
'react/button-has-type': 'off',
|
'react/button-has-type': 'off',
|
||||||
|
|
|
@ -53,9 +53,8 @@ export class Chooser {
|
||||||
state[this.editUrlStateKey] = this.editLink.getAttribute('href');
|
state[this.editUrlStateKey] = this.editLink.getAttribute('href');
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getState() {
|
getState() {
|
||||||
|
|
|
@ -188,6 +188,7 @@ export class LayoutController {
|
||||||
pinnedCommentPosition - previousBlock.pinnedCommentPosition;
|
pinnedCommentPosition - previousBlock.pinnedCommentPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-continue
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,8 @@ export function findLeastCommonCommentId(block: ContentBlock, offset: number) {
|
||||||
const styleCount = styles.count();
|
const styleCount = styles.count();
|
||||||
if (styleCount === 0) {
|
if (styleCount === 0) {
|
||||||
return null;
|
return null;
|
||||||
} else if (styleCount > 1) {
|
}
|
||||||
|
if (styleCount > 1) {
|
||||||
// We're dealing with overlapping comments.
|
// We're dealing with overlapping comments.
|
||||||
// Find the least frequently occurring style and use that - this isn't foolproof, but in
|
// Find the least frequently occurring style and use that - this isn't foolproof, but in
|
||||||
// most cases should ensure that all comments have at least one clickable section. This
|
// most cases should ensure that all comments have at least one clickable section. This
|
||||||
|
@ -890,7 +891,8 @@ function CommentableEditor({
|
||||||
return {
|
return {
|
||||||
backgroundColor: background,
|
backgroundColor: background,
|
||||||
};
|
};
|
||||||
} else if (numStyles > 1) {
|
}
|
||||||
|
if (numStyles > 1) {
|
||||||
// Otherwise if we're in a region with overlapping comments, use a different colour than usual
|
// Otherwise if we're in a region with overlapping comments, use a different colour than usual
|
||||||
// to indicate that
|
// to indicate that
|
||||||
background = overlappingHighlight;
|
background = overlappingHighlight;
|
||||||
|
|
|
@ -41,7 +41,7 @@ export type Action =
|
||||||
* - Whether the explorer is open or not.
|
* - Whether the explorer is open or not.
|
||||||
*/
|
*/
|
||||||
export default function explorer(
|
export default function explorer(
|
||||||
prevState = defaultState,
|
prevState = defaultState /* eslint-disable-line default-param-last */,
|
||||||
action: Action,
|
action: Action,
|
||||||
): State {
|
): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
|
@ -131,7 +131,10 @@ export type Action =
|
||||||
/**
|
/**
|
||||||
* A single page node in the explorer.
|
* A single page node in the explorer.
|
||||||
*/
|
*/
|
||||||
const node = (state = defaultPageState, action: Action): PageState => {
|
const node = (
|
||||||
|
state = defaultPageState /* eslint-disable-line default-param-last */,
|
||||||
|
action: Action,
|
||||||
|
): PageState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case GET_PAGE_SUCCESS:
|
case GET_PAGE_SUCCESS:
|
||||||
return { ...state, ...action.payload.data, isError: false };
|
return { ...state, ...action.payload.data, isError: false };
|
||||||
|
@ -194,7 +197,10 @@ const defaultState: State = {};
|
||||||
/**
|
/**
|
||||||
* Contains all of the page nodes in one object.
|
* Contains all of the page nodes in one object.
|
||||||
*/
|
*/
|
||||||
export default function nodes(state = defaultState, action: Action) {
|
export default function nodes(
|
||||||
|
state = defaultState /* eslint-disable-line default-param-last */,
|
||||||
|
action: Action,
|
||||||
|
) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case OPEN_EXPLORER: {
|
case OPEN_EXPLORER: {
|
||||||
return { ...state, [action.payload.id]: { ...defaultPageState } };
|
return { ...state, [action.payload.id]: { ...defaultPageState } };
|
||||||
|
|
|
@ -63,16 +63,15 @@ export const Sidebar: React.FunctionComponent<SidebarProps> = ({
|
||||||
if (checkWindowSizeIsMobile()) {
|
if (checkWindowSizeIsMobile()) {
|
||||||
setIsMobile(true);
|
setIsMobile(true);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
|
||||||
setIsMobile(false);
|
|
||||||
|
|
||||||
// Close the menu and animate out as this state is not used in desktop
|
|
||||||
setVisibleOnMobile(false);
|
|
||||||
// wait for animation to finish then hide menu from screen readers as well.
|
|
||||||
return setTimeout(() => {
|
|
||||||
setClosedOnMobile(true);
|
|
||||||
}, SIDEBAR_TRANSITION_DURATION);
|
|
||||||
}
|
}
|
||||||
|
setIsMobile(false);
|
||||||
|
|
||||||
|
// Close the menu and animate out as this state is not used in desktop
|
||||||
|
setVisibleOnMobile(false);
|
||||||
|
// wait for animation to finish then hide menu from screen readers as well.
|
||||||
|
return setTimeout(() => {
|
||||||
|
setClosedOnMobile(true);
|
||||||
|
}, SIDEBAR_TRANSITION_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', handleResize);
|
window.addEventListener('resize', handleResize);
|
||||||
|
|
|
@ -99,7 +99,8 @@ function enableDirtyFormCheck(formSelector, options) {
|
||||||
const isFormDirty = () => {
|
const isFormDirty = () => {
|
||||||
if (alwaysDirty) {
|
if (alwaysDirty) {
|
||||||
return true;
|
return true;
|
||||||
} else if (!initialData) {
|
}
|
||||||
|
if (!initialData) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +117,8 @@ function enableDirtyFormCheck(formSelector, options) {
|
||||||
const oldValue = initialData.get(key);
|
const oldValue = initialData.get(key);
|
||||||
if (newValue === oldValue) {
|
if (newValue === oldValue) {
|
||||||
return false;
|
return false;
|
||||||
} else if (Array.isArray(newValue) && Array.isArray(oldValue)) {
|
}
|
||||||
|
if (Array.isArray(newValue) && Array.isArray(oldValue)) {
|
||||||
return (
|
return (
|
||||||
newValue.length !== oldValue.length ||
|
newValue.length !== oldValue.length ||
|
||||||
newValue.some((value, index) => value !== oldValue[index])
|
newValue.some((value, index) => value !== oldValue[index])
|
||||||
|
@ -155,29 +157,22 @@ function enableDirtyFormCheck(formSelector, options) {
|
||||||
|
|
||||||
$form.on('change keyup', updateDirtyCheck).trigger('change');
|
$form.on('change keyup', updateDirtyCheck).trigger('change');
|
||||||
|
|
||||||
const validInputNodeInList = (nodeList) => {
|
const isValidInputNode = (node) =>
|
||||||
for (const node of nodeList) {
|
node.nodeType === node.ELEMENT_NODE &&
|
||||||
if (
|
['INPUT', 'TEXTAREA', 'SELECT'].includes(node.tagName);
|
||||||
node.nodeType === node.ELEMENT_NODE &&
|
|
||||||
['INPUT', 'TEXTAREA', 'SELECT'].includes(node.tagName)
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const observer = new MutationObserver((mutationList) => {
|
const observer = new MutationObserver((mutationList) => {
|
||||||
for (const mutation of mutationList) {
|
const hasMutationWithValidInputNode = mutationList.some(
|
||||||
if (
|
(mutation) =>
|
||||||
validInputNodeInList(mutation.addedNodes) ||
|
mutation.addedNodes.some(isValidInputNode) ||
|
||||||
validInputNodeInList(mutation.removedNodes)
|
mutation.removedNodes.some(isValidInputNode),
|
||||||
) {
|
);
|
||||||
updateDirtyCheck();
|
|
||||||
return;
|
if (hasMutationWithValidInputNode) {
|
||||||
}
|
updateDirtyCheck();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe($form[0], {
|
observer.observe($form[0], {
|
||||||
childList: true,
|
childList: true,
|
||||||
attributes: false,
|
attributes: false,
|
||||||
|
|
|
@ -133,10 +133,11 @@ window.updateFooterSaveWarning = (formDirty, commentsDirty) => {
|
||||||
}
|
}
|
||||||
clearTimeout(updateFooterTextTimeout);
|
clearTimeout(updateFooterTextTimeout);
|
||||||
const updateWarnings = () => {
|
const updateWarnings = () => {
|
||||||
for (const warning of warnings) {
|
warnings.forEach((warning) => {
|
||||||
const visible = typeVisibility[warning.dataset.unsavedType];
|
const visible = typeVisibility[warning.dataset.unsavedType];
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
warning.hidden = !visible;
|
warning.hidden = !visible;
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
if (hiding) {
|
if (hiding) {
|
||||||
// If hiding, we want to keep the text as-is before it disappears
|
// If hiding, we want to keep the text as-is before it disappears
|
||||||
|
|
|
@ -295,6 +295,7 @@ class BoundDraftailWidget {
|
||||||
if (!value || !value.blocks) return '';
|
if (!value || !value.blocks) return '';
|
||||||
|
|
||||||
let result = '';
|
let result = '';
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
for (const block of value.blocks) {
|
for (const block of value.blocks) {
|
||||||
if (block.text) {
|
if (block.text) {
|
||||||
result += result ? ' ' + block.text : block.text;
|
result += result ? ' ' + block.text : block.text;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-restricted-syntax */
|
||||||
/* global $ */
|
/* global $ */
|
||||||
|
|
||||||
import { escapeHtml as h } from '../../../utils/text';
|
import { escapeHtml as h } from '../../../utils/text';
|
||||||
|
|
|
@ -61,7 +61,8 @@ class VersionNumber {
|
||||||
(that.preReleaseStep === 'b' || that.preReleaseStep === 'rc')
|
(that.preReleaseStep === 'b' || that.preReleaseStep === 'rc')
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
} else if (this.preReleaseStep === 'b' && that.preReleaseStep === 'rc') {
|
}
|
||||||
|
if (this.preReleaseStep === 'b' && that.preReleaseStep === 'rc') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -73,9 +74,11 @@ class VersionNumber {
|
||||||
howMuchBehind(that) {
|
howMuchBehind(that) {
|
||||||
if (this.major < that.major) {
|
if (this.major < that.major) {
|
||||||
return VersionDeltaType.MAJOR;
|
return VersionDeltaType.MAJOR;
|
||||||
} else if (this.major === that.major && this.minor < that.minor) {
|
}
|
||||||
|
if (this.major === that.major && this.minor < that.minor) {
|
||||||
return VersionDeltaType.MINOR;
|
return VersionDeltaType.MINOR;
|
||||||
} else if (
|
}
|
||||||
|
if (
|
||||||
this.major === that.major &&
|
this.major === that.major &&
|
||||||
this.minor === that.minor &&
|
this.minor === that.minor &&
|
||||||
!this.isPreRelease() &&
|
!this.isPreRelease() &&
|
||||||
|
@ -83,16 +86,19 @@ class VersionNumber {
|
||||||
this.patch < that.patch
|
this.patch < that.patch
|
||||||
) {
|
) {
|
||||||
return VersionDeltaType.PATCH;
|
return VersionDeltaType.PATCH;
|
||||||
} else if (
|
}
|
||||||
|
if (
|
||||||
this.major === that.major &&
|
this.major === that.major &&
|
||||||
this.minor === that.minor &&
|
this.minor === that.minor &&
|
||||||
this.isPreRelease()
|
this.isPreRelease()
|
||||||
) {
|
) {
|
||||||
if (!that.isPreRelease()) {
|
if (!that.isPreRelease()) {
|
||||||
return VersionDeltaType.MINOR;
|
return VersionDeltaType.MINOR;
|
||||||
} else if (this.isPreReleaseStepBehind(that)) {
|
}
|
||||||
|
if (this.isPreReleaseStepBehind(that)) {
|
||||||
return VersionDeltaType.PRE_RELEASE_STEP;
|
return VersionDeltaType.PRE_RELEASE_STEP;
|
||||||
} else if (
|
}
|
||||||
|
if (
|
||||||
this.preReleaseStep === that.preReleaseStep &&
|
this.preReleaseStep === that.preReleaseStep &&
|
||||||
this.preReleaseVersion < that.preReleaseVersion
|
this.preReleaseVersion < that.preReleaseVersion
|
||||||
) {
|
) {
|
||||||
|
|
Ładowanie…
Reference in New Issue