Unverified Commit ba0db6f1 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Convert eslint-config-next project to TypeScript (#84839)

This PR is a preparation for supporting Flat config, which the users will have to import `eslint-config-next` to use the plugin. Therefore, we need to generate types.
parent d0ffcfcb
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
}
}
module.exports = {
extends: [require.resolve('.'), 'plugin:@next/next/core-web-vitals-legacy'],
}
......@@ -2,13 +2,15 @@
"name": "eslint-config-next",
"version": "16.0.0-canary.5",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
"repository": {
"url": "vercel/next.js",
"directory": "packages/eslint-config-next"
},
"homepage": "https://nextjs.org/docs/app/api-reference/config/eslint",
"files": [
"dist"
],
"dependencies": {
"@next/eslint-plugin-next": "16.0.0-canary.5",
"@rushstack/eslint-patch": "^1.10.3",
......@@ -29,5 +31,33 @@
"typescript": {
"optional": true
}
},
"devDependencies": {
"@types/eslint": "9.6.1",
"typescript": "5.9.2"
},
"scripts": {
"dev": "pnpm build",
"build": "swc -d dist src && pnpm types",
"types": "tsc --skipLibCheck --declaration --emitDeclarationOnly --esModuleInterop --outDir dist",
"prepublishOnly": "cd ../../ && turbo run build"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./core-web-vitals": {
"types": "./dist/core-web-vitals.d.ts",
"default": "./dist/core-web-vitals.js"
},
"./typescript": {
"types": "./dist/typescript.d.ts",
"default": "./dist/typescript.js"
},
"./parser": {
"types": "./dist/parser.d.ts",
"default": "./dist/parser.js"
}
}
}
import type { Linter } from 'eslint'
const config: Linter.LegacyConfig = {
extends: [require.resolve('.'), 'plugin:@next/next/core-web-vitals-legacy'],
}
// Use `export =` instead of `export default` for ESLint parser compatibility.
// ESLint expects parser modules to be directly importable as CommonJS modules (module.exports).
export = config
import type { Linter } from 'eslint'
import module from 'module'
/*
* @rushstack/eslint-patch is used to include plugins as dev
* dependencies instead of imposing them as peer dependencies
*
* https://www.npmjs.com/package/@rushstack/eslint-patch
*/
const keptPaths = []
const sortedPaths = []
const keptPaths: string[] = []
const sortedPaths: string[] = []
const cwd = process.cwd().replace(/\\/g, '/')
const originalPaths = require.resolve.paths('eslint-plugin-import')
const originalPaths = require.resolve.paths('eslint-plugin-import') || []
// eslint throws a conflict error when plugins resolve to different
// locations, since we want to lock our dependencies by default
......@@ -40,9 +43,14 @@ const hookPropertyMap = new Map(
])
)
const mod = require('module')
const mod = module as any
const resolveFilename = mod._resolveFilename
mod._resolveFilename = function (request, parent, isMain, options) {
mod._resolveFilename = function (
request: string,
parent: any,
isMain?: boolean,
options?: any
) {
const hookResolved = hookPropertyMap.get(request)
if (hookResolved) {
request = hookResolved
......@@ -50,9 +58,11 @@ mod._resolveFilename = function (request, parent, isMain, options) {
return resolveFilename.call(mod, request, parent, isMain, options)
}
// TODO: Will remove soon as we convert this to flat config.
// eslint-disable-next-line @next/internal/typechecked-require
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
const config: Linter.LegacyConfig = {
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
......@@ -127,3 +137,7 @@ module.exports = {
node: true,
},
}
// Use `export =` instead of `export default` for ESLint parser compatibility.
// ESLint expects parser modules to be directly importable as CommonJS modules (module.exports).
export = config
import type { Linter } from 'eslint'
const {
parse,
parseForESLint,
// No types for compiled modules.
// eslint-disable-next-line @next/internal/typechecked-require
} = require('next/dist/compiled/babel/eslint-parser')
const { version } = require('./package.json')
const { version } = require('../package.json')
module.exports = {
const parser: Linter.Parser = {
parse,
parseForESLint,
meta: {
......@@ -12,3 +16,7 @@ module.exports = {
version,
},
}
// Use `export =` instead of `export default` for ESLint parser compatibility.
// ESLint expects parser modules to be directly importable as CommonJS modules (module.exports).
export = parser
module.exports = {
import type { Linter } from 'eslint'
const config: Linter.LegacyConfig = {
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/no-unused-vars': 1,
'@typescript-eslint/no-unused-expressions': 1,
},
}
export = config
{
"compilerOptions": {
"module": "commonjs",
"target": "es2019",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"declaration": true,
"resolveJsonModule": true,
"outDir": "dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
This diff is collapsed.
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