Skip to content

Commit

Permalink
Disable head element lint rule for appDir (#40921)
Browse files Browse the repository at this point in the history
Only lint `<head>` elements usage in `pages/`, `<head>` should be able
to use in appDir
  • Loading branch information
huozhi committed Sep 26, 2022
1 parent 3837aa1 commit 82682a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/eslint-plugin-next/lib/rules/no-head-element.js
Expand Up @@ -14,7 +14,11 @@ module.exports = {
create: function (context) {
return {
JSXOpeningElement(node) {
if (node.name.name !== 'head') {
const paths = context.getFilename()

const isInAppDir = paths.includes('app/') && !paths.includes('pages/')
// Only lint the <head> element in pages directory
if (node.name.name !== 'head' || isInAppDir) {
return
}

Expand Down
17 changes: 16 additions & 1 deletion test/unit/eslint-plugin-next/no-head-element.test.ts
Expand Up @@ -48,6 +48,21 @@ ruleTester.run('no-head-element', rule, {
`,
filename: 'pages/index.tsx',
},
{
code: `
export default function Layout({ children }) {
return (
<html>
<head>
<title>layout</title>
</head>
<body>{children}</body>
</html>
);
}
`,
filename: './app/layout.js',
},
],
invalid: [
{
Expand All @@ -63,7 +78,7 @@ ruleTester.run('no-head-element', rule, {
);
}
}`,
filename: 'pages/index.js',
filename: './pages/index.js',
errors: [
{
message:
Expand Down

0 comments on commit 82682a3

Please sign in to comment.