-
Notifications
You must be signed in to change notification settings - Fork 26k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ESLint Plugin] Updates no-document-import-in-page
rule to use path
separators
#28768
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import path from 'path' | ||
|
||
import rule from '@next/eslint-plugin-next/lib/rules/no-document-import-in-page' | ||
import { RuleTester } from 'eslint' | ||
;(RuleTester as any).setDefaultConfig({ | ||
|
@@ -40,7 +42,7 @@ ruleTester.run('no-document-import-in-page', rule, { | |
} | ||
} | ||
`, | ||
filename: 'pages\\_document.js', | ||
filename: `pages${path.sep}_document.js`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
edit this is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for catching my mistake. |
||
}, | ||
{ | ||
code: `import NextDocument from "next/document" | ||
|
@@ -54,7 +56,7 @@ ruleTester.run('no-document-import-in-page', rule, { | |
} | ||
} | ||
`, | ||
filename: 'pages/_document.tsx', | ||
filename: `pages${path.posix.sep}_document.tsx`, | ||
}, | ||
{ | ||
code: `import Document from "next/document" | ||
|
@@ -147,7 +149,7 @@ ruleTester.run('no-document-import-in-page', rule, { | |
|
||
export const Test = () => <p>Test</p> | ||
`, | ||
filename: 'pages\\test.js', | ||
filename: `pages${path.sep}test.js`, | ||
errors: [ | ||
{ | ||
message: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test this on Windows?
For what I can tell, this will behave identical to the existing code.
https://nodejs.org/api/path.html#path_path_sep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't test it on Windows (don't have a VM I can use unfortunately), but I didn't submit this change to fix the particular issue of it it still failing in some instances. Just thought it would make more sense to use
path.sep
as @kimbaudi suggested even though it'll likely behave the exact same way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, i'm the one that was confused with
path.sep
andpath.posix.sep
. I just tested on Windows andpath.sep
is\\
andpath.posix.sep
is/
. and yes, this will behave same as existing code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had a build on Windows fail in CI (GitHub actions) due to this exact rule:
Edit:
./pages/_document.js
was the page it was attempting to build when the failure occurred.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just looked across the code, actually it seems to check out. So, now I'm not entirely sure what's gone wrong...