Skip to content

Commit

Permalink
refactor(eslint): migrate to eslint-plugin-n (#12895)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 18, 2023
1 parent 93e095c commit 62ebe28
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 43 deletions.
45 changes: 20 additions & 25 deletions .eslintrc.cjs
Expand Up @@ -6,7 +6,7 @@ module.exports = defineConfig({
root: true,
extends: [
'eslint:recommended',
'plugin:node/recommended',
'plugin:n/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:regexp/recommended',
],
Expand All @@ -29,37 +29,32 @@ module.exports = defineConfig({
},
],

'node/no-missing-import': [
'error',
{
allowModules: ['types', 'estree', 'less', 'sass', 'stylus'],
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'],
},
],
'node/no-missing-require': [
'n/no-process-exit': 'off',
'n/no-missing-import': 'off',
'n/no-missing-require': [
'error',
{
// for try-catching yarn pnp
allowModules: ['pnpapi', 'vite'],
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'],
},
],
'node/no-extraneous-import': [
'n/no-extraneous-import': [
'error',
{
allowModules: ['vite', 'less', 'sass', 'vitest'],
allowModules: ['vite', 'less', 'sass', 'vitest', 'unbuild'],
},
],
'node/no-extraneous-require': [
'n/no-extraneous-require': [
'error',
{
allowModules: ['vite'],
},
],
'node/no-deprecated-api': 'off',
'node/no-unpublished-import': 'off',
'node/no-unpublished-require': 'off',
'node/no-unsupported-features/es-syntax': 'off',
'n/no-deprecated-api': 'off',
'n/no-unpublished-import': 'off',
'n/no-unpublished-require': 'off',
'n/no-unsupported-features/es-syntax': 'off',

'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/ban-types': 'off', // TODO: we should turn this on in a new PR
Expand Down Expand Up @@ -118,7 +113,7 @@ module.exports = defineConfig({
{
files: 'packages/vite/**/*.*',
rules: {
'node/no-restricted-require': [
'n/no-restricted-require': [
'error',
Object.keys(
require('./packages/vite/package.json').devDependencies,
Expand All @@ -141,32 +136,32 @@ module.exports = defineConfig({
{
files: ['packages/vite/src/types/**', '*.spec.ts'],
rules: {
'node/no-extraneous-import': 'off',
'n/no-extraneous-import': 'off',
},
},
{
files: ['packages/create-vite/template-*/**', '**/build.config.ts'],
rules: {
'no-undef': 'off',
'node/no-missing-import': 'off',
'n/no-missing-import': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
},
{
files: ['playground/**'],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off',
'node/no-missing-import': 'off',
'node/no-missing-require': 'off',
'n/no-extraneous-import': 'off',
'n/no-extraneous-require': 'off',
'n/no-missing-import': 'off',
'n/no-missing-require': 'off',
// engine field doesn't exist in playgrounds
'node/no-unsupported-features/es-builtins': [
'n/no-unsupported-features/es-builtins': [
'error',
{
version: '^14.18.0 || >=16.0.0',
},
],
'node/no-unsupported-features/node-builtins': [
'n/no-unsupported-features/node-builtins': [
'error',
{
version: '^14.18.0 || >=16.0.0',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -64,7 +64,7 @@
"eslint": "^8.36.0",
"eslint-define-config": "^1.17.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-regexp": "^1.13.0",
"execa": "^7.1.1",
"fast-glob": "^3.2.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-legacy/src/index.ts
@@ -1,4 +1,4 @@
/* eslint-disable node/no-extraneous-import */
/* eslint-disable n/no-extraneous-import */
import path from 'node:path'
import { createHash } from 'node:crypto'
import { createRequire } from 'node:module'
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/client/client.ts
Expand Up @@ -2,7 +2,6 @@ import type { ErrorPayload, HMRPayload, Update } from 'types/hmrPayload'
import type { ModuleNamespace, ViteHotContext } from 'types/hot'
import type { InferCustomEventPayload } from 'types/customEvent'
import { ErrorOverlay, overlayId } from './overlay'
// eslint-disable-next-line node/no-missing-import
import '@vite/env'

// injected by the hmr plugin when served
Expand Down
@@ -1,4 +1,3 @@
// eslint-disable-next-line node/no-missing-import
import { foo } from './non-existent.js'

export const hello = 'world'
2 changes: 0 additions & 2 deletions packages/vite/src/node/ssr/ssrTransform.ts
Expand Up @@ -9,8 +9,6 @@ import type {
Node as _Node,
} from 'estree'
import { extract_names as extractNames } from 'periscopic'
// `eslint-plugin-node` doesn't support package without main
// eslint-disable-next-line node/no-missing-import
import { walk as eswalk } from 'estree-walker'
import type { RawSourceMap } from '@ampproject/remapping'
import type { TransformResult } from '../server/transformRequest'
Expand Down
47 changes: 35 additions & 12 deletions pnpm-lock.yaml

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

0 comments on commit 62ebe28

Please sign in to comment.