From 9de871e61be72ba8bd4040ed0b7fdc531edf8c0b Mon Sep 17 00:00:00 2001 From: Oscar Busk Date: Wed, 2 Nov 2022 21:43:39 +0100 Subject: [PATCH] [eslint-plugin] Stop warning for head element in app/layout on Windows (#42336) ## Bug ![image](https://user-images.githubusercontent.com/13413409/199451248-051751e5-0a5b-4ee0-bcae-05d2933f0090.png) When trying to use app directory on Windows, the automatically created `Layout.tsx` get's a lint problem for having a `` element. ## Solution Update the rule to check paths using `path.sep` rather than hardcoded `/` I also checked with `path.posix.sep` because some other rules was doing that (both `path.sep` and `path.posix.sep`), so I'm just following pattern --- packages/eslint-plugin-next/src/rules/no-head-element.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin-next/src/rules/no-head-element.ts b/packages/eslint-plugin-next/src/rules/no-head-element.ts index 1bcd4874cf4c5..1852b34eca3f9 100644 --- a/packages/eslint-plugin-next/src/rules/no-head-element.ts +++ b/packages/eslint-plugin-next/src/rules/no-head-element.ts @@ -1,3 +1,4 @@ +import path = require('path') import { defineRule } from '../utils/define-rule' const url = 'https://nextjs.org/docs/messages/no-head-element' @@ -18,9 +19,13 @@ export = defineRule({ JSXOpeningElement(node) { const paths = context.getFilename() - const isInAppDir = paths.includes('app/') && !paths.includes('pages/') + const isInAppDir = () => + (paths.includes(`app${path.sep}`) || + paths.includes(`app${path.posix.sep}`)) && + !paths.includes(`pages${path.sep}`) && + !paths.includes(`pages${path.posix.sep}`) // Only lint the element in pages directory - if (node.name.name !== 'head' || isInAppDir) { + if (node.name.name !== 'head' || isInAppDir()) { return }