Skip to content

Commit 59ab7e0

Browse files
committed
eslint activated with basic rules
1 parent 5f5a79b commit 59ab7e0

16 files changed

+101
-72
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
dist/
3+
doc/
4+
examples/static/watson-speech.js
5+
examples/static/bower_components/
6+
examples/node_modules/

.eslintrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"node": true // not actually, but we're writing code as if it were and letting browserify handle it
5+
},
6+
"extends": "eslint:recommended",
7+
"globals": {
8+
// false meaning this code doesn't define it
9+
Promise: false,
10+
DataView: false,
11+
ArrayBuffer: false
12+
},
13+
"rules": {
14+
15+
}
16+
};

dist/watson-speech.js

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/.eslintrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
extends: '../.eslintrc.js',
3+
"env": {
4+
"browser": true,
5+
"node": true
6+
},
7+
rules: {
8+
'no-console': 0
9+
}
10+
};

examples/stt-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var sttConfig = extend({
1717
}, vcapServices.getCredentials('speech_to_text'));
1818

1919
// quick hack to make development easier
20-
try { extend(sttConfig, require('../test/resources/stt-auth.json')) } catch (ex) {console.log(ex)}
20+
try { extend(sttConfig, require('../test/resources/stt-auth.json')) } catch (ex) { console.log(ex) }
2121

2222
var sttAuthService = watson.authorization(sttConfig);
2323

examples/tts-token.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ var ttsConfig = extend({
1616
password: process.env.TTS_PASSWORD || '<password>'
1717
}, vcapServices.getCredentials('text_to_speech'));
1818

19-
// quick hack to make development easier
20-
try { extend(ttsConfig, require('../test/resources/tts-auth.json')) } catch (ex) {}
21-
2219
var ttsAuthService = watson.authorization(ttsConfig);
2320

2421
router.get('/token', function(req, res) {

test/resources/karma.conf.js renamed to karma.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function(config) {
1515

1616
// list of files / patterns to load in the browser
1717
files: [
18-
'../*-spec.js'
18+
'test/*-spec.js'
1919
],
2020

2121

@@ -27,15 +27,15 @@ module.exports = function(config) {
2727
// preprocess matching files before serving them to the browser
2828
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
2929
preprocessors: {
30-
'../*-spec.js': [ 'browserify' ]
30+
'test/*-spec.js': ['browserify']
3131
},
3232

3333
browserify: {
3434
debug: true,
3535
// 'brfs' makes fs.read* work
3636
// 'browserify-shim' wraps non-browserify modules
3737
// 'envify' makes process.env work
38-
transform: [ 'envify' ]
38+
transform: ['envify']
3939
},
4040

4141

@@ -96,7 +96,7 @@ module.exports = function(config) {
9696
port: 9877,
9797
// this function takes express app object and allows you to modify it
9898
// to your liking. For more see http://expressjs.com/4x/api.html
99-
appVisitor: (process.env.TEST_MODE === 'integration') ? require('./integration_test_server.js') : require('./offline_test_server.js')
99+
appVisitor: (process.env.TEST_MODE === 'integration') ? require('./test/resources/integration_test_server.js') : require('./test/resources/offline_test_server.js')
100100
},
101101

102102
browserDisconnectTimeout: 15000,

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
"description": "IBM Watson Speech to Text and Text to Speech SDK for web browsers.",
55
"main": "index.js",
66
"scripts": {
7-
"watch-test": "karma start test/resources/karma.conf.js",
8-
"lint": "eslint --config test/resources/.eslintrc.js *.js speech-to-text/*.js text-to-speech/*.js util/*.js",
9-
"test": "karma start test/resources/karma.conf.js --single-run",
10-
"test-integration": "TEST_MODE=integration karma start test/resources/karma.conf.js --single-run",
7+
"watch-test": "karma start",
8+
"test": "eslint . && karma start --single-run",
9+
"test-integration": "TEST_MODE=integration karma start --single-run",
1110
"browserify": "browserify index.js --standalone WatsonSpeech --outfile dist/watson-speech.js --transform envify",
1211
"minify": "uglifyjs --compress --mangle --screw-ie8 dist/watson-speech.js --output dist/watson-speech.min.js --preamble \"// IBM Watson Speech JavaScript SDK\n// $npm_package_version\n// Generated at `date`\n// Copyright IBM ($npm_package_license)\n// $npm_package_homepage\"",
1312
"watchify": "watchify index.js --standalone WatsonSpeech --outfile dist/watson-speech.js --debug --verbose",
@@ -20,8 +19,7 @@
2019
"browserify": "^13.0.0",
2120
"concat-stream": "^1.5.1",
2221
"envify": "^3.4.0",
23-
"eslint": "^1.10.3",
24-
"eslint-config-google": "^0.3.0",
22+
"eslint": "^2.4.0",
2523
"expect.js": "^0.3.1",
2624
"jquery": "^2.2.1",
2725
"jsdoc": "^3.4.0",
@@ -40,7 +38,9 @@
4038
"dependencies": {
4139
"clone": "^1.0.2",
4240
"defaults": "^1.0.3",
41+
"eslint": "^2.4.0",
4342
"get-user-media-promise": "^1.0.0",
43+
"karma-eslint": "^2.1.0",
4444
"microphone-stream": "^3.0.2",
4545
"object.assign": "^4.0.3",
4646
"object.pick": "^1.1.1",

speech-to-text/recognize-microphone.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,20 @@ module.exports = function recognizeMicrophone(options) {
7979
});
8080
}
8181

82+
// set up the output first so that we have a place to emit errors
83+
// if there's trouble with the input stream
84+
var stream = recognizeStream;
85+
if (options.format !== false) {
86+
stream = stream.pipe(new FormatStream(options));
87+
stream.stop = recognizeStream.stop.bind(recognizeStream);
88+
}
89+
90+
if (options.outputElement) {
91+
stream.pipe(new WritableElementStream(options))
92+
}
93+
8294
getMicStream.catch(function(err) {
83-
console.log(err);
95+
stream.emit('error', err);
8496
});
8597

8698
getMicStream.then(function(micStream) {
@@ -110,16 +122,6 @@ module.exports = function recognizeMicrophone(options) {
110122
}).catch(recognizeStream.emit.bind(recognizeStream, 'error'));
111123

112124

113-
var stream = recognizeStream;
114-
if (options.format !== false) {
115-
stream = stream.pipe(new FormatStream(options));
116-
stream.stop = recognizeStream.stop.bind(recognizeStream);
117-
}
118-
119-
if (options.outputElement) {
120-
stream.pipe(new WritableElementStream(options))
121-
}
122-
123125
return stream;
124126
};
125127

speech-to-text/recognize-stream.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ function RecognizeStream(options) {
142142
}); // todo: is there a better way to put a stream in flowing mode?
143143
});
144144
if (!options.silent) {
145+
// todo: move this to the node.js wrapper
146+
// eslint-disable-next-line no-console
145147
console.log(new Error('Watson Speech to Text RecognizeStream: the ' + event + ' event is deprecated and will be removed from a future release. ' +
146148
'Please set {objectMode: true} and listen for the data event instead. ' +
147149
'Pass {silent: true} to disable this message.'));
@@ -338,7 +340,7 @@ RecognizeStream.prototype.sendData = function sendData(data) {
338340
return this.socket.send(data);
339341
};
340342

341-
RecognizeStream.prototype._read = function (size) {
343+
RecognizeStream.prototype._read = function (/*size*/) {
342344
// there's no easy way to control reads from the underlying library
343345
// so, the best we can do here is a no-op
344346
};

0 commit comments

Comments
 (0)