Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 20, 2024
1 parent 2859841 commit cfaafa0
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 190 deletions.
110 changes: 6 additions & 104 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,118 +6,24 @@ We want this community to be friendly and respectful to each other. Please follo

## Development workflow

This project is a monorepo managed using [Yarn workspaces](https://yarnpkg.com/features/workspaces). It contains the following packages:
The code is in `package/`, and the Example app (`package/example/`) is used for testing and development.

- The library package in the root directory.
- An example app in the `example/` directory.
Open the Example app in Xcode or Android Studio to work on react-native-filament.

To get started with the project, run `yarn` in the root directory to install the required dependencies for each package:

```sh
yarn
```

> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

If you want to use Android Studio or XCode to edit the native code, you can open the `example/android` or `example/ios` directories respectively in those editors. To edit the Objective-C or Swift files, open `example/ios/FilamentExample.xcworkspace` in XCode and find the source files at `Pods > Development Pods > react-native-filament`.

To edit the Java or Kotlin files, open `example/android` in Android studio and find the source files at `react-native-filament` under `Android`.

You can use various commands from the root directory to work with the project.

To start the packager:

```sh
yarn example start
```

To run the example app on Android:

```sh
yarn example android
```

To run the example app on iOS:

```sh
yarn example ios
```

By default, the example is configured to build with the old architecture. To run the example with the new architecture, you can do the following:

1. For Android, run:

```sh
ORG_GRADLE_PROJECT_newArchEnabled=true yarn example android
```

2. For iOS, run:

```sh
cd example/ios
RCT_NEW_ARCH_ENABLED=1 pod install
cd -
yarn example ios
```

If you are building for a different architecture than your previous build, make sure to remove the build folders first. You can run the following command to cleanup all build folders:

```sh
yarn clean
```

To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:

```sh
Running "FilamentExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
```

Note the `"fabric":true` and `"concurrentRoot":true` properties.

Make sure your code passes TypeScript and ESLint. Run the following to verify:

```sh
yarn typecheck
yarn lint
```

To fix formatting errors, run the following:

```sh
yarn lint --fix
```

Remember to add tests for your change if possible. Run the unit tests by:

```sh
yarn test
```
Before committing, run `yarn check-all` to format and lint the project.

### Commit message convention

We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:

- `fix`: bug fixes, e.g. fix crash due to deprecated method.
- `feat`: new features, e.g. add new method to the module.
- `refactor`: code refactor, e.g. migrate from class components to hooks.
- `perf`: various performance improvements.
- `docs`: changes into documentation, e.g. add usage example for the module..
- `test`: adding or updating tests, e.g. add integration tests using detox.
- `chore`: tooling changes, e.g. change CI config.

Our pre-commit hooks verify that your commit message matches this format when committing.

### Linting and tests

[ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/)

We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing.

Our pre-commit hooks verify that the linter and tests pass when committing.

### Publishing to npm

We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.
Expand All @@ -133,12 +39,8 @@ yarn release
The `package.json` file contains various scripts for common tasks:

- `yarn`: setup project by installing dependencies.
- `yarn typecheck`: type-check files with TypeScript.
- `yarn lint`: lint files with ESLint.
- `yarn test`: run unit tests with Jest.
- `yarn example start`: start the Metro server for the example app.
- `yarn example android`: run the example app on Android.
- `yarn example ios`: run the example app on iOS.
- `yarn check-all`: lint and format the project's C++ and JS codebase.
- `yarn typescript`: type-check files with TypeScript.

### Sending a pull request

Expand Down
21 changes: 9 additions & 12 deletions package/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
module.exports = {
root: true,
extends: [
"@react-native",
"prettier"
],
extends: ['@react-native', 'prettier'],
rules: {
"prettier/prettier": [
"error",
'prettier/prettier': [
'error',
{
quoteProps: "consistent",
quoteProps: 'consistent',
singleQuote: true,
tabWidth: 2,
trailingComma: "es5",
useTabs: false
}
]
}
trailingComma: 'es5',
useTabs: false,
},
],
},
}
2 changes: 1 addition & 1 deletion package/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
};
}
6 changes: 3 additions & 3 deletions package/example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path');
const pak = require('../package.json');
const path = require('path')
const pak = require('../package.json')

module.exports = {
presets: ['module:@react-native/babel-preset'],
Expand All @@ -14,4 +14,4 @@ module.exports = {
},
],
],
};
}
8 changes: 4 additions & 4 deletions package/example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppRegistry } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';
import { AppRegistry } from 'react-native'
import App from './src/App'
import { name as appName } from './app.json'

AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerComponent(appName, () => App)
29 changes: 12 additions & 17 deletions package/example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const path = require('path');
const escape = require('escape-string-regexp');
const exclusionList = require('metro-config/src/defaults/exclusionList');
const pak = require('../package.json');
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config')
const path = require('path')
const escape = require('escape-string-regexp')
const exclusionList = require('metro-config/src/defaults/exclusionList')
const pak = require('../package.json')

