Skip to content

Problem setting up in a Next.js project with flat config, rules not enforced at all #240

@alexander-larsson

Description

@alexander-larsson

I am migrating a Next.js project to ESLint 9 with flat file format. I have gotten every plugin to work quite simply by following what it says in each projects docs. However, I cannot make "eslint-plugin-cypress" work at all. I add the configuration, and ESLint runs just fine but the cypress eslint rules are never enforced. For example to test it I add cy.wait(5000) and cy.pause() in some cypress tests and run the linter and it doesn't give any errors as I have configured it to do.

Is there something weird going on when using this together with Next.js? I have spent hours trying different things.

The cypress files are in a /cypress folder and all other code in /src under the __basedir. But this should not matter right?

Versions:

    "cypress": "13.15.0",
    "eslint": "^9.13.0",
    "eslint-config-next": "15.0.1",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-cypress": "^4.0.0",
    "eslint-plugin-formatjs": "^5.1.5",
    "eslint-plugin-prettier": "^5.2.1",
    "eslint-plugin-testing-library": "^6.4.0",

The config:

import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import pluginCypress from 'eslint-plugin-cypress/flat';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
  baseDirectory: __dirname,
  recommendedConfig: js.configs.recommended,
  allConfig: js.configs.all,
});

export default [
  ...compat.extends('next/core-web-vitals', 'next/typescript'),
  ...compat.plugins('formatjs'),
  {
    rules: {
     // some other rules here
    },
  },
  eslintPluginPrettierRecommended,
  pluginCypress.configs.recommended,
  {
    rules: {
      'cypress/no-pause': 'error',
      'cypress/no-unnecessary-waiting': 'error',
      'cypress/unsafe-to-chain-command': 'off',
    },
  },
  {
    ignores: [
      '**/node_modules/',
      '**/coverage/',
      '**/dist/',
      '**/build/',
      '**/out/',
      '**/.next/',
    ],
  },
];

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions