Skip to content

Commit 51dd4a0

Browse files
committed
Stricter eslint
One bug fixed + a number of changes to pass the tests. One issue with valid-jsdoc, it's set to a warning for now.
1 parent 59ab7e0 commit 51dd4a0

27 files changed

+510
-244
lines changed

.eslintrc.js

Lines changed: 211 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,216 @@
11
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
2+
'env': {
3+
'browser': true,
4+
'node': true
55
},
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": {
146

7+
'globals': {
8+
// false meaning this code doesn't define it
9+
Promise: false,
10+
DataView: false,
11+
ArrayBuffer: false
12+
},
13+
'myrules': {
14+
'consistent-return': 2,
15+
'curly': 2,
16+
eqeqeq: [2, 'smart'],
17+
'no-alert': 2,
18+
'no-eq-null': 2,
19+
'no-eval': 2,
20+
'no-extend-native': 2
21+
},
22+
'extends': 'eslint:recommended',
23+
'rules': {
24+
'accessor-pairs': 2,
25+
'array-bracket-spacing': [
26+
2,
27+
'never'
28+
],
29+
'array-callback-return': 2,
30+
'arrow-body-style': 2,
31+
'arrow-parens': 2,
32+
'arrow-spacing': 2,
33+
'block-scoped-var': 1,
34+
'block-spacing': 2,
35+
'brace-style': [
36+
2,
37+
'1tbs'
38+
],
39+
'callback-return': 2,
40+
'camelcase': [
41+
2,
42+
{
43+
'properties': 'never'
44+
}
45+
],
46+
'comma-spacing': 0,
47+
'comma-style': [
48+
2,
49+
'last'
50+
],
51+
'complexity': 2,
52+
'computed-property-spacing': [
53+
2,
54+
'never'
55+
],
56+
'consistent-this': [ 1, 'self', 'that' ],
57+
'curly': 2,
58+
'default-case': 2,
59+
'dot-location': [
60+
2,
61+
'property'
62+
],
63+
'dot-notation': [
64+
2,
65+
{
66+
'allowKeywords': true
67+
}
68+
],
69+
'eol-last': 2,
70+
'eqeqeq': [2, 'smart'],
71+
'func-names': 0,
72+
'func-style': [
73+
2,
74+
'declaration'
75+
],
76+
'generator-star-spacing': 2,
77+
'global-require': 0,
78+
'guard-for-in': 2,
79+
'handle-callback-err': 2,
80+
'id-blacklist': 2,
81+
'id-match': 2,
82+
'indent': [1, 2],
83+
'jsx-quotes': 2,
84+
'key-spacing': 2,
85+
'keyword-spacing': 1,
86+
'linebreak-style': [
87+
2,
88+
'unix'
89+
],
90+
'max-depth': 2,
91+
'max-len': [
92+
1,
93+
{
94+
'code': 160,
95+
'tabWidth': 2,
96+
'ignoreComments': true,
97+
'ignoreUrls': true
98+
}
99+
],
100+
'max-nested-callbacks': 2,
101+
'max-params': 2,
102+
'new-cap': 2,
103+
'new-parens': 2,
104+
'no-alert': 2,
105+
'no-array-constructor': 2,
106+
'no-bitwise': [
107+
2,
108+
{
109+
'int32Hint': true
110+
}
111+
],
112+
'no-caller': 2,
113+
'no-catch-shadow': 2,
114+
'no-confusing-arrow': 2,
115+
'no-continue': 2,
116+
'no-div-regex': 2,
117+
'no-else-return': 2,
118+
'no-eq-null': 2,
119+
'no-eval': 2,
120+
'no-extend-native': 2,
121+
'no-extra-bind': 2,
122+
'no-extra-label': 2,
123+
'no-floating-decimal': 2,
124+
'no-implicit-globals': 2,
125+
'no-implied-eval': 2,
126+
'no-inner-declarations': [
127+
2,
128+
'functions'
129+
],
130+
'no-invalid-this': 2,
131+
'no-iterator': 2,
132+
'no-label-var': 2,
133+
'no-labels': 2,
134+
'no-lone-blocks': 2,
135+
'no-lonely-if': 0,
136+
'no-loop-func': 2,
137+
'no-multi-spaces': 1,
138+
'no-multi-str': 2,
139+
'no-native-reassign': 2,
140+
'no-negated-condition': 2,
141+
'no-nested-ternary': 2,
142+
'no-new': 2,
143+
'no-new-func': 2,
144+
'no-new-object': 2,
145+
'no-new-require': 2,
146+
'no-new-wrappers': 2,
147+
'no-octal-escape': 2,
148+
'no-proto': 2,
149+
'no-restricted-imports': 2,
150+
'no-restricted-modules': 2,
151+
'no-restricted-syntax': 2,
152+
'no-return-assign': 2,
153+
'no-script-url': 2,
154+
'no-self-compare': 2,
155+
'no-sequences': 2,
156+
'no-shadow': 2,
157+
'no-shadow-restricted-names': 2,
158+
'no-spaced-func': 2,
159+
'no-throw-literal': 2,
160+
'no-trailing-spaces': 2,
161+
'no-undef-init': 2,
162+
'no-undefined': 2,
163+
'no-unmodified-loop-condition': 2,
164+
'no-unneeded-ternary': 2,
165+
'no-unused-expressions': 2,
166+
'no-use-before-define': 2,
167+
'no-useless-call': 2,
168+
'no-useless-concat': 2,
169+
'no-useless-constructor': 2,
170+
'no-void': 2,
171+
'no-warning-comments': 1,
172+
'no-whitespace-before-property': 2,
173+
'no-with': 2,
174+
'object-curly-spacing': [
175+
2,
176+
'never'
177+
],
178+
'one-var-declaration-per-line': 2,
179+
'operator-assignment': [
180+
2,
181+
'always'
182+
],
183+
'operator-linebreak': 2,
184+
'quote-props': [2, 'as-needed'],
185+
'quotes': [1, 'single', 'avoid-escape'],
186+
'radix': 2,
187+
'require-jsdoc': 2,
188+
'require-yield': 2,
189+
'semi': 1,
190+
'semi-spacing': [
191+
2,
192+
{
193+
'after': true,
194+
'before': false
195+
}
196+
],
197+
'sort-imports': 2,
198+
'space-before-function-paren': [1, 'never'],
199+
'space-in-parens': [1, 'never'],
200+
'space-infix-ops': 1,
201+
'space-unary-ops': 2,
202+
'spaced-comment': 1,
203+
'strict': 2,
204+
'template-curly-spacing': 2,
205+
'valid-jsdoc': [1, {
206+
'requireReturn': false,
207+
'requireParamDescription': false,
208+
'requireReturnDescription': false
209+
}],
210+
'wrap-iife': 2,
211+
'yoda': [
212+
2,
213+
'never'
214+
]
15215
}
16216
};

examples/server.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
'use strict';
1818

19-
var express = require('express'),
20-
app = express();
19+
var express = require('express'),
20+
app = express();
2121

2222
// allows environment properties to be set in a file named .env
2323
require('dotenv').load({silent: true});
@@ -31,23 +31,23 @@ app.use('/api/text-to-speech/', require('./tts-token.js'));
3131

3232
var port = process.env.VCAP_APP_PORT || 3000;
3333
app.listen(port, function() {
34-
console.log('Example IBM Watson Speech JS SDK client app & token server live at http://localhost:%s/', port);
34+
console.log('Example IBM Watson Speech JS SDK client app & token server live at http://localhost:%s/', port);
3535
});
3636

3737
// chrome requires https to access the user's microphone unless it's a localhost url so
3838
// this sets up a basic server at https://localhost3001/ using an included self-signed certificate
3939
// note: this is not suitable for production use
4040
// however bluemix automatically adds https support at http://<myapp>.mybluemix.net
4141
if (!process.env.VCAP_APP_PORT) {
42-
var fs = require("fs"),
43-
https = require("https"),
44-
HTTPS_PORT = 3001;
45-
46-
var options = {
47-
key: fs.readFileSync(__dirname + '/keys/localhost.pem'),
48-
cert: fs.readFileSync(__dirname + '/keys/localhost.cert')
49-
};
50-
https.createServer(options, app).listen(HTTPS_PORT, function () {
51-
console.log('Secure server live at https://localhost:%s/', HTTPS_PORT)
52-
});
42+
var fs = require('fs'),
43+
https = require('https'),
44+
HTTPS_PORT = 3001;
45+
46+
var options = {
47+
key: fs.readFileSync(__dirname + '/keys/localhost.pem'),
48+
cert: fs.readFileSync(__dirname + '/keys/localhost.cert')
49+
};
50+
https.createServer(options, app).listen(HTTPS_PORT, function() {
51+
console.log('Secure server live at https://localhost:%s/', HTTPS_PORT);
52+
});
5353
}

examples/stt-token.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
var express = require('express'),
4-
router = express.Router(),
3+
var express = require('express'),
4+
router = express.Router(), // eslint-disable-line new-cap
55
vcapServices = require('vcap_services'),
6-
extend = require('util')._extend,
7-
watson = require('watson-developer-cloud');
6+
extend = require('util')._extend,
7+
watson = require('watson-developer-cloud');
88

99
// set up an endpoint to serve speech-to-text auth tokens
1010

@@ -16,16 +16,14 @@ var sttConfig = extend({
1616
password: process.env.STT_PASSWORD || '<password>'
1717
}, vcapServices.getCredentials('speech_to_text'));
1818

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

2421
router.get('/token', function(req, res) {
2522
sttAuthService.getToken({url: sttConfig.url}, function(err, token) {
2623
if (err) {
2724
console.log('Error retrieving token: ', err);
28-
return res.status(500).send('Error retrieving token')
25+
res.status(500).send('Error retrieving token');
26+
return;
2927
}
3028
res.send(token);
3129
});

examples/tts-token.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
var express = require('express'),
4-
router = express.Router(),
3+
var express = require('express'),
4+
router = express.Router(), // eslint-disable-line new-cap
55
vcapServices = require('vcap_services'),
6-
extend = require('util')._extend,
7-
watson = require('watson-developer-cloud');
6+
extend = require('util')._extend,
7+
watson = require('watson-developer-cloud');
88

99
// another endpoint for the text to speech service
1010

@@ -22,7 +22,8 @@ router.get('/token', function(req, res) {
2222
ttsAuthService.getToken({url: ttsConfig.url}, function(err, token) {
2323
if (err) {
2424
console.log('Error retrieving token: ', err);
25-
return res.status(500).send('Error retrieving token')
25+
res.status(500).send('Error retrieving token');
26+
return;
2627
}
2728
res.send(token);
2829
});

karma.conf.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// Karma configuration
22
// Generated on Fri Jan 15 2016 13:36:31 GMT-0500 (EST)
3+
'use strict';
4+
5+
var testServer;
6+
if (process.env.TEST_MODE === 'integration') {
7+
testServer = require('./test/resources/integration_test_server.js');
8+
} else {
9+
testServer = require('./test/resources/offline_test_server.js');
10+
}
11+
312

413
module.exports = function(config) {
514
config.set({
@@ -72,7 +81,12 @@ module.exports = function(config) {
7281
ChromeWithPrerecordedMic: {
7382
base: 'Chrome',
7483
// --no-sandbox is required for travis-ci
75-
flags: ['--use-fake-device-for-media-stream','--use-fake-ui-for-media-stream', '--use-file-for-fake-audio-capture=test/resources/audio.wav', '--no-sandbox']
84+
flags: [
85+
'--use-fake-device-for-media-stream',
86+
'--use-fake-ui-for-media-stream',
87+
'--use-file-for-fake-audio-capture=test/resources/audio.wav',
88+
'--no-sandbox'
89+
]
7690
},
7791
// automatically approve getUserMedia calls
7892
FirefoxAutoGUM: {
@@ -96,7 +110,7 @@ module.exports = function(config) {
96110
port: 9877,
97111
// this function takes express app object and allows you to modify it
98112
// to your liking. For more see http://expressjs.com/4x/api.html
99-
appVisitor: (process.env.TEST_MODE === 'integration') ? require('./test/resources/integration_test_server.js') : require('./test/resources/offline_test_server.js')
113+
appVisitor: testServer
100114
},
101115

102116
browserDisconnectTimeout: 15000,

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"main": "index.js",
66
"scripts": {
77
"watch-test": "karma start",
8-
"test": "eslint . && karma start --single-run",
8+
"lint": "eslint .",
9+
"autofix": "eslint . --fix",
10+
"test": "npm run lint &&npm run test-offline",
11+
"test-offline": "karma start --single-run",
912
"test-integration": "TEST_MODE=integration karma start --single-run",
1013
"browserify": "browserify index.js --standalone WatsonSpeech --outfile dist/watson-speech.js --transform envify",
1114
"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\"",

speech-to-text/content-type.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// these are the only content-types currently supported by the speech-to-tet service
44
var contentTypes = {
5-
'fLaC': 'audio/flac',
6-
'RIFF': 'audio/wav',
7-
'OggS': 'audio/ogg; codecs=opus'
5+
fLaC: 'audio/flac',
6+
RIFF: 'audio/wav',
7+
OggS: 'audio/ogg; codecs=opus'
88
};
99

1010
/**

0 commit comments

Comments
 (0)