Skip to content

Commit

Permalink
tools, actions: Fix some JS lints ahead of the eslint 9 upgrade (#40484)
Browse files Browse the repository at this point in the history
To make the eslint 9 upgrade PR smaller, let's fix some of the lints
that it'll complain about ahead of time.
  • Loading branch information
anomiex authored Dec 5, 2024
1 parent 5baf0a9 commit bb536db
Show file tree
Hide file tree
Showing 30 changed files with 35 additions and 46 deletions.
9 changes: 9 additions & 0 deletions .github/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
node: true,
},
rules: {
'no-console': 'off',
'n/no-process-exit': 'off',
},
};
2 changes: 0 additions & 2 deletions .github/actions/tool-setup/packagist-proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* Note it needs to be passed paths to certificate key and crt files.
*/

/* eslint-disable no-console */

import * as fs from 'node:fs';
import * as https from 'node:https';

Expand Down
2 changes: 0 additions & 2 deletions .github/actions/tool-setup/post-run-action/post.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as fs from 'node:fs';
import * as path from 'node:path';

/* eslint-disable no-console */

console.log( '::group::Composer 304 short-circuiting proxy log' );

const file = path.join( process.env.HOME, 'proxy.log' );
Expand Down
3 changes: 0 additions & 3 deletions .github/files/e2e-tests/e2e-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,11 @@ switch ( process.env.GITHUB_EVENT_NAME ) {
}
}
} else {
// eslint-disable-next-line no-console
console.error( 'Undefined DISPATCH_REPO!' );
}
break;
default:
// eslint-disable-next-line no-console
console.error( `Unsupported GITHUB_EVENT_NAME ${ process.env.GITHUB_EVENT_NAME }.` );
}

