Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eslint-plugin-simple-import-sort #52090

Merged
merged 14 commits into from
Feb 2, 2023
Merged
17 changes: 11 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"es6": true
},
"plugins": [
"@typescript-eslint", "no-null", "import", "eslint-plugin-local"
"@typescript-eslint", "no-null", "import", "eslint-plugin-local", "simple-import-sort"
],
"ignorePatterns": [
"**/node_modules/**",
Expand All @@ -25,11 +25,8 @@
"/coverage/**"
],
"rules": {
"sort-imports": ["error", {
"ignoreCase": true,
"ignoreDeclarationSort": true,
"allowSeparatedGroups": true
}],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",

"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
Expand Down Expand Up @@ -180,6 +177,14 @@
{ "name": "exports" }
]
}
},
{
// These files contain imports in a specific order that are generally unsafe to modify.
"files": ["**/_namespaces/**"],
"rules": {
"simple-import-sort/imports": "off",
"simple-import-sort/exports": "off"
}
}
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
// ".git-blame-ignore-revs"
// ]

// Match eslint-plugin-simple-import-sort in organize/auto-imports.
"typescript.unstable": {
"organizeImportsCollation": "unicode",
"organizeImportsCaseFirst": "upper",
"organizeImportsIgnoreCase": false,
"organizeImportsNumericCollation": true
},

// These options search the repo recursively and slow down
// the build task menu. We define our own in tasks.json.
"typescript.tsc.autoDetect": "off",
Expand Down
25 changes: 13 additions & 12 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// @ts-check
import path from "path";
import fs from "fs";
import { CancelToken } from "@esfx/canceltoken";
import chalk from "chalk";
import chokidar from "chokidar";
import del from "del";
import { task } from "hereby";
import esbuild from "esbuild";
import { EventEmitter } from "events";
import fs from "fs";
import fsExtra from "fs-extra";
import _glob from "glob";
import { task } from "hereby";
import path from "path";
import util from "util";
import chalk from "chalk";
import fsExtra from "fs-extra";
import { Debouncer, Deferred, exec, getDiffTool, getDirSize, memoize, needsUpdate, readJson } from "./scripts/build/utils.mjs";
import { localBaseline, localRwcBaseline, refBaseline, refRwcBaseline, runConsoleTests } from "./scripts/build/tests.mjs";
import { buildProject, cleanProject, watchProject } from "./scripts/build/projects.mjs";

import { localizationDirectories } from "./scripts/build/localization.mjs";
import cmdLineOptions from "./scripts/build/options.mjs";
import esbuild from "esbuild";
import chokidar from "chokidar";
import { EventEmitter } from "events";
import { CancelToken } from "@esfx/canceltoken";
import { buildProject, cleanProject, watchProject } from "./scripts/build/projects.mjs";
import { localBaseline, localRwcBaseline, refBaseline, refRwcBaseline, runConsoleTests } from "./scripts/build/tests.mjs";
import { Debouncer, Deferred, exec, getDiffTool, getDirSize, memoize, needsUpdate, readJson } from "./scripts/build/utils.mjs";

const glob = util.promisify(_glob);

Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-local": "^1.0.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"fast-xml-parser": "^4.0.11",
"fs-extra": "^9.1.0",
"glob": "latest",
Expand Down
2 changes: 1 addition & 1 deletion scripts/browserIntegrationTest.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from "chalk";
import { join } from "path";
import { readFileSync } from "fs";
import { join } from "path";

let playwright;
try {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/findUpDir.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname, join, resolve } from "path";
import { existsSync } from "fs";
import { dirname, join, resolve } from "path";
import url from "url";

const __filename = url.fileURLToPath(new URL(import.meta.url));
Expand Down
3 changes: 2 additions & 1 deletion scripts/build/projects.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Debouncer, exec } from "./utils.mjs";
import { resolve } from "path";

import { findUpRoot } from "./findUpDir.mjs";
import cmdLineOptions from "./options.mjs";
import { Debouncer, exec } from "./utils.mjs";

