Skip to content

chore: Run clang-format on everything #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ buck-out/
*.keystore

# Editor config
.vscode
.vscode/*
!.vscode/extensions.json
.expo
/web-build

Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ README.md

# Config files
babel.config.js
.clang-format
.eslintrc
.flowconfig
.watchmanconfig
Expand Down
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-vscode.cpptools"
]
}
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ When you're sending a pull request:
* Communication is a key. If you want fix/add something, please open new/find existing issue, so we can discuss it.
* We prefer small pull requests focused on one change, as those are easier to test/check.
* Please make sure that all tests are passing on your local machine.
* Please make sure you've run formatters and linters locally.
* In VS Code, you can press ⇧+Alt+F or ⇧⌥F to format the current file.
* 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.
* To format JavaScript files, please install [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode).
* 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).
* Follow the template when opening a PR.


## Commits and versioning
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.

*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.
*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.


Most notably prefixes you'll see:

* **fix**: Bug fixes, triggers *patch* release
* **feat**: New feature implemented, triggers *minor*
* **feat**: New feature implemented, triggers *minor*
* **chore**: Changes that are not affecting end user (CI config changes, scripts, ["grunt work"](https://stackoverflow.com/a/26944812/3510245))
* **docs**: Documentation changes.
* **perf**: A code change that improves performance.
Expand Down
2 changes: 1 addition & 1 deletion example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class App extends Component<Props, State> {
this.setState({restarting: true}, () => this.setState({restarting: false}));
};

_changeTest = testName => {
_changeTest = (testName) => {
this.setState({currentTest: TESTS[testName]});
};

Expand Down
6 changes: 5 additions & 1 deletion example/ios/AsyncStorageExample/AsyncStorageDevSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
return [bridge moduleForClass:[RNCAsyncStorage class]];
}

@interface AsyncStorageTestSupport : NSObject<RCTBridgeModule>
@interface AsyncStorageTestSupport : NSObject <RCTBridgeModule>
@end

@implementation AsyncStorageDevSupport {
Expand Down Expand Up @@ -139,14 +139,18 @@ @implementation AsyncStorageTestSupport

RCT_EXPORT_MODULE()

// clang-format off
RCT_EXPORT_METHOD(test_setDelegate:(RCTResponseSenderBlock)callback)
// clang-format on
{
RNCAsyncStorage *asyncStorage = RNCAsyncStorageGetInstance(_bridge);
asyncStorage.delegate = _sharedInstance;
callback(@[]);
}

// clang-format off
RCT_EXPORT_METHOD(test_unsetDelegate:(RCTResponseSenderBlock)callback)
// clang-format on
{
RNCAsyncStorage *asyncStorage = RNCAsyncStorageGetInstance(_bridge);
asyncStorage.delegate = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,155 +5,165 @@
* LICENSE file in the root directory of this source tree.
*/

#import <XCTest/XCTest.h>
#import <RNCAsyncStorage/RNCAsyncStorage.h>
#import <XCTest/XCTest.h>

@interface AsyncStorageExample_macOSUITests : XCTestCase

@end

@implementation AsyncStorageExample_macOSUITests
{
XCUIApplication *_app;
XCUIElement *_window;
XCUIElement *_restartButton;
XCUIElement *_getSetClearButton;
XCUIElement *_mergeItemButton;
@implementation AsyncStorageExample_macOSUITests {
XCUIApplication *_app;
XCUIElement *_window;
XCUIElement *_restartButton;
XCUIElement *_getSetClearButton;
XCUIElement *_mergeItemButton;
}

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

_app = [[XCUIApplication alloc] init];
[_app launch];

_window = _app.windows[@"RNCAsyncStorageExample macOS"];
XCTAssert(_window.exists);
_app = [[XCUIApplication alloc] init];
[_app launch];

_restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch;
XCTAssert(_restartButton.exists);
_window = _app.windows[@"RNCAsyncStorageExample macOS"];
XCTAssert(_window.exists);

_getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch;
XCTAssert(_getSetClearButton.exists);
_restartButton = _window.otherElements[@"restart_button"].staticTexts.firstMatch;
XCTAssert(_restartButton.exists);

_mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch;
XCTAssert(_mergeItemButton.exists);

[self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"];
_getSetClearButton = _window.buttons[@"testType_getSetClear"].staticTexts.firstMatch;
XCTAssert(_getSetClearButton.exists);

_mergeItemButton = _window.buttons[@"testType_mergeItem"].staticTexts.firstMatch;
XCTAssert(_mergeItemButton.exists);

[self sendTestAppCommand:@"rnc-asyncstorage://clear-all-storage"];
}

- (void)testShouldStoreValueInAsyncStorage {
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
- (void)testShouldStoreValueInAsyncStorage
{
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_getSetClearButton click];

[_getSetClearButton click];
XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];

XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
XCTAssertEqualObjects(storedNumber.label, @"");

XCTAssertEqualObjects(storedNumber.label, @"");
XCUIElement *increaseBy10Button =
_window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;

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

int tapTimes = arc4random_uniform(10) + 1;

for (int i = 0; i < tapTimes; i++) {
[increaseBy10Button click];
}
for (int i = 0; i < tapTimes; i++) {
[increaseBy10Button click];
}

NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10];
XCTAssertEqualObjects(storedNumber.label, expectedText);
NSString *expectedText = [NSString stringWithFormat:@"%d", tapTimes * 10];

XCTAssertEqualObjects(storedNumber.label, expectedText);
}

