Skip to content

Commit

Permalink
eslint/prettier rig & fixes for example app, fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boorad committed Aug 31, 2024
1 parent e02b2fb commit 80beb50
Show file tree
Hide file tree
Showing 46 changed files with 481 additions and 349 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export default typescriptEslint.config(
},
// don't lint config files or example app (in this run)
{
ignores: ['.prettierrc.js', '*.config.js', '**/lib/**', '**/test/**', 'example/**'],
ignores: ['*.config.mjs', '*.config.js', '**/lib/**', '**/test/**', 'example/**'],
},
);
7 changes: 0 additions & 7 deletions example/.eslintrc.js

This file was deleted.

Binary file modified example/bun.lockb
Binary file not shown.
33 changes: 33 additions & 0 deletions example/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { fixupPluginRules } from '@eslint/compat';
import js from '@eslint/js';
import eslintReactNative from 'eslint-plugin-react-native';
import typescriptEslint from 'typescript-eslint';

export default typescriptEslint.config(
// don't lint config files
{
ignores: ['*.config.*js'],
},
{
plugins: {
'@typescript-eslint': typescriptEslint.plugin,
},
rules: {},
},
js.configs.recommended,
...typescriptEslint.configs.recommended,
// react-native
{
name: 'eslint-plugin-react-native',
plugins: {
'react-native': fixupPluginRules({
rules: eslintReactNative.rules,
}),
},
rules: {
...eslintReactNative.configs.all.rules,
'react-native/sort-styles': 'off',
'react-native/no-inline-styles': 'warn',
},
},
);
8 changes: 4 additions & 4 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AppRegistry } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';
import { install } from 'react-native-quick-crypto';

const global = globalThis;
install();
global.process.cwd = () => 'sxsx';
global.process.env = { NODE_ENV: 'production' };
global.location = {};

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

AppRegistry.registerComponent(appName, () => App);
13 changes: 8 additions & 5 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"packageManager": "[email protected]",
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios --simulator='iPhone 15'",
"ios": "react-native run-ios",
"tsc": "tsc --noEmit",
"typescript": "tsc --noEmit",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
Expand Down Expand Up @@ -41,9 +41,10 @@
"@babel/plugin-transform-class-static-block": "^7.24.7",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@eslint/compat": "^1.1.1",
"@eslint/js": "10.0.0",
"@react-native/gradle-plugin": "0.74.87",
"@react-native/metro-config": "^0.73.2",
"@tsconfig/react-native": "^2.0.2",
"@types/chai": "^4.3.4",
"@types/jest": "^29.2.1",
"@types/mocha": "^10.0.1",
Expand All @@ -52,11 +53,13 @@
"@types/react-test-renderer": "^18.0.0",
"@types/readable-stream": "^4.0.11",
"babel-plugin-module-resolver": "^5.0.0",
"eslint": "^8.4.1",
"eslint": "9.9.1",
"metro-react-native-babel-preset": "0.76.8",
"prettier": "^2.4.1"
"prettier": "3.3.3",
"typescript": "5.5.4",
"typescript-eslint": "8.3.0"
},
"jest": {
"preset": "react-native"
}
}
}
7 changes: 7 additions & 0 deletions example/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: true,
singleQuote: true,
trailingComma: 'all',
};
5 changes: 3 additions & 2 deletions example/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { colors } from '../styles/colors';