class ProjectQueue {
/**
Expand Down
7 changes: 4 additions & 3 deletions scripts/build/tests.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { CancelError } from "@esfx/canceltoken";
import chalk from "chalk";
import del from "del";
import fs from "fs";
import os from "os";
import path from "path";
import chalk from "chalk";

import { findUpFile, findUpRoot } from "./findUpDir.mjs";
import cmdLineOptions from "./options.mjs";
import { exec } from "./utils.mjs";
import { findUpFile, findUpRoot } from "./findUpDir.mjs";
import { CancelError } from "@esfx/canceltoken";

const mochaJs = path.resolve(findUpRoot(), "node_modules", "mocha", "bin", "_mocha");
export const localBaseline = "tests/baselines/local/";
Expand Down
10 changes: 5 additions & 5 deletions scripts/build/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* eslint-disable no-restricted-globals */

import fs from "fs";
import path from "path";
import { CancelError } from "@esfx/canceltoken";
import assert from "assert";
import chalk from "chalk";
import which from "which";
import { spawn } from "child_process";
import assert from "assert";
import fs from "fs";
import JSONC from "jsonc-parser";
import { CancelError } from "@esfx/canceltoken";
import path from "path";
import which from "which";

/**
* Executes the provided command once with the supplied arguments.
Expand Down
2 changes: 1 addition & 1 deletion scripts/configurePrerelease.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { normalize, relative } from "path";
import assert from "assert";
import { readFileSync, writeFileSync } from "fs";
import { normalize, relative } from "path";
import url from "url";

const __filename = url.fileURLToPath(new URL(import.meta.url));
Expand Down
5 changes: 3 additions & 2 deletions scripts/dtsBundler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* bundle as namespaces again, even though the project is modules.
*/

import assert, { fail } from "assert";
import fs from "fs";
import path from "path";
import minimist from "minimist";
import path from "path";
import url from "url";

import ts from "../lib/typescript.js";
import assert, { fail } from "assert";

const __filename = url.fileURLToPath(new URL(import.meta.url));
const __dirname = path.dirname(__filename);
Expand Down
2 changes: 1 addition & 1 deletion scripts/find-unused-diganostic-messages.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// This file requires a modern version of node 14+, and grep to be available.

// node scripts/find-unused-diagnostic-messages.mjs
import { execSync } from "child_process";
import { readFileSync } from "fs";
import { EOL } from "os";
import { execSync } from "child_process";

const diags = readFileSync("src/compiler/diagnosticInformationMap.generated.ts", "utf8");
const startOfDiags = diags.split("export const Diagnostics")[1];
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateLocalizedDiagnosticMessages.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { XMLParser } from "fast-xml-parser";
import fs from "fs";
import path from "path";
import { XMLParser } from "fast-xml-parser";

/** @typedef {{
LCX: {
Expand Down
4 changes: 2 additions & 2 deletions scripts/importDefinitelyTypedTests.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as childProcess from "child_process";
import * as fs from "fs";
import * as path from "path";
import * as os from "os";
import * as childProcess from "child_process";
import * as path from "path";
import url from "url";

const __filename = url.fileURLToPath(new URL(import.meta.url));
Expand Down
1 change: 1 addition & 0 deletions scripts/link-hooks.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs";
import path from "path";
import url from "url";

import { findUpRoot } from "./build/findUpDir.mjs";

const __filename = url.fileURLToPath(new URL(import.meta.url));
Expand Down
3 changes: 2 additions & 1 deletion scripts/open-cherry-pick-pr.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Octokit } from "@octokit/rest";
import { runSequence } from "./run-sequence.mjs";
import fs from "fs";
import path from "path";
import url from "url";

import { runSequence } from "./run-sequence.mjs";

const __filename = url.fileURLToPath(new URL(import.meta.url));
const __dirname = path.dirname(__filename);

Expand Down
1 change: 1 addition & 0 deletions scripts/open-user-pr.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "@octokit/rest";

import { runSequence } from "./run-sequence.mjs";

const userName = process.env.GH_USERNAME || "typescript-bot";
Expand Down
4 changes: 2 additions & 2 deletions scripts/perf-result-post.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Octokit } from "@octokit/rest";
import fs from "fs";
import assert from "assert";
import ado from "azure-devops-node-api";
import fs from "fs";
import fetch from "node-fetch";
import assert from "assert";


async function main() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/processDiagnosticMessages.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import fs from "fs";
import path from "path";

/** @typedef {{
category: string;
Expand Down
5 changes: 3 additions & 2 deletions scripts/produceLKG.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import del from "del";
import fs from "fs-extra";
import path from "path";
import glob from "glob";
import path from "path";
import url from "url";
import del from "del";

import { localizationDirectories } from "./build/localization.mjs";

const __filename = url.fileURLToPath(new URL(import.meta.url));
Expand Down
1 change: 1 addition & 0 deletions scripts/update-experimental-branches.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "@octokit/rest";

import { runSequence } from "./run-sequence.mjs";

// The first is used by bot-based kickoffs, the second by automatic triggers
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,8 @@ import {
WithStatement,
YieldExpression,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers";
import * as performance from "./_namespaces/ts.performance";

const ambientModuleSymbolRegex = /^".+"$/;
const anon = "(anonymous)" as __String & string;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ import {
tryExtractTSExtension,
tryGetExtensionFromPath,
tryParsePatterns,
version,
Version,
version,
versionMajorMinor,
VersionRange,
} from "./_namespaces/ts";
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ import {
transformECMAScriptModule,
Transformer,
TransformerFactory,
transformES5,
transformES2015,
transformES2016,
transformES2017,
transformES2018,
transformES2019,
transformES2020,
transformES2021,
transformES5,
transformESDecorators,
transformESNext,
transformGenerators,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ import {
HasExpressionInitializer,
hasExtension,
HasFlowNode,
hasInitializer,
HasInitializer,
hasInitializer,
HasJSDoc,
hasJSDocNodes,
HasModifiers,
Expand Down
2 changes: 1 addition & 1 deletion src/deprecatedCompat/deprecate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
DeprecationOptions,
formatStringFromArgs,
noop,
version,
Version,
version,
} from "./_namespaces/ts";

export let enableDeprecationWarnings = true;
Expand Down
4 changes: 2 additions & 2 deletions src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as performance from "../compiler/_namespaces/ts.performance";
import * as ts from "./_namespaces/ts";
import {
arrayFrom,
Expand All @@ -19,8 +20,8 @@ import {
createDiagnosticReporter,
createGetCanonicalFileName,
createIncrementalCompilerHost,
createProgram,
CreateProgram,
createProgram,
CreateProgramOptions,
createSolutionBuilder,
createSolutionBuilderHost,
Expand Down Expand Up @@ -87,7 +88,6 @@ import {
WatchCompilerHost,
WatchOptions,
} from "./_namespaces/ts";
import * as performance from "../compiler/_namespaces/ts.performance";

interface Statistic {
name: string;
Expand Down
Loading