diff --git a/eslint.config.js b/eslint.config.js index 1b2ff21dc..caff4342c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -9,12 +9,7 @@ import globals from 'globals' export default tseslint.config( { - ignores: [ - '**/dist/**', - '**/playground-temp/**', - '**/temp/**', - 'packages/plugin-rsc/**', - ], + ignores: ['**/dist/**', '**/playground-temp/**', '**/temp/**'], }, eslint.configs.recommended, ...tseslint.configs.recommended, @@ -168,4 +163,83 @@ export default tseslint.config( '@typescript-eslint/triple-slash-reference': 'off', }, }, + { + name: 'plugin-rsc/import-sorting-only', + files: ['packages/plugin-rsc/**/*.?([cm])[jt]s?(x)'], + plugins: { + 'import-x': pluginImportX, + }, + rules: { + // Disable all existing rules from the main config + eqeqeq: 'off', + 'no-debugger': 'off', + 'no-empty': 'off', + 'no-empty-pattern': 'off', + 'no-constant-condition': 'off', + 'no-extra-boolean-cast': 'off', + 'prefer-const': 'off', + 'prefer-spread': 'off', + + // Disable Node.js plugin rules + 'n/no-process-exit': 'off', + 'n/no-deprecated-api': 'off', + 'n/no-unpublished-import': 'off', + 'n/no-unpublished-require': 'off', + 'n/no-unsupported-features/es-syntax': 'off', + 'n/no-unsupported-features/node-builtins': 'off', + 'n/no-unsupported-features/es-builtins': 'off', + 'n/no-missing-import': 'off', + 'n/no-missing-require': 'off', + 'n/no-extraneous-import': 'off', + 'n/no-extraneous-require': 'off', + + // Disable TypeScript rules + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-extra-semi': 'off', + '@typescript-eslint/no-inferrable-types': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/consistent-type-imports': 'off', + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/consistent-type-definitions': 'off', + '@typescript-eslint/prefer-for-of': 'off', + '@typescript-eslint/prefer-function-type': 'off', + '@typescript-eslint/consistent-indexed-object-style': 'off', + '@typescript-eslint/triple-slash-reference': 'off', + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', + '@typescript-eslint/no-namespace': 'off', + + // Disable regexp rules + 'regexp/prefer-regexp-exec': 'off', + 'regexp/prefer-regexp-test': 'off', + 'regexp/use-ignore-case': 'off', + 'regexp/no-super-linear-backtracking': 'off', + 'regexp/no-unused-capturing-group': 'off', + + // Disable other import rules except the ones we want + 'import-x/no-nodejs-modules': 'off', + + // Disable globals restriction + 'no-restricted-globals': 'off', + + // Enable only import sorting related rules + 'import-x/no-duplicates': 'error', + 'import-x/order': 'error', + 'sort-imports': [ + 'error', + { + ignoreCase: false, + ignoreDeclarationSort: true, + ignoreMemberSort: false, + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], + allowSeparatedGroups: false, + }, + ], + }, + }, ) diff --git a/packages/plugin-rsc/e2e/browser-mode.test.ts b/packages/plugin-rsc/e2e/browser-mode.test.ts index 42e2e6d6a..45fbbef7d 100644 --- a/packages/plugin-rsc/e2e/browser-mode.test.ts +++ b/packages/plugin-rsc/e2e/browser-mode.test.ts @@ -1,4 +1,4 @@ -import { expect, test, type Page } from '@playwright/test' +import { type Page, expect, test } from '@playwright/test' import { useFixture } from './fixture' import { defineStarterTest } from './starter' diff --git a/packages/plugin-rsc/e2e/build-app.test.ts b/packages/plugin-rsc/e2e/build-app.test.ts index d4b831cf8..cf323ca87 100644 --- a/packages/plugin-rsc/e2e/build-app.test.ts +++ b/packages/plugin-rsc/e2e/build-app.test.ts @@ -1,6 +1,6 @@ -import { test, expect } from '@playwright/test' -import { setupInlineFixture, useFixture } from './fixture' +import { expect, test } from '@playwright/test' import { x } from 'tinyexec' +import { setupInlineFixture, useFixture } from './fixture' import { waitForHydration } from './helper' test.describe('buildApp hook', () => { diff --git a/packages/plugin-rsc/e2e/isolated.test.ts b/packages/plugin-rsc/e2e/isolated.test.ts index a457daf5f..986112422 100644 --- a/packages/plugin-rsc/e2e/isolated.test.ts +++ b/packages/plugin-rsc/e2e/isolated.test.ts @@ -1,8 +1,8 @@ +import path from 'node:path' +import os from 'node:os' import { test } from '@playwright/test' import { setupIsolatedFixture, useFixture } from './fixture' import { defineStarterTest } from './starter' -import path from 'node:path' -import os from 'node:os' test.describe(() => { // use RUNNER_TEMP on Github Actions diff --git a/packages/plugin-rsc/e2e/no-ssr.test.ts b/packages/plugin-rsc/e2e/no-ssr.test.ts index 16e814162..b507b7a63 100644 --- a/packages/plugin-rsc/e2e/no-ssr.test.ts +++ b/packages/plugin-rsc/e2e/no-ssr.test.ts @@ -1,8 +1,8 @@ +import path from 'node:path' +import fs from 'node:fs' import { expect, test } from '@playwright/test' import { useFixture } from './fixture' import { defineStarterTest } from './starter' -import path from 'node:path' -import fs from 'node:fs' test.describe('dev-no-ssr', () => { const f = useFixture({ root: 'examples/no-ssr', mode: 'dev' }) diff --git a/packages/plugin-rsc/e2e/react-router.test.ts b/packages/plugin-rsc/e2e/react-router.test.ts index e62352e84..bb4f3ed77 100644 --- a/packages/plugin-rsc/e2e/react-router.test.ts +++ b/packages/plugin-rsc/e2e/react-router.test.ts @@ -1,9 +1,9 @@ import { createHash } from 'node:crypto' +import { readFileSync } from 'node:fs' import { expect, test } from '@playwright/test' +import React from 'react' import { type Fixture, useFixture } from './fixture' import { expectNoReload, testNoJs, waitForHydration } from './helper' -import { readFileSync } from 'node:fs' -import React from 'react' test.describe('dev-default', () => { test.skip(/canary|experimental/.test(React.version)) diff --git a/packages/plugin-rsc/e2e/render-built-url.test.ts b/packages/plugin-rsc/e2e/render-built-url.test.ts index 565bb499e..49c6b4bfc 100644 --- a/packages/plugin-rsc/e2e/render-built-url.test.ts +++ b/packages/plugin-rsc/e2e/render-built-url.test.ts @@ -1,8 +1,8 @@ +import fs from 'node:fs' import { expect, test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' import { defineStarterTest } from './starter' import { expectNoPageError, waitForHydration } from './helper' -import fs from 'node:fs' test.describe(() => { const root = 'examples/e2e/temp/renderBuiltUrl-runtime' diff --git a/packages/plugin-rsc/e2e/ssr-thenable.test.ts b/packages/plugin-rsc/e2e/ssr-thenable.test.ts index 7bf9e14e4..4b7e3d92b 100644 --- a/packages/plugin-rsc/e2e/ssr-thenable.test.ts +++ b/packages/plugin-rsc/e2e/ssr-thenable.test.ts @@ -1,5 +1,5 @@ import { test } from '@playwright/test' -import { setupInlineFixture, type Fixture, useFixture } from './fixture' +import { type Fixture, setupInlineFixture, useFixture } from './fixture' import { expectNoPageError, waitForHydration as waitForHydration_, diff --git a/packages/plugin-rsc/e2e/syntax-error.test.ts b/packages/plugin-rsc/e2e/syntax-error.test.ts index a44980d95..25e3b1a18 100644 --- a/packages/plugin-rsc/e2e/syntax-error.test.ts +++ b/packages/plugin-rsc/e2e/syntax-error.test.ts @@ -1,6 +1,6 @@ -import { test, expect } from '@playwright/test' +import { expect, test } from '@playwright/test' import { setupInlineFixture, useFixture } from './fixture' -import { waitForHydration, expectNoReload } from './helper' +import { expectNoReload, waitForHydration } from './helper' test.describe(() => { const root = 'examples/e2e/temp/syntax-error' diff --git a/packages/plugin-rsc/e2e/validate-imports.test.ts b/packages/plugin-rsc/e2e/validate-imports.test.ts index 7f032bad4..51910f0b6 100644 --- a/packages/plugin-rsc/e2e/validate-imports.test.ts +++ b/packages/plugin-rsc/e2e/validate-imports.test.ts @@ -1,6 +1,6 @@ -import { test, expect } from '@playwright/test' -import { setupInlineFixture, useFixture, type Fixture } from './fixture' +import { expect, test } from '@playwright/test' import { x } from 'tinyexec' +import { type Fixture, setupInlineFixture, useFixture } from './fixture' import { expectNoPageError, waitForHydration } from './helper' test.describe('validate imports', () => { diff --git a/packages/plugin-rsc/examples/basic/src/routes/root.tsx b/packages/plugin-rsc/examples/basic/src/routes/root.tsx index 41d73ace8..511da12a3 100644 --- a/packages/plugin-rsc/examples/basic/src/routes/root.tsx +++ b/packages/plugin-rsc/examples/basic/src/routes/root.tsx @@ -1,4 +1,5 @@ import React from 'react' +import TestDepCssInServer from '@vitejs/test-dep-css-in-server/server' import { TestServerActionBindAction, TestServerActionBindClient, @@ -31,7 +32,6 @@ import { TestReactCache } from './react-cache/server' import { TestHydrationMismatch } from './hydration-mismatch/server' import { TestBrowserOnly } from './browser-only/client' import { TestTransitiveCjsClient } from './deps/transitive-cjs/client' -import TestDepCssInServer from '@vitejs/test-dep-css-in-server/server' import { TestHmrSharedServer } from './hmr-shared/server' import { TestHmrSharedClient } from './hmr-shared/client' import { TestHmrSharedAtomic } from './hmr-shared/atomic/server' diff --git a/packages/plugin-rsc/examples/basic/vite.config.ts b/packages/plugin-rsc/examples/basic/vite.config.ts index 94df04e00..4db0945b6 100644 --- a/packages/plugin-rsc/examples/basic/vite.config.ts +++ b/packages/plugin-rsc/examples/basic/vite.config.ts @@ -1,10 +1,10 @@ import assert from 'node:assert' +import path from 'node:path' import rsc, { transformHoistInlineDirective } from '@vitejs/plugin-rsc' import tailwindcss from '@tailwindcss/vite' import react from '@vitejs/plugin-react' import { type Plugin, defineConfig, normalizePath, parseAstAsync } from 'vite' import inspect from 'vite-plugin-inspect' -import path from 'node:path' export default defineConfig({ clearScreen: false, diff --git a/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx b/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx index 343e6751c..f0966de2b 100644 --- a/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx +++ b/packages/plugin-rsc/examples/browser-mode/src/framework/entry.rsc.tsx @@ -1,7 +1,7 @@ import * as ReactServer from '@vitejs/plugin-rsc/react/rsc' import type React from 'react' -import { Root } from '../root' import type { ReactFormState } from 'react-dom/client' +import { Root } from '../root' export type RscPayload = { root: React.ReactNode diff --git a/packages/plugin-rsc/examples/no-ssr/vite.config.ts b/packages/plugin-rsc/examples/no-ssr/vite.config.ts index ce349c6e9..36cee6268 100644 --- a/packages/plugin-rsc/examples/no-ssr/vite.config.ts +++ b/packages/plugin-rsc/examples/no-ssr/vite.config.ts @@ -1,7 +1,7 @@ +import fsp from 'node:fs/promises' import rsc from '@vitejs/plugin-rsc' import react from '@vitejs/plugin-react' -import { defineConfig, type Plugin } from 'vite' -import fsp from 'node:fs/promises' +import { type Plugin, defineConfig } from 'vite' export default defineConfig({ plugins: [ diff --git a/packages/plugin-rsc/examples/react-router/react-router-vite/entry.browser.tsx b/packages/plugin-rsc/examples/react-router/react-router-vite/entry.browser.tsx index 56e028872..2d267310e 100644 --- a/packages/plugin-rsc/examples/react-router/react-router-vite/entry.browser.tsx +++ b/packages/plugin-rsc/examples/react-router/react-router-vite/entry.browser.tsx @@ -4,13 +4,13 @@ import { encodeReply, setServerCallback, } from '@vitejs/plugin-rsc/browser' -import { startTransition, StrictMode } from 'react' +import { StrictMode, startTransition } from 'react' import { hydrateRoot } from 'react-dom/client' import { - unstable_createCallServer as createCallServer, - unstable_getRSCStream as getRSCStream, unstable_RSCHydratedRouter as RSCHydratedRouter, type unstable_RSCPayload as RSCServerPayload, + unstable_createCallServer as createCallServer, + unstable_getRSCStream as getRSCStream, } from 'react-router' // Create and set the callServer function to support post-hydration server actions. diff --git a/packages/plugin-rsc/examples/react-router/react-router-vite/entry.ssr.tsx b/packages/plugin-rsc/examples/react-router/react-router-vite/entry.ssr.tsx index c80cde622..8ad5e4af1 100644 --- a/packages/plugin-rsc/examples/react-router/react-router-vite/entry.ssr.tsx +++ b/packages/plugin-rsc/examples/react-router/react-router-vite/entry.ssr.tsx @@ -1,8 +1,8 @@ import { createFromReadableStream } from '@vitejs/plugin-rsc/ssr' import { renderToReadableStream as renderHTMLToReadableStream } from 'react-dom/server.edge' import { - unstable_routeRSCServerRequest as routeRSCServerRequest, unstable_RSCStaticRouter as RSCStaticRouter, + unstable_routeRSCServerRequest as routeRSCServerRequest, } from 'react-router' export async function generateHTML( diff --git a/packages/plugin-rsc/src/core/rsc.ts b/packages/plugin-rsc/src/core/rsc.ts index d00452555..585380212 100644 --- a/packages/plugin-rsc/src/core/rsc.ts +++ b/packages/plugin-rsc/src/core/rsc.ts @@ -1,4 +1,5 @@ import { memoize, tinyassert } from '@hiogawa/utils' +import * as ReactServer from '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' import type { BundlerConfig, ImportManifestEntry, ModuleMap } from '../types' import { SERVER_DECODE_CLIENT_PREFIX, @@ -9,7 +10,6 @@ import { } from './shared' // @ts-ignore -import * as ReactServer from '@vitejs/plugin-rsc/vendor/react-server-dom/server.edge' let init = false let requireModule!: (id: string) => unknown diff --git a/packages/plugin-rsc/src/transforms/test-utils.ts b/packages/plugin-rsc/src/transforms/test-utils.ts index 31818b9a2..7a4f53370 100644 --- a/packages/plugin-rsc/src/transforms/test-utils.ts +++ b/packages/plugin-rsc/src/transforms/test-utils.ts @@ -1,6 +1,6 @@ import { dirname } from 'path' -import { hashString } from '@hiogawa/utils' import { mkdir, writeFile } from 'fs/promises' +import { hashString } from '@hiogawa/utils' import type MagicString from 'magic-string' export async function debugSourceMap(output: MagicString): Promise { diff --git a/packages/plugin-rsc/src/vite-utils.ts b/packages/plugin-rsc/src/vite-utils.ts index d65a5f008..89726ec88 100644 --- a/packages/plugin-rsc/src/vite-utils.ts +++ b/packages/plugin-rsc/src/vite-utils.ts @@ -2,8 +2,8 @@ import fs from 'node:fs' import path from 'node:path' -import type { DevEnvironment, ErrorPayload, Rollup } from 'vite' import { stripVTControlCharacters as strip } from 'node:util' +import type { DevEnvironment, ErrorPayload, Rollup } from 'vite' export const VALID_ID_PREFIX = `/@id/`