From c055e81c02cc8a6be55ee40692c35da9770c186b Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 8 Mar 2023 11:38:44 +0100 Subject: [PATCH] chore(react): remove unused common/ code and simplify eslint config to json --- packages/react/.eslintrc.js | 21 ------ packages/react/.eslintrc.json | 14 ++++ .../react/src/common/shallowUntilTarget.ts | 68 ------------------- 3 files changed, 14 insertions(+), 89 deletions(-) delete mode 100644 packages/react/.eslintrc.js create mode 100644 packages/react/.eslintrc.json delete mode 100644 packages/react/src/common/shallowUntilTarget.ts diff --git a/packages/react/.eslintrc.js b/packages/react/.eslintrc.js deleted file mode 100644 index f90777356cd34b..00000000000000 --- a/packages/react/.eslintrc.js +++ /dev/null @@ -1,21 +0,0 @@ -// @ts-check -const configHelpers = require('@fluentui/eslint-plugin/src/utils/configHelpers'); - -/** @type {import("eslint").Linter.Config} */ -module.exports = { - extends: ['plugin:@fluentui/eslint-plugin/react--legacy'], - plugins: ['@fluentui'], - root: true, - rules: { - '@fluentui/ban-imports': ['error', { pathRegex: '^(\\.\\./)+Styling$', names: ['FontSizes'] }], - '@typescript-eslint/no-explicit-any': 'off', - }, - overrides: [ - { - files: [...configHelpers.devDependenciesFiles, 'src/common/{shallowUntilTarget,testUtilities}.ts'], - rules: { - 'import/no-extraneous-dependencies': ['error', { packageDir: ['.', configHelpers.findGitRoot()] }], - }, - }, - ], -}; diff --git a/packages/react/.eslintrc.json b/packages/react/.eslintrc.json new file mode 100644 index 00000000000000..ea772989a97830 --- /dev/null +++ b/packages/react/.eslintrc.json @@ -0,0 +1,14 @@ +{ + "extends": ["plugin:@fluentui/eslint-plugin/react--legacy"], + "root": true, + "rules": { + "@fluentui/ban-imports": [ + "error", + { + "pathRegex": "^(\\.\\./)+Styling$", + "names": ["FontSizes"] + } + ], + "@typescript-eslint/no-explicit-any": "off" + } +} diff --git a/packages/react/src/common/shallowUntilTarget.ts b/packages/react/src/common/shallowUntilTarget.ts deleted file mode 100644 index 4641925afbf680..00000000000000 --- a/packages/react/src/common/shallowUntilTarget.ts +++ /dev/null @@ -1,68 +0,0 @@ -import * as React from 'react'; -import { shallow, ShallowWrapper } from 'enzyme'; - -/** - * Duplicated enzyme's ShallowRendererProps - * - * @internal - */ -export interface IShallowRendererProps { - lifecycleExperimental?: boolean; - disableLifecycleMethods?: boolean; -} - -/** - * ShallowUntilTarget Interface - * - * @internal - */ -export interface IShallowUntilTarget { - maxTries: number; - shallowOptions: IShallowRendererProps; -} - -/** - * An extention of enzyme's shallow function which will fail to work - * with decorated components and/or components using the styled() function. - * This function allows you to pass a 'target' component (e.g. ComponentBase) - * and keep running shallow on each child component till a match is found. - * - * @public - */ -export function shallowUntilTarget( - componentInstance: React.ReactElement

, - TargetComponent: string, - options: IShallowUntilTarget = { - maxTries: 10, - shallowOptions: {}, - }, -): ShallowWrapper { - const { maxTries, shallowOptions } = options; - - let root = shallow(componentInstance, shallowOptions); - let rootType = root.type(); - - if (typeof rootType === 'string' || rootType.toString().indexOf(TargetComponent) !== -1) { - // Default shallow() - // If type() is a string then it's a DOM Node. - // If it were wrapped, it would be a React component. - return root; - } - - for (let tries = 1; tries <= maxTries; tries++) { - // Check for target as a string to avoid conflicts - // with decoratored components name - if (rootType.toString().indexOf(TargetComponent) !== -1) { - // Now that we found the target component, render it. - return root.first().shallow(shallowOptions); - } - // Unwrap the next component in the hierarchy. - root = root.first().shallow(shallowOptions); - rootType = root.type(); - } - - throw new Error( - `Could not find ${TargetComponent} in React instance: ${componentInstance}; - gave up after ${maxTries} tries`, - ); -}