Skip to content

Commit

Permalink
Add sort-imports (microsoft#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanBoltonMN authored Dec 31, 2021
1 parent fb31020 commit 6fadccd
Show file tree
Hide file tree
Showing 74 changed files with 160 additions and 127 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ module.exports = {
"prettier/prettier": ["error"],
"security/detect-non-literal-fs-filename": "off",
"security/detect-object-injection": "off",
"sort-imports": [
"error",
{
allowSeparatedGroups: true,
ignoreCase: true,
},
],
},
};
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/assert.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { CommonError } from ".";
import { ErrorResult, OkResult, Result, ResultUtils } from "./result";
import { CommonError } from ".";

export function asDefined<T>(maybeValue: T | undefined, maybeMessage?: string, maybeDetails?: object): NonNullable<T> {
isDefined(maybeValue, maybeMessage, maybeDetails);
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Assert } from ".";
import { Localization, LocalizationUtils, Templates } from "../localization";
import { Assert } from ".";
import { ICancellationToken } from "./cancellationToken/ICancellationToken";

export type TInnerCommonError = CancellationError | InvariantError | UnknownError;
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/common/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT license.

import { Assert, CommonError, Result } from ".";
import { Ast } from "../language";
import { NodeIdMap, NodeIdMapUtils, ParseContext, TXorNode, XorNodeKind, XorNodeUtils } from "../parser";
import { Ast } from "../language";
import { ResultUtils } from "./result";

export type TriedTraverse<ResultType> = Result<ResultType, CommonError.CommonError>;
Expand Down
1 change: 0 additions & 1 deletion src/powerquery-parser/language/ast/astUtils/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

import * as TypeGuards from "./typeGuards";

import { Ast } from "..";
import { CommonError } from "../../../common";

Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/ast/astUtils/astUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ast } from "..";
import { Assert, CommonError } from "../../../common";
import { Ast } from "..";
import { Constant } from "../../constant";
import { TokenKind } from "../../token";

Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/constant/constantUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Constant } from ".";
import { Assert } from "../../common";
import { Constant } from ".";
import { TokenKind } from "../token";

