Skip to content

Commit 88d94af

Browse files
Merge pull request #208 from microsoftgraph/Fix-Linter-Issues-For-DefinitelyTyped
Fix linter issues for definitely typed
2 parents 7744be6 + e3c64c1 commit 88d94af

File tree

2 files changed

+176
-24
lines changed

2 files changed

+176
-24
lines changed
Lines changed: 139 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<# // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. #>
22
<#@ template debug="true" hostspecific="true" language="C#" #>
3+
<#@ include file="utils.tt" #>
34
<#@ output extension="\\" #>
45
<#
56
CustomT4Host host = (CustomT4Host) Host;
@@ -9,45 +10,159 @@
910
var entityTypes = model.GetEntityTypes();
1011
var enumTypes = model.GetEnumTypes();
1112
var complexTypes = model.GetComplexTypes();
13+
14+
var maxLineLength = 120;
1215
#>
13-
// Type definitions for the Microsoft Graph <VERSION_STRING>
16+
// Type definitions for non-npm package microsoft-graph <VERSION_STRING>
1417
// Project: https://github.com/microsoftgraph/msgraph-typescript-typings
1518
// Definitions by: Microsoft Graph Team <https://github.com/microsoftgraph>
1619
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
1720
// TypeScript Version: 2.1
1821

1922
export as namespace microsoftgraph;
2023

21-
<# foreach(var enumType in enumTypes) { #>
22-
export type <#= enumType.Name.UpperCaseFirstChar() #> = <#= enumType.GetEnumValues() #>;
23-
<# } #>
2424
<#
25-
foreach(var entityType in entityTypes)
26-
{
27-
var methods = entityType.Methods;
25+
foreach(var enumType in enumTypes) {
26+
var enumTypeName = enumType.Name.UpperCaseFirstChar();
27+
var enumValues = enumType.GetEnumValues();
28+
var exportTypeLength = "export type".Length + enumTypeName.Length + enumValues.Length + 3;
29+
if (exportTypeLength < maxLineLength) {
30+
#>
31+
export type <#= enumTypeName #> = <#= enumValues #>;
32+
<#
33+
} else {
34+
#>
35+
export type <#= enumTypeName #> =<#
36+
var enums = enumValues.Split('|');
37+
for(var i = 0; i < enums.Length; i++) {
38+
#>
39+
40+
| <#= enums[i].Trim() #><#
41+
}
42+
#>;
43+
<#
44+
}
45+
}
46+
47+
foreach(var entityType in entityTypes) {
48+
var propCount = entityType.Properties.ToList().Count;
49+
var entityTypeName = entityType.Name.UpperCaseFirstChar();
50+
if(propCount == 0 && entityTypeName[0] == 'I') {
51+
#>
52+
// tslint:disable-next-line: interface-name no-empty-interface
53+
<#
54+
} else if (entityTypeName[0] == 'I') {
55+
#>
56+
// tslint:disable-next-line: interface-name
57+
<#
58+
} else if(propCount == 0) {
59+
#>
60+
// tslint:disable-next-line: no-empty-interface
61+
<#
62+
}
63+
#>
64+
export interface <#= entityTypeName #><#
65+
if (entityType.Base != null) {
66+
#>
67+
extends <#= entityType.Base.Name.UpperCaseFirstChar() #><#
68+
}
69+
#> {<#
70+
if(propCount == 0){
71+
#>}
72+
<#
73+
} else {
2874
#>
2975

30-
export interface <#= entityType.Name.UpperCaseFirstChar() #><# if (entityType.Base != null) { #> extends <#= entityType.Base.Name.UpperCaseFirstChar() #><# }#> {
31-
<# foreach(var prop in entityType.Properties.ToList()) { #>
32-
<# if (prop.LongDescription != null || prop.Description != null) { #>
33-
/** <#=prop.GetSanitizedLongDescription()#> */
34-
<# } #>
35-
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
36-
<# } #>
76+
<#
77+
foreach(var prop in entityType.Properties.ToList()) {
78+
if (prop.LongDescription != null || prop.Description != null) {
79+
List<string> multiLineDescriptions = Utils.splitString(prop.GetSanitizedLongDescription(), maxLineLength);
80+
if(multiLineDescriptions.Count() == 1) {
81+
#>
82+
// <#= multiLineDescriptions.First() #>
83+
<#
84+
} else {
85+
#>
86+
/**
87+
<#
88+
foreach(var descriptionLine in multiLineDescriptions) {
89+
#>
90+
* <#= descriptionLine #>
91+
<#
92+
}
93+
#>
94+
*/
95+
<#
96+
}
97+
}
98+
#>
99+
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
100+
<#
101+
}
102+
#>
37103
}
38104
<#
105+
}
39106
}
107+
108+
foreach(var complexType in complexTypes) {
109+
var propCount = complexType.Properties.ToList().Count;
110+
var complexTypeName = complexType.Name.UpperCaseFirstChar();
111+
if(propCount == 0 && complexTypeName[0] == 'I') {
112+
#>
113+
// tslint:disable-next-line: interface-name no-empty-interface
114+
<#
115+
} else if (complexTypeName[0] == 'I') {
116+
#>
117+
// tslint:disable-next-line: interface-name
118+
<#
119+
} else if(propCount == 0) {
120+
#>
121+
// tslint:disable-next-line: no-empty-interface
122+
<#
123+
}
124+
#>
125+
export interface <#= complexTypeName #><#
126+
if (complexType.Base != null) {
127+
#>
128+
extends <#= complexType.Base.Name.UpperCaseFirstChar() #><#
129+
}
130+
#> {<#
131+
if(propCount == 0){
132+
#>}
133+
<#
134+
} else {
135+
#>
136+
137+
<#
138+
foreach(var prop in complexType.Properties) {
139+
if (prop.LongDescription != null || prop.Description != null) {
140+
List<string> multiLineDescriptions = Utils.splitString(prop.GetSanitizedLongDescription(), maxLineLength);
141+
if(multiLineDescriptions.Count() == 1) {
142+
#>
143+
// <#= multiLineDescriptions.First() #>
144+
<#
145+
} else {
40146
#>
147+
/**
41148
<#
42-
foreach(var complexType in complexTypes)
43-
{
149+
foreach(var descriptionLine in multiLineDescriptions) {
150+
#>
151+
* <#= descriptionLine #>
152+
<#
153+
}
154+
#>
155+
*/
156+
<#
157+
}
158+
}
159+
#>
160+
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
161+
<#
162+
}
44163
#>
45-
export interface <#= complexType.Name.UpperCaseFirstChar()#><# if (complexType.Base != null) { #> extends <#= complexType.Base.Name.UpperCaseFirstChar() #><# }#> {
46-
<# foreach(var prop in complexType.Properties) { #>
47-
<# if (prop.LongDescription != null || prop.Description != null) { #>
48-
/** <#=prop.GetSanitizedLongDescription()#> */
49-
<# } #>
50-
<#= prop.Name #>?: <#= prop.GetTypeString() #>;
51-
<# } #>
52164
}
53-
<# } #>
165+
<#
166+
}
167+
}
168+
#>

