Skip to content

Commit 01701e3

Browse files
authored
Merge pull request #279 from microsoftgraph/zengin/lintingFixes
Fix linting errors in TypeScript namespace generation
2 parents ec7009c + d4a8169 commit 01701e3

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

Templates/TypeScript/src/entity_types.ts.tt

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ export as namespace microsoftgraph;
2323
export type NullableOption<T> = T | null;
2424

2525
<#=typeScriptNamespaces.MainNamespace.ToString()#>
26-
2726
<#
2827
foreach (var subNamespace in typeScriptNamespaces.SubNamespaces)
2928
{
30-
#>
31-
<#=subNamespace.Value.ToString()#>
32-
<#
29+
#><#=subNamespace.Value.ToString()#><#
3330
}
34-
#>
31+
#>

src/GraphODataTemplateWriter/CodeHelpers/TypeScript/TypeScriptNamespace.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,17 @@ public override string ToString()
111111
/// <param name="enumType">enum</param>
112112
private void AddEnum(OdcmEnum enumType)
113113
{
114+
var export = IsMainNamespace ? "export " : string.Empty;
114115
var enumTypeName = enumType.Name.UpperCaseFirstChar();
115116
var enumValues = enumType.GetEnumValues();
116-
var exportTypeLength = "export type".Length + enumTypeName.Length + enumValues.Length + 3;
117+
var exportTypeLength = (export + "type").Length + enumTypeName.Length + enumValues.Length + 3;
117118
if (exportTypeLength < MaxLineLength)
118119
{
119-
sb.AppendLine($"{NamespaceIndent}export type {enumTypeName} = {enumValues};");
120+
sb.AppendLine($"{NamespaceIndent}{export}type {enumTypeName} = {enumValues};");
120121
}
121122
else
122123
{
123-
sb.AppendLine($"{NamespaceIndent}export type {enumTypeName} =");
124+
sb.AppendLine($"{NamespaceIndent}{export}type {enumTypeName} =");
124125
var enums = enumValues.Split('|');
125126
sb.Append($"{NamespaceIndent}{TabSpace}| ");
126127
sb.Append(string.Join(Environment.NewLine + NamespaceIndent + TabSpace + "| ", enums.Select(@enum => @enum.Trim())));
@@ -141,6 +142,7 @@ private void AddEnum(OdcmEnum enumType)
141142
/// <param name="class">entity or complex type</param>
142143
private void AddEntityOrComplexType(OdcmClass @class)
143144
{
145+
var export = IsMainNamespace ? "export " : string.Empty;
144146
var propCount = @class.Properties.Count;
145147
var entityTypeName = @class.Name.UpperCaseFirstChar();
146148
if (propCount == 0 && entityTypeName[0] == 'I')
@@ -159,7 +161,7 @@ private void AddEntityOrComplexType(OdcmClass @class)
159161
var extendsStatement = @class.Base == null
160162
? string.Empty
161163
: $" extends {GetFullyQualifiedTypeScriptTypeName(@class.Base.GetTypeString(), @class.Base.Namespace.GetNamespaceName())}";
162-
var exportInterfaceLine = NamespaceIndent + "export interface " + entityTypeName + extendsStatement + " {";
164+
var exportInterfaceLine = NamespaceIndent + $"{export}interface " + entityTypeName + extendsStatement + " {";
163165
if (propCount == 0)
164166
{
165167
sb.AppendLine(exportInterfaceLine + "}");

test/Typewriter.Test/TestDataTypeScript/com/microsoft/graph/src/Microsoft-graph.d.ts

+30-32
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,22 @@ export interface IdentitySet {
9090
user?: NullableOption<Identity>;
9191
}
9292

93-
9493
export namespace CallRecords {
95-
export type CallType = "unknown" | "groupCall";
96-
export type ClientPlatform = "unknown" | "windows";
97-
export type FailureStage = "unknown" | "callSetup";
98-
export type MediaStreamDirection = "callerToCallee" | "calleeToCaller";
99-
export type NetworkConnectionType = "unknown" | "wired";
100-
export type ProductFamily = "unknown" | "teams";
101-
export type ServiceRole = "unknown" | "customBot";
102-
export type UserFeedbackRating = "notRated" | "bad";
103-
export type WifiBand = "unknown" | "frequency24GHz";
104-
export type WifiRadioType = "unknown" | "wifi80211a";
105-
export type Modality = "audio" | "video";
106-
export interface SingletonEntity1 extends microsoftgraph.Entity {
94+
type CallType = "unknown" | "groupCall";
95+
type ClientPlatform = "unknown" | "windows";
96+
type FailureStage = "unknown" | "callSetup";
97+
type MediaStreamDirection = "callerToCallee" | "calleeToCaller";
98+
type NetworkConnectionType = "unknown" | "wired";
99+
type ProductFamily = "unknown" | "teams";
100+
type ServiceRole = "unknown" | "customBot";
101+
type UserFeedbackRating = "notRated" | "bad";
102+
type WifiBand = "unknown" | "frequency24GHz";
103+
type WifiRadioType = "unknown" | "wifi80211a";
104+
type Modality = "audio" | "video";
105+
interface SingletonEntity1 extends microsoftgraph.Entity {
107106
testSingleNav?: NullableOption<microsoftgraph.TestType>;
108107
}
109-
export interface CallRecord extends microsoftgraph.Entity {
108+
interface CallRecord extends microsoftgraph.Entity {
110109
version?: number;
111110
type?: CallType;
112111
modalities?: Modality[];
@@ -119,7 +118,7 @@ export namespace CallRecords {
119118
sessions?: NullableOption<Session[]>;
120119
recipients?: NullableOption<microsoftgraph.EntityType2[]>;
121120
}
122-
export interface Session extends microsoftgraph.Entity {
121+
interface Session extends microsoftgraph.Entity {
123122
modalities?: Modality[];
124123
startDateTime?: string;
125124
endDateTime?: string;
@@ -128,7 +127,7 @@ export namespace CallRecords {
128127
failureInfo?: NullableOption<FailureInfo>;
129128
segments?: NullableOption<Segment[]>;
130129
}
131-
export interface Segment extends microsoftgraph.Entity {
130+
interface Segment extends microsoftgraph.Entity {
132131
startDateTime?: string;
133132
endDateTime?: string;
134133
caller?: NullableOption<Endpoint>;
@@ -141,42 +140,42 @@ export namespace CallRecords {
141140
photo?: NullableOption<Photo>;
142141
}
143142
// tslint:disable-next-line: no-empty-interface
144-
export interface Option extends microsoftgraph.Entity {}
145-
export interface Photo extends microsoftgraph.Entity {
143+
interface Option extends microsoftgraph.Entity {}
144+
interface Photo extends microsoftgraph.Entity {
146145
failureInfo?: NullableOption<FailureInfo>;
147146
option?: NullableOption<Option>;
148147
}
149-
export interface Endpoint {
148+
interface Endpoint {
150149
userAgent?: NullableOption<UserAgent>;
151150
}
152-
export interface UserAgent {
151+
interface UserAgent {
153152
headerValue?: NullableOption<string>;
154153
applicationVersion?: NullableOption<string>;
155154
}
156-
export interface FailureInfo {
155+
interface FailureInfo {
157156
stage?: FailureStage;
158157
reason?: NullableOption<string>;
159158
}
160-
export interface Media {
159+
interface Media {
161160
label?: NullableOption<string>;
162161
callerNetwork?: NullableOption<NetworkInfo>;
163162
callerDevice?: NullableOption<DeviceInfo>;
164163
streams?: NullableOption<MediaStream[]>;
165164
}
166-
export interface NetworkInfo {
165+
interface NetworkInfo {
167166
connectionType?: NetworkConnectionType;
168167
wifiBand?: WifiBand;
169168
basicServiceSetIdentifier?: NullableOption<string>;
170169
wifiRadioType?: WifiRadioType;
171170
wifiSignalStrength?: NullableOption<number>;
172171
bandwidthLowEventRatio?: NullableOption<number>;
173172
}
174-
export interface DeviceInfo {
173+
interface DeviceInfo {
175174
captureDeviceName?: NullableOption<string>;
176175
sentSignalLevel?: NullableOption<number>;
177176
speakerGlitchRate?: NullableOption<number>;
178177
}
179-
export interface MediaStream {
178+
interface MediaStream {
180179
streamId?: NullableOption<string>;
181180
startDateTime?: NullableOption<string>;
182181
streamDirection?: MediaStreamDirection;
@@ -185,25 +184,24 @@ export namespace CallRecords {
185184
lowVideoProcessingCapabilityRatio?: NullableOption<number>;
186185
averageAudioNetworkJitter?: NullableOption<string>;
187186
}
188-
export interface ParticipantEndpoint extends Endpoint {
187+
interface ParticipantEndpoint extends Endpoint {
189188
identity?: NullableOption<microsoftgraph.IdentitySet>;
190189
feedback?: NullableOption<UserFeedback>;
191190
}
192-
export interface UserFeedback {
191+
interface UserFeedback {
193192
text?: NullableOption<string>;
194193
rating?: UserFeedbackRating;
195194
tokens?: NullableOption<FeedbackTokenSet>;
196195
}
197196
// tslint:disable-next-line: no-empty-interface
198-
export interface FeedbackTokenSet {}
197+
interface FeedbackTokenSet {}
199198
// tslint:disable-next-line: no-empty-interface
200-
export interface ServiceEndpoint extends Endpoint {}
201-
export interface ClientUserAgent extends UserAgent {
199+
interface ServiceEndpoint extends Endpoint {}
200+
interface ClientUserAgent extends UserAgent {
202201
platform?: ClientPlatform;
203202
productFamily?: ProductFamily;
204203
}
205-
export interface ServiceUserAgent extends UserAgent {
204+
interface ServiceUserAgent extends UserAgent {
206205
role?: ServiceRole;
207206
}
208207
}
209-

0 commit comments

Comments
 (0)