Skip to content

Commit

Permalink
fix: enforce separate type imports (#9288)
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh authored Dec 4, 2023
1 parent bd99078 commit 4aa8091
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 45 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ module.exports = {
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-explicit-any': 'off',

// Enforce separate type imports for type-only imports to avoid bundling unneeded code
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
disallowTypeAnnotations: false,
},
],

// These rules enabled by the preset configs don't work well for us
'@typescript-eslint/await-thenable': 'off',
'prefer-const': 'off',
Expand Down
10 changes: 5 additions & 5 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import rss, { getRssString } from '../dist/index.js';
import { rssSchema } from '../dist/schema.js';
import chai from 'chai';
import chaiPromises from 'chai-as-promised';
import chaiXml from 'chai-xml';
import rss, { getRssString } from '../dist/index.js';
import { rssSchema } from '../dist/schema.js';
import {
title,
description,
site,
phpFeedItem,
phpFeedItemWithContent,
phpFeedItemWithCustomData,
site,
title,
web1FeedItem,
web1FeedItemWithContent,
web1FeedItemWithAllData,
web1FeedItemWithContent,
} from './test-utils.js';

chai.use(chaiPromises);
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/assets/build/generate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dim, green } from 'kleur/colors';
import fs, { readFileSync } from 'node:fs';
import { basename, join } from 'node:path/posix';
import PQueue from 'p-queue';
import type PQueue from 'p-queue';
import type { AstroConfig } from '../../@types/astro.js';
import type { BuildPipeline } from '../../core/build/buildPipeline.js';
import { getOutDirWithinCwd } from '../../core/build/common.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/buildPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AstroConfig, AstroSettings, SSRLoadedRenderer } from '../../@types
import { getOutputDirectory, isServerLikeOutput } from '../../prerender/utils.js';
import { BEFORE_HYDRATION_SCRIPT_ID } from '../../vite-plugin-scripts/index.js';
import type { SSRManifest } from '../app/types.js';
import { Logger } from '../logger/core.js';
import type { Logger } from '../logger/core.js';
import { Pipeline } from '../pipeline.js';
import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js';
import { createEnvironment } from '../render/index.js';
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
GetStaticPathsItem,
RouteData,
RouteType,
SSRElement,
SSRError,
SSRLoadedRenderer,
SSRManifest,
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { resolveConfig } from '../config/config.js';
import { createNodeLogger } from '../config/logging.js';
import { createSettings } from '../config/settings.js';
import { createVite } from '../create-vite.js';
import { Logger, levels, timerMessage } from '../logger/core.js';
import type { Logger } from '../logger/core.js';
import { levels, timerMessage } from '../logger/core.js';
import { apply as applyPolyfill } from '../polyfill.js';
import { RouteCache } from '../render/route-cache.js';
import { createRouteManifest } from '../routing/index.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/compile/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import type { AstroConfig } from '../../@types/astro.js';
import { transform } from '@astrojs/compiler';
import { fileURLToPath } from 'node:url';
import { normalizePath } from 'vite';
import { AggregateError, AstroError, CompilerError } from '../errors/errors.js';
import type { AstroError } from '../errors/errors.js';
import { AggregateError, CompilerError } from '../errors/errors.js';
import { AstroErrorData } from '../errors/index.js';
import { resolvePath } from '../util.js';
import { createStylePreprocessor } from './style.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/restart.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nodeFs from 'node:fs';
import type nodeFs from 'node:fs';
import { fileURLToPath } from 'node:url';
import * as vite from 'vite';
import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/logger/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import debugPackage from 'debug';
import { Writable } from 'node:stream';
import type { Writable } from 'node:stream';
import { getEventPrefix, levels, type LogMessage, type LogWritable } from './core.js';