Templates/TypeScript/src/utils.tt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<# // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. #>
2+
<#@ template debug="true" hostspecific="true" language="C#" #>
3+
<#@ output extension="\\" #>
4+
<#+
5+
class Utils {
6+
public static List<string> splitString(string str, int chunkSize) {
7+
// Removing non-breaking space in a string
8+
str = str.Replace("\u00A0", " ");
9+
List<string> multiLineDescription = new List<string>();
10+
if(str != null) {
11+
string[] words = str.Split(' ');
12+
string singleLineDescription = "";
13+
foreach(var word in words) {
14+
if(word == "") {
15+
continue;
16+
}
17+
var descriptionBeforeValuation = "";
18+
if(singleLineDescription == "") {
19+
descriptionBeforeValuation = word;
20+
} else {
21+
descriptionBeforeValuation = singleLineDescription + " " + word;
22+
}
23+
if(descriptionBeforeValuation.Length < chunkSize) {
24+
singleLineDescription = descriptionBeforeValuation;
25+
} else {
26+
multiLineDescription.Add(singleLineDescription);
27+
singleLineDescription = word;
28+
}
29+
}
30+
if(singleLineDescription != "") {
31+
multiLineDescription.Add(singleLineDescription);
32+
}
33+
}
34+
return multiLineDescription;
35+
}
36+
}
37+
#>

0 commit comments

Comments
 (0)