From 30744d0beb834c7f04a32bf1a2e6821c5e6bdfe5 Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Thu, 9 Sep 2021 23:28:45 +1200 Subject: [PATCH] ESLint Plugin: Use Jest related rules only when the package is installed (#33120) * Add Jest to eslint plugin dependencies * Add test rules only when jest is installed Co-authored-by: Grzegorz Ziolkowski --- packages/eslint-plugin/CHANGELOG.md | 4 ++++ .../configs/recommended-with-formatting.js | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 2ae76dde0321c9..7f4f0701deb9b3 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -6,6 +6,10 @@ - The bundled `eslint-plugin-jsdoc` dependency has been updated from requiring `^34.1.0` to requiring `^36.0.8` ([#34338](https://github.com/WordPress/gutenberg/pull/34338)). +### Bug Fix + +- Use Jest related rules only when the `jest` package is installed ([#33120](https://github.com/WordPress/gutenberg/pull/33120)). + ## 9.1.2 (2021-09-09) ### Bug Fix diff --git a/packages/eslint-plugin/configs/recommended-with-formatting.js b/packages/eslint-plugin/configs/recommended-with-formatting.js index 51970f2c238cf1..a51697c9112ba2 100644 --- a/packages/eslint-plugin/configs/recommended-with-formatting.js +++ b/packages/eslint-plugin/configs/recommended-with-formatting.js @@ -1,4 +1,9 @@ -module.exports = { +/** + * Internal dependencies + */ +const { isPackageInstalled } = require( '../utils' ); + +const config = { parser: 'babel-eslint', extends: [ require.resolve( './jsx-a11y.js' ), @@ -27,7 +32,10 @@ module.exports = { 'import/default': 'warn', 'import/named': 'warn', }, - overrides: [ +}; + +if ( isPackageInstalled( 'jest' ) ) { + config.overrides = [ { // Unit test files and their helpers only. files: [ '**/@(test|__tests__)/**/*.js', '**/?(*.)test.js' ], @@ -38,5 +46,7 @@ module.exports = { files: [ '**/specs/**/*.js', '**/?(*.)spec.js' ], extends: [ require.resolve( './test-e2e.js' ) ], }, - ], -}; + ]; +} + +module.exports = config;