Skip to content

Commit

Permalink
Improve usage of eslint-disable directives (WordPress#16941)
Browse files Browse the repository at this point in the history
* Remove unused `eslint-disable` directives
* Leverage `eslint-plugin-eslint-comments` and fix reported errors
  • Loading branch information
swissspidy authored Aug 9, 2019
1 parent c1d4497 commit 853b3cb
Show file tree
Hide file tree
Showing 35 changed files with 48 additions and 55 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
extends: [
'plugin:@wordpress/eslint-plugin/recommended',
'plugin:jest/recommended',
'plugin:eslint-comments/recommended',
],
plugins: [
'import',
Expand Down
2 changes: 2 additions & 0 deletions bin/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,5 @@ program
} );

program.parse( process.argv );

/* eslint-enable no-console */
2 changes: 2 additions & 0 deletions bin/packages/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,5 @@ stream
} ) )
.on( 'end', () => ended = true )
.resume();

/* eslint-enable no-console */
18 changes: 18 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 @@ -99,6 +99,7 @@
"cssnano": "4.1.10",
"deep-freeze": "0.0.1",
"enzyme": "3.9.0",
"eslint-plugin-eslint-comments": "3.1.2",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-jest": "22.14.1",
"fast-glob": "2.2.7",
Expand Down
11 changes: 0 additions & 11 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,6 @@ function BlockListBlock( {
blockEdit = <div style={ { display: 'none' } }>{ blockEdit }</div>;
}

// Disable reasons:
//
// jsx-a11y/mouse-events-have-key-events:
// - onMouseOver is explicitly handling hover effects
//
// jsx-a11y/no-static-element-interactions:
// - Each block can be selected by clicking on it

/* eslint-disable jsx-a11y/mouse-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */

return (
<IgnoreNestedEvents
id={ blockElementId }
Expand Down Expand Up @@ -618,7 +608,6 @@ function BlockListBlock( {
) }
</IgnoreNestedEvents>
);
/* eslint-enable jsx-a11y/mouse-events-have-key-events, jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}

const applyWithSelect = withSelect(
Expand Down
3 changes: 1 addition & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export class InserterMenu extends Component {

this.props.setTimeout( () => {
// We need a generic way to access the panel's container
// eslint-disable-next-line react/no-find-dom-node
scrollIntoView( this.panels[ panel ], this.inserterResults.current, {
alignWithTop: true,
} );
Expand Down Expand Up @@ -361,7 +360,7 @@ export class InserterMenu extends Component {
}
</div>
);
/* eslint-enable jsx-a11y/no-autofocus, jsx-a11y/no-noninteractive-element-interactions */
/* eslint-enable jsx-a11y/no-autofocus, jsx-a11y/no-static-element-interactions */
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export class InserterMenu extends Component {
/>
</BottomSheet>
);
/* eslint-enable jsx-a11y/no-autofocus, jsx-a11y/no-noninteractive-element-interactions */
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/utils/transform-styles/ast/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,5 @@ function addParent( obj, parent ) {

return obj;
}

/* eslint-enable @wordpress/no-unused-vars-before-return */
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,5 @@ Compiler.prototype.indent = function( level ) {

return Array( this.level ).join( this.indentation || ' ' );
};

/* eslint-enable @wordpress/no-unused-vars-before-return */
2 changes: 0 additions & 2 deletions packages/block-library/src/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class AudioEdit extends Component {
);
}

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<>
<BlockControls>
Expand Down Expand Up @@ -210,7 +209,6 @@ class AudioEdit extends Component {
</figure>
</>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
}
export default compose( [
Expand Down
8 changes: 2 additions & 6 deletions packages/block-library/src/classic/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,8 @@ export default class ClassicEdit extends Component {
// jsx-a11y/no-static-element-interactions
// - the toolbar itself is non-interactive, but must capture events
// from the KeyboardShortcuts component to stop their propagation.
//
// jsx-a11y/no-static-element-interactions
// - Clicking on this visual placeholder should create the
// toolbar, it can also be created by focussing the field below.

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/no-static-element-interactions */
return [
<div
key="toolbar"
Expand All @@ -205,6 +201,6 @@ export default class ClassicEdit extends Component {
className="wp-block-freeform block-library-rich-text__tinymce"
/>,
];
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/no-static-element-interactions */
}
}
4 changes: 2 additions & 2 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EmbedPreview extends Component {
// Disabled because the overlay div doesn't actually have a role or functionality
// as far as the user is concerned. We're just catching the first click so that
// the block can be selected without interacting with the embed preview that the overlay covers.
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/no-static-element-interactions */
const embedWrapper = 'wp-embed' === type ? (
<WpEmbedPreview
html={ html }
Expand All @@ -88,7 +88,7 @@ class EmbedPreview extends Component {
onMouseUp={ this.hideOverlay } /> }
</div>
);
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/no-static-element-interactions */
/* eslint-enable jsx-a11y/no-static-element-interactions */

return (
<figure className={ classnames( className, 'wp-block-embed', { 'is-type-video': 'video' === type } ) }>
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ export class ImageEdit extends Component {
);

// Disable reason: Each block can be selected by clicking on it
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/click-events-have-key-events */
return (
<>
{ controls }
Expand Down Expand Up @@ -924,7 +924,7 @@ export class ImageEdit extends Component {
{ mediaPlaceholder }
</>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/click-events-have-key-events */
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const registerBlock = ( block ) => {
}
const { metadata, settings, name } = block;
if ( metadata ) {
unstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } ); // eslint-disable-line camelcase
unstable__bootstrapServerSideBlockDefinitions( { [ name ]: metadata } );
}
registerBlockType( name, settings );
};
Expand Down
2 changes: 0 additions & 2 deletions packages/block-library/src/video/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class VideoEdit extends Component {
}
const videoPosterDescription = `video-block__poster-image-description-${ instanceId }`;

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
return (
<>
<BlockControls>
Expand Down Expand Up @@ -314,7 +313,6 @@ class VideoEdit extends Component {
</figure>
</>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,5 @@ describe( 'blocks', () => {
} );
} );
} );

/* eslint-enable react/forbid-elements */
4 changes: 2 additions & 2 deletions packages/components/src/color-picker/saturation.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class Saturation extends Component {
home: () => this.saturate( -1 ),
};

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/no-noninteractive-element-interactions */
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
return (
<KeyboardShortcuts shortcuts={ shortcuts }>
<div
Expand Down Expand Up @@ -181,7 +181,7 @@ export class Saturation extends Component {
</div>
</KeyboardShortcuts>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/no-noninteractive-element-interactions */
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/form-token-field/suggestions-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SuggestionsList extends Component {
'is-selected': index === this.props.selectedIndex,
} );

/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
/* eslint-disable jsx-a11y/click-events-have-key-events */
return (
<li
id={ `components-form-token-suggestions-${ this.props.instanceId }-${ index }` }
Expand All @@ -117,7 +117,7 @@ class SuggestionsList extends Component {
}
</li>
);
/* eslint-enable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */
/* eslint-enable jsx-a11y/click-events-have-key-events */
} )
}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export default createHigherOrderComponent(
// Disable reason: See `normalizeButtonFocus` for browser-specific
// focus event normalization.

/* eslint-disable jsx-a11y/no-static-element-interactions */
return (
<View
onFocus={ this.cancelBlurCheck }
Expand All @@ -132,7 +131,6 @@ export default createHigherOrderComponent(
{ ...this.props } />
</View>
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
}
};
}, 'withFocusOutside'
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Components
export * from './primitives';
// eslint-disable-next-line camelcase
export { default as Animate } from './animate';
export { default as Autocomplete } from './autocomplete';
export { default as BaseControl } from './base-control';
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class Modal extends Component {

// Disable reason: this stops mouse events from triggering tooltips and
// other elements underneath the modal overlay.
/* eslint-disable jsx-a11y/no-static-element-interactions */
return createPortal(
<IsolatedEventContainer
className={ classnames( 'components-modal__screen-overlay', overlayClassName ) }
Expand Down Expand Up @@ -157,7 +156,6 @@ class Modal extends Component {
</IsolatedEventContainer>,
this.node
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
}
}

Expand Down
3 changes: 0 additions & 3 deletions packages/components/src/navigable-container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ class NavigableContainer extends Component {

render() {
const { children, ...props } = this.props;
// Disable reason: Assumed role is applied by parent via props spread.
/* eslint-disable jsx-a11y/no-static-element-interactions */
return (
<div ref={ this.bindContainer }
{ ...omit( props, [
Expand All @@ -132,7 +130,6 @@ class NavigableContainer extends Component {
{ children }
</div>
);
/* eslint-enable jsx-a11y/no-static-element-interactions */
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ const Popover = ( {
// Disable reason: We care to capture the _bubbled_ events from inputs
// within popover as inferring close intent.

/* eslint-disable jsx-a11y/no-static-element-interactions */
let content = (
<PopoverDetectOutside onFocusOutside={ handleOnFocusOutside }>
<Animate
Expand Down Expand Up @@ -420,7 +419,6 @@ const Popover = ( {
</Animate>
</PopoverDetectOutside>
);
/* eslint-enable jsx-a11y/no-static-element-interactions */

// Apply focus to element as long as focusOnMount is truthy; false is
// the only "disabled" value.
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/sandbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Sandbox extends Component {
if ( 'string' === typeof data ) {
try {
data = JSON.parse( data );
} catch ( e ) {} // eslint-disable-line no-empty
} catch ( e ) {}
}

// Verify that the mounted element is the source of the message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const ShortcutList = ( { shortcuts } ) => (
</li>
) ) }
</ul>
/* eslint-enable jsx-a11y/no-redundant-roles */
);

const ShortcutSection = ( { title, shortcuts, className } ) => (
Expand Down
2 changes: 0 additions & 2 deletions packages/editor/src/components/post-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function PostFormat( { onUpdatePostFormat, postFormat = 'standard', supportedFor

// Disable reason: We need to change the value immiediately to show/hide the suggestion if needed

/* eslint-disable jsx-a11y/no-onchange */
return (
<PostFormatCheck>
<div className="editor-post-format">
Expand Down Expand Up @@ -64,7 +63,6 @@ function PostFormat( { onUpdatePostFormat, postFormat = 'standard', supportedFor
</div>
</PostFormatCheck>
);
/* eslint-enable jsx-a11y/no-onchange */
}

export default compose( [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ class HierarchicalTermSelector extends Component {
</form>
),
];
/* eslint-enable jsx-a11y/no-onchange */
}
}

Expand Down
2 changes: 0 additions & 2 deletions packages/hooks/src/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

/**
* Internal dependencies
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-console/src/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ describe( 'jest-console', () => {
}
);
} );

/* eslint-enable no-console */
1 change: 0 additions & 1 deletion packages/keycodes/src/platform.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { Platform } from 'react-native';
*
* @return {boolean} True if iOS; false otherwise.
*/
// eslint-disable-next-line no-unused-vars
export function isAppleOS() {
return Platform.OS === 'ios';
}
Loading

0 comments on commit 853b3cb

Please sign in to comment.