// eslint-disable-next-line no-console
console.log( JSON.stringify( matrix ) );
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Fix some JS lints ahead of eslint 9 upgrade.


Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function flagOss( payload, octokit ) {
org: owner.login,
username: head.user.login,
} );
} catch ( error ) {
} catch {
debug( `flag-oss: Adding OSS Citizen label to PR #${ number }` );
await octokit.rest.issues.addLabels( {
owner: owner.login,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function addCommentAskLabels( octokit, ownerLogin, authorLogin, repo, issu
org: ownerLogin,
username: authorLogin,
} );
} catch ( error ) {
} catch {
debug(
`triage-issues > auto-label: Author ${ authorLogin } is not an org member. Skipping comment.`
);
Expand Down
1 change: 0 additions & 1 deletion tools/cli/commands/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ const printPostCmdMsg = argv => {
}
};

// eslint-disable-next-line jsdoc/require-returns-check -- false positive
/**
* Default executor with error handler
*
Expand Down
4 changes: 2 additions & 2 deletions tools/cli/commands/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function promptForGenerate( options ) {
// Some basic cleanup to avoid causing issues due to mixed caps or external whitespace.
options.name = options.name.trim().toLowerCase();
nameAnswer.name = checkNameValid( typeAnswer.type, options.name ) ? options.name : null;
} catch ( e ) {
} catch {
// Do nothing. Allow the script to continue on as if no value was passed.
}
}
Expand Down Expand Up @@ -726,7 +726,7 @@ async function createComposerJson( composerJson, answers ) {
// For testing, add a third arg here for the org.
await mirrorRepo( composerJson, name, answers.type );
}
} catch ( e ) {
} catch {
// This means we couldn't create the mirror repo or something else failed, GitHub API is down, etc.
// Add error handling for mirror repo couldn't be created or verified.
// Output to console instructions on how to add it.
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/commands/phan.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export async function handler( argv ) {
}
throw new Error( 'Output is JSON but not an array' );
}
} catch ( e2 ) {
} catch {
if ( argv.v ) {
sstdout.write( stdout );
}
Expand Down
3 changes: 1 addition & 2 deletions tools/cli/helpers/json.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from 'fs';
import chalk from 'chalk';

// eslint-disable-next-line no-console
const log = console.log;

/**
Expand All @@ -17,7 +16,7 @@ function readJson( project, packageManager, output ) {
let data;
try {
data = fs.readFileSync( `projects/${ project }/${ file }`, 'utf8' );
} catch ( err ) {
} catch {
output && log( chalk.yellow( `This project does not have a ${ file } file.` ) );
return undefined;
}
Expand Down
1 change: 1 addition & 0 deletions tools/cli/tests/integration/helpers/github.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { doesRepoExist } from '../../../helpers/github.js';

/** @todo Fix these tests and un-skip them. They work locally, but not in CI. */
// eslint-disable-next-line jest/no-disabled-tests
describe.skip( 'doesRepoExist Integration Tests', function () {
test( 'checks for an existing mirror repo', async () => {
await expect( doesRepoExist( 'jetpack' ) ).resolves.toBe( true );
Expand Down
7 changes: 0 additions & 7 deletions tools/cli/tests/unit/helpers/styling.test.js

This file was deleted.

1 change: 1 addition & 0 deletions tools/e2e-commons/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
},
rules: {
'no-console': 0,
'n/no-process-exit': 0,
'playwright/no-skipped-test': 0,
// False positives when using `page.getByRole()`
'testing-library/prefer-screen-queries': 0,
Expand Down
2 changes: 0 additions & 2 deletions tools/e2e-commons/bin/tunnel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

/* eslint-disable n/no-process-exit */

import childProcess from 'child_process';
import fs from 'fs';
import { fileURLToPath } from 'url';
Expand Down
2 changes: 0 additions & 2 deletions tools/e2e-commons/bin/update-beta-version.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { fileURLToPath } from 'url';
import fetch from 'node-fetch';

/* eslint-disable n/no-process-exit */

// Below call should be BEFORE requiring config, so library wil pick it up.
process.env.NODE_CONFIG_DIR = fileURLToPath( new URL( '../config', import.meta.url ) );
const { resolveSiteUrl, getSiteCredentials } = await import( '../helpers/utils-helper.js' );
Expand Down
2 changes: 1 addition & 1 deletion tools/e2e-commons/helpers/partner-provisioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function provisionJetpackStartConnection( userId, plan = 'free', us
// catch a command failed error so that secrets are not logged
try {
response = execSyncShellCommand( cmd );
} catch ( error ) {
} catch {
throw new Error( `Jetpack Start provisioning command failed.` );
}

Expand Down
2 changes: 1 addition & 1 deletion tools/e2e-commons/helpers/plan-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export async function syncPlanData( page ) {
let i = 0;
do {
await page.reload( { waitFor: 'domcontentloaded' } );
// eslint-disable-next-line no-undef, camelcase
// eslint-disable-next-line no-undef
fePlan = await page.evaluate( () => Initial_State.siteData.plan.product_slug );
logger.debug( `PLANS: frontend: ${ fePlan }, backend: ${ bePlan.product_slug }` );
isSame = fePlan.trim() === bePlan.product_slug.trim();
Expand Down
1 change: 0 additions & 1 deletion tools/e2e-commons/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const stringFormat = format.combine(
format.uncolorize()
);

// eslint-disable-next-line no-unused-vars
export default createLogger( {
levels: myCustomLevels.levels,
format: format.combine(
Expand Down
2 changes: 1 addition & 1 deletion tools/e2e-commons/pages/page-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export default class PageActions {
try {
await this.page.locator( selector ).first().waitFor( { timeout } );
return true;
} catch ( e ) {
} catch {
logger.warn( `Element '${ selector }' was not visible. Waited for ${ timeout }ms` );
return false;
}
Expand Down
9 changes: 9 additions & 0 deletions tools/js-tools/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
env: {
node: true,
},
rules: {
'no-console': 'off',
'n/no-process-exit': 'off',
},
};
2 changes: 0 additions & 2 deletions tools/js-tools/await-packagist-updates.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

/* eslint-disable no-console, n/no-process-exit */

import events from 'node:events';
import http2 from 'node:http2';
import path from 'node:path';
Expand Down
3 changes: 0 additions & 3 deletions tools/js-tools/check-excludelist-diff.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env node

/* eslint-env node */
/* eslint-disable no-console, n/no-process-exit */

const spawnSync = require( 'child_process' ).spawnSync;
const parseDiff = require( 'parse-diff' );

Expand Down
2 changes: 0 additions & 2 deletions tools/js-tools/git-hooks/jetpack-draft.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

/**
* Checks if we're in draft mode and sets the draft mode flag
*/
Expand Down
1 change: 0 additions & 1 deletion tools/js-tools/git-hooks/pre-commit-hook.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

/* eslint-disable no-console, n/no-process-exit */
const spawnSync = require( 'child_process' ).spawnSync;
const fs = require( 'fs' );
const path = require( 'path' );
Expand Down
1 change: 0 additions & 1 deletion tools/js-tools/git-hooks/pre-push-hook.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

/* eslint-disable no-console */
import { spawn, spawnSync } from 'child_process';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
Expand Down
3 changes: 1 addition & 2 deletions tools/js-tools/jest/setup-after-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ require( '@testing-library/jest-dom' );
//
// Note `console.debug` and `console.trace` are not mocked, and so may be used for debugging.
require( '@wordpress/jest-console' );

// Work around https://github.com/WordPress/gutenberg/issues/48042
beforeEach( () => {
for ( const func of [ 'log', 'info', 'warn', 'error' ] ) {
// eslint-disable-next-line no-console
if ( console[ func ]?.mockReturnValue ) {
// eslint-disable-next-line no-console
console[ func ].mockReturnValue();
}
}
Expand Down
1 change: 0 additions & 1 deletion tools/js-tools/lint-gh-actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

/* eslint-env node */
/* eslint-disable no-console */

const fs = require( 'fs' );
const chalk = require( 'chalk' );
Expand Down
2 changes: 0 additions & 2 deletions tools/js-tools/list-gh-secrets.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

/* eslint-disable no-console */

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
Expand Down
2 changes: 0 additions & 2 deletions tools/js-tools/mass-update-gh-secret.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

/* eslint-disable no-console */

import { createTokenAuth } from '@octokit/auth-token';
import { Octokit } from '@octokit/rest';
import chalk from 'chalk';
Expand Down

0 comments on commit bb536db

Please sign in to comment.