Skip to content

Commit 57d78c1

Browse files
authored
Clean up formatting, spelling, and licenses (#262)
This PR sets RNX's `.clang-format` config to match RNW's, reformats the RNX code, fixes typos, and adds missing license info to source files.
1 parent 6d4198f commit 57d78c1

33 files changed

+1718
-1168
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ SpacesInSquareBrackets: false
8989
Standard: Cpp11
9090
TabWidth: 8
9191
UseTab: Never
92-
...
92+
...

.cspell.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// cSpell Settings
2+
{
3+
"version": "0.2",
4+
"language": "en",
5+
"dictionaryDefinitions": [
6+
{
7+
"name": "project-words",
8+
"path": "./.spelling",
9+
"addWords": true
10+
}
11+
],
12+
"dictionaries": ["project-words"],
13+
"files": ["**/*.{cpp,h,idl,cs,js,jsx,ts,tsx,tt}"],
14+
"ignorePaths": [
15+
"**/*.g.*",
16+
"package/Codegen/EventArgsTypeProperties.cs",
17+
"package/Codegen/TSEnums.cs",
18+
"package/Codegen/TSProps.cs",
19+
"package/Codegen/TSTypes.cs",
20+
"package/Codegen/TypeCreator.cs",
21+
"package/Codegen/TypeEnums.cs",
22+
"package/Codegen/TypeEvents.cs",
23+
"package/Codegen/TypeProperties.cs",
24+
"package/Codegen/VersionHeader.cs"
25+
],
26+
"useGitignore": true,
27+
"ignoreRegExpList": [
28+
"require\\('.+'\\)", // Node require
29+
" from '.+';", // Node import from
30+
"[@#][a-z\\-\\.]+", // Ignore @name or #name tags
31+
]
32+
}

.spelling

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Static list for misspelled API names
2+
3+
# Dynamic list extracted from our repo. To update, truncate the list and run:
4+
# npx cspell --words-only --unique | sort /uniq >> .spelling
5+
Activatable
6+
APSTUDIO
7+
ARRAYSIZE
8+
Behaviour
9+
cdebug
10+
clsid
11+
cppout
12+
CXXUNITTESTS
13+
declspec
14+
endregion
15+
examplenuget
16+
FILEFLAGS
17+
FILEOS
18+
Hanja
19+
Hojo
20+
hostspecific
21+
hresult
22+
HSTRING
23+
inspectable
24+
JSVALUEXAML
25+
Junja
26+
Linq
27+
msbuild
28+
noexcept
29+
noinline
30+
NOMINMAX
31+
nullptr
32+
PRODUCTNAME
33+
REACTNATIVE
34+
REACTTAG
35+
runtimeclass
36+
STRINGIZE
37+
struct
38+
svgz
39+
SYMED
40+
Thumbstick
41+
tsout
42+
Unicase
43+
Unviewable
44+
Viewbox
45+
wchar
46+
wcslen
47+
webhosthidden
48+
winmd
49+
winmds
50+
winrt
51+
winstring
52+
wstring

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"xaver.clang-format",
4+
"dbaeumer.vscode-eslint",
5+
"streetsidesoftware.code-spell-checker",
6+
]
7+
}

USAGE.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ If you have questions about a scenario you don't see below, please [file an issu
3131
}} />
3232

3333
<Border verticalAlignment="center" background="paleturquoise" >
34-
<TextBlock text="this is a textblock" foreground='red' textAlignment="center" />
34+
<TextBlock text="this is a text block" foreground='red' textAlignment="center" />
3535
</Border>
3636

37-
<TextBlock text="this is another textblock" foreground='green' textAlignment="center" />
37+
<TextBlock text="this is another text block" foreground='green' textAlignment="center" />
3838
<Button content="this is a button" onClick={() => { alert("you clicked the button!"); }} />
3939
</StackPanel>
4040
```
@@ -120,7 +120,7 @@ Menus can contain cascading items:
120120
## ComboBox
121121

122122
```jsx
123-
<ComboBox text="this is a combobox" description="best bois"
123+
<ComboBox text="this is a combobox" description="best pets"
124124
onSelectionChanged={(args) =>
125125
{ alert(`sel changed! Native event args: ${JSON.stringify(args.nativeEvent)}`); }
126126
} >
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Clean up formatting and licenses",
4+
"packageName": "react-native-xaml",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

