File size: 917 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import path = require('path')
import { defineRule } from '../utils/define-rule'
const url = 'https://nextjs.org/docs/messages/no-head-element'
export = defineRule({
meta: {
docs: {
description: 'Prevent usage of `<head>` element.',
category: 'HTML',
recommended: true,
url,
},
type: 'problem',
schema: [],
},
create(context) {
return {
JSXOpeningElement(node) {
const paths = context.filename
const isInAppDir = () =>
paths.includes(`app${path.sep}`) ||
paths.includes(`app${path.posix.sep}`)
// Only lint the <head> element in pages directory
if (node.name.name !== 'head' || isInAppDir()) {
return
}
context.report({
node,
message: `Do not use \`<head>\` element. Use \`<Head />\` from \`next/head\` instead. See: ${url}`,
})
},
}
},
})
|