Unverified Commit 35706e30 authored by Yuns's avatar Yuns Committed by GitHub

fix: eslint-plugin-next glob (#68773)

Closes https://github.com/vercel/next.js/issues/68752

---------
Co-authored-by: 's avatarSam Ko <sam@vercel.com>
parent e99f7362
...@@ -5,9 +5,9 @@ import type { Rule } from 'eslint' ...@@ -5,9 +5,9 @@ import type { Rule } from 'eslint'
* Process a Next.js root directory glob. * Process a Next.js root directory glob.
*/ */
const processRootDir = (rootDir: string): string[] => { const processRootDir = (rootDir: string): string[] => {
// Ensures we only match folders. return globSync(rootDir, {
if (!rootDir.endsWith('/')) rootDir += '/' onlyDirectories: true,
return globSync(rootDir) })
} }
/** /**
......
...@@ -5,6 +5,7 @@ import assert from 'assert' ...@@ -5,6 +5,7 @@ import assert from 'assert'
import path from 'path' import path from 'path'
const withCustomPagesDirectory = path.join(__dirname, 'with-custom-pages-dir') const withCustomPagesDirectory = path.join(__dirname, 'with-custom-pages-dir')
const withNestedPagesDirectory = path.join(__dirname, 'with-nested-pages-dir')
const withoutPagesLinter = new Linter({ const withoutPagesLinter = new Linter({
cwd: path.join(__dirname, 'without-pages-dir'), cwd: path.join(__dirname, 'without-pages-dir'),
...@@ -12,6 +13,9 @@ const withoutPagesLinter = new Linter({ ...@@ -12,6 +13,9 @@ const withoutPagesLinter = new Linter({
const withAppLinter = new Linter({ const withAppLinter = new Linter({
cwd: path.join(__dirname, 'with-app-dir'), cwd: path.join(__dirname, 'with-app-dir'),
}) })
const withNestedPagesLinter = new Linter({
cwd: withNestedPagesDirectory,
})
const withCustomPagesLinter = new Linter({ const withCustomPagesLinter = new Linter({
cwd: withCustomPagesDirectory, cwd: withCustomPagesDirectory,
}) })
...@@ -50,6 +54,14 @@ const linterConfigWithMultipleDirectories = { ...@@ -50,6 +54,14 @@ const linterConfigWithMultipleDirectories = {
], ],
}, },
} }
const linterConfigWithNestedContentRootDirDirectory = {
...linterConfig,
settings: {
next: {
rootDir: path.join(withNestedPagesDirectory, 'demos/with-nextjs'),
},
},
}
withoutPagesLinter.defineRules({ withoutPagesLinter.defineRules({
'no-html-link-for-pages': rule, 'no-html-link-for-pages': rule,
...@@ -57,6 +69,9 @@ withoutPagesLinter.defineRules({ ...@@ -57,6 +69,9 @@ withoutPagesLinter.defineRules({
withAppLinter.defineRules({ withAppLinter.defineRules({
'no-html-link-for-pages': rule, 'no-html-link-for-pages': rule,
}) })
withNestedPagesLinter.defineRules({
'no-html-link-for-pages': rule,
})
withCustomPagesLinter.defineRules({ withCustomPagesLinter.defineRules({
'no-html-link-for-pages': rule, 'no-html-link-for-pages': rule,
}) })
...@@ -212,6 +227,19 @@ export class Blah extends Head { ...@@ -212,6 +227,19 @@ export class Blah extends Head {
` `
describe('no-html-link-for-pages', function () { describe('no-html-link-for-pages', function () {
it('does not print warning when there are "pages" or "app" directories with rootDir in context settings', function () {
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation()
withNestedPagesLinter.verify(
validCode,
linterConfigWithNestedContentRootDirDirectory,
{
filename: 'foo.js',
}
)
expect(consoleSpy).not.toHaveBeenCalled()
consoleSpy.mockRestore()
})
it('prints warning when there are no "pages" or "app" directories', function () { it('prints warning when there are no "pages" or "app" directories', function () {
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation() const consoleSpy = jest.spyOn(console, 'warn').mockImplementation()
withoutPagesLinter.verify(validCode, linterConfig, { withoutPagesLinter.verify(validCode, linterConfig, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment