Skip to content

Commit

Permalink
feat(lint): add lint, prettier and lint-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
sibelius committed Nov 4, 2018
1 parent fade2bd commit cdca151
Show file tree
Hide file tree
Showing 6 changed files with 5,918 additions and 43 deletions.
69 changes: 69 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true,
"jest": true,
"es6": true,
},
"plugins": [
"react",
"react-native",
"flowtype",
"import"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:import/errors"
],
"rules": {
"comma-dangle": [2, "always-multiline"],
"quotes": [2, "single", { "allowTemplateLiterals": true }],
"react/prop-types": 0,
"no-case-declarations": 0,
"react/jsx-no-bind": 0,
"react/display-name": 0,
"new-cap": 0,
"react-native/no-unused-styles": 2,
"react-native/split-platform-components": 0,
"react-native/no-inline-styles": 0,
"react-native/no-color-literals": 0,
"no-unexpected-multiline": 0,
"no-class-assign": 1,
"no-console": 2,
"object-curly-spacing": [1, "always"],
"flowtype/define-flow-type": 1,
"flowtype/use-flow-type": 1,
"import/first": 2,
"import/default": 0,
"no-unused-vars": ["error", { "ignoreRestSiblings": true }],
"import/named": 0,
"import/namespace": [2, { "allowComputed": true }],
"no-extra-boolean-cast": 0,
"import/no-duplicates": 2,
"react/no-deprecated": 0
},
"settings": {
"import/resolver": {
"node": {
"extensions":[
".js",
".android.js",
".ios.js",
".json"
]
}
}
},
"globals": {
"__DEV__": true
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ node_modules

build/
VoiceModule.iml
yarn-error.log
10 changes: 5 additions & 5 deletions VoiceTest/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"name": "VoiceTest",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "^16.0.0-alpha.12",
"react-native": "^0.45.1"
Expand All @@ -18,5 +13,10 @@
},
"jest": {
"preset": "react-native"
},
"scripts": {
"clear": "node node_modules/react-native/local-cli/cli.js clear",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
}
}
43 changes: 33 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
{
"name": "react-native-voice",
"version": "0.2.6",
"description": "React Native Native Voice library for iOS and Android",
"main": "index.js",
"version": "0.2.6",
"author": "Sam Wenke <[email protected]>",
"peerDependencies": {
"react-native": ">=0.40.0"
},
"devDependencies": {
"react": ">=16.0.0-alpha.12"
"eslint": "^5.3.0",
"eslint-plugin-flowtype": "^2.50.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-react": "^7.10.0",
"eslint-plugin-react-native": "^3.2.1",
"pre-commit": "^1.2.2",
"prettier": "^1.12.0",
"lint-staged": "^7.2.0",
"babel-eslint": "^8.2.6",
"react": "16.4.2",
"react-native": "^0.56.0"
},
"keywords": [
"android",
"ios",
"react-native",
"speech",
"voice",
"android",
"ios"
"voice"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"yarn prettier",
"eslint --fix",
"git add"
]
},
"main": "src/index.js",
"peerDependencies": {
"react-native": ">=0.40.0"
},
"pre-commit": "lint:staged",
"repository": {
"type": "git",
"url": "git://github.com/wenkesj/react-native-voice.git"
},
"license": "MIT"
"scripts": {
"lint": "eslint src --max-warnings=0",
"lint:staged": "lint-staged",
"prettier": "prettier --write --single-quote true --trailing-comma all --print-width 100"
}
}
59 changes: 31 additions & 28 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
'use strict';
import React, {
NativeModules,
NativeEventEmitter,
Platform,
} from 'react-native';
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';

const { Voice } = NativeModules;

// NativeEventEmitter is only availabe on React Native platforms, so this conditional is used to avoid import conflicts in the browser/server
const voiceEmitter = Platform.OS !== "web" ? new NativeEventEmitter(Voice) : null;
const voiceEmitter = Platform.OS !== 'web' ? new NativeEventEmitter(Voice) : null;

class RCTVoice {
constructor() {
this._loaded = false;
this._listeners = null;
this._events = {
'onSpeechStart': this._onSpeechStart.bind(this),
'onSpeechRecognized': this._onSpeechRecognized.bind(this),
'onSpeechEnd': this._onSpeechEnd.bind(this),
'onSpeechError': this._onSpeechError.bind(this),
'onSpeechResults': this._onSpeechResults.bind(this),
'onSpeechPartialResults': this._onSpeechPartialResults.bind(this),
'onSpeechVolumeChanged': this._onSpeechVolumeChanged.bind(this)
onSpeechStart: this._onSpeechStart.bind(this),
onSpeechRecognized: this._onSpeechRecognized.bind(this),
onSpeechEnd: this._onSpeechEnd.bind(this),
onSpeechError: this._onSpeechError.bind(this),
onSpeechResults: this._onSpeechResults.bind(this),
onSpeechPartialResults: this._onSpeechPartialResults.bind(this),
onSpeechVolumeChanged: this._onSpeechVolumeChanged.bind(this),
};
}
removeAllListeners() {
Expand All @@ -38,12 +33,12 @@ class RCTVoice {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
Voice.destroySpeech((error) => {
Voice.destroySpeech(error => {
if (error) {
reject(new Error(error));
} else {
if (this._listeners) {
this._listeners.map((listener, index) => listener.remove());
this._listeners.map(listener => listener.remove());
this._listeners = null;
}
resolve();
Expand All @@ -53,25 +48,33 @@ class RCTVoice {
}
start(locale, options = {}) {
if (!this._loaded && !this._listeners && voiceEmitter !== null) {
this._listeners = Object.keys(this._events)
.map((key, index) => voiceEmitter.addListener(key, this._events[key]));
this._listeners = Object.keys(this._events).map(key =>
voiceEmitter.addListener(key, this._events[key]),
);
}

return new Promise((resolve, reject) => {
const callback = (error) => {
const callback = error => {
if (error) {
reject(new Error(error));
} else {
resolve();
}
};
if (Platform.OS === 'android') {
Voice.startSpeech(locale, Object.assign({
EXTRA_LANGUAGE_MODEL: "LANGUAGE_MODEL_FREE_FORM",
EXTRA_MAX_RESULTS: 5,
EXTRA_PARTIAL_RESULTS: true,
REQUEST_PERMISSIONS_AUTO: true,
}, options), callback);
Voice.startSpeech(
locale,
Object.assign(
{
EXTRA_LANGUAGE_MODEL: 'LANGUAGE_MODEL_FREE_FORM',
EXTRA_MAX_RESULTS: 5,
EXTRA_PARTIAL_RESULTS: true,
REQUEST_PERMISSIONS_AUTO: true,
},
options,
),
callback,
);
} else {
Voice.startSpeech(locale, callback);
}
Expand All @@ -82,7 +85,7 @@ class RCTVoice {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
Voice.stopSpeech((error) => {
Voice.stopSpeech(error => {
if (error) {
reject(new Error(error));
} else {
Expand All @@ -96,7 +99,7 @@ class RCTVoice {
return Promise.resolve();
}
return new Promise((resolve, reject) => {
Voice.cancelSpeech((error) => {
Voice.cancelSpeech(error => {
if (error) {
reject(new Error(error));
} else {
Expand All @@ -117,7 +120,7 @@ class RCTVoice {
});
}
isRecognizing() {
return new Promise((resolve, reject) => {
return new Promise(resolve => {
Voice.isRecognizing(isRecognizing => resolve(isRecognizing));
});
}
Expand Down
Loading

0 comments on commit cdca151

Please sign in to comment.