Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: replace deprecated/removed functions in eslint-plugin-next #64251

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"glob": "10.3.10"
},
"devDependencies": {
"eslint": "7.24.0"
"eslint": "8.56.0"
},
"scripts": {
"build": "swc -d dist src",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export = defineRule({
scriptImportName = node.local.name
},
JSXOpeningElement(node) {
const pathname = convertToCorrectSeparator(context.getFilename())
const pathname = convertToCorrectSeparator(context.filename)

const isInAppDir = pathname.includes(`${path.sep}app${path.sep}`)

Expand Down Expand Up @@ -57,7 +57,7 @@ export = defineRule({
return
}

const document = context.getFilename().split('pages', 2)[1]
const document = context.filename.split('pages', 2)[1]
if (document && path.parse(document).name.startsWith('_document')) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export = defineRule({
return
}

const paths = context.getFilename().split('pages')
const paths = context.filename.split('pages')
const page = paths[paths.length - 1]

if (
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-next/src/rules/no-duplicate-head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export = defineRule({
schema: [],
},
create(context) {
const { sourceCode } = context
let documentImportName
return {
ImportDeclaration(node) {
Expand All @@ -26,7 +27,7 @@ export = defineRule({
}
},
ReturnStatement(node) {
const ancestors = context.getAncestors()
const ancestors = sourceCode.getAncestors(node)
const documentClass = ancestors.find(
(ancestorNode) =>
ancestorNode.type === 'ClassDeclaration' &&
Expand All @@ -39,7 +40,6 @@ export = defineRule({
return
}

// @ts-expect-error - `node.argument` could be a `JSXElement` which has property `children`
if (
node.argument &&
'children' in node.argument &&
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/src/rules/no-head-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export = defineRule({
create(context) {
return {
JSXOpeningElement(node) {
const paths = context.getFilename()
const paths = context.filename

const isInAppDir = () =>
paths.includes(`app${path.sep}`) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export = defineRule({
return
}

const document = context.getFilename().split('pages', 2)[1]
const document = context.filename.split('pages', 2)[1]
if (!document) {
return
}
Expand Down
5 changes: 3 additions & 2 deletions packages/eslint-plugin-next/src/rules/no-page-custom-font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export = defineRule({
schema: [],
},
create(context) {
const paths = context.getFilename().split('pages')
const { sourceCode } = context
const paths = context.filename.split('pages')
const page = paths[paths.length - 1]

// outside of a file within `pages`, bail
Expand Down Expand Up @@ -71,7 +72,7 @@ export = defineRule({
return
}

const ancestors = context.getAncestors()
const ancestors = sourceCode.getAncestors(node)

// if `export default <name>` is further down within the file after the
// currently traversed component, then `localDefaultExportName` will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export = defineRule({
create(context) {
return {
JSXOpeningElement(node) {
const document = context.getFilename().split('pages', 2)[1]
const document = context.filename.split('pages', 2)[1]
if (!document) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/src/rules/no-typos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export = defineRule({
}
return {
ExportNamedDeclaration(node) {
const page = context.getFilename().split('pages', 2)[1]
const page = context.filename.split('pages', 2)[1]
if (!page || path.parse(page).dir.startsWith('/api')) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/src/utils/get-root-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const processRootDir = (rootDir: string): string[] => {
* Gets one or more Root, returns an array of root directories.
*/
export const getRootDirs = (context: Rule.RuleContext) => {
let rootDirs = [context.getCwd()]
let rootDirs = [context.cwd]

const nextSettings: { rootDir?: string | string[] } =
context.settings.next || {}
Expand Down
35 changes: 11 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading