Skip to content

Commit

Permalink
eslint activated with basic rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nfriedly committed Mar 18, 2016
1 parent 5f5a79b commit 59ab7e0
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 72 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
@@ -0,0 +1,6 @@
node_modules/
dist/
doc/
examples/static/watson-speech.js
examples/static/bower_components/
examples/node_modules/
16 changes: 16 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,16 @@
module.exports = {
"env": {
"browser": true,
"node": true // not actually, but we're writing code as if it were and letting browserify handle it
},
"extends": "eslint:recommended",
"globals": {
// false meaning this code doesn't define it
Promise: false,
DataView: false,
ArrayBuffer: false
},
"rules": {

}
};
34 changes: 17 additions & 17 deletions dist/watson-speech.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
extends: '../.eslintrc.js',
"env": {
"browser": true,
"node": true
},
rules: {
'no-console': 0
}
};
2 changes: 1 addition & 1 deletion examples/stt-token.js
Expand Up @@ -17,7 +17,7 @@ var sttConfig = extend({
}, vcapServices.getCredentials('speech_to_text'));

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

var sttAuthService = watson.authorization(sttConfig);

Expand Down
3 changes: 0 additions & 3 deletions examples/tts-token.js
Expand Up @@ -16,9 +16,6 @@ var ttsConfig = extend({
password: process.env.TTS_PASSWORD || '<password>'
}, vcapServices.getCredentials('text_to_speech'));

// quick hack to make development easier
try { extend(ttsConfig, require('../test/resources/tts-auth.json')) } catch (ex) {}

var ttsAuthService = watson.authorization(ttsConfig);

router.get('/token', function(req, res) {
Expand Down
8 changes: 4 additions & 4 deletions test/resources/karma.conf.js → karma.conf.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'../*-spec.js'
'test/*-spec.js'
],


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

browserify: {
debug: true,
// 'brfs' makes fs.read* work
// 'browserify-shim' wraps non-browserify modules
// 'envify' makes process.env work
transform: [ 'envify' ]
transform: ['envify']
},


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

browserDisconnectTimeout: 15000,
Expand Down
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -4,10 +4,9 @@
"description": "IBM Watson Speech to Text and Text to Speech SDK for web browsers.",
"main": "index.js",
"scripts": {
"watch-test": "karma start test/resources/karma.conf.js",
"lint": "eslint --config test/resources/.eslintrc.js *.js speech-to-text/*.js text-to-speech/*.js util/*.js",
"test": "karma start test/resources/karma.conf.js --single-run",
"test-integration": "TEST_MODE=integration karma start test/resources/karma.conf.js --single-run",
"watch-test": "karma start",
"test": "eslint . && karma start --single-run",
"test-integration": "TEST_MODE=integration karma start --single-run",
"browserify": "browserify index.js --standalone WatsonSpeech --outfile dist/watson-speech.js --transform envify",
"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\"",
"watchify": "watchify index.js --standalone WatsonSpeech --outfile dist/watson-speech.js --debug --verbose",
Expand All @@ -20,8 +19,7 @@
"browserify": "^13.0.0",
"concat-stream": "^1.5.1",
"envify": "^3.4.0",
"eslint": "^1.10.3",
"eslint-config-google": "^0.3.0",
"eslint": "^2.4.0",
"expect.js": "^0.3.1",
"jquery": "^2.2.1",
"jsdoc": "^3.4.0",
Expand All @@ -40,7 +38,9 @@
"dependencies": {
"clone": "^1.0.2",
"defaults": "^1.0.3",
"eslint": "^2.4.0",
"get-user-media-promise": "^1.0.0",
"karma-eslint": "^2.1.0",
"microphone-stream": "^3.0.2",
"object.assign": "^4.0.3",
"object.pick": "^1.1.1",
Expand Down
24 changes: 13 additions & 11 deletions speech-to-text/recognize-microphone.js
Expand Up @@ -79,8 +79,20 @@ module.exports = function recognizeMicrophone(options) {
});
}

// set up the output first so that we have a place to emit errors
// if there's trouble with the input stream
var stream = recognizeStream;
if (options.format !== false) {
stream = stream.pipe(new FormatStream(options));
stream.stop = recognizeStream.stop.bind(recognizeStream);
}

if (options.outputElement) {
stream.pipe(new WritableElementStream(options))
}

getMicStream.catch(function(err) {
console.log(err);
stream.emit('error', err);
});

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


var stream = recognizeStream;
if (options.format !== false) {
stream = stream.pipe(new FormatStream(options));
stream.stop = recognizeStream.stop.bind(recognizeStream);
}

if (options.outputElement) {
stream.pipe(new WritableElementStream(options))
}

return stream;
};

Expand Down
4 changes: 3 additions & 1 deletion speech-to-text/recognize-stream.js
Expand Up @@ -142,6 +142,8 @@ function RecognizeStream(options) {
}); // todo: is there a better way to put a stream in flowing mode?
});
if (!options.silent) {
// todo: move this to the node.js wrapper
// eslint-disable-next-line no-console
console.log(new Error('Watson Speech to Text RecognizeStream: the ' + event + ' event is deprecated and will be removed from a future release. ' +
'Please set {objectMode: true} and listen for the data event instead. ' +
'Pass {silent: true} to disable this message.'));
Expand Down Expand Up @@ -338,7 +340,7 @@ RecognizeStream.prototype.sendData = function sendData(data) {
return this.socket.send(data);
};

RecognizeStream.prototype._read = function (size) {
RecognizeStream.prototype._read = function (/*size*/) {
// there's no easy way to control reads from the underlying library
// so, the best we can do here is a no-op
};
Expand Down
2 changes: 1 addition & 1 deletion speech-to-text/timing-stream.js
Expand Up @@ -51,7 +51,7 @@ TimingStream.prototype._write = function(result, encoding, next) {
next();
};

TimingStream.prototype._read = function(size) {
TimingStream.prototype._read = function(/*size*/) {
// ignore - we'll emit results once the time has come
};

Expand Down
11 changes: 11 additions & 0 deletions test/.eslintrc.js
@@ -0,0 +1,11 @@
module.exports = {
extends: '../.eslintrc.js',
"env": {
"browser": true,
"node": true,
"mocha": true
},
rules: {
'no-console': 0
}
};
1 change: 0 additions & 1 deletion test/end-to-end-spec.js
Expand Up @@ -4,7 +4,6 @@ var assert = require('assert');

var SpeechToText = require('../speech-to-text');

var expect = require('expect.js');
var concat = require('concat-stream');

if (typeof fetch == "undefined") {
Expand Down
16 changes: 8 additions & 8 deletions test/format-stream-spec.js
Expand Up @@ -20,18 +20,18 @@ describe('FormatStream', function() {

it('should format objects', function(done) {
var stream = new FormatStream({objectMode: true});
var source = { alternatives:
[ {
var source = {alternatives:
[{
confidence: 0.881,
transcript: 'foo bar ',
final: true } ],
result_index: 0 };
var expected = { alternatives:
[ {
final: true}],
result_index: 0};
var expected = {alternatives:
[{
confidence: 0.881,
transcript: 'Foo bar. ',
final: true } ],
result_index: 0 };
final: true}],
result_index: 0};
stream.on('data', function(actual) {
assert(actual, expected);
done();
Expand Down
14 changes: 0 additions & 14 deletions test/resources/.eslintrc.js

This file was deleted.

0 comments on commit 59ab7e0

Please sign in to comment.