From 8db43d7a45072677f4c4db6bdfef72ee5d76fb1c Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Wed, 9 Aug 2023 15:49:01 +0200 Subject: [PATCH] feat(linter): simplify cypress --- packages/cypress/src/utils/add-linter.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/cypress/src/utils/add-linter.ts b/packages/cypress/src/utils/add-linter.ts index 0bb6ff3d560f37..21b1332adea900 100644 --- a/packages/cypress/src/utils/add-linter.ts +++ b/packages/cypress/src/utils/add-linter.ts @@ -11,6 +11,11 @@ import { Linter, lintProjectGenerator } from '@nx/linter'; import { javaScriptOverride } from '@nx/linter/src/generators/init/global-eslint-config'; import { installedCypressVersion } from './cypress-version'; import { eslintPluginCypressVersion } from './versions'; +import { + addExtendsToLintConfig, + addOverrideToLintConfig, + findEslintFile, +} from '@nx/linter/src/generators/utils/eslint-file'; export interface CyLinterOptions { project: string; @@ -42,7 +47,8 @@ export async function addLinterToCyProject( const tasks: GeneratorCallback[] = []; const projectConfig = readProjectConfiguration(tree, options.project); - if (!tree.exists(joinPathFragments(projectConfig.root, '.eslintrc.json'))) { + const eslintFile = findEslintFile(tree, projectConfig.root); + if (!eslintFile) { tasks.push( await lintProjectGenerator(tree, { project: options.project, @@ -73,16 +79,15 @@ export async function addLinterToCyProject( : () => {} ); + addExtendsToLintConfig( + tree, + projectConfig.root, + 'plugin:cypress/recommended' + ); updateJson( tree, joinPathFragments(projectConfig.root, '.eslintrc.json'), (json) => { - if (options.rootProject) { - json.plugins = ['@nx']; - json.extends = ['plugin:cypress/recommended']; - } else { - json.extends = ['plugin:cypress/recommended', ...json.extends]; - } json.overrides ??= []; const globals = options.rootProject ? [javaScriptOverride] : []; const override = {