Skip to content

Commit

Permalink
gha & lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
boorad committed Aug 11, 2024
1 parent e017f60 commit 71dd547
Show file tree
Hide file tree
Showing 56 changed files with 745 additions and 697 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
${{ runner.os }}-gradle-
- name: Run Gradle Build for android/
run: cd android && ./gradlew assembleDebug && cd ..
run: cd packages/react-native-quick-crypto/android && ./gradlew assembleDebug && cd ../..

- name: Run Gradle Build for example/android/
run: cd example/android && ./gradlew assembleDebug --build-cache && cd ../..
5 changes: 1 addition & 4 deletions .github/workflows/build-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
build_ios_example:
name: Build iOS Example App
runs-on: macOS-latest
defaults:
run:
working-directory: example/ios
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -61,7 +58,7 @@ jobs:

- name: Install xcpretty
run: gem install xcpretty

- name: Build App
run: "set -o pipefail && xcodebuild \
CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ \
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/validate-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ jobs:
validate_android:
name: Gradle Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/react-native-quick-crypto/android
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -53,11 +50,10 @@ jobs:
${{ runner.os }}-gradle-
- name: Run Gradle Lint
run: cd ../../example/android && ./gradlew lint
run: cd example/android && ./gradlew lint

- name: Parse Gradle Lint Report
uses: yutailang0119/action-android-lint@v4
with:
# ignore-warnings: true
report-path: example/android/app/build/reports/*.xml

8 changes: 4 additions & 4 deletions .github/workflows/validate-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ jobs:
run: |
bun install_tsc
- name: Run ESLint
run: bun lint -f @jamesacarr/github-actions
- name: Run ESLint (rnqc)
run: cd packages/react-native-quick-crypto && bun lint

- name: Run ESLint with auto-fix
run: bun lint --fix
- name: Run ESLint (example)
run: cd example && bun lint

- name: Verify no files have changed after auto-fix
run: git diff --exit-code HEAD
6 changes: 3 additions & 3 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// polyfills
import { install } from 'react-native-quick-crypto';
import {install} from 'react-native-quick-crypto';
install();

// mocha things
Expand All @@ -10,8 +10,8 @@ global.process.version = 'v22.0.0';
// global.process.env = { NODE_ENV: 'production' };
// global.location = {};

import { AppRegistry } from 'react-native';
import {AppRegistry} from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
9 changes: 4 additions & 5 deletions example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const escape = require('escape-string-regexp');
const pack = require('../package.json');

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

/**
* Metro configuration
Expand All @@ -21,17 +21,16 @@ const config = {
resolver: {
blacklistRE: blacklist(
peerModules.map(
(m) =>
new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`)
)
m => new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`),
),
),

extraNodeModules: {
...peerModules.reduce((acc, name) => {
acc[name] = path.join(__dirname, 'node_modules', name);
return acc;
}, {}),
'stream': require.resolve('readable-stream'),
stream: require.resolve('readable-stream'),
},
},

Expand Down
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Root } from './navigators/Root';
import {Root} from './navigators/Root';

export default function App() {
return <Root />;
Expand Down
4 changes: 2 additions & 2 deletions example/src/benchmarks/crypto-browserify/random.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-ignore
import { randomBytes } from 'crypto-browserify';
import type { RandomBytesFn } from '../types';
import {randomBytes} from 'crypto-browserify';
import type {RandomBytesFn} from '../types';

const randomBytes10: RandomBytesFn = () => {
randomBytes(10);
Expand Down
2 changes: 1 addition & 1 deletion example/src/benchmarks/rnqc/random.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import rnqc from 'react-native-quick-crypto';
import { RandomBytesFn } from '../types';
import {RandomBytesFn} from '../types';

const randomBytes10: RandomBytesFn = () => {
rnqc.randomBytes(10);
Expand Down
14 changes: 9 additions & 5 deletions example/src/benchmarks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { BenchmarkResult } from "../types/Results";
import {BenchmarkResult} from '../types/Results';

export const formatNumber = (n: number, decimals: number, suffix: string): string => {
export const formatNumber = (
n: number,
decimals: number,
suffix: string,
): string => {
if (isNaN(n)) {
return '';
}
return n.toFixed(decimals) + suffix;
};

export const calculateTimes = (result: BenchmarkResult): number => {
return result.type === 'faster' ?
1 + (result.them - result.us) / result.us :
1 + (result.us - result.them) / result.them;
return result.type === 'faster'
? 1 + (result.them - result.us) / result.us
: 1 + (result.us - result.them) / result.them;
};
9 changes: 5 additions & 4 deletions example/src/components/BenchmarkItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {View, Text, StyleSheet, TouchableOpacity} from 'react-native';
import BouncyCheckbox from 'react-native-bouncy-checkbox';
import type {BenchmarkResult} from '../types/Results';
import {useNavigation} from '@react-navigation/native';
import type {NativeStackNavigationProp} from '@react-navigation/native-stack';
import { calculateTimes, formatNumber } from '../benchmarks/utils';
import {calculateTimes, formatNumber} from '../benchmarks/utils';

type BenchmarkItemProps = {
description: string;
Expand All @@ -26,7 +25,7 @@ export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
us: 0,
them: 0,
};
results.map((r) => {
results.map(r => {
stats.us += r.us;
stats.them += r.them;
});
Expand Down Expand Up @@ -63,7 +62,9 @@ export const BenchmarkItem: React.FC<BenchmarkItemProps> = ({
<Text style={styles.label} numberOfLines={1}>
{description}
</Text>
<Text style={[styles.times, styles[timesType]]} numberOfLines={1}>{formatNumber(times, 2, 'x')}</Text>
<Text style={[styles.times, styles[timesType]]} numberOfLines={1}>
{formatNumber(times, 2, 'x')}
</Text>
<Text style={styles.count} numberOfLines={1}>
{count}
</Text>
Expand Down
14 changes: 9 additions & 5 deletions example/src/components/BenchmarkResultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { BenchmarkResult } from '../types/Results';
import { calculateTimes, formatNumber } from '../benchmarks/utils';
import {View, Text, StyleSheet} from 'react-native';
import {BenchmarkResult} from '../types/Results';
import {calculateTimes, formatNumber} from '../benchmarks/utils';

type BenchmarkResultItemProps = {
result: BenchmarkResult;
Expand Down Expand Up @@ -29,8 +29,12 @@ export const BenchmarkResultItem: React.FC<BenchmarkResultItemProps> = ({
return (
<View style={styles.itemContainer}>
<Text style={styles.text}>{emoji}</Text>
<Text style={[styles.text, styles.description]}>{result.description}</Text>
<Text style={[styles.value, styles[timesType]]}>{formatNumber(times, 2, 'x')}</Text>
<Text style={[styles.text, styles.description]}>
{result.description}
</Text>
<Text style={[styles.value, styles[timesType]]}>
{formatNumber(times, 2, 'x')}
</Text>
<Text style={styles.value}>{formatNumber(result.us, 2, 'ms')}</Text>
<Text style={styles.value}>{formatNumber(result.them, 2, 'ms')}</Text>
</View>
Expand Down
5 changes: 2 additions & 3 deletions example/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import {View, Text, TouchableOpacity, StyleSheet} from 'react-native';

type ButtonProps = {
title: string;
Expand All @@ -16,8 +16,7 @@ export const Button: React.FC<ButtonProps> = ({
<View>
<TouchableOpacity
style={[styles.container, {backgroundColor: colors[color]}]}
onPress={onPress}
>
onPress={onPress}>
<Text style={styles.label}>{title}</Text>
</TouchableOpacity>
</View>
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/CorrectResultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import {View, Text, StyleSheet} from 'react-native';

type CorrectResultItemProps = {
description: string;
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/IncorrectResultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import {View, Text, StyleSheet} from 'react-native';

type IncorrectResultItemProps = {
description: string;
Expand Down
4 changes: 2 additions & 2 deletions example/src/components/Suite.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import {View, Text, StyleSheet} from 'react-native';

type SuiteProps = {
description: string;
};

export const Suite: React.FC<SuiteProps> = ({ description }: SuiteProps) => {
export const Suite: React.FC<SuiteProps> = ({description}: SuiteProps) => {
const emoji = '↘️ ';
const fullText = emoji + description;

Expand Down
1 change: 0 additions & 1 deletion example/src/components/TestItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {View, Text, StyleSheet, TouchableOpacity} from 'react-native';
import BouncyCheckbox from 'react-native-bouncy-checkbox';
import type {TestResult} from '../types/Results';
import {useNavigation} from '@react-navigation/native';
import type {NativeStackNavigationProp} from '@react-navigation/native-stack';

type TestItemProps = {
description: string;
Expand Down
44 changes: 25 additions & 19 deletions example/src/hooks/useBenchmarksList.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
import { useCallback, useState } from "react";
import { Benchmark, BenchmarkSuite, Suites } from "../types/Suite";
import {useCallback, useState} from 'react';
import {Benchmark, BenchmarkSuite, Suites} from '../types/Suite';

export const useBenchmarksList = (challenger: string): [
export const useBenchmarksList = (
challenger: string,
): [
Suites<BenchmarkSuite>,
(description: string) => void,
() => void,
() => void,
] => {
const [suites, setSuites] = useState<Suites<BenchmarkSuite>>(getInitialSuites(challenger));
const [suites, setSuites] = useState<Suites<BenchmarkSuite>>(
getInitialSuites(challenger),
);

const toggle = useCallback(
(description: string) => {
setSuites((tests) => {
setSuites(tests => {
tests[description]!.value = !tests[description]!.value;
return tests;
});
},
[setSuites]
[setSuites],
);

const clearAll = useCallback(() => {
setSuites((suites) => {
Object.entries(suites).forEach(([_, suite]) => {
setSuites(prev => {
Object.entries(prev).forEach(([_, suite]) => {
suite.value = false;
});
return { ...suites };
return {...prev};
});
}, [setSuites]);

const checkAll = useCallback(() => {
setSuites((suites) => {
Object.entries(suites).forEach(([_, suite]) => {
setSuites(prev => {
Object.entries(prev).forEach(([_, suite]) => {
suite.value = true;
});
return { ...suites };
return {...prev};
});
}, [setSuites]);

return [suites, toggle, clearAll, checkAll];
};

Expand All @@ -45,9 +50,9 @@ const getInitialSuites = (challenger: string) => {
'random',
];
let suites: Suites<BenchmarkSuite> = {};
suiteNames.forEach((suiteName) => {
suiteNames.forEach(suiteName => {
const benchmarks = loadBenchmarks(suiteName, challenger);
suites[suiteName] = { value: false, count: benchmarks.length, benchmarks };
suites[suiteName] = {value: false, count: benchmarks.length, benchmarks};
});

// return count-enhanced list and totals
Expand All @@ -61,19 +66,20 @@ const loadBenchmarks = (suiteName: string, challenger: string): Benchmark[] => {
const themKeys = Object.keys(them);
// add all 'us' benchmarks
Object.entries(us).forEach(([name, fn]) => {
ret.push({ name, us: fn, them: them[name] });
ret.push({name, us: fn, them: them[name]});
// remove from themKeys
themKeys.splice(themKeys.indexOf(name), 1);
});
// add all 'them' benchmarks that are not in 'us'
themKeys.forEach((name) => {
ret.push({ name, us: us[name], them: them[name] });
themKeys.forEach(name => {
ret.push({name, us: us[name], them: them[name]});
});
return ret;
};

// can't use dynamic strings here, as require() is compile-time
const allBenchmarks: Record<string, Record<string, Function>> = {
'rnqc/random': require('../benchmarks/rnqc/random').default,
'crypto-browserify/random': require('../benchmarks/crypto-browserify/random').default,
}
'crypto-browserify/random': require('../benchmarks/crypto-browserify/random')
.default,
};
Loading

0 comments on commit 71dd547

Please sign in to comment.