Skip to content

Commit

Permalink
feat(linter): simplify cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Aug 9, 2023
1 parent 14d600c commit 8db43d7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/cypress/src/utils/add-linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 8db43d7

Please sign in to comment.