const root = path.resolve(__dirname, '..');
const modules = Object.keys({ ...pak.peerDependencies });
const root = path.resolve(__dirname, '..')
const modules = Object.keys({ ...pak.peerDependencies })

/**
* Metro configuration
Expand All @@ -19,16 +19,11 @@ const config = {
// We need to make sure that only one version is loaded for peerDependencies
// So we block them at the root, and alias them to the versions in example's node_modules
resolver: {
blacklistRE: exclusionList(
modules.map(
(m) =>
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
),
blacklistRE: exclusionList(modules.map((m) => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`))),

extraNodeModules: modules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
acc[name] = path.join(__dirname, 'node_modules', name)
return acc
}, {}),
},

Expand All @@ -40,6 +35,6 @@ const config = {
},
}),
},
};
}

module.exports = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = mergeConfig(getDefaultConfig(__dirname), config)
6 changes: 3 additions & 3 deletions package/example/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path');
const pak = require('../package.json');
const path = require('path')
const pak = require('../package.json')

module.exports = {
dependencies: {
[pak.name]: {
root: path.join(__dirname, '..'),
},
},
};
}
32 changes: 14 additions & 18 deletions package/ios/FilamentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ @interface FilamentView () <RCTFilamentViewViewProtocol>
@end

@implementation FilamentView {
UIView * _view;
UIView* _view;
}

+ (ComponentDescriptorProvider)componentDescriptorProvider
{
return concreteComponentDescriptorProvider<FilamentViewComponentDescriptor>();
+ (ComponentDescriptorProvider)componentDescriptorProvider {
return concreteComponentDescriptorProvider<FilamentViewComponentDescriptor>();
}

- (instancetype)initWithFrame:(CGRect)frame
{
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const FilamentViewProps>();
_props = defaultProps;
Expand All @@ -38,22 +36,20 @@ - (instancetype)initWithFrame:(CGRect)frame
return self;
}

- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
const auto &oldViewProps = *std::static_pointer_cast<FilamentViewProps const>(_props);
const auto &newViewProps = *std::static_pointer_cast<FilamentViewProps const>(props);
- (void)updateProps:(Props::Shared const&)props oldProps:(Props::Shared const&)oldProps {
const auto& oldViewProps = *std::static_pointer_cast<FilamentViewProps const>(_props);
const auto& newViewProps = *std::static_pointer_cast<FilamentViewProps const>(props);

if (oldViewProps.color != newViewProps.color) {
NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
[_view setBackgroundColor: [Utils hexStringToColor:colorToConvert]];
}
if (oldViewProps.color != newViewProps.color) {
NSString* colorToConvert = [[NSString alloc] initWithUTF8String:newViewProps.color.c_str()];
[_view setBackgroundColor:[Utils hexStringToColor:colorToConvert]];
}

[super updateProps:props oldProps:oldProps];
[super updateProps:props oldProps:oldProps];
}

Class<RCTComponentViewProtocol> FilamentViewCls(void)
{
return FilamentView.class;
Class<RCTComponentViewProtocol> FilamentViewCls(void) {
return FilamentView.class;
}

@end
Expand Down
12 changes: 5 additions & 7 deletions package/ios/FilamentViewManager.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import "RCTBridge.h"
#import "Utils.h"
#import <React/RCTUIManager.h>
#import <React/RCTViewManager.h>

@interface FilamentViewManager : RCTViewManager
@end
Expand All @@ -10,14 +10,12 @@ @implementation FilamentViewManager

RCT_EXPORT_MODULE(FilamentView)

- (UIView *)view
{
- (UIView*)view {
return [[UIView alloc] init];
}

RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView)
{
[view setBackgroundColor: [Utils hexStringToColor:json]];
RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView) {
[view setBackgroundColor:[Utils hexStringToColor:json]];
}

@end
2 changes: 1 addition & 1 deletion package/ios/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define Utils_h

@interface Utils : NSObject
+ hexStringToColor:(NSString *)stringToConvert;
+ hexStringToColor:(NSString*)stringToConvert;
@end

#endif /* Utils_h */
26 changes: 13 additions & 13 deletions package/ios/Utils.m
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#import <Foundation/Foundation.h>
#import "Utils.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@implementation Utils

+ hexStringToColor:(NSString *)stringToConvert
{
NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
unsigned hex;
if (![stringScanner scanHexInt:&hex]) return nil;
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
+ hexStringToColor:(NSString*)stringToConvert {
NSString* noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
NSScanner* stringScanner = [NSScanner scannerWithString:noHashString];

unsigned hex;
if (![stringScanner scanHexInt:&hex])
return nil;
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;

return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
}

+ (id)alloc {
Expand Down
3 changes: 2 additions & 1 deletion package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"!**/.*"
],
"scripts": {
"typecheck": "tsc --noEmit",
"typescript": "tsc --noEmit",
"check-all": "scripts/check-all.sh",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"clean": "rm -rf android/build example/android/build example/android/app/build example/ios/build lib",
"prepare": "bob build",
Expand Down
Loading

0 comments on commit cfaafa0

Please sign in to comment.