export function maybeUnaryOperatorKindFrom(maybeTokenKind: TokenKind | undefined): Constant.UnaryOperator | undefined {
Expand Down
3 changes: 1 addition & 2 deletions src/powerquery-parser/language/type/typeUtils/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Licensed under the MIT license.

import * as isType from "./isType";

import { Type } from "..";
import { CommonError } from "../../../common";
import { Type } from "..";

export function assertAsAction(type: Type.TPowerQueryType): Type.Action {
assertIsAction(type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Assert, CommonError, ImmutableSet } from "../../../common";
import {
isEqualAnyUnion,
Expand All @@ -21,6 +20,7 @@ import {
isEqualTextLiteral,
isEqualType,
} from "./isEqualType";
import { Type } from "..";

export type TCategory = TExtendedCategory | NonExtendedCategory;
export type TExtendedCategory =
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/type/typeUtils/factories.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Assert, CommonError, StringUtils } from "../../../common";
import { PrimitiveTypeConstantMap, primitiveTypeMapKey } from "./primitive";
import { simplify } from "./simplify";
import { Type } from "..";

export function createPrimitiveType<T extends Type.TypeKind>(isNullable: boolean, typeKind: T): Type.TPrimitiveType {
const key: string = primitiveTypeMapKey(isNullable, typeKind);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Assert, CommonError, MapUtils } from "../../../common";
import { isEqualFunctionSignature, isEqualType } from "./isEqualType";
import { isFieldSpecificationList, isFunctionSignature } from "./isType";
import { Type } from "..";

// Returns `${left} is compatible with ${right}. Eg.
// `Type.TextInstance is compatible with Type.AnyInstance` -> true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { ArrayUtils, Assert, MapUtils } from "../../../common";
import { isTypeInArray } from "./typeUtils";
import { Type } from "..";

export function isEqualType(left: Type.TPowerQueryType, right: Type.TPowerQueryType): boolean {
if (left === right) {
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/type/typeUtils/isType.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Assert } from "../../../common";
import { Type } from "..";

export function isAction(type: Type.TPowerQueryType): type is Type.Action {
return type.kind === Type.TypeKind.Action;
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/language/type/typeUtils/nameOf.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Constant } from "../..";
import { Assert } from "../../../common";
import { Constant } from "../..";
import { Type } from "..";

export function nameOf(type: Type.TPowerQueryType): string {
if (type.kind === Type.TypeKind.Null) {
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/language/type/typeUtils/primitive.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Assert } from "../../../common";
import { Constant } from "../../constant";
import { Type } from "..";

export function maybePrimitiveTypeConstantKindFromTypeKind(
typeKind: Type.TypeKind,
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/language/type/typeUtils/simplify.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { ArrayUtils, ImmutableSet } from "../../../common";
import {
AnyCategory,
categorize,
Expand All @@ -16,7 +14,9 @@ import {
TextCategory,
TypeCategory,
} from "./categorize";
import { ArrayUtils, ImmutableSet } from "../../../common";
import { isEqualType } from "./isEqualType";
import { Type } from "..";

export function simplify(types: ReadonlyArray<Type.TPowerQueryType>): ReadonlyArray<Type.TPowerQueryType> {
const categorized: CategorizedPowerQueryTypes = categorize(types);
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/language/type/typeUtils/typeCheck.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { ArrayUtils } from "../../../common";
import { isCompatible, isCompatibleWithFunctionParameter } from "./isCompatible";
import { ArrayUtils } from "../../../common";
import { isEqualFunctionParameter } from "./isEqualType";
import { Type } from "..";

export type TChecked =
| CheckedDefinedFunction
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/language/type/typeUtils/typeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Type } from "..";
import { Ast, AstUtils } from "../..";
import { Assert } from "../../../common";
import { NodeIdMap, NodeIdMapUtils, ParseContext, XorNode, XorNodeKind } from "../../../parser";
import { Assert } from "../../../common";
import { createPrimitiveType } from "./factories";
import { isCompatible } from "./isCompatible";
import { isEqualType } from "./isEqualType";
import { Type } from "..";
import { typeKindFromPrimitiveTypeConstantKind } from "./primitive";

export function typeKindFromLiteralKind(literalKind: Ast.LiteralKind): Type.TypeKind {
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/lexer/error.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Lexer } from "..";
import { CommonError, StringUtils } from "../common";
import { Localization, LocalizationUtils } from "../localization";
import { Lexer } from "..";

export type TLexError = CommonError.CommonError | LexError;

Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/lexer/lexer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { LexError } from ".";
import {
ArrayUtils,
Assert,
Expand All @@ -16,6 +15,7 @@ import {
StringUtils,
} from "../common";
import { Keyword, Token } from "../language";
import { LexError } from ".";
import { LexSettings } from "../settings";

// Call Lexer.stateFrom to instantiate a new State instance.
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/lexer/lexerSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { LexError } from ".";
import { Lexer } from "..";
import { Assert, CommonError, ICancellationToken, Result, ResultUtils, StringUtils } from "../common";
import { Comment, Token } from "../language";
import { Lexer } from "..";
import { LexError } from ".";

// The lexer is a multiline aware lexer.
// That in part means multiline tokens are split up into <begin>, <content>, and <end> components.
Expand Down
8 changes: 4 additions & 4 deletions src/powerquery-parser/localization/localization.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Lexer } from "..";
import { Assert, StringUtils } from "../common";
import { Token } from "../language";
import { LexError } from "../lexer";
import { ParseError } from "../parser";
import { SequenceKind, TokenWithColumnNumber } from "../parser/error";
import { ILocalizationTemplates } from "./templates";
import { Lexer } from "..";
import { LexError } from "../lexer";
import { ParseError } from "../parser";
import { Token } from "../language";

interface ILocalization {
readonly error_common_cancellationError: (templates: ILocalizationTemplates) => string;
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/localization/templates.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Locale } from "./locale";
import * as bg_BG from "./templates/template.bg-BG.json";
import * as ca_ES from "./templates/template.ca-ES.json";
import * as cs_CZ from "./templates/template.cs-CZ.json";
import * as da_DK from "./templates/template.da-DK.json";
import * as de_DE from "./templates/template.de-DE.json";
import * as el_GR from "./templates/template.el-GR.json";
import * as en_US from "./templates/template.json";
import * as es_ES from "./templates/template.es-ES.json";
import * as et_EE from "./templates/template.et-EE.json";
import * as eu_ES from "./templates/template.eu-ES.json";
Expand All @@ -20,7 +20,6 @@ import * as hu_HU from "./templates/template.hu-HU.json";
import * as id_ID from "./templates/template.id-ID.json";
import * as it_IT from "./templates/template.it-IT.json";
import * as ja_JP from "./templates/template.ja-JP.json";
import * as en_US from "./templates/template.json";
import * as kk_KZ from "./templates/template.kk-KZ.json";
import * as ko_KR from "./templates/template.ko-KR.json";
import * as lt_LT from "./templates/template.lt-LT.json";
Expand All @@ -44,6 +43,7 @@ import * as uk_UA from "./templates/template.uk-UA.json";
import * as vi_VN from "./templates/template.vi-VN.json";
import * as zh_CN from "./templates/template.zh-CN.json";
import * as zh_TW from "./templates/template.zh-TW.json";
import { Locale } from "./locale";

export {
bg_BG,
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/parser/context/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { NodeIdMap } from "..";
import { Ast, Token } from "../../language";
import { NodeIdMap } from "..";

// Parsing use to be one giant evaluation, leading to an all-or-nothing outcome which was unsuitable for a
// document that was being live edited.
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/parser/context/contextUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { NodeIdMap, ParseContext } from "..";
import { ArrayUtils, Assert, CommonError, MapUtils, SetUtils, TypeScriptUtils } from "../../common";
import { Ast, Token } from "../../language";
import { NodeIdMap, ParseContext } from "..";
import { NodeIdMapIterator, NodeIdMapUtils, TXorNode } from "../nodeIdMap";

export function assertIsNodeKind<T extends Ast.TNode>(
Expand Down
4 changes: 2 additions & 2 deletions src/powerquery-parser/parser/disambiguation/disambiguation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ParseError } from "..";
import { Result } from "../../common";
import { Ast } from "../../language";
import { ParseError } from "..";
import { ParseState } from "../parseState";
import { Result } from "../../common";

export type TAmbiguousBracketNode = Ast.FieldProjection | Ast.FieldSelector | Ast.RecordExpression;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ParseError } from "..";
import { ArrayUtils, Assert, Result, ResultUtils, TypeScriptUtils } from "../../common";
import { Trace, TraceConstant } from "../../common/trace";
import { Ast, AstUtils, Constant, Token } from "../../language";
import { NodeIdMapUtils } from "../nodeIdMap";
import { Parser, ParseStateCheckpoint } from "../parser";
import { ParseState, ParseStateUtils } from "../parseState";
import {
AmbiguousParse,
BracketDisambiguation,
Expand All @@ -16,6 +9,13 @@ import {
TAmbiguousBracketNode,
TAmbiguousParenthesisNode,
} from "./disambiguation";
import { ArrayUtils, Assert, Result, ResultUtils, TypeScriptUtils } from "../../common";
import { Ast, AstUtils, Constant, Token } from "../../language";
import { Parser, ParseStateCheckpoint } from "../parser";
import { ParseState, ParseStateUtils } from "../parseState";
import { Trace, TraceConstant } from "../../common/trace";
import { NodeIdMapUtils } from "../nodeIdMap";
import { ParseError } from "..";

// For each given parse function it'll create a deep copy of the state then parse with the function.
// Mutates the given state to whatever parse state which matched the most amount of tokens.
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/parser/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT license.

import { Assert, CommonError, StringUtils } from "../common";
import { Token } from "../language";
import { Localization, LocalizationUtils } from "../localization";
import { ParseState } from "./parseState";
import { Token } from "../language";

export type TParseError = CommonError.CommonError | ParseError;

Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/parser/nodeIdMap/ancestryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT license.

import { NodeIdMap, NodeIdMapIterator, XorNodeUtils } from ".";
import { TXorNode, XorNode } from "./xorNode";
import { Assert } from "../../common";
import { Ast } from "../../language";
import { TXorNode, XorNode } from "./xorNode";

export function assertGetAncestry(nodeIdMapCollection: NodeIdMap.Collection, rootId: number): ReadonlyArray<TXorNode> {
const ancestryIds: number[] = [rootId];
Expand Down
2 changes: 1 addition & 1 deletion src/powerquery-parser/parser/nodeIdMap/nodeIdMap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ParseContext } from "..";
import { Ast } from "../../language";
import { ParseContext } from "..";

export type AstNodeById = NumberMap<Ast.TNode>;
export type ChildIdsById = NumberMap<ReadonlyArray<number>>;
Expand Down
Loading

0 comments on commit 6fadccd

Please sign in to comment.