Skip to content

Commit 5d76561

Browse files
committed
refactor(tts-cli): Linting fixes
1 parent b306226 commit 5d76561

16 files changed

+86
-84
lines changed

packages/tts-cli/lib/cleanup.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const fs = require('fs-extra')
66
*/
77
exports.cleanup = ctx => {
88
const manifestFile = ctx.manifestFile
9-
let manifest = fs.readFileSync(manifestFile, 'utf8')
9+
const manifest = fs.readFileSync(manifestFile, 'utf8')
1010
debug(`Manifest is ${manifest}`)
11-
let regexpState = /^file\s+'(.*)'$/gm
11+
const regexpState = /^file\s+'(.*)'$/gm
1212
let match
1313
while ((match = regexpState.exec(manifest)) !== null) {
1414
debug(`Deleting temporary file ${match[1]}`)

packages/tts-cli/lib/combine-parts.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { extensionFor } = require('./file-extensions')
88
* Combines MP3 or OGG files into one file.
99
*/
1010
exports.combineEncodedAudio = (binary, manifestFile, outputFile) => {
11-
let args = [
11+
const args = [
1212
'-f', 'concat',
1313
'-safe', '0',
1414
'-i', manifestFile,
@@ -17,7 +17,7 @@ exports.combineEncodedAudio = (binary, manifestFile, outputFile) => {
1717
]
1818
return new Promise((resolve, reject) => {
1919
debug('combineEncodedAudio')(`Running ${binary} ${args.join(' ')}`)
20-
let ffmpeg = spawn(binary, args)
20+
const ffmpeg = spawn(binary, args)
2121
let stderr = ''
2222
ffmpeg.stderr.on('data', (data) => {
2323
stderr += `\n${data}`
@@ -40,17 +40,17 @@ exports.combineEncodedAudio = (binary, manifestFile, outputFile) => {
4040
* Concatenates raw PCM audio into one file.
4141
*/
4242
exports.combineRawAudio = (manifestFile, outputFile) => {
43-
let manifest = fs.readFileSync(manifestFile, 'utf8')
43+
const manifest = fs.readFileSync(manifestFile, 'utf8')
4444
debug('combineRawAudio')(`Manifest contains: ${manifest}`)
45-
let regexpState = /^file\s+'(.*)'$/gm
45+
const regexpState = /^file\s+'(.*)'$/gm
4646
debug('combineRawAudio')(`Creating file ${outputFile}`)
4747
fs.createFileSync(outputFile)
4848
debug('combineRawAudio')(`Truncating file ${outputFile}`)
4949
fs.truncateSync(outputFile)
5050
let match
5151
while ((match = regexpState.exec(manifest)) !== null) {
5252
debug('combineRawAudio')(`Reading data from ${match[1]}`)
53-
let dataBuffer = fs.readFileSync(match[1])
53+
const dataBuffer = fs.readFileSync(match[1])
5454
debug('combineRawAudio')(`Appending data to ${outputFile}`)
5555
fs.appendFileSync(outputFile, dataBuffer)
5656
}
@@ -64,9 +64,9 @@ exports.combineRawAudio = (manifestFile, outputFile) => {
6464
exports.combine = (ctx) => {
6565
const manifestFile = ctx.manifestFile
6666
const opts = ctx.opts
67-
let newFile = tempfile(`.${extensionFor(opts.format, ctx.service)}`)
67+
const newFile = tempfile(`.${extensionFor(opts.format, ctx.service)}`)
6868
debug('combine')(`Combining files into ${newFile}`)
69-
let combiner = opts.format === 'pcm' && ctx.service === 'aws'
69+
const combiner = opts.format === 'pcm' && ctx.service === 'aws'
7070
? exports.combineRawAudio(manifestFile, newFile)
7171
: exports.combineEncodedAudio(opts.ffmpeg, manifestFile, newFile)
7272
return combiner.then(() => {

packages/tts-cli/lib/generate-speech.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const { sanitizeOpts } = require('./sanitize-opts')
1111
exports.buildInfo = (text, instance, task, ctx) => {
1212
return Object.assign({
1313
opts: ctx.opts,
14-
task: task,
14+
task,
1515
tempfile: tempfile(`.${extensionFor(ctx.opts.format, ctx.service)}`),
16-
text: text
16+
text
1717
}, instance.buildPart(text, task, ctx.opts))
1818
}
1919

@@ -22,9 +22,9 @@ exports.buildInfo = (text, instance, task, ctx) => {
2222
* Returns the text filename.
2323
*/
2424
exports.createManifest = parts => {
25-
let txtFile = tempfile('.txt')
25+
const txtFile = tempfile('.txt')
2626
debug('createManifest')(`Creating ${txtFile} for manifest`)
27-
let contents = parts.map(info => {
27+
const contents = parts.map(info => {
2828
return `file '${info.tempfile}'`
2929
}).join('\n')
3030
debug('createManifest')(`Writing manifest contents:\n${contents}`)
@@ -36,7 +36,7 @@ exports.createManifest = parts => {
3636
* Calls the API for each text part (throttled). Returns a Promise.
3737
*/
3838
exports.generateAll = (parts, opts, func, task) => {
39-
let count = parts.length
39+
const count = parts.length
4040
task.title = `Convert to audio (0/${count})`
4141
return (new Promise((resolve, reject) => {
4242
debug('generateAll')(`Requesting ${count} audio segments, ${opts.limit} at a time`)
@@ -106,7 +106,7 @@ exports.generateSpeech = (ctx, task) => {
106106
const instance = provider.create(ctx.opts)
107107

108108
// Compile the text parts and options together in a packet.
109-
let parts = strParts.map(part => exports.buildInfo(part, instance, task, ctx))
109+
const parts = strParts.map(part => exports.buildInfo(part, instance, task, ctx))
110110

111111
return exports.generateAll(parts, ctx.opts, instance.generate.bind(instance), task)
112112
.then(exports.createManifest)

packages/tts-cli/lib/providers/aws.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PollyProvider.prototype.buildPart = function () {
2626
PollyProvider.prototype.generate = (info, i, callback) => {
2727
info.task.title = info.task.title.replace(/\d+\//, `${i}/`)
2828

29-
let command = new SynthesizeSpeechCommand({
29+
const command = new SynthesizeSpeechCommand({
3030
Engine: info.opts.engine,
3131
LanguageCode: info.opts.language,
3232
LexiconNames: info.opts.lexicon,

packages/tts-cli/lib/providers/gcp.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const GoogleClient = require('@google-cloud/text-to-speech').TextToSpeechClient
66
const GoogleProvider = function (opts) {
77
try {
88
this.instance = new GoogleClient({
9-
credentials: opts.email || opts.privateKey ? {
10-
client_email: opts.email,
11-
private_key: opts.privateKey
12-
} : undefined,
9+
credentials: opts.email || opts.privateKey
10+
? {
11+
client_email: opts.email,
12+
private_key: opts.privateKey
13+
}
14+
: undefined,
1315
keyFilename: opts.projectFile ? path.resolve(opts.projectFile) : undefined,
1416
projectId: opts.projectId
1517
})
@@ -43,7 +45,8 @@ GoogleProvider.prototype.generate = (info, i, callback) => {
4345
name: info.opts.voice
4446
},
4547
audioConfig: {
46-
audioEncoding: info.opts.format === 'pcm' ? 'LINEAR16'
48+
audioEncoding: info.opts.format === 'pcm'
49+
? 'LINEAR16'
4750
: info.opts.format === 'ogg' ? 'OGG_OPUS' : 'MP3',
4851
effectsProfileId: info.opts.effect,
4952
pitch: info.opts.pitch,
@@ -78,6 +81,6 @@ GoogleProvider.prototype.generate = (info, i, callback) => {
7881
* Create a Google Cloud TTS instance.
7982
*/
8083
exports.create = opts => {
81-
debug('create')(`Creating Google Cloud TTS instance`)
84+
debug('create')('Creating Google Cloud TTS instance')
8285
return new GoogleProvider(opts)
8386
}

packages/tts-cli/lib/read-text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exports.readText = (ctx) => {
2323
let data = ''
2424
proc.stdin.setEncoding('utf8')
2525
proc.stdin.on('readable', () => {
26-
let chunk = proc.stdin.read()
26+
const chunk = proc.stdin.read()
2727
/* istanbul ignore else: need to add test for this */
2828
if (chunk !== null) { data += chunk }
2929
})

packages/tts-cli/lib/sanitize-opts.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ exports.sanitizeOpts = (opts) => {
22
const sanitizedOpts = Object.assign({}, opts)
33
sanitizedOpts['access-key'] = sanitizedOpts['access-key'] ? 'XXXXXXXX' : undefined
44
sanitizedOpts['secret-key'] = sanitizedOpts['secret-key'] ? 'XXXXXXXX' : undefined
5-
sanitizedOpts['accessKey'] = sanitizedOpts['accessKey'] ? 'XXXXXXXX' : undefined
6-
sanitizedOpts['privateKey'] = sanitizedOpts['privateKey'] ? 'XXXXXXXX' : undefined
7-
sanitizedOpts['secretKey'] = sanitizedOpts['secretKey'] ? 'XXXXXXXX' : undefined
5+
sanitizedOpts.accessKey = sanitizedOpts.accessKey ? 'XXXXXXXX' : undefined
6+
sanitizedOpts.privateKey = sanitizedOpts.privateKey ? 'XXXXXXXX' : undefined
7+
sanitizedOpts.secretKey = sanitizedOpts.secretKey ? 'XXXXXXXX' : undefined
88
return sanitizedOpts
99
}

packages/tts-cli/lib/split-text.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const textchunk = require('textchunk')
55
* Chunk text into pieces.
66
*/
77
const chunkText = (text, maxCharacterCount) => {
8-
let parts = textchunk.chunk(text, maxCharacterCount)
8+
const parts = textchunk.chunk(text, maxCharacterCount)
99
debug('chunkText')(`Chunked into ${parts.length} text parts`)
1010
return Promise.resolve(parts)
1111
}
@@ -22,9 +22,9 @@ const chunkXml = (xml, maxCharacterCount) => {
2222
debug('chunkXml')('Started SAX XML parser')
2323
const attributeString = attrs => {
2424
let str = ''
25-
for (let prop in attrs) {
25+
for (const prop in attrs) {
2626
/* istanbul ignore else: need to add test for this */
27-
if (attrs.hasOwnProperty(prop)) {
27+
if (Object.prototype.hasOwnProperty.call(attrs, prop)) {
2828
str += ` ${prop}="${attrs[prop]}"`
2929
}
3030
}
@@ -33,16 +33,16 @@ const chunkXml = (xml, maxCharacterCount) => {
3333
return new Promise((resolve, reject) => {
3434
let err = null
3535
let extraTags = '' // self-closing tags
36-
let tags = [] // stack of open tags
37-
let parts = []
36+
const tags = [] // stack of open tags
37+
const parts = []
3838
/* istanbul ignore next */
3939
parser.onerror = e => {
4040
debug('chunkXml')(`Encountered error: ${e}`)
4141
err = e
4242
}
4343
parser.ontext = text => {
4444
debug('chunkXml')(`Found text: ${text.substr(0, 50)}...`) // eslint-disable-line no-magic-numbers
45-
let chunks = textchunk.chunk(text, maxCharacterCount).map((chunk, index) => {
45+
const chunks = textchunk.chunk(text, maxCharacterCount).map((chunk, index) => {
4646
if (index === 0) {
4747
debug('chunkXml')('Adding unused self-closing tags:', extraTags)
4848
chunk = `${extraTags}${chunk}`
@@ -62,7 +62,7 @@ const chunkXml = (xml, maxCharacterCount) => {
6262
parser.onopentag = tagData => {
6363
debug('chunkXml')(`Found tag: ${JSON.stringify(tagData)}`)
6464
if (tagData.isSelfClosing) {
65-
let attrs = attributeString(tagData.attributes)
65+
const attrs = attributeString(tagData.attributes)
6666
debug('chunkXml')(`Adding "${tagData.name}" to self-closing tags`)
6767
extraTags += `<${tagData.name}${attrs}/>`
6868
} else {
@@ -78,7 +78,7 @@ const chunkXml = (xml, maxCharacterCount) => {
7878
tags.pop()
7979
} else {
8080
// TODO should error
81-
debug('chunkXml')(`Problem: mismatched tags`)
81+
debug('chunkXml')('Problem: mismatched tags')
8282
}
8383
}
8484
parser.onend = () => {
@@ -101,7 +101,7 @@ exports.splitText = (ctx) => {
101101
const text = ctx.text
102102
const maxCharacterCount = ctx.maxCharacterCount
103103
const opts = ctx.args || {}
104-
let chunker = opts.type === 'ssml' ? chunkXml : chunkText
104+
const chunker = opts.type === 'ssml' ? chunkXml : chunkText
105105
return chunker(text, maxCharacterCount).then(parts => {
106106
debug('splitText')('Stripping whitespace')
107107
return parts.map(str => {

packages/tts-cli/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"yarn.lock"
1313
],
1414
"scripts": {
15-
"lint": "standard --fix --verbose",
15+
"lint": "standard --env jasmine --fix --verbose",
1616
"report-coverage": "codecov",
1717
"test": "cross-env JASMINE_CONFIG_PATH=test/jasmine.json nyc jasmine"
1818
},
@@ -52,7 +52,6 @@
5252
},
5353
"standard": {
5454
"env": {
55-
"jasmine": true,
5655
"node": true
5756
}
5857
},

packages/tts-cli/test/build-info.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('buildInfo()', () => {
3838
expect(output.text).toBe(text)
3939
})
4040

41-
it(`should add in the instance's properties`, () => {
41+
it('should add in the instance\'s properties', () => {
4242
expect(output.foo).toBe(instance.foo)
4343
expect(output.bar).toBe(instance.bar)
4444
})

packages/tts-cli/test/check-usage.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ describe('checkUsage()', () => {
88
write = jasmine.createSpy('process.stderr.write')
99
proc = {
1010
argv: ['node', 'tts.js'],
11-
exit: exit,
11+
exit,
1212
stderr: {
13-
write: write
13+
write
1414
}
1515
}
1616
})

packages/tts-cli/test/generate-all.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('generateAll()', () => {
1818

1919
it('should asynchronously call the function for each of the parts', done => {
2020
generateAll(textParts, { limit: testLimit }, iteratorFunction, task).then(() => {
21-
let [parts] = async.eachOfLimit.calls.mostRecent().args
21+
const [parts] = async.eachOfLimit.calls.mostRecent().args
2222
expect(parts).toEqual(textParts)
2323
expect(parts.length).toBe(textParts.length)
2424
expect(iteratorFunction.calls.count()).toBe(textParts.length)
@@ -27,7 +27,7 @@ describe('generateAll()', () => {
2727

2828
it('should limit the async calls according to the option', done => {
2929
generateAll(textParts, { limit: testLimit }, iteratorFunction, task).then(() => {
30-
let [, limit] = async.eachOfLimit.calls.mostRecent().args
30+
const [, limit] = async.eachOfLimit.calls.mostRecent().args
3131
expect(limit).toBe(testLimit)
3232
}).then(done)
3333
})

packages/tts-cli/test/helpers.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ exports.loadLib = (file) => {
77
spyOn(async, 'eachOfLimit').and.callThrough()
88

99
// Stub out the fs(-extra) module with spies.
10-
let fs = jasmine.createSpyObj('fs', [
10+
const fs = jasmine.createSpyObj('fs', [
1111
'appendFileSync',
1212
'createFileSync',
1313
'createWriteStream',
@@ -27,18 +27,18 @@ exports.loadLib = (file) => {
2727
fs.writeFile.and.callFake((dest, data, opts, callback) => { callback() })
2828

2929
// Stub out a provider.
30-
let providerStub = {
30+
const providerStub = {
3131
create: () => ({
3232
buildPart: () => ({}),
3333
generate: (item, key, callback) => callback(null, null)
3434
})
3535
}
3636

37-
let spawnOnSpy = jasmine.createSpy('spawn.on').and.callFake((type, callback) => {
37+
const spawnOnSpy = jasmine.createSpy('spawn.on').and.callFake((type, callback) => {
3838
if (type === 'close') { callback() }
3939
})
40-
let spawnStderrOn = jasmine.createSpy('spawn.stderr.on')
41-
let spawn = jasmine.createSpy('spawn').and.callFake(() => {
40+
const spawnStderrOn = jasmine.createSpy('spawn.stderr.on')
41+
const spawn = jasmine.createSpy('spawn').and.callFake(() => {
4242
return {
4343
on: spawnOnSpy,
4444
stderr: {
@@ -48,10 +48,10 @@ exports.loadLib = (file) => {
4848
})
4949

5050
// Load the library module.
51-
let lib = proxyquire(`../lib/${file}`, {
51+
const lib = proxyquire(`../lib/${file}`, {
5252
'./providers/aws': providerStub,
5353
'./providers/gcp': providerStub,
54-
async: async,
54+
async,
5555
child_process: { spawn }, // eslint-disable-line camelcase
5656
'fs-extra': fs
5757
})

0 commit comments

Comments
 (0)