Unverified Commit 2aa68ae2 authored by 최지원's avatar 최지원 Committed by GitHub

fix: eslint not ignoring "/app" (#50261)

## Why?
```
src/app/layout.tsx
```
![code](https://github.com/vercel/next.js/assets/120007119/3cc991f8-a96d-4ffb-9f84-4dfdbcac5318)

**eslint[@next/next/no-before-interactive-script-outside-document](https://nextjs.org/docs/messages/no-before-interactive-script-outside-document)**
> `next/script`'s `beforeInteractive` strategy should not be used outside of `pages/_document.js`. 

## How?
- Possibility of pathname starts with "/" on OS X and Linux, so added condition to check file path starting with "/"
- e.g. "/src/app" or "/app"
- Added test code



Passed 
- `pnpm build && pnpm lint`
- `pnpm jest test/unit/eslint-plugin-next/no-before-interactive-script-outside-document.test.ts`

Extends #46609
Fixes #50096
Fixes NEXT-1230

parent 62af2007
......@@ -34,10 +34,15 @@ export = defineRule({
if (startsWithUsingCorrectSeparators(pathname, 'src/')) {
pathname = pathname.slice(4)
} else if (startsWithUsingCorrectSeparators(pathname, '/src/')) {
pathname = pathname.slice(5)
}
// This rule shouldn't fire in `app/`
if (startsWithUsingCorrectSeparators(pathname, 'app/')) {
if (
startsWithUsingCorrectSeparators(pathname, 'app/') ||
startsWithUsingCorrectSeparators(pathname, '/app/')
) {
return
}
......
......@@ -163,6 +163,40 @@ ruleTester.run('no-before-interactive-script-outside-document', rule, {
}`,
filename: 'src/app/deep/randomFile.tsx',
},
{
code: `
import Script from "next/script";
export default function Index() {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<Script
src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js?a=scriptBeforeInteractive"
strategy='beforeInteractive'
/>
</html>
);
}`,
filename: '/src/app/layout.tsx',
},
{
code: `
import Script from "next/script";
export default function Index() {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<Script
src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js?a=scriptBeforeInteractive"
strategy='beforeInteractive'
/>
</html>
);
}`,
filename: '/app/layout.tsx',
},
].map((obj, idx) => ({
...obj,
code: `// valid-${idx}
......
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