type ButtonProps = {
title: string;
Expand All @@ -21,13 +22,13 @@ export const Button: React.FC<ButtonProps> = ({

const styles = StyleSheet.create({
container: {
backgroundColor: '#1976d2',
backgroundColor: colors.blue,
padding: 10,
borderRadius: 5,
alignContent: 'center',
justifyContent: 'center',
},
label: {
color: 'white',
color: colors.white,
},
});
3 changes: 2 additions & 1 deletion example/src/components/IncorrectResultItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { colors } from '../styles/colors';

type IncorrectResultItemProps = {
description: string;
Expand Down Expand Up @@ -32,6 +33,6 @@ const styles = StyleSheet.create({
flexShrink: 1,
},
error: {
color: 'red',
color: colors.red,
},
});
5 changes: 1 addition & 4 deletions example/src/components/Suite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ export const Suite: React.FC<SuiteProps> = ({ description }: SuiteProps) => {

return (
<View style={styles.itemContainer}>
<Text style={[styles.text]}>{fullText}</Text>
<Text style={styles.text}>{fullText}</Text>
</View>
);
};

const styles = StyleSheet.create({
scroll: {
flex: 1,
},
itemContainer: {
borderWidth: 1,
margin: 10,
Expand Down
7 changes: 4 additions & 3 deletions example/src/components/TestItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { TestResult } from '../types/TestResults';
import { useNavigation } from '@react-navigation/native';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import type { RootStackParamList } from '../navigators/RootProps';
import { colors } from '../styles/colors';

type TestItemProps = {
description: string;
Expand Down Expand Up @@ -80,7 +81,7 @@ const styles = StyleSheet.create({
justifyContent: 'space-evenly',
gap: 10,
borderBottomWidth: 1,
borderBottomColor: '#ccc',
borderBottomColor: colors.gray,
},
checkbox: {
transform: [{ scaleX: 0.7 }, { scaleY: 0.7 }],
Expand All @@ -94,10 +95,10 @@ const styles = StyleSheet.create({
flexDirection: 'row',
},
pass: {
color: 'green',
color: colors.green,
},
fail: {
color: 'red',
color: colors.red,
},
count: {
fontSize: 12,
Expand Down
11 changes: 7 additions & 4 deletions example/src/hooks/useRunTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const run = (
EVENT_SUITE_END,
} = Mocha.Runner.constants;

let stats: Stats = { ...defaultStats };
const stats: Stats = { ...defaultStats };

var runner = new Mocha.Runner(rootSuite) as MochaTypes.Runner;
const runner = new Mocha.Runner(rootSuite) as MochaTypes.Runner;
runner.stats = stats;

// enable/disable tests based on checkbox value
Expand All @@ -68,7 +68,10 @@ const run = (
s.tests.map((t) => {
try {
t.skip();
} catch (e) {} // do nothing w error
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (_e) {
// do nothing w error
}
});
} else {
// console.log(`will run '${suiteName}' suite`);
Expand All @@ -86,7 +89,7 @@ const run = (
stats.start = new Date();
})
.on(EVENT_SUITE_BEGIN, (suite: MochaTypes.Suite) => {
suite.root || stats.suites++;
if (suite.root) stats.suites++;
indents++;
})
.on(EVENT_SUITE_END, () => {
Expand Down
9 changes: 5 additions & 4 deletions example/src/hooks/useTestList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-shadow */
import { useState, useCallback } from 'react';
import type * as MochaTypes from 'mocha';
import type { Suites } from '../types/TestSuite';
Expand All @@ -8,8 +7,8 @@ import '../testing/tests/pbkdf2Tests/pbkdf2Tests';
import '../testing/tests/RandomTests/randomTests';
import '../testing/tests/HmacTests/HmacTests';
import '../testing/tests/HashTests/HashTests';
import '../testing/tests/CipherTests/CipherTestFirst';
import '../testing/tests/CipherTests/CipherTestSecond';
import '../testing/tests/CipherTests/CipherDecipher';
import '../testing/tests/CipherTests/CipherivDecipheriv';
import '../testing/tests/CipherTests/test398';
import '../testing/tests/CipherTests/PublicCipherTests';
import '../testing/tests/CipherTests/generateKey';
Expand Down Expand Up @@ -44,6 +43,7 @@ export const useTestList = (): [

const clearAll = useCallback(() => {
setSuites((suites) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Object.entries(suites).forEach(([_, suite]) => {
suite.value = false;
});
Expand All @@ -53,6 +53,7 @@ export const useTestList = (): [

const checkAll = useCallback(() => {
setSuites((suites) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Object.entries(suites).forEach(([_, suite]) => {
suite.value = true;
});
Expand All @@ -64,7 +65,7 @@ export const useTestList = (): [
};

const getInitialSuites = () => {
let suites: Suites = {};
const suites: Suites = {};

// interrogate the loaded mocha suites/tests via a temporary runner
const runner = new Mocha.Runner(rootSuite) as MochaTypes.Runner;
Expand Down
8 changes: 3 additions & 5 deletions example/src/navigators/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import type { RootStackParamList } from './RootProps';
import { Entry } from './children/Entry/Entry';
import { Benchmarks } from './children/benchmarks/Benchmarks';
import { TestingScreen } from './children/TestingScreen/TestingScreen';

const Stack = createNativeStackNavigator<RootStackParamList>();

Expand All @@ -15,14 +18,12 @@ export const Root: React.FC = () => {
title: 'Test Suites',
}}
getComponent={() => {
const { Entry } = require('./children/Entry/Entry');
return Entry;
}}
/>
<Stack.Screen
name="Benchmarks"
getComponent={() => {
const { Benchmarks } = require('./children/benchmarks/Benchmarks');
return Benchmarks;
}}
/>
Expand All @@ -32,9 +33,6 @@ export const Root: React.FC = () => {
title: 'Tests',
}}
getComponent={() => {
const {
TestingScreen,
} = require('./children/TestingScreen/TestingScreen');
return TestingScreen;
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion example/src/navigators/children/Entry/Entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useRunTests } from '../../../hooks/useRunTests';

type EntryProps = NativeStackScreenProps<RootStackParamList, 'Entry'>;

export const Entry: React.FC<EntryProps> = ({}: EntryProps) => {
export const Entry: React.FC<EntryProps> = () => {
const [tests, toggle, clearAll, checkAll] = useTestList();
const [results, runTests] = useRunTests();
const navigation =
Expand Down
7 changes: 7 additions & 0 deletions example/src/styles/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const colors: Record<string, string> = {
gray: '#ccc',
white: '#fff',
green: '#3cb043',
red: '#e60000',
blue: '#1976d2',
};
9 changes: 3 additions & 6 deletions example/src/testing/MochaRNAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'mocha';
import type * as MochaTypes from 'mocha';

// polyfill encoders for all tests
// @ts-expect-error
// @ts-expect-error - can't import but it's there
import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctions';
import RNFE from 'react-native-fast-encoder';
polyfillGlobal('TextEncoder', () => RNFE);
Expand All @@ -11,16 +11,13 @@ export const rootSuite = new Mocha.Suite('') as MochaTypes.Suite;
rootSuite.timeout(10 * 1000);

let mochaContext = rootSuite;
let only = false;

export const it = (
name: string,
f: MochaTypes.Func | MochaTypes.AsyncFunc
): void => {
if (!only) {
const test = new Mocha.Test(name, f);
mochaContext.addTest(test);
}
const test = new Mocha.Test(name, f);
mochaContext.addTest(test);
};

export const describe = (name: string, f: () => void): void => {
Expand Down
6 changes: 3 additions & 3 deletions example/src/testing/fixtures/aes_cbc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ const decryptionFailing: AesEncryptDecryptTestVector[] = [];
kKeyLengths.forEach(function (keyLength) {
['zeroPadChar', 'bigPadChar', 'inconsistentPadChars'].forEach(
(paddingProblem) => {
// @ts-expect-error
// @ts-expect-error bad padding
const badCiphertext = new Uint8Array(kCipherText[keyLength].byteLength);
badCiphertext.set(
// @ts-expect-error
// @ts-expect-error bad padding
kCipherText[keyLength].slice(0, kCipherText[keyLength].byteLength - 16)
);
// @ts-expect-error
// @ts-expect-error bad padding
badCiphertext.set(kBadPadding[keyLength][paddingProblem]);

decryptionFailing.push({
Expand Down
2 changes: 1 addition & 1 deletion example/src/testing/fixtures/aes_gcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ kKeyLengths.forEach((keyLength) => {
name: 'AES-GCM',
iv,
additionalData,
// @ts-expect-error
// @ts-expect-error bad tag length
tagLength: badTagLength,
},
plaintext: kPlaintext,
Expand Down
Loading

0 comments on commit 80beb50

Please sign in to comment.