type ConsoleStream = Writable & {
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/core/render/params-and-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { Logger } from '../logger/core.js';
import { routeIsFallback } from '../redirects/helpers.js';
import { routeIsRedirect } from '../redirects/index.js';
import { getParams } from '../routing/params.js';
import { RouteCache, callGetStaticPaths, findPathItemByKey } from './route-cache.js';
import type { RouteCache } from './route-cache.js';
import { callGetStaticPaths, findPathItemByKey } from './route-cache.js';

interface GetParamsAndPropsOptions {
mod: ComponentInstance | undefined;
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/render/route-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
RouteData,
RuntimeMode,
} from '../../@types/astro.js';
import { AstroError, AstroErrorData } from '../errors/index.js';
import type { Logger } from '../logger/core.js';

import { stringifyParams } from '../routing/params.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { SerializedSSRManifest } from '../core/app/types.js';
import type { PageBuildData } from '../core/build/types.js';
import { buildClientDirectiveEntrypoint } from '../core/client-directive/index.js';
import { mergeConfig } from '../core/config/index.js';
import { AstroIntegrationLogger, type Logger } from '../core/logger/core.js';
import type { AstroIntegrationLogger, Logger } from '../core/logger/core.js';
import { isServerLikeOutput } from '../prerender/utils.js';
import { validateSupportedFeatures } from './astroFeaturesValidation.js';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DevOverlayPlugin as DevOverlayPluginDefinition } from '../../../@types/astro.js';
import { type AstroDevOverlay, type DevOverlayPlugin } from './overlay.js';
import type { AstroDevOverlay, DevOverlayPlugin } from './overlay.js';
import { settings } from './settings.js';
// @ts-expect-error
import { loadDevOverlayPlugins } from 'astro:dev-overlay';
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/runtime/server/render/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { SSRResult } from '../../../@types/astro.js';
import type { RenderInstruction } from './instruction.js';

import { HTMLBytes, HTMLString, markHTMLString } from '../escape.js';
import type { HTMLBytes, HTMLString } from '../escape.js';
import { markHTMLString } from '../escape.js';
import {
determineIfNeedsHydrationScript,
determinesIfNeedsDirectiveScript,
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/runtime/server/render/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { createRenderInstruction, type RenderInstruction } from './instruction.j

import { clsx } from 'clsx';
import { AstroError, AstroErrorData } from '../../../core/errors/index.js';
import { HTMLBytes, markHTMLString } from '../escape.js';
import type { HTMLBytes } from '../escape.js';
import { markHTMLString } from '../escape.js';
import { extractDirectives, generateHydrateScript } from '../hydration.js';
import { serializeProps } from '../serialize.js';
import { shorthash } from '../shorthash.js';
Expand Down
9 changes: 2 additions & 7 deletions packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
TRANSITION_AFTER_SWAP,
TransitionBeforeSwapEvent,
doPreparation,
doSwap,
type TransitionBeforePreparationEvent,
} from './events.js';
import type { TransitionBeforePreparationEvent, TransitionBeforeSwapEvent } from './events.js';
import { TRANSITION_AFTER_SWAP, doPreparation, doSwap } from './events.js';
import type { Direction, Fallback, Options } from './types.js';

type State = {
Expand Down
8 changes: 2 additions & 6 deletions packages/astro/src/vite-plugin-astro/hmr.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { HmrContext, ModuleNode } from 'vite';
import type { AstroConfig } from '../@types/astro.js';
import {
cachedCompilation,
invalidateCompilation,
isCached,
type CompileResult,
} from '../core/compile/index.js';
import type { cachedCompilation } from '../core/compile/index.js';
import { invalidateCompilation, isCached, type CompileResult } from '../core/compile/index.js';
import type { Logger } from '../core/logger/core.js';
import { isAstroSrcFile } from '../core/logger/vite.js';
import { isAstroScript } from './query.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/i18n-routing.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';
import * as cheerio from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

describe('astro:i18n virtual module', () => {
/** @type {import('./test-utils').Fixture} */
Expand Down
12 changes: 6 additions & 6 deletions packages/integrations/markdoc/components/TreeNode.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { AstroInstance } from 'astro';
import type { RenderableTreeNode } from '@markdoc/markdoc';
import Markdoc from '@markdoc/markdoc';
import type { AstroInstance } from 'astro';
import type { HTMLString } from 'astro/runtime/server/index.js';
import {
createComponent,
renderComponent,
createHeadAndContent,
isHTMLString,
render,
renderComponent,
renderScriptElement,
renderTemplate,
renderUniqueStylesheet,
createHeadAndContent,
unescapeHTML,
renderTemplate,
HTMLString,
isHTMLString,
} from 'astro/runtime/server/index.js';

export type TreeNode =
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IncomingMessage, ServerResponse } from 'node:http';
import type { IncomingMessage, ServerResponse } from 'node:http';

export interface UserOptions {
/**
Expand Down
8 changes: 2 additions & 6 deletions packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import type { AstroConfig, AstroIntegration } from 'astro';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import {
EnumChangefreq,
simpleSitemapAndIndex,
type LinkItem as LinkItemBase,
type SitemapItemLoose,
} from 'sitemap';
import type { EnumChangefreq, LinkItem as LinkItemBase, SitemapItemLoose } from 'sitemap';
import { simpleSitemapAndIndex } from 'sitemap';
import { ZodError } from 'zod';

import { generateSitemap } from './generate-sitemap.js';
Expand Down

0 comments on commit 4aa8091

Please sign in to comment.