Skip to content

Commit

Permalink
tsp format and linter stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjprescott committed Apr 16, 2024
1 parent 46c5f81 commit 1f42ff5
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 88 deletions.
80 changes: 70 additions & 10 deletions packages/compiler/test/formatter/scenarios/inputs/alias.tsp
Original file line number Diff line number Diff line change
@@ -1,20 +1,80 @@
alias UnionOfType = Foo | Bar;

alias UnionOfManyType = "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "height" | "nine" | "ten";
alias UnionOfManyType =
| "one"
| "two"
| "three"
| "four"
| "five"
| "six"
| "seven"
| "height"
| "nine"
| "ten";

alias UnionOfObject = {foo: string} | {bar: string};
alias UnionOfObject = {
foo: string;
} | {
bar: string;
};

alias UnionOfManyObject = {one: string} | {two: string} | {three: string} | {four: string} | {five: string};
alias UnionOfManyObject =
| {
one: string;
}
| {
two: string;
}
| {
three: string;
}
| {
four: string;
}
| {
five: string;
};

alias UnionOfMix = Foo | { bar: string};
alias UnionOfMix = Foo | {
bar: string;
};

alias UnionOfManyMix = Foo | { bar: string} | Bar | Other | {other: string};
alias UnionOfManyMix =
| Foo
| {
bar: string;
}
| Bar
| Other
| {
other: string;
};

alias InterOfObject = {foo: string} & {bar: string};
alias InterOfObject = {
foo: string;
} & {
bar: string;
};

alias InterOfManyObject = {one: string} & {two: string} & {three: string} & {four: string} & {five: string};
alias InterOfManyObject = {
one: string;
} & {
two: string;
} & {
three: string;
} & {
four: string;
} & {
five: string;
};

alias InterOfMix = Foo & { bar: string};

alias InterOfManyMix = Foo & { bar: string} & Bar & Other & {other: string};
alias InterOfMix = Foo & {
bar: string;
};

alias InterOfManyMix = Foo & {
bar: string;
} & Bar &
Other & {
other: string;
};
25 changes: 8 additions & 17 deletions packages/compiler/test/formatter/scenarios/inputs/interface.tsp
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
interface
Foo {
x (
n: int32
) :
string,
y (x: int32, y: int32): int32
interface Foo {
x(n: int32): string;
y(x: int32, y: int32): int32;
}

interface Bar extends
ResourceOperations<BarResource> {
interface Bar extends ResourceOperations<BarResource> {
blerp(n: int32): string;
}

interface Baz extends ResourceRead<BarResource>,

ResourceCreate<BarResource>, ResourceDelete<BarResource>
{
interface Baz
extends ResourceRead<BarResource>,
ResourceCreate<BarResource>,
ResourceDelete<BarResource> {
glorp(n: int32): string;
}


interface WithMultipleOperation {

keepSeparation1(): string;



keepSeperation2(): string;
}
76 changes: 46 additions & 30 deletions packages/compiler/test/formatter/scenarios/inputs/misc.tsp
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
import "@typespec/rest";
import "@typespec/rest";
import "@typespec/openapi";
import "@typespec/openapi3";

alias Bar = "that" | "this";
alias Bar = "that" | "this";

// This is a comment
alias VeryLong = "one" | "two" | "three" | "four" | "five" | "six" | "seven" | "height" | "nine" | "ten";

alias Inter = {foo: string} & {bar: string} ;


alias Inter2 = Foo &
Inter;

alias Generic< A, B> = A | B;
alias VeryLong =
| "one"
| "two"
| "three"
| "four"
| "five"
| "six"
| "seven"
| "height"
| "nine"
| "ten";

alias Inter = {
foo: string;
} & {
bar: string;
};

alias Inter2 = Foo & Inter;

alias Generic<A, B> = A | B;

/**
* Model comment
* Model comment
*/
model Foo {
id: number;
type: Bar;
type: Bar;

/*
* Name is special and comment is unaligned.
*/
name?: string = "foo";
isArray: string[] ;

address: { street: string, country?: string};

* Name is special and comment is unaligned.
*/
name?: string = "foo";

isArray: string[];
address: {
street: string;
country?: string;
};
...Bar;
}


@bar
enum SomeEnum { A, B, C}

enum
SomeNamedEnum { A: "a",
B: "b", @val() C: "c" }

enum SomeEnum {
A,
B,
C,
}

enum SomeNamedEnum {
A: "a",
B: "b",
@val C: "c",
}

/**
* Multi line comment still works,
Expand All @@ -50,9 +67,8 @@ enum
@resource("/operations")
namespace Operations {
// Comment here too
@get @doc("Abc") op get(@path id: string): OkResponse<OperationStatusResult>;

@get @doc("Abc") op get(@path id: string): OkResponse<OperationStatusResult>;

#suppress "no-list-op" "This is actually needed"
#suppress "no-list-op" "This is actually needed"
@get op list(): OkResponse<OperationListResult> | ErrorResponse;
}
31 changes: 13 additions & 18 deletions packages/compiler/test/formatter/scenarios/inputs/model.tsp
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
model Empty {
}
model Empty {}

model WithProps {
foo: string;
bar: string
model WithProps {
foo: string;
bar: string;
}

model WithSpreadAndProps {
foo: string;
... WithProps


other:
int16;
foo: string;
...WithProps;
other: int16;
}

model GenericExtension<T> extends Parent<T> {

}
model GenericExtension<T> extends Parent<T> {}

model Foo<
T extends string,
K extends {
foo: int32;
some: string;
eveneveneveneveneveneven: string;
someveryveryveryveryverylong: string;
}> {}
some: string;
eveneveneveneveneveneven: string;
someveryveryveryveryverylong: string;
}
> {}
5 changes: 3 additions & 2 deletions packages/compiler/test/formatter/scenarios/inputs/union.tsp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
union Foo
<x, y> { x: int32 }
union Foo<x, y> {
x: int32,
}
1 change: 0 additions & 1 deletion packages/compiler/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { formatDiagnostic, logVerboseTestOutput } from "../src/core/diagnostics.
import { hasParseError, parse, visitChildren } from "../src/core/parser.js";
import {
IdentifierNode,
NamespaceStatementNode,
Node,
ParseOptions,
SourceFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import "@typespec/http";

using TypeSpec.Http;

@service({ title: "Accounting firm" }) namespace MyOrg.Accounting;


@service({
title: "Accounting firm",
})
namespace MyOrg.Accounting;

model Account {
id: string;
name: string;
balance: decimal128;
id: string;
name: string;
balance: decimal128;
}

interface Accounts {

@route(":open") open(account: Account): void;
@route(":close") close(id: string): void;

@route(":open") open(account: Account): void;
@route(":close") close(id: string): void;
}

0 comments on commit 1f42ff5

Please sign in to comment.