Skip to content

Commit af0677c

Browse files
authored
chore: Run clang-format on everything (#486)
1 parent 1f3f88f commit af0677c

23 files changed

+1109
-892
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ buck-out/
4646
*.keystore
4747

4848
# Editor config
49-
.vscode
49+
.vscode/*
50+
!.vscode/extensions.json
5051
.expo
5152
/web-build
5253

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ README.md
88

99
# Config files
1010
babel.config.js
11+
.clang-format
1112
.eslintrc
1213
.flowconfig
1314
.watchmanconfig

.vscode/extensions.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint",
6+
"esbenp.prettier-vscode",
7+
"ms-vscode.cpptools"
8+
]
9+
}

CONTRIBUTING.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ When you're sending a pull request:
1919
* Communication is a key. If you want fix/add something, please open new/find existing issue, so we can discuss it.
2020
* We prefer small pull requests focused on one change, as those are easier to test/check.
2121
* Please make sure that all tests are passing on your local machine.
22+
* Please make sure you've run formatters and linters locally.
23+
* In VS Code, you can press ⇧+Alt+F or ⇧⌥F to format the current file.
24+
* To format C++ and Objective-C files, make sure you have the [C/C++ extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) installed.
25+
* To format JavaScript files, please install [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
26+
* From the command line, you can run `yarn format:c` and `yarn format:js` to format C-based languages and JavaScript respectively. The first command requires that you've already installed [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html).
2227
* Follow the template when opening a PR.
2328

2429

2530
## Commits and versioning
2631
All PRs are squashed into `master` branch and wrapped up in a single commit, following [conventional commit message](https://www.conventionalcommits.org/en/v1.0.0-beta.3). Combined with [semantic versioning](https://semver.org/), this allows us to have a frequent releases of the library.
2732

28-
*Note*: We don't force this convention on Pull Requests from contributors, but it's a clean way to see what type of changes are made, so feel free to follow it.
33+
*Note*: We don't force this convention on Pull Requests from contributors, but it's a clean way to see what type of changes are made, so feel free to follow it.
2934

3035

3136
Most notably prefixes you'll see:
3237

3338
* **fix**: Bug fixes, triggers *patch* release
34-
* **feat**: New feature implemented, triggers *minor*
39+
* **feat**: New feature implemented, triggers *minor*
3540
* **chore**: Changes that are not affecting end user (CI config changes, scripts, ["grunt work"](https://stackoverflow.com/a/26944812/3510245))
3641
* **docs**: Documentation changes.
3742
* **perf**: A code change that improves performance.

example/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class App extends Component<Props, State> {
5454
this.setState({restarting: true}, () => this.setState({restarting: false}));
5555
};
5656

57-
_changeTest = testName => {
57+
_changeTest = (testName) => {
5858
this.setState({currentTest: TESTS[testName]});
5959
};
6060

example/ios/AsyncStorageExample/AsyncStorageDevSupport.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return [bridge moduleForClass:[RNCAsyncStorage class]];
1212
}
1313

14-
@interface AsyncStorageTestSupport : NSObject<RCTBridgeModule>
14+
@interface AsyncStorageTestSupport : NSObject <RCTBridgeModule>
1515
@end
1616

1717
@implementation AsyncStorageDevSupport {
@@ -139,14 +139,18 @@ @implementation AsyncStorageTestSupport
139139

140140
RCT_EXPORT_MODULE()
141141

142+
// clang-format off
142143
RCT_EXPORT_METHOD(test_setDelegate:(RCTResponseSenderBlock)callback)
144+
// clang-format on
143145
{
144146
RNCAsyncStorage *asyncStorage = RNCAsyncStorageGetInstance(_bridge);
145147
asyncStorage.delegate = _sharedInstance;
146148
callback(@[]);
147149
}
148150

151+
// clang-format off
149152
RCT_EXPORT_METHOD(test_unsetDelegate:(RCTResponseSenderBlock)callback)
153+
// clang-format on
150154
{
151155
RNCAsyncStorage *asyncStorage = RNCAsyncStorageGetInstance(_bridge);
152156
asyncStorage.delegate = nil;

example/macos/AsyncStorageExample-macOSUITests/AsyncStorageExample_macOSUITests.m

+125-115
Original file line numberDiff line numberDiff line change
@@ -5,155 +5,165 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <XCTest/XCTest.h>
98
#import <RNCAsyncStorage/RNCAsyncStorage.h>
9+
#import <XCTest/XCTest.h>
1010

1111
@interface AsyncStorageExample_macOSUITests : XCTestCase
1212

1313
@end
1414

15-
@implementation AsyncStorageExample_macOSUITests
16-
{
17-
XCUIApplication *_app;
18-
XCUIElement *_window;
19-
XCUIElement *_restartButton;
20-
XCUIElement *_getSetClearButton;
21-
XCUIElement *_mergeItemButton;
15+
@implementation AsyncStorageExample_macOSUITests {
16+
XCUIApplication *_app;
17+
XCUIElement *_window;
18+
XCUIElement *_restartButton;
19+
XCUIElement *_getSetClearButton;
20+
XCUIElement *_mergeItemButton;
2221
}
2322

24-
- (void)setUp {
25-
// In UI tests it is usually best to stop immediately when a failure occurs.
26-
self.continueAfterFailure = NO;
23+
- (void)setUp
24+
{
25+
// In UI tests it is usually best to stop immediately when a failure occurs.
26+
self.continueAfterFailure = NO;
2727

28-
_app = [[XCUIApplication alloc] init];
29-
[_app launch];
30-
31-
_window = _app.windows[@"RNCAsyncStorageExample macOS"];
32-
XCTAssert(_window.exists);
28+
_app = [[XCUIApplication alloc] init];
29+
[_app launch];
3330

34-
_restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch;
35-
XCTAssert(_restartButton.exists);
31+
_window = _app.windows[@"RNCAsyncStorageExample macOS"];
32+
XCTAssert(_window.exists);
3633

37-
_getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch;
38-
XCTAssert(_getSetClearButton.exists);
34+
_restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch;
35+
XCTAssert(_restartButton.exists);
3936

40-
_mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch;
41-
XCTAssert(_mergeItemButton.exists);
42-
43-
[self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"];
37+
_getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch;
38+
XCTAssert(_getSetClearButton.exists);
39+
40+
_mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch;
41+
XCTAssert(_mergeItemButton.exists);
42+
43+
[self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"];
4444
}
4545

46-
- (void)testShouldStoreValueInAsyncStorage {
47-
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
46+
- (void)testShouldStoreValueInAsyncStorage
47+
{
48+
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
49+
50+
[_getSetClearButton click];
4851

49-
[_getSetClearButton click];
52+
XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
5053

51-
XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
54+
XCTAssertEqualObjects(storedNumber.label, @"");
5255

53-
XCTAssertEqualObjects(storedNumber.label, @"");
56+
XCUIElement *increaseBy10Button =
57+
_window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;
5458

55-
XCUIElement *increaseBy10Button = _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;
59+
int tapTimes = arc4random_uniform(10) + 1;
5660

57-
int tapTimes = arc4random_uniform(10) + 1;
58-
59-
for (int i = 0; i < tapTimes; i++) {
60-
[increaseBy10Button click];
61-
}
61+
for (int i = 0; i < tapTimes; i++) {
62+
[increaseBy10Button click];
63+
}
6264

63-
NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10];
64-
65-
XCTAssertEqualObjects(storedNumber.label, expectedText);
65+
NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10];
66+
67+
XCTAssertEqualObjects(storedNumber.label, expectedText);
6668
}
6769

68-
- (void)testShouldClearItem {
69-
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
70+
- (void)testShouldClearItem
71+
{
72+
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
7073

71-
[_getSetClearButton click];
74+
[_getSetClearButton click];
7275

73-
XCUIElement *increaseBy10Button = _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;
74-
[increaseBy10Button click];
76+
XCUIElement *increaseBy10Button =
77+
_window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;
78+
[increaseBy10Button click];
7579

76-
XCUIElement *clearButton = _window.buttons[@"clear_button"].staticTexts.firstMatch;
77-
[clearButton click];
78-
[_restartButton click];
80+
XCUIElement *clearButton = _window.buttons[@"clear_button"].staticTexts.firstMatch;
81+
[clearButton click];
82+
[_restartButton click];
7983

80-
XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
81-
XCTAssertEqualObjects(storedNumber.label, @"");
84+
XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
85+
XCTAssertEqualObjects(storedNumber.label, @"");
8286
}
8387

84-
- (NSString *)performInputWithFormat:format {
85-
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
86-
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
87-
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
88-
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";
89-
90-
XCUIElement *nameInput = _window.textFields[@"testInput-name"];
91-
[nameInput click];
92-
[nameInput typeText:name];
93-
94-
XCUIElement *ageInput = _window.textFields[@"testInput-age"];
95-
[ageInput click];
96-
[ageInput typeText:age];
97-
98-
XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
99-
[eyesInput click];
100-
[eyesInput typeText:eyeColor];
101-
102-
XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
103-
[showInput click];
104-
[showInput typeText:shoeSize];
105-
106-
return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
88+
- (NSString *)performInputWithFormat:format
89+
{
90+
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
91+
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
92+
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
93+
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";
94+
95+
XCUIElement *nameInput = _window.textFields[@"testInput-name"];
96+
[nameInput click];
97+
[nameInput typeText:name];
98+
99+
XCUIElement *ageInput = _window.textFields[@"testInput-age"];
100+
[ageInput click];
101+
[ageInput typeText:age];
102+
103+
XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
104+
[eyesInput click];
105+
[eyesInput typeText:eyeColor];
106+
107+
XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
108+
[showInput click];
109+
[showInput typeText:shoeSize];
110+
111+
return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
107112
}
108113

109-
- (void)testShouldMergeItemsInAsyncStorage {
110-
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
111-
112-
[_mergeItemButton click];
113-
114-
XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
115-
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
116-
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
117-
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];
118-
119-
NSString *messageFormat = @"%@ is %@, has %@ eyes and shoe size of %@.";
120-
121-
NSString *story = [self performInputWithFormat:messageFormat];
122-
[saveItemButton click];
123-
[_restartButton click];
124-
[restoreItemButton click];
125-
XCTAssertEqualObjects(storyText.label, story);
126-
[_restartButton click];
127-
128-
// merging here
129-
130-
NSString *newStory = [self performInputWithFormat:messageFormat];
131-
[mergeItemButton click];
132-
[_restartButton click];
133-
[restoreItemButton click];
134-
XCTAssertEqualObjects(storyText.label, newStory);
114+
- (void)testShouldMergeItemsInAsyncStorage
115+
{
116+
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
117+
118+
[_mergeItemButton click];
119+
120+
XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
121+
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
122+
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
123+
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];
124+
125+
NSString *messageFormat = @"%@ is %@, has %@ eyes and shoe size of %@.";
126+
127+
NSString *story = [self performInputWithFormat:messageFormat];
128+
[saveItemButton click];
129+
[_restartButton click];
130+
[restoreItemButton click];
131+
XCTAssertEqualObjects(storyText.label, story);
132+
[_restartButton click];
133+
134+
// merging here
135+
136+
NSString *newStory = [self performInputWithFormat:messageFormat];
137+
[mergeItemButton click];
138+
[_restartButton click];
139+
[restoreItemButton click];
140+
XCTAssertEqualObjects(storyText.label, newStory);
135141
}
136142

137-
- (void)testMergeItemDelegate {
138-
[self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"];
139-
140-
[_mergeItemButton click];
141-
142-
XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
143-
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
144-
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
145-
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];
146-
147-
NSString *story = [self performInputWithFormat:@"%@ from delegate is %@ from delegate, has %@ eyes and shoe size of %@."];
148-
[mergeItemButton click];
149-
[_restartButton click];
150-
[restoreItemButton click];
151-
XCTAssertEqualObjects(storyText.label, story);
143+
- (void)testMergeItemDelegate
144+
{
145+
[self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"];
146+
147+
[_mergeItemButton click];
148+
149+
XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
150+
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
151+
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
152+
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];
153+
154+
NSString *story =
155+
[self performInputWithFormat:
156+
@"%@ from delegate is %@ from delegate, has %@ eyes and shoe size of %@."];
157+
[mergeItemButton click];
158+
[_restartButton click];
159+
[restoreItemButton click];
160+
XCTAssertEqualObjects(storyText.label, story);
152161
}
153162

154-
- (void)sendTestAppCommand:(NSString *)URLString {
155-
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]];
156-
sleep(.25);
163+
- (void)sendTestAppCommand:(NSString *)URLString
164+
{
165+
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]];
166+
sleep(.25);
157167
}
158168

159169
@end

example/windows/AsyncStorageExample/App.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "pch.h"
2+
23
#include "App.h"
4+
35
#include "ReactPackageProvider.h"
46

57
using namespace winrt::AsyncStorageExample;
@@ -30,10 +32,11 @@ App::App() noexcept
3032
InstanceSettings().EnableDeveloperMenu(false);
3133
#endif
3234

33-
PackageProviders().Append(make<ReactPackageProvider>()); // Includes all modules in this project
35+
// Includes all modules in this project
36+
PackageProviders().Append(make<ReactPackageProvider>());
3437
PackageProviders().Append(winrt::ReactNativeAsyncStorage::ReactPackageProvider());
3538

36-
REACT_REGISTER_NATIVE_MODULE_PACKAGES(); //code-gen macro from autolink
39+
REACT_REGISTER_NATIVE_MODULE_PACKAGES(); // code-gen macro from autolink
3740

3841
InitializeComponent();
3942
}

0 commit comments

Comments
 (0)