- (void)testShouldClearItem {
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];
- (void)testShouldClearItem
{
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_getSetClearButton click];
[_getSetClearButton click];

XCUIElement *increaseBy10Button = _window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;
[increaseBy10Button click];
XCUIElement *increaseBy10Button =
_window.buttons[@"increaseByTen_button"].staticTexts.firstMatch;
[increaseBy10Button click];

XCUIElement *clearButton = _window.buttons[@"clear_button"].staticTexts.firstMatch;
[clearButton click];
[_restartButton click];
XCUIElement *clearButton = _window.buttons[@"clear_button"].staticTexts.firstMatch;
[clearButton click];
[_restartButton click];

XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
XCTAssertEqualObjects(storedNumber.label, @"");
XCUIElement *storedNumber = _window.staticTexts[@"storedNumber_text"];
XCTAssertEqualObjects(storedNumber.label, @"");
}

- (NSString *)performInputWithFormat:format {
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";

XCUIElement *nameInput = _window.textFields[@"testInput-name"];
[nameInput click];
[nameInput typeText:name];

XCUIElement *ageInput = _window.textFields[@"testInput-age"];
[ageInput click];
[ageInput typeText:age];

XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
[eyesInput click];
[eyesInput typeText:eyeColor];

XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
[showInput click];
[showInput typeText:shoeSize];

return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
- (NSString *)performInputWithFormat:format
{
NSString *name = arc4random_uniform(2) == 0 ? @"Jerry" : @"Sarah";
NSString *age = arc4random_uniform(2) == 0 ? @"21" : @"23";
NSString *eyeColor = arc4random_uniform(2) == 0 ? @"blue" : @"green";
NSString *shoeSize = arc4random_uniform(2) == 0 ? @"9" : @"10";

XCUIElement *nameInput = _window.textFields[@"testInput-name"];
[nameInput click];
[nameInput typeText:name];

XCUIElement *ageInput = _window.textFields[@"testInput-age"];
[ageInput click];
[ageInput typeText:age];

XCUIElement *eyesInput = _window.textFields[@"testInput-eyes"];
[eyesInput click];
[eyesInput typeText:eyeColor];

XCUIElement *showInput = _window.textFields[@"testInput-shoe"];
[showInput click];
[showInput typeText:shoeSize];

return [NSString stringWithFormat:format, name, age, eyeColor, shoeSize];
}

- (void)testShouldMergeItemsInAsyncStorage {
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_mergeItemButton click];

XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];

NSString *messageFormat = @"%@ is %@, has %@ eyes and shoe size of %@.";

NSString *story = [self performInputWithFormat:messageFormat];
[saveItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, story);
[_restartButton click];

// merging here

NSString *newStory = [self performInputWithFormat:messageFormat];
[mergeItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, newStory);
- (void)testShouldMergeItemsInAsyncStorage
{
[self sendTestAppCommand:@"rnc-asyncstorage://unset-delegate"];

[_mergeItemButton click];

XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];

NSString *messageFormat = @"%@ is %@, has %@ eyes and shoe size of %@.";

NSString *story = [self performInputWithFormat:messageFormat];
[saveItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, story);
[_restartButton click];

// merging here

NSString *newStory = [self performInputWithFormat:messageFormat];
[mergeItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, newStory);
}

- (void)testMergeItemDelegate {
[self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"];

[_mergeItemButton click];

XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];

NSString *story = [self performInputWithFormat:@"%@ from delegate is %@ from delegate, has %@ eyes and shoe size of %@."];
[mergeItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, story);
- (void)testMergeItemDelegate
{
[self sendTestAppCommand:@"rnc-asyncstorage://set-delegate"];

[_mergeItemButton click];

XCUIElement *saveItemButton = _window.buttons[@"saveItem_button"].staticTexts.firstMatch;
XCUIElement *restoreItemButton = _window.buttons[@"restoreItem_button"].staticTexts.firstMatch;
XCUIElement *mergeItemButton = _window.buttons[@"mergeItem_button"].staticTexts.firstMatch;
XCUIElement *storyText = _window.staticTexts[@"storyTextView"];

NSString *story =
[self performInputWithFormat:
@"%@ from delegate is %@ from delegate, has %@ eyes and shoe size of %@."];
[mergeItemButton click];
[_restartButton click];
[restoreItemButton click];
XCTAssertEqualObjects(storyText.label, story);
}

- (void)sendTestAppCommand:(NSString *)URLString {
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]];
sleep(.25);
- (void)sendTestAppCommand:(NSString *)URLString
{
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:URLString]];
sleep(.25);
}

@end
7 changes: 5 additions & 2 deletions example/windows/AsyncStorageExample/App.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"

#include "App.h"

#include "ReactPackageProvider.h"

using namespace winrt::AsyncStorageExample;
Expand Down Expand Up @@ -30,10 +32,11 @@ App::App() noexcept
InstanceSettings().EnableDeveloperMenu(false);
#endif

PackageProviders().Append(make<ReactPackageProvider>()); // Includes all modules in this project
// Includes all modules in this project
PackageProviders().Append(make<ReactPackageProvider>());
PackageProviders().Append(winrt::ReactNativeAsyncStorage::ReactPackageProvider());

REACT_REGISTER_NATIVE_MODULE_PACKAGES(); //code-gen macro from autolink
REACT_REGISTER_NATIVE_MODULE_PACKAGES(); // code-gen macro from autolink

InitializeComponent();
}
Loading