Files
Jiwon ChoiandGitHub 4bee38175c [Breaking] Flat config as default in @next/eslint-plugin-next (#83763)
> [!NOTE]
> This is not a breaking change for `eslint-config-next` as they are
modified to use the legacy. Therefore, CNA templates or current users
that use `eslint-config-next` won't be affected.

### Why?

This PR uses v16 as an opportunity to make the Flat config the default
for `@next/eslint-plugin-next`. Since ESLint v10 will drop the Legacy
config, it is recommended for the plugins to migrate the default config
to Flat. This follows the recommended [plugin migration guide to flat
config](https://eslint.org/docs/latest/extend/plugin-migration-flat-config)
from ESLint.

Along with the migration, it uses the types from ESLint to let users
have correct type safety when using the plugin.

Fixes https://github.com/vercel/next.js/issues/81695
Fixes https://github.com/vercel/next.js/issues/81083
Fixes https://github.com/vercel/next.js/issues/82967
Closes NEXT-4663
2025-09-15 16:34:13 +02:00

60 lines
2.0 KiB
TypeScript

import { basename } from 'path'
import glob from 'glob'
import index from '@next/eslint-plugin-next'
const getRuleNameFromRulePath = (path) => basename(path, '.js')
const rulePaths = glob.sync('packages/eslint-plugin-next/dist/rules/*js', {
absolute: true,
})
describe('@next/eslint-plugin-next index', () => {
it('should include all defined rules and no extra / undefined rules', () => {
const rules = rulePaths.map((rulePath) => getRuleNameFromRulePath(rulePath))
expect(index.rules).toContainAllKeys(rules)
})
it('should have meta information', () => {
expect(index.meta).toBeDefined()
expect(index.meta.name).toBe('@next/eslint-plugin-next')
})
it('should have proper flat config structure for recommended', () => {
const config = index.configs.recommended
expect(config.name).toBe('next/recommended')
expect(config.rules).toBeDefined()
})
it('should have proper flat config structure for core-web-vitals', () => {
const config = index.configs['core-web-vitals']
expect(config.name).toBe('next/core-web-vitals')
expect(config.rules).toBeDefined()
})
it('should have legacy recommended config', () => {
const config = index.configs['recommended-legacy']
expect(config.plugins).toContain('@next/next')
expect(config.rules).toBeDefined()
})
it('should have legacy core-web-vitals config', () => {
const config = index.configs['core-web-vitals-legacy']
expect(config.plugins).toContain('@next/next')
expect(config.extends).toContain('plugin:@next/next/recommended-legacy')
expect(config.rules).toBeDefined()
})
rulePaths.forEach((rulePath) => {
let rule = require(rulePath)
rule = rule.default ?? rule
const ruleName = getRuleNameFromRulePath(rulePath)
const { recommended = false } = rule.meta.docs
it(`${ruleName}: recommend should be \`${recommended}\``, () => {
expect(`@next/next/${ruleName}` in index.configs.recommended.rules).toBe(
recommended
)
})
})
})