Skip to content

Commit

Permalink
eslint: For no-empty, set allowEmptyCatch false (#38486)
Browse files Browse the repository at this point in the history
The "no-empty" can be satisfied with anything, even a comment saying why
we're ignoring the exception. Since that's probably a useful comment to
have, let's do that.

For a few files, do something different:
* `projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js`
  can return directly from the `catch`, the following check would only
  fail if the catch caught.
* `projects/plugins/jetpack/modules/shortcodes/js/jmpress.js` is a
  copy-pasted external library. We should `.eslintignore` it as well as
  two others in that directory.
* `projects/plugins/jetpack/tools/webpack.config.extensions.js` would
  error on the next line after the catch anyway, so skip catching at
  all.

This brings us more in line with the ruleset imported from
`@wordpress/eslint-plugin`.

Also, have tools/cleanup-excludelists.sh clean up ignored files. The
"File ignored because of a matching ignore pattern" warning shouldn't
keep files in the list.
  • Loading branch information
anomiex authored Jul 30, 2024
1 parent 7f32df3 commit d1c2b52
Show file tree
Hide file tree
Showing 43 changed files with 115 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Add comment to empty `catch` blocks. No change to functionality.


2 changes: 1 addition & 1 deletion projects/js-packages/ai-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "@automattic/jetpack-ai-client",
"version": "0.16.0",
"version": "0.16.1-alpha",
"description": "A JS client for consuming Jetpack AI services",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/ai-client/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@ export async function clearDeletedMedia( siteId: string ) {
responses
.filter( ( { exists } ) => ! exists )
.forEach( ( { mediaId } ) => removeLogo( { siteId, mediaId } ) );
} catch ( error ) {} // Assume that the media exists if there was a network error and do nothing to avoid data loss.
} catch ( error ) {
// Assume that the media exists if there was a network error and do nothing to avoid data loss.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Add comment to empty `catch` blocks. No change to functionality.


Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ try {
if ( globals?.es2022 ) {
flatBase.languageOptions.globals = globals.es2022;
}
} catch ( e ) {}
} catch ( e ) {
// `globals` is optional.
}

module.exports = flatBase;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Added version bumps.


2 changes: 1 addition & 1 deletion projects/js-packages/publicize-components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-publicize-components",
"version": "0.57.0",
"version": "0.58.0-alpha",
"description": "A library of JS components required by the Publicize editor plugin",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/publicize-components/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Add comment to empty `catch` blocks. No change to functionality.


