Unverified Commit 9de871e6 authored by Oscar Busk's avatar Oscar Busk Committed by GitHub

[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 `<head>` 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
parent f0e768e0
import path = require('path')
import { defineRule } from '../utils/define-rule' import { defineRule } from '../utils/define-rule'
const url = 'https://nextjs.org/docs/messages/no-head-element' const url = 'https://nextjs.org/docs/messages/no-head-element'
...@@ -18,9 +19,13 @@ export = defineRule({ ...@@ -18,9 +19,13 @@ export = defineRule({
JSXOpeningElement(node) { JSXOpeningElement(node) {
const paths = context.getFilename() 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 <head> element in pages directory // Only lint the <head> element in pages directory
if (node.name.name !== 'head' || isInAppDir) { if (node.name.name !== 'head' || isInAppDir()) {
return return
} }
......
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