Skip to content

Commit

Permalink
refactor: add @ianvs/prettier-plugin-sort-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpza committed Aug 19, 2024
1 parent 36643ff commit 3cd353b
Show file tree
Hide file tree
Showing 28 changed files with 525 additions and 75 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";

export default [
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
],
"devDependencies": {
"@eslint/js": "^9.8.0",
"@ianvs/prettier-plugin-sort-imports": "^4.3.1",
"@tsconfig/node18": "^18.2.4",
"@types/eslint": "^9",
"@types/minimatch": "^5.1.2",
Expand All @@ -86,7 +87,8 @@
},
"prettier": {
"plugins": [
"prettier-plugin-jsdoc"
"prettier-plugin-jsdoc",
"@ianvs/prettier-plugin-sort-imports"
]
},
"packageManager": "[email protected]+sha512.91d93b445d9284e7ed52931369bc89a663414e5582d00eea45c67ddc459a2582919eece27c412d6ffd1bd0793ff35399381cb229326b961798ce4f4cc60ddfdb"
Expand Down
2 changes: 1 addition & 1 deletion src/harmony/versions/four-seven.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-48 */
import type {
default as TsCurrentModule,
AssertClause,
ExportDeclaration,
Expression,
Expand All @@ -11,6 +10,7 @@ import type {
ModuleDeclaration,
ModuleName,
NamedExportBindings,
default as TsCurrentModule,
} from "typescript";
import type TsFourSevenModule from "typescript-4.7";
import type { TsTransformPathsContext } from "../../types";
Expand Down
2 changes: 1 addition & 1 deletion src/harmony/versions/three-eight.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/** Changes after this point: https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#typescript-40 */
import type {
default as TsCurrentModule,
EntityName,
ExportDeclaration,
Expression,
Expand All @@ -15,6 +14,7 @@ import type {
ModuleName,
NamedExportBindings,
NamedImportBindings,
default as TsCurrentModule,
TypeNode,
} from "typescript";
import type TsThreeEightModule from "typescript-3";
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import transformer from "./transformer";

export default transformer;

export { TsTransformPathsConfig } from "./types";
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/nx-transformer-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import transformer from "../transformer";
import ts from "typescript";
import transformer from "../transformer";

export interface TsTransformPathsConfig {
readonly useRootDirs?: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/transformer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from "path";
import { Minimatch } from "minimatch";
import { TransformerExtras } from "ts-patch";
import ts, { CompilerOptions } from "typescript";
import { RunMode, TsNodeState, TsTransformPathsConfig, TsTransformPathsContext, VisitorContext } from "./types";
import { nodeVisitor } from "./visitor";
import { createHarmonyFactory } from "./harmony";
import { Minimatch } from "minimatch";
import { RunMode, TsNodeState, TsTransformPathsConfig, TsTransformPathsContext, VisitorContext } from "./types";
import { createSyntheticEmitHost, getTsNodeRegistrationProperties } from "./utils/ts-helpers";
import { TransformerExtras } from "ts-patch";
import { nodeVisitor } from "./visitor";

/* ****************************************************************************************************************** */
// region: Helpers
Expand Down
5 changes: 2 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ts, { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript";
import { PluginConfig } from "ts-patch";
import { Minimatch } from "minimatch";

import { PluginConfig } from "ts-patch";
import ts, { CompilerOptions, EmitHost, Pattern, SourceFile } from "typescript";
import { HarmonyFactory } from "./harmony";

/* ****************************************************************************************************************** */
Expand Down
2 changes: 1 addition & 1 deletion src/utils/elide-import-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* import { A, B } from "./b";
* export { A } from "./b";
*/
import { ImportOrExportDeclaration, VisitorContext } from "../types";
import {
Debug,
EmitResolver,
Expand All @@ -53,6 +52,7 @@ import {
Visitor,
VisitResult,
} from "typescript";
import { ImportOrExportDeclaration, VisitorContext } from "../types";

/* ****************************************************************************************************************** */
// region: Utilities
Expand Down
2 changes: 1 addition & 1 deletion src/utils/general-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import url from "url";
import path from "path";
import url from "url";

/* ****************************************************************************************************************** *
* General Utilities & Helpers
Expand Down
6 changes: 3 additions & 3 deletions src/utils/resolve-module-name.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { VisitorContext } from "../types";
import { isBaseDir, isURL, maybeAddRelativeLocalPrefix } from "./general-utils";
import * as path from "path";
import { removeFileExtension, removeSuffix, ResolvedModuleFull, SourceFile } from "typescript";
import { getOutputDirForSourceFile } from "./ts-helpers";
import { VisitorContext } from "../types";
import { isBaseDir, isURL, maybeAddRelativeLocalPrefix } from "./general-utils";
import { getRelativePath } from "./get-relative-path";
import { getOutputDirForSourceFile } from "./ts-helpers";

/* ****************************************************************************************************************** */
// region: Types
Expand Down
2 changes: 1 addition & 1 deletion src/utils/resolve-path-update-node.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ts from "typescript";
import { VisitorContext } from "../types";
import { isURL, maybeAddRelativeLocalPrefix } from "./general-utils";
import { isModulePathsMatch } from "./ts-helpers";
import { resolveModuleName } from "./resolve-module-name";
import { isModulePathsMatch } from "./ts-helpers";

/* ****************************************************************************************************************** */
// region: Node Updater Utility
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ts-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ts, { GetCanonicalFileName, SourceFile } from "typescript";
import path from "path";
import { VisitorContext } from "../types";
import type { REGISTER_INSTANCE } from "ts-node";
import ts, { GetCanonicalFileName, SourceFile } from "typescript";
import { VisitorContext } from "../types";

/* ****************************************************************************************************************** */
// region: TS Helpers
Expand Down
2 changes: 1 addition & 1 deletion test/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import ts from "typescript";
import tsThree from "typescript-3";
import tsFourSeven from "typescript-4.7";
import path from "path";

export { ts };

Expand Down
3 changes: 2 additions & 1 deletion test/projects/extras/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "#identifier";
import { b } from "#identifier";

export * from "#identifier";

console.log(b);
15 changes: 8 additions & 7 deletions test/projects/general/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { NoRuntimecodeHere, subs } from "@utils/index";
import "@circular/b";
import * as path from "path";
import { A } from "@circular/a";
import { myNative } from "@utils/utils.native";
import * as b from "circular/a";
import * as c from "../circular/a";

// @ts-ignore
import sum = require("@utils/sum");
export { sum } from "@utils/index";
export { g } from "#utils/hello";
export { sum as sum2 } from "#utils/sum";
export { NoRuntimecodeHere } from "@utils/types-only";
import { subs, NoRuntimecodeHere } from "@utils/index";
import "@circular/b";
import { A } from "@circular/a";
import * as path from "path";
import * as b from "circular/a";
import * as c from "../circular/a";
import { myNative } from "@utils/utils.native";

c.A;
b.A;
Expand Down
1 change: 1 addition & 0 deletions test/projects/nx/packages/library1/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { name as library2Name } from "library2";

export default library2Name;

console.log(library2Name);
5 changes: 3 additions & 2 deletions test/projects/specific/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { A as ATypeOnly } from "#root/dir/src-file";
import type ATypeOnlyDefault from "#root/dir/src-file";

export { b } from "#root/dir/gen-file";
export { a } from "#root/dir/src-file";

import type { A as ATypeOnly } from "#root/dir/src-file";
import type ATypeOnlyDefault from "#root/dir/src-file";
export { ATypeOnly, ATypeOnlyDefault };

import(/* webpackChunkName: "Comment" */ "#root/dir/src-file");
Expand Down
25 changes: 9 additions & 16 deletions test/projects/specific/src/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,38 @@

/** @no-transform-path */
import * as skipTransform1 from "#root/index";

/**
* @multi-tag1
* @no-transform-path
* @multi-tag2
*/
import * as skipTransform2 from "#root/index";
/* ****************************************************************************************************************** *
* JS Tag
* ****************************************************************************************************************** */

// @no-transform-path
import * as skipTransform3 from "#root/index";
// @multi-tag1
// @no-transform-path
// @multi-tag2
import * as skipTransform4 from "#root/index";
/**
* @multi-tag1
* @transform-path ./dir/src-file
* @multi-tag2
*/
import * as explicitTransform1 from "./index";

/**
* @multi-tag1
* @transform-path http://www.go.com/react.js
* @multi-tag2
*/
import * as explicitTransform2 from "./index";

/* ****************************************************************************************************************** *
* JS Tag
* ****************************************************************************************************************** */

// @no-transform-path
import * as skipTransform3 from "#root/index";

// @multi-tag1
// @no-transform-path
// @multi-tag2
import * as skipTransform4 from "#root/index";

// @multi-tag1
// @transform-path ./dir/src-file
// @multi-tag2
import * as explicitTransform3 from "./index";

// @multi-tag1
// @transform-path http://www.go.com/react.js
// @multi-tag2
Expand Down
25 changes: 16 additions & 9 deletions test/projects/specific/src/type-elision/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { ConstB, TypeA } from "#elision/a";
import { TypeA as TypeA2 } from "#elision/a";
/* Import type */

/* Export type */

/* Unreferenced import type */ import {
ConstB as __,
ConstB as ___,
ConstB as ____,
ConstB,
TypeA,
TypeA as TypeA2,
TypeAndConst as TypeAndConst2,
type TypeAndConst,
type TypeAndConst as TypeAndConst3,
} from "#elision/a";

export { ConstB, TypeA };
export { TypeA2 };

/* Import type */
import { type TypeAndConst, ConstB as __ } from "#elision/a";
export { TypeAndConst, __ };

/* Export type */
import { TypeAndConst as TypeAndConst2, ConstB as ___ } from "#elision/a";
export { type TypeAndConst2, ___ };

const b = TypeAndConst2;

/* Unreferenced import type */
import { ConstB as ____, type TypeAndConst as TypeAndConst3 } from "#elision/a";
6 changes: 3 additions & 3 deletions test/tests/extras.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createTsProgram, getEmitResultFromProgram, ModuleNotFoundError } from "../utils";
import { projectsPaths } from "../config";
import { execSync } from "child_process";
import path from "path";
import ts from "typescript";
import { projectsPaths } from "../config";
import * as config from "../config";
import { execSync } from "child_process";
import { createTsProgram, getEmitResultFromProgram, ModuleNotFoundError } from "../utils";

/* ****************************************************************************************************************** *
* Tests
Expand Down
3 changes: 0 additions & 3 deletions test/tests/nx.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { execSync } from "node:child_process";
import { readFileSync, rmSync } from "node:fs";
import path from "node:path";

import ts from "typescript";

import { nxTransformerPlugin } from "typescript-transform-paths";
import * as transformerModule from "../../dist/transformer";

import { projectsPaths } from "../config";

/* ****************************************************************************************************************** *
Expand Down
2 changes: 1 addition & 1 deletion test/tests/project-ref.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// noinspection ES6UnusedImports
import * as path from "path";
import { createTsSolutionBuilder, EmittedFiles } from "../utils";
import { projectsPaths, ts } from "../config";
import { createTsSolutionBuilder, EmittedFiles } from "../utils";

/* ****************************************************************************************************************** *
* Config
Expand Down
2 changes: 0 additions & 2 deletions test/tests/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import * as tsNode from "ts-node";
import { REGISTER_INSTANCE } from "ts-node";
import { PluginConfig } from "ts-patch";
import { CustomTransformers, PluginImport, Program } from "typescript";

import { register } from "typescript-transform-paths";
import * as transformerModule from "../../dist/transformer";

import { ModuleNotFoundError } from "../utils";

/* ****************************************************************************************************************** *
Expand Down
2 changes: 1 addition & 1 deletion test/tests/transformer/general.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// noinspection ES6UnusedImports
import * as path from "path";
import { projectsPaths, ts, tsModules } from "../../config";
import { createTsProgram, EmittedFiles, getEmitResultFromProgram } from "../../utils";
import { ts, tsModules, projectsPaths } from "../../config";

/* ****************************************************************************************************************** *
* Helpers
Expand Down
6 changes: 3 additions & 3 deletions test/tests/transformer/specific.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// noinspection ES6UnusedImports
import * as path from "path";
import TS from "typescript";
import { TsTransformPathsConfig } from "typescript-transform-paths";
import { projectsPaths, ts, tsModules } from "../../config";
import {
createTsProgram,
EmittedFiles,
getEmitResultFromProgram,
getManualEmitResult,
getTsNodeEmitResult,
} from "../../utils";
import { projectsPaths, ts, tsModules } from "../../config";
import { TsTransformPathsConfig } from "typescript-transform-paths";
import TS from "typescript";

/* ****************************************************************************************************************** *
* Config
Expand Down
4 changes: 2 additions & 2 deletions test/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { default as tstpTransform, TsTransformPathsConfig } from "typescript-transform-paths";
import fs from "fs";
import ts from "typescript";
import * as tsNode from "ts-node";
import ts from "typescript";
import { default as tstpTransform, TsTransformPathsConfig } from "typescript-transform-paths";
import * as config from "../config";

/* ****************************************************************************************************************** */
Expand Down
Loading

0 comments on commit 3cd353b

Please sign in to comment.