Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply no-html-link-for-pages rule to app directory #68099

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export = defineRule({
}

const pageUrls = getUrlFromPagesDirectories('/', foundPagesDirs)
const appUrls = getUrlFromPagesDirectories('/', foundAppDirs)

return {
JSXOpeningElement(node) {
if (node.name.name !== 'a') {
Expand Down Expand Up @@ -134,7 +136,7 @@ export = defineRule({
return
}

pageUrls.forEach((pageUrl) => {
;[...pageUrls, ...appUrls].forEach((pageUrl) => {
if (pageUrl.test(normalizeURL(hrefPath))) {
context.report({
node,
Expand Down
22 changes: 22 additions & 0 deletions test/unit/eslint-plugin-next/no-html-link-for-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ describe('no-html-link-for-pages', function () {
assert.deepEqual(report, [])
})

it('valid link element with app linter', function () {
const report = withAppLinter.verify(validCode, linterConfig, {
filename: 'foo.js',
})
assert.deepEqual(report, [])
})

it('valid link element with multiple directories', function () {
const report = withCustomPagesLinter.verify(
validCode,
Expand Down Expand Up @@ -332,6 +339,21 @@ describe('no-html-link-for-pages', function () {
)
})

it('invalid static route with app directory linter', function () {
const [report] = withAppLinter.verify(
invalidStaticCode,
linterConfigWithCustomDirectory,
{
filename: 'foo.js',
}
)
assert.notEqual(report, undefined, 'No lint errors found.')
assert.equal(
report.message,
'Do not use an `<a>` element to navigate to `/`. Use `<Link />` from `next/link` instead. See: https://nextjs.org/docs/messages/no-html-link-for-pages'
)
})

it('invalid dynamic route', function () {
const [report] = withCustomPagesLinter.verify(
invalidDynamicCode,
Expand Down
Loading