Skip to content

Commit

Permalink
Add linting & code formatting with prettier (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Mar 1, 2021
1 parent 5441078 commit 8391c1a
Show file tree
Hide file tree
Showing 12 changed files with 1,168 additions and 170 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**/*.d.ts
14 changes: 14 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": [
"@react-native-community",
"prettier",
"prettier/react"
],
"plugins": [
"prettier"
],
"parser": "babel-eslint",
"rules": {
"prettier/prettier": "error"
}
}
1 change: 0 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

{
"default": true,
"no-inline-html": false,
Expand Down
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
language: node_js
node_js:
- stable
- stable
cache:
yarn: true
directories:
- node_modules
- node_modules
install:
- yarn
- yarn
script:
- yarn run test
- yarn run test
- yarn run lint
deploy:
provider: npm
email: joel@oblador.se
api_key:
secure: "E/JmYEY98KbLaw2Dmw6JFNQUtdKN8RfScuY3wjhVoKmXQ1we1hu0fCEuGtZQvYA/6rQRfcTEmvSf1w2uCOk6eYQfzKZDZ5tzQvpv7BwNMsY8D5ACphohlfB+DKx9RKM2zBrD9zaDip2SbSrB5KfYsg2R1YMq5z9ZNQrYp6kdyXNY8kyZaZtDuk18s1ZB3HTviQVQwyHPnevEEHCZZDckPfgPb4d4m32SfCqLLMkETWJojBcfQQafXoVAmK5Fhoe6WxDa6UHj6z9NqOKenKHa+u1XfZhmkMHi25x8tfmQtgFMmegQL1X0phy26zC3pLasGIsgs1lcZ/Jila5QXZIe3eoOj9w/oBJo0JQwDrKlp0o2A1x+RwhE7TxbYV04cEa6n3tY20ZBej1etFptjMtcIajqH3PRpDZ71YYl3JxgEyX3xqzL7HTOONehKLVXBuecISKxMSdr9bmQa16fYT2vXWFq8d2rkUb24Sxn/S7b60x1f2vt/6KY7d/BD6iQj4sxCJM6NWtnC3bET3Md8WbjUA7lrWxA/yXY9pAYxg0ice30w+JH4OSdbo7a9slKSPCPCNa1BUwY6R3+D74qymqu7hq/i513mxCqhWSS7LyfpTbGSXkpnSvg7UqqzqnudBlpFQcgP57oKnaf3QqPHBvRjEttAEFZjRbsZEd01k84cCk="
secure: 'E/JmYEY98KbLaw2Dmw6JFNQUtdKN8RfScuY3wjhVoKmXQ1we1hu0fCEuGtZQvYA/6rQRfcTEmvSf1w2uCOk6eYQfzKZDZ5tzQvpv7BwNMsY8D5ACphohlfB+DKx9RKM2zBrD9zaDip2SbSrB5KfYsg2R1YMq5z9ZNQrYp6kdyXNY8kyZaZtDuk18s1ZB3HTviQVQwyHPnevEEHCZZDckPfgPb4d4m32SfCqLLMkETWJojBcfQQafXoVAmK5Fhoe6WxDa6UHj6z9NqOKenKHa+u1XfZhmkMHi25x8tfmQtgFMmegQL1X0phy26zC3pLasGIsgs1lcZ/Jila5QXZIe3eoOj9w/oBJo0JQwDrKlp0o2A1x+RwhE7TxbYV04cEa6n3tY20ZBej1etFptjMtcIajqH3PRpDZ71YYl3JxgEyX3xqzL7HTOONehKLVXBuecISKxMSdr9bmQa16fYT2vXWFq8d2rkUb24Sxn/S7b60x1f2vt/6KY7d/BD6iQj4sxCJM6NWtnC3bET3Md8WbjUA7lrWxA/yXY9pAYxg0ice30w+JH4OSdbo7a9slKSPCPCNa1BUwY6R3+D74qymqu7hq/i513mxCqhWSS7LyfpTbGSXkpnSvg7UqqzqnudBlpFQcgP57oKnaf3QqPHBvRjEttAEFZjRbsZEd01k84cCk='
on:
tags: true
repo: oblador/react-native-keychain
Expand Down
27 changes: 14 additions & 13 deletions KeychainExample/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Component } from 'react';
import {
Alert,
KeyboardAvoidingView,
Platform,
SegmentedControlIOS,
StyleSheet,
Text,
TextInput,
Expand Down Expand Up @@ -51,7 +51,7 @@ export default class KeychainExample extends Component {
};

componentDidMount() {
Keychain.getSupportedBiometryType({}).then(biometryType => {
Keychain.getSupportedBiometryType({}).then((biometryType) => {
this.setState({ biometryType });
});
}
Expand All @@ -75,8 +75,9 @@ export default class KeychainExample extends Component {
this.setState({
username: '',
password: '',
status: `Credentials saved! takes: ${end.getTime() -
start.getTime()} millis`,
status: `Credentials saved! takes: ${
end.getTime() - start.getTime()
} millis`,
});
} catch (err) {
this.setState({ status: 'Could not save credentials, ' + err });
Expand Down Expand Up @@ -126,14 +127,14 @@ export default class KeychainExample extends Component {
);
console.log(`setSharedWebCredentials: ${JSON.stringify(reply)}`);
} catch (err) {
alert(`setSharedWebCredentials: ${err}`);
Alert.alert('setSharedWebCredentials error', err.message);
}

try {
const reply = await Keychain.requestSharedWebCredentials();
console.log(`requestSharedWebCredentials: ${JSON.stringify(reply)}`);
} catch (err) {
alert(`requestSharedWebCredentials: ${err}`);
Alert.alert('requestSharedWebCredentials error', err.message);
}
}

Expand Down Expand Up @@ -164,7 +165,7 @@ export default class KeychainExample extends Component {
onSubmitEditing={() => {
this.passwordTextInput.focus();
}}
onChange={event =>
onChange={(event) =>
this.setState({ username: event.nativeEvent.text })
}
underlineColorAndroid="transparent"
Expand All @@ -179,10 +180,10 @@ export default class KeychainExample extends Component {
password={true}
autoCapitalize="none"
value={this.state.password}
ref={input => {
ref={(input) => {
this.passwordTextInput = input;
}}
onChange={event =>
onChange={(event) =>
this.setState({ password: event.nativeEvent.text })
}
underlineColorAndroid="transparent"
Expand All @@ -197,7 +198,7 @@ export default class KeychainExample extends Component {
? [...VALUES, this.state.biometryType]
: VALUES
}
onTabPress={index =>
onTabPress={(index) =>
this.setState({
...this.state,
accessControl: AC_MAP[index],
Expand All @@ -212,7 +213,7 @@ export default class KeychainExample extends Component {
<SegmentedControlTab
selectedIndex={this.state.selectedSecurityIndex}
values={SECURITY_LEVEL_OPTIONS}
onTabPress={index =>
onTabPress={(index) =>
this.setState({
...this.state,
securityLevel: SL_MAP[index],
Expand All @@ -225,7 +226,7 @@ export default class KeychainExample extends Component {
<SegmentedControlTab
selectedIndex={this.state.selectedStorageIndex}
values={SECURITY_STORAGE_OPTIONS}
onTabPress={index =>
onTabPress={(index) =>
this.setState({
...this.state,
storageSelection: ST_MAP[index],
Expand Down Expand Up @@ -273,7 +274,7 @@ export default class KeychainExample extends Component {
<TouchableHighlight
onPress={async () => {
const level = await Keychain.getSecurityLevel();
alert(level);
Alert.alert('Security Level', level);
}}
style={styles.button}
>
Expand Down
9 changes: 7 additions & 2 deletions KeychainExample/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Example App
first run

first run

```
$ yarn
```

in this folder

## iOS

To run the app on iOS starting from the KeychainExample folder execute
the following commands:

Expand All @@ -20,9 +24,10 @@ pod install

cd ..
react-native run-ios
```
```

## Android

just run

```bash
Expand Down
2 changes: 1 addition & 1 deletion KeychainExample/app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "KeychainExample",
"displayName": "KeychainExample"
}
}
4 changes: 2 additions & 2 deletions KeychainExample/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ["module:metro-react-native-babel-preset"],
}
presets: ['module:metro-react-native-babel-preset'],
};
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,10 @@ The `setInternetCredentials(server, username, password)` call will be resolved a

#### Configuring the Android-specific behavior

Android implementation has behavioural specifics incurred by existing inconsistency between implementations by different vendors. E.g., some Samsung devices show very slow startup of crypto system. To alleviate this, a warm-up strategy is introduced in Android implementation of this library.
Android implementation has behavioural specifics incurred by existing inconsistency between implementations by different vendors. E.g., some Samsung devices show very slow startup of crypto system. To alleviate this, a warm-up strategy is introduced in Android implementation of this library.

Using default constructor you get default behaviour, i.e. with the warming up on.

```java
private List<ReactPackage> createPackageList() {
return Arrays.asList(
Expand All @@ -469,8 +470,10 @@ Using default constructor you get default behaviour, i.e. with the warming up on
...
)

```
```

Those who want finer control are required to use constructor with a builder which can be configured as they like:

```java
private List<ReactPackage> createPackageList() {
return Arrays.asList(
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"RNKeychain.podspec"
],
"scripts": {
"format": "prettier '{,typings/,KeychainExample/}*.{md,js,json,ts,tsx}' --write",
"lint": "eslint .",
"test": "flow"
},
"keywords": [
Expand Down Expand Up @@ -41,7 +43,11 @@
},
"license": "MIT",
"devDependencies": {
"@react-native-community/eslint-config": "^2.0.0",
"eslint": "^7.2.0",
"flow-bin": "^0.107.0",
"react-native": "^0.61.2"
"prettier": "^2.2.1",
"react-native": "^0.61.2",
"typescript": "^4.2.2"
}
}
29 changes: 15 additions & 14 deletions test_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ACCESS_CONTROL,
ACCESSIBLE,
AUTHENTICATION_TYPE,
BIOMETRY_TYPE,
BIOMETRY_TYPE, // eslint-disable-line no-unused-vars
canImplyAuthentication,
getGenericPassword,
getInternetCredentials,
Expand All @@ -18,13 +18,14 @@ import {
type Options,
type Result,
type UserCredentials,
type SharedWebCredentials,
type SharedWebCredentials, // eslint-disable-line no-unused-vars
} from 'react-native-keychain';

canImplyAuthentication().then(result => {
canImplyAuthentication().then((result) => {
(result: boolean);
});

// eslint-disable-next-line no-unused-vars
const simpleOptions2: Options = {
// $FlowExpectedError - not valid accessible value
accessible: 'ACCESSIBLE.ALWAYS',
Expand All @@ -44,32 +45,32 @@ const simpleOptions: Options = {
service: 'service',
};

canImplyAuthentication(simpleOptions).then(result => {
canImplyAuthentication(simpleOptions).then((result) => {
(result: boolean);
});

getSupportedBiometryType().then(result => {
getSupportedBiometryType().then((result) => {
(result: ?string);
});

// $FlowExpectedError - First 3 arguments are required
setInternetCredentials();
setInternetCredentials('server', 'username', 'password');
setInternetCredentials('server', 'username', 'password', simpleOptions).then(
result => {
(result) => {
(result: boolean | Result);
}
);

// $FlowExpectedError - First argument is required
hasInternetCredentials();
hasInternetCredentials('server').then(result => {
hasInternetCredentials('server').then((result) => {
(result: boolean | Result);
});

// $FlowExpectedError - First argument is required
getInternetCredentials();
getInternetCredentials('server', simpleOptions).then(credentials => {
getInternetCredentials('server', simpleOptions).then((credentials) => {
if (credentials) {
(credentials.username: string);
(credentials.password: string);
Expand All @@ -80,19 +81,19 @@ getInternetCredentials('server', simpleOptions).then(credentials => {

// $FlowExpectedError - First argument is required
resetInternetCredentials();
resetInternetCredentials('server').then(result => {
resetInternetCredentials('server').then((result) => {
(result: void);
});

// $FlowExpectedError - First two arguments are required
setGenericPassword();
setGenericPassword('username', 'password').then(result => {
setGenericPassword('username', 'password').then((result) => {
(result: boolean | Result);
});
setGenericPassword('username', 'password', simpleOptions);
setGenericPassword('username', 'password', 'service');

getGenericPassword().then(result => {
getGenericPassword().then((result) => {
(result: boolean | UserCredentials);
});
getGenericPassword(simpleOptions);
Expand All @@ -101,13 +102,13 @@ getGenericPassword({
});
getGenericPassword('service');

resetGenericPassword().then(result => {
resetGenericPassword().then((result) => {
(result: boolean);
});
resetGenericPassword(simpleOptions);
resetGenericPassword('service');

requestSharedWebCredentials().then(result => {
requestSharedWebCredentials().then((result) => {
if (result) {
(result.server: string);
(result.username: string);
Expand All @@ -117,6 +118,6 @@ requestSharedWebCredentials().then(result => {
}
});

setSharedWebCredentials('server', 'username', 'password').then(result => {
setSharedWebCredentials('server', 'username', 'password').then((result) => {
(result: void);
});
Loading

0 comments on commit 8391c1a

Please sign in to comment.