2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "5.51.x-dev"
"dev-trunk": "5.52.x-dev"
},
"textdomain": "jetpack-mu-wpcom",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/jetpack-mu-wpcom/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom",
"version": "5.51.0",
"version": "5.52.0-alpha",
"description": "Enhances your site with features powered by WordPress.com",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Jetpack_Mu_Wpcom main class.
*/
class Jetpack_Mu_Wpcom {
const PACKAGE_VERSION = '5.51.0';
const PACKAGE_VERSION = '5.52.0-alpha';
const PKG_DIR = __DIR__ . '/../';
const BASE_DIR = __DIR__ . '/';
const BASE_FILE = __FILE__;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ test( 'Simple: author_must_fill_name_and_email', async ( { page } ) => {
.frameLocator( '#cmp-app-container iframe' )
.getByRole( 'button', { name: 'I Agree!' } )
.click();
} catch ( e ) {}
} catch ( e ) {
// It's ok if it wasn't there to be dismissed.
}

// Reply button should be disabled before log in.
await expect( page.locator( '#comment-submit' ) ).toBeDisabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ test( 'Simple: open_comments_for_everyone - Anonymous', async ( { page } ) => {
.frameLocator( '#cmp-app-container iframe' )
.getByRole( 'button', { name: 'I Agree!' } )
.click();
} catch ( e ) {}
} catch ( e ) {
// It's ok if it wasn't there to be dismissed.
}

const existingAnonComments = await page.getByText( 'Anonymous' ).count();
await page.goto( sites.simple.open_comments_for_everyone + '#respond' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ test( 'Simple: user_must_be_registered_and_logged_in_to_comment - Anonymous', as
.frameLocator( '#cmp-app-container iframe' )
.getByRole( 'button', { name: 'I Agree!' } )
.click();
} catch ( e ) {}
} catch ( e ) {
// It's ok if it wasn't there to be dismissed.
}

await page.getByText( 'Leave a comment', { exact: true } ).click();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Added version bumps.


2 changes: 1 addition & 1 deletion projects/packages/my-jetpack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-my-jetpack",
"version": "4.30.0",
"version": "4.30.1-alpha",
"description": "WP Admin page with information and configuration shared among all Jetpack stand-alone plugins",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/my-jetpack/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Initializer {
*
* @var string
*/
const PACKAGE_VERSION = '4.30.0';
const PACKAGE_VERSION = '4.30.1-alpha';

/**
* HTML container ID for the IDC screen on My Jetpack page.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Add comment to empty `catch` blocks. No change to functionality.


2 changes: 1 addition & 1 deletion projects/packages/videopress/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-videopress",
"version": "0.23.29",
"version": "0.23.30-alpha",
"description": "VideoPress package",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/videopress/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/videopress/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* The Package_Version class.
*/
class Package_Version {
const PACKAGE_VERSION = '0.23.29';
const PACKAGE_VERSION = '0.23.30-alpha';

const PACKAGE_SLUG = 'videopress';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ const VideoPressUploader = ( {
const parsedBody = JSON.parse( body );
setUploadErrorDataState( parsedBody );
return;
} catch {}
} catch {
// If it failed to parse, handle generically below.
}
}

setUploadErrorDataState( error );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Add comment to empty `catch` blocks. No change to functionality.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: In webpack.config.extensions.js, remove a catch for JSON errors that would fail with "Cannot read properties of undefined (reading 'replace')" on the next line anyway.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Add copy-pasted libraries in `projects/plugins/jetpack/modules/shortcodes/js/` to `.eslintignore`, we don't want to lint them.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Simplify code in projects/plugins/jetpack/extensions/shared/block-editor-asset-loader.js


Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ domReady( function () {
remove();
const dismissEvent = new Event( 'eucookielaw-dismissed' );
document.dispatchEvent( dismissEvent );
} catch ( err ) {}
} catch ( err ) {
// Avoid sending an error to the browser console.
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ export class MapBoxComponent extends Component {
this.setState( { boundsSetProgrammatically: true } );
try {
map.removeControl( zoomControl );
} catch ( e ) {}
} catch ( e ) {
// Ok if control wasn't there to remove.
}
return;
}
// If there is only one point, center map around it.
Expand Down Expand Up @@ -358,7 +360,9 @@ export class MapBoxComponent extends Component {
// If there's an old map instance hanging around, try to
// clean it up.
prevMap?.remove();
} catch ( error ) {}
} catch ( error ) {
// Ok if there wasn't one to clean up.
}

return { map, zoomControl, fullscreenControl };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ export function loadBlockEditorAssets( resources, callbacks, elementRef ) {

try {
editorAssetsUrl = new URL( 'editor-assets', __webpack_public_path__ );
} catch ( e ) {}

if ( ! editorAssetsUrl ) {
} catch ( e ) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions projects/plugins/jetpack/modules/shortcodes/js/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copy-pasted libraries that we don't want to mess with linting.
# @todo Can we bring these in via pnpm instead?
jmpress.js
jquery.cycle.min.js
recipes-printthis.js
7 changes: 1 addition & 6 deletions projects/plugins/jetpack/tools/webpack.config.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,7 @@ module.exports = [
noErrorOnMissing: true,
// Automatically link scripts and styles
transform( content ) {
let metadata = {};

try {
metadata = JSON.parse( content.toString() );
} catch ( e ) {}

const metadata = JSON.parse( content.toString() );
const name = metadata.name.replace( 'jetpack/', '' );

if ( ! name ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
]
},
"config": {
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_5_2"
"autoloader-suffix": "d9d132a783958a00a2c7cccff60ca42d_jetpack_mu_wpcom_pluginⓥ2_5_3_alpha"
}
}
4 changes: 2 additions & 2 deletions projects/plugins/mu-wpcom-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Plugin Name: WordPress.com Features
* Description: Test plugin for the jetpack-mu-wpcom package
* Version: 2.5.2
* Version: 2.5.3-alpha
* Author: Automattic
* License: GPLv2 or later
* Text Domain: jetpack-mu-wpcom-plugin
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/mu-wpcom-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-mu-wpcom-plugin",
"version": "2.5.2",
"version": "2.5.3-alpha",
"description": "Test plugin for the jetpack-mu-wpcom package",
"homepage": "https://jetpack.com",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"composer/installers": true,
"roots/wordpress-core-installer": true
},
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_0"
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_1_alpha"
},
"extra": {
"mirror-repo": "Automattic/wpcom-site-helper",
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@automattic/jetpack-wpcomsh",
"description": "A helper for connecting WordPress.com sites to external host infrastructure.",
"homepage": "https://jetpack.com",
"version": "5.1.0",
"version": "5.1.1-alpha",
"bugs": {
"url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Plugin Name: WordPress.com Site Helper
* Description: A helper for connecting WordPress.com sites to external host infrastructure.
* Version: 5.1.0
* Version: 5.1.1-alpha
* Author: Automattic
* Author URI: http://automattic.com/
*
* @package wpcomsh
*/

define( 'WPCOMSH_VERSION', '5.1.0' );
define( 'WPCOMSH_VERSION', '5.1.1-alpha' );

// If true, Typekit fonts will be available in addition to Google fonts
add_filter( 'jetpack_fonts_enable_typekit', '__return_true' );
Expand Down
2 changes: 1 addition & 1 deletion tools/cleanup-excludelists.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trap 'rm "$TEMP"' EXIT
: > "$TEMP"
pnpm run lint-file --max-warnings=0 --format=json --output-file="$TEMP" $(for f in $(jq -r '.[]' tools/eslint-excludelist.json); do [[ -e "$f" ]] && echo $f; done) || true
[[ -s "$TEMP" ]] && jq -e '.' < "$TEMP" >/dev/null || die "No JSON data found"
jq --tab -r --arg pwd "$PWD/" '[ .[] | select( .messages[0] ) | .filePath | ltrimstr($pwd) ] | sort' "$TEMP" > tools/eslint-excludelist.json
jq --tab -r --arg pwd "$PWD/" '[ .[] | select( .messages[0]?.ruleId ) | .filePath | ltrimstr($pwd) ] | sort' "$TEMP" > tools/eslint-excludelist.json

: > "$TEMP"
composer phpcs:lint -- -m --file-list=<(for f in $(jq -r '.[]' tools/phpcs-excludelist.json); do [[ -e "$f" ]] && echo $f; done) --report=json --report-file="$TEMP" || true
Expand Down
2 changes: 0 additions & 2 deletions tools/eslint-excludelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
"projects/plugins/jetpack/modules/infinite-scroll/infinity.js",
"projects/plugins/jetpack/modules/plugin-search/plugin-search.js",
"projects/plugins/jetpack/modules/scan/admin-bar-notice.js",
"projects/plugins/jetpack/modules/shortcodes/js/jmpress.js",
"projects/plugins/jetpack/modules/shortcodes/js/recipes-printthis.js",
"projects/plugins/jetpack/modules/shortcodes/js/slideshow-shortcode.js",
"projects/plugins/jetpack/modules/videopress/js/gutenberg-video-upload.js",
"projects/plugins/jetpack/modules/videopress/js/videopress-plupload.js",
Expand Down
Loading

0 comments on commit d1c2b52

Please sign in to comment.