example/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ function App(): JSX.Element {
192192
{/* alert(`clicked! Native event args: ${JSON.stringify(args.nativeEvent)}`);*/}
193193
{/* }} />*/}
194194
{/* <Border verticalAlignment="center" background="paleturquoise" >*/}
195-
{/* <TextBlock text="this is a textblock" foreground='red' textAlignment="center" />*/}
195+
{/* <TextBlock text="this is a text block" foreground='red' textAlignment="center" />*/}
196196
{/* </Border>*/}
197-
{/* <TextBlock text="this is another textblock" foreground='green' textAlignment="center" />*/}
197+
{/* <TextBlock text="this is another text block" foreground='green' textAlignment="center" />*/}
198198
{/* <Button content="this is a button" onClick={() => { alert("you clicked the button!"); }} />*/}
199199
{/*</StackPanel>*/}
200200
<ComboBox
201201
text="this is a combobox"
202-
description={{string: 'best bois'}}
202+
description={{string: 'best cats'}}
203203
onSelectionChanged={args => {
204204
alert(
205205
`sel changed! Native event args: ${JSON.stringify(

package/Codegen/Model.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
using MiddleweightReflection;
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
24
using System;
35
using System.Collections.Generic;
46
using System.Diagnostics.CodeAnalysis;
57

8+
using MiddleweightReflection;
9+
610
namespace Codegen
711
{
812
public struct FakeEnum
@@ -138,15 +142,18 @@ public bool Equals(MrTypeAndMemberBase that, MrTypeAndMemberBase other)
138142
var p2 = other as MrProperty;
139143
string n1;
140144
string n2;
141-
if (!Util.propNameMap.TryGetValue($"{p1.DeclaringType.GetFullName()}.{p1.GetName()}", out n1)) {
145+
if (!Util.propNameMap.TryGetValue($"{p1.DeclaringType.GetFullName()}.{p1.GetName()}", out n1))
146+
{
142147
n1 = p1.GetName();
143148
}
144-
if (!Util.propNameMap.TryGetValue($"{p2.DeclaringType.GetFullName()}.{p2.GetName()}", out n2)) {
149+
if (!Util.propNameMap.TryGetValue($"{p2.DeclaringType.GetFullName()}.{p2.GetName()}", out n2))
150+
{
145151
n2 = p2.GetName();
146152
}
147153

148154
return n1 == n2;
149-
} else if (that is MrType t1 && other is MrType t2)
155+
}
156+
else if (that is MrType t1 && other is MrType t2)
150157
{
151158
return t1.GetFullName() == t2.GetFullName();
152159
}

package/Codegen/Program.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using MiddleweightReflection;
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
24
using System;
35
using System.Collections.Generic;
46
using System.IO;
@@ -7,6 +9,8 @@
79
using System.Text.RegularExpressions;
810
using System.Text.Json;
911

12+
using MiddleweightReflection;
13+
1014
namespace Codegen
1115
{
1216

@@ -225,13 +229,13 @@ private void DumpTypes(Version version)
225229
var typeName = val.Substring(0, val.LastIndexOf('.'));
226230
var eventName = val.Substring(val.LastIndexOf('.') + 1);
227231

228-
if (context.TryFindMrType(GetTypeNameFromJson(entry.Value), out var ptype))
232+
if (context.TryFindMrType(GetTypeNameFromJson(entry.Value), out var pType))
229233
{
230234
syntheticEvents.Add(new SyntheticProperty()
231235
{
232236
Name = eventName,
233237
DeclaringType = context.GetType(typeName),
234-
PropertyType = ptype,
238+
PropertyType = pType,
235239
});
236240
}
237241
else
@@ -561,20 +565,20 @@ private static bool UpdateFile(string path, string newContent)
561565

562566
private static uint HashName(string input)
563567
{
564-
var accum = 5381u;
568+
var result = 5381u;
565569
for (var i = input.Length - 1; i >= 0; i--)
566570
{
567571
var c = (uint)input[i];
568572
if (i == input.Length - 1)
569573
{
570-
accum += c;
574+
result += c;
571575
}
572576
else
573577
{
574-
accum = c + 33 * accum;
578+
result = c + 33 * result;
575579
}
576580
}
577-
return accum;
581+
return result;
578582
}
579583

580584
private static uint GetPropertySortKey(MrProperty p1)

package/Codegen/SyntheticProperty.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
using MiddleweightReflection;
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
24
using System;
35

6+
using MiddleweightReflection;
7+
48
namespace Codegen
59
{
610
public class SyntheticProperty : IEquatable<SyntheticProperty>

package/Codegen/Util.cs

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
using MiddleweightReflection;
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
24
using System;
35
using System.Collections.Generic;
46
using System.Collections.Immutable;
57
using System.Linq;
68
using System.Reflection;
79

10+
using MiddleweightReflection;
11+
812
namespace Codegen
913
{
1014
public static class Util
@@ -15,7 +19,7 @@ public static string GetPropFullName(MrProperty p)
1519
{
1620
return $"{p.DeclaringType.GetFullName()}.{p.GetName()}";
1721
}
18-
22+
1923
public static string ToJsName(MrProperty prop)
2024
{
2125
if (IsDependencyProperty(prop))
@@ -33,7 +37,7 @@ public static bool IsDependencyProperty(MrProperty prop)
3337
{
3438
return false; // special case Windows.UI.Xaml.DependencyPropertyChangedEventArgs.Property
3539
}
36-
return prop.GetName().EndsWith("Property") &&
40+
return prop.GetName().EndsWith("Property") &&
3741
prop.GetPropertyType().GetName() == "DependencyProperty";
3842
}
3943

@@ -165,12 +169,14 @@ public static string GetCppWinRTType(MrType t)
165169

166170

167171
public static HashSet<FakeEnum> fakeEnums = new HashSet<FakeEnum>();
168-
private static HashSet<MrType> enumsToGenerateConvertersFor = new ();
169-
public static IReadOnlyList<MrType> GetEnums() {
172+
private static HashSet<MrType> enumsToGenerateConvertersFor = new();
173+
public static IReadOnlyList<MrType> GetEnums()
174+
{
170175
return enumsToGenerateConvertersFor.OrderBy(e => Util.GetTSNamespace(e)).ToImmutableList();
171176
}
172177

173-
public static void VisitEnum(MrType t) {
178+
public static void VisitEnum(MrType t)
179+
{
174180
enumsToGenerateConvertersFor.Add(t);
175181
}
176182

@@ -241,7 +247,8 @@ private static ViewManagerPropertyType GetVMPropertyType(MrType propType)
241247
return ViewManagerPropertyType.Map;
242248
}
243249

244-
if (TypeMapping.TryGetValue(propType.GetFullName(), out var mapping)) {
250+
if (TypeMapping.TryGetValue(propType.GetFullName(), out var mapping))
251+
{
245252
return mapping.VM;
246253
}
247254

@@ -469,7 +476,8 @@ public static string GetJsTypeProperty(MrType t, Dictionary<string, List<MrType>
469476
if (listDerived.Count() < 5)
470477
{
471478
return string.Join(" | ", listDerived);
472-
} else
479+
}
480+
else
473481
{
474482
return string.Join(" |\n ", listDerived);
475483
}
@@ -486,7 +494,7 @@ public static string GetEventArgsTSType(MrType t, string prefix)
486494

487495
public static string GetEventArgsTSName(MrEvent evt, string prefix = "")
488496
{
489-
var evtType= evt.GetEventType();
497+
var evtType = evt.GetEventType();
490498
if (evtType.GetPrettyFullName().StartsWith("Windows.Foundation.TypedEventHandler<"))
491499
{
492500
var evtArgs = evtType.GetGenericArguments()[1];
@@ -609,7 +617,7 @@ public static IEnumerable<Command> GetCommands(string typeName)
609617
return new Command[] { };
610618
}
611619

612-
public static HashSet<MrType> eventArgsTypes = new (new NameEqualityComparer());
620+
public static HashSet<MrType> eventArgsTypes = new(new NameEqualityComparer());
613621
public static void FoundEventArgsType(MrType type)
614622
{
615623
if (type.GetFullName() == "System.Object")
@@ -619,7 +627,7 @@ public static void FoundEventArgsType(MrType type)
619627
eventArgsTypes.Add(type);
620628
}
621629

622-
public static Dictionary<string, IEnumerable<string>> eventArgsMethods { get; private set; } = new ();
630+
public static Dictionary<string, IEnumerable<string>> eventArgsMethods { get; private set; } = new();
623631
public static IEnumerable<string> GetEventArgsMethods(string typeName)
624632
{
625633
if (Util.eventArgsMethods.TryGetValue(typeName, out var ms))
@@ -631,7 +639,8 @@ public static IEnumerable<string> GetEventArgsMethods(string typeName)
631639

632640
private static string GetEventArgMethodParamType(string name, MrType paramType)
633641
{
634-
if (Util.DerivesFrom(paramType, $"{XamlNames.XamlNamespace}.DependencyObject")) {
642+
if (Util.DerivesFrom(paramType, $"{XamlNames.XamlNamespace}.DependencyObject"))
643+
{
635644
return "tag: number";
636645
}
637646
return $"{name}: {GetTypeScriptType(paramType)}";
@@ -642,7 +651,7 @@ public static string GetEventArgsMethodArgs(MrType argType, string methodName)
642651
argType.GetMethodsAndConstructors(out var methods, out var ctors);
643652
var method = methods.Where(m => m.GetName() == methodName).First();
644653
var inputParams = method.GetParameters().Where(p => p.Attributes.HasFlag(System.Reflection.ParameterAttributes.In));
645-
string paramTypes = string.Join(", ", inputParams.Select(p =>
654+
string paramTypes = string.Join(", ", inputParams.Select(p =>
646655
GetEventArgMethodParamType(p.GetParameterName(), p.GetParameterType())));
647656
return paramTypes;
648657
}
@@ -660,7 +669,8 @@ public static string GetEventArgsMethodReturnType(MrType argType, string methodN
660669
var allTypes = string.Join(", ", outParamTypes.Append(retType));
661670
return $"{{ {allTypes} }}";
662671

663-
} else
672+
}
673+
else
664674
{
665675
return GetTypeScriptType(method.ReturnType);
666676
}

package/Codegen/XamlNames.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace Codegen
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace Codegen
25
{
36
public static class XamlNames
47
{
@@ -8,4 +11,3 @@ public static class XamlNames
811
public const string WebView2Namespace = "Microsoft.Web.WebView2";
912
}
1013
}
11-

0 commit comments

Comments
 (0)