Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts: Ensure that typescript-eslint checks for unused vars #62925

Merged
merged 15 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/components/src/autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
useRef,
useMemo,
} from '@wordpress/element';
import { __, _n } from '@wordpress/i18n';
import { useInstanceId, useMergeRefs, useRefEffect } from '@wordpress/compose';
import {
create,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/date-time/date-time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { ForwardedRef } from 'react';
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';
import { __, _x } from '@wordpress/i18n';

/**
* Internal dependencies
Expand Down
5 changes: 0 additions & 5 deletions packages/components/src/font-size-picker/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/palette-edit/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ async function clearInput( input: HTMLInputElement ) {
await click( input );

// Press backspace as many times as the input's current value
for ( const _ of Array( input.value.length ) ) {
await press.Backspace();
}
[ ...Array( input.value.length ) ].forEach(
async () => await press.Backspace()
);
Chrico marked this conversation as resolved.
Show resolved Hide resolved
}

describe( 'getNameAndSlugForPosition', () => {
Expand Down
5 changes: 0 additions & 5 deletions packages/components/src/private-apis.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';

/**
* Internal dependencies
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/theme/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export const ColorScheme: StoryFn< typeof Theme > = ( {
} ) => {
const { colors } = generateThemeVariables( { accent, background } );
const { gray, ...otherColors } = colors;
/* eslint-disable @typescript-eslint/no-unused-vars */
const contrastIssues = Object.entries(
checkContrasts( { accent, background }, colors )
).filter( ( [ _, error ] ) => !! error );
/* eslint-enable @typescript-eslint/no-unused-vars */

const Chip = ( { color, name }: { color: string; name: string } ) => (
<HStack justify="flex-start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { LayoutGroup } from 'framer-motion';
* WordPress dependencies
*/
import { useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';

/**
Expand Down
1 change: 0 additions & 1 deletion packages/compose/src/higher-order/test/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe( 'compose', () => {
const c = ( value ) => ( value += 'c' );
const d = ( value ) => ( value += 'd' );
const e = ( value ) => ( value += 'e' );
const f = ( value ) => ( value += 'f' );

expect( compose( [ a, b ], c, [ d ], e )( 'test' ) ).toBe(
'testedcba'
Expand Down
1 change: 0 additions & 1 deletion packages/compose/src/higher-order/test/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe( 'pipe', () => {
const c = ( value ) => ( value += 'c' );
const d = ( value ) => ( value += 'd' );
const e = ( value ) => ( value += 'e' );
const f = ( value ) => ( value += 'f' );

expect( pipe( [ a, b ], c, [ d ], e )( 'test' ) ).toBe( 'testabcde' );
} );
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/entity-types/menu-location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco

declare module './base-entity-records' {
export namespace BaseEntityRecords {
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export interface MenuLocation< C extends Context > {
/**
* The name of the menu location.
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/entity-types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco

declare module './base-entity-records' {
export namespace BaseEntityRecords {
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export interface Settings< C extends Context > {
/**
* What to show on the front page
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/entity-types/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco

declare module './base-entity-records' {
export namespace BaseEntityRecords {
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export interface Theme< C extends Context > {
/**
* The theme's stylesheet. This uniquely identifies the theme.
Expand Down
1 change: 1 addition & 0 deletions packages/core-data/src/entity-types/widget-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco

declare module './base-entity-records' {
export namespace BaseEntityRecords {
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
export interface WidgetType< C extends Context > {
/**
* Unique slug identifying the widget type.
Expand Down
6 changes: 6 additions & 0 deletions packages/core-data/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ export function getEntitiesByKind( state: State, kind: string ): Array< any > {
export const getEntitiesConfig = createSelector(
( state: State, kind: string ): Array< any > =>
state.entities.config.filter( ( entity ) => entity.kind === kind ),
/* eslint-disable @typescript-eslint/no-unused-vars */
( state: State, kind: string ) => state.entities.config
/* eslint-enable @typescript-eslint/no-unused-vars */
);
/**
* Returns the entity config given its kind and name.
Expand Down Expand Up @@ -992,6 +994,7 @@ export function getLastEntityDeleteError(
?.error;
}

/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Returns the previous edit from the current undo offset
* for the entity records edits history, if any.
Expand All @@ -1008,7 +1011,9 @@ export function getUndoEdit( state: State ): Optional< any > {
} );
return undefined;
}
/* eslint-enable @typescript-eslint/no-unused-vars */

/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Returns the next edit from the current undo offset
* for the entity records edits history, if any.
Expand All @@ -1025,6 +1030,7 @@ export function getRedoEdit( state: State ): Optional< any > {
} );
return undefined;
}
/* eslint-enable @typescript-eslint/no-unused-vars */

/**
* Returns true if there is a previous edit from the current undo offset
Expand Down
1 change: 0 additions & 1 deletion packages/editor/src/dataviews/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* WordPress dependencies
*/
import { combineReducers } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import type { Action } from '@wordpress/dataviews';

type ReduxAction =
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- `@typescript-eslint/no-unused-vars` is now turned on with level "error" when running `wp-scripts lint-js`.
Chrico marked this conversation as resolved.
Show resolved Hide resolved

## 19.2.0 (2024-06-26)

## 19.1.0 (2024-06-15)
Expand Down
9 changes: 8 additions & 1 deletion packages/eslint-plugin/configs/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ if ( isPackageInstalled( 'typescript' ) ) {
// Don't require redundant JSDoc types in TypeScript files.
'jsdoc/require-param-type': 'off',
'jsdoc/require-returns-type': 'off',
// Handled by TS itself.
// Use eslint for unused variable and parameter detection.
// This overlaps with TypeScript noUnusedLocals and noUnusedParameters settings.
// TypeScript may only run on a subset of files. Prefer eslint which is more
// likely to run on the entire codebase.
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true },
sirreal marked this conversation as resolved.
Show resolved Hide resolved
],
// no-shadow doesn't work correctly in TS, so let's use a TS-dedicated version instead.
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
Expand Down
1 change: 0 additions & 1 deletion packages/report-flaky-tests/src/__tests__/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import * as core from '@actions/core';
import * as github from '@actions/github';

/**
* Internal dependencies
Expand Down
2 changes: 2 additions & 0 deletions packages/token-list/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export default class TokenList {
return true;
}

/* eslint-disable @typescript-eslint/no-unused-vars */
/**
* Returns true if `token` is in the associated attribute’s supported
* tokens. Returns false otherwise.
Expand All @@ -207,4 +208,5 @@ export default class TokenList {
supports( _token: string ): boolean {
return true;
}
/* eslint-enable @typescript-eslint/no-unused-vars */
}
2 changes: 1 addition & 1 deletion test/performance/config/performance-reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function curateResults(
return Object.fromEntries(
Object.entries( output )
// Reduce the output to contain taken metrics only.
.filter( ( [ _, value ] ) => value !== undefined )
.filter( ( [ , value ] ) => value !== undefined )
);
}

Expand Down
2 changes: 0 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
"strict": true,

/* Additional Checks */
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,

Expand Down
Loading