Skip to content

Commit babb755

Browse files
committed
test: add linting to lib and fix errors
1 parent 621ede0 commit babb755

12 files changed

+25
-29
lines changed

lib/add-template-mapping.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const sourceMap = require('source-map')
21
const splitRE = /\r?\n/g
32

43
module.exports = function addTemplateMapping (content, parts, output, map, beforeLines) {

lib/compilers/babel-compiler.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
const babel = require('babel-core')
2-
const path = require('path')
3-
const fs = require('fs')
42
const findBabelConfig = require('find-babel-config')
5-
const throwError = require('../throw-error')
63
const logger = require('../logger')
74

85
var defaultBabelOptions = {
@@ -11,16 +8,16 @@ var defaultBabelOptions = {
118
}
129

1310
module.exports = function compileBabel (scriptContent) {
14-
const { file, config } = findBabelConfig.sync(process.cwd(), 0);
11+
const { file, config } = findBabelConfig.sync(process.cwd(), 0)
1512

1613
if (!file) {
1714
logger.info('no .babelrc found, defaulting to default babel options')
1815
}
1916

2017
const baseBabelOptions = file ? config : defaultBabelOptions
21-
const babelOptions = Object.assign({sourceMaps: true}, baseBabelOptions)
18+
const babelOptions = Object.assign({ sourceMaps: true }, baseBabelOptions)
2219

23-
const res = babel.transform(scriptContent, babelOptions)
20+
const res = babel.transform(scriptContent, babelOptions)
2421

2522
return {
2623
code: res.code,

lib/compilers/coffee-compiler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function (raw, cb, compiler) {
1414
throwError(err)
1515
}
1616
return {
17-
code: compiled.js,
18-
map: compiled.v3SourceMap
19-
}
17+
code: compiled.js,
18+
map: compiled.v3SourceMap
2019
}
20+
}

lib/compilers/jade-compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ var ensureRequire = require('../ensure-require.js')
22
const throwError = require('../throw-error')
33

44
module.exports = function (raw) {
5-
var html;
5+
var html
66
ensureRequire('jade', 'jade')
77
var jade = require('jade')
88
try {
9-
var html = jade.compile(raw)()
9+
html = jade.compile(raw)()
1010
} catch (err) {
1111
throwError(err)
1212
}

lib/compilers/pug-compiler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ var ensureRequire = require('../ensure-require.js')
22
const throwError = require('../throw-error')
33

44
module.exports = function (raw) {
5-
var html;
5+
var html
66
ensureRequire('pug', 'pug')
77
var jade = require('pug')
88
try {
9-
var html = jade.compile(raw)()
9+
html = jade.compile(raw)()
1010
} catch (err) {
1111
throwError(err)
1212
}

lib/compilers/typescript-compiler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const typescript = require('typescript')
22

33
module.exports = function compileTypescript (scriptContent) {
4-
const res = typescript.transpileModule(scriptContent,{"compilerOptions": {
5-
"sourceMap": true
6-
}})
4+
const res = typescript.transpileModule(scriptContent, { 'compilerOptions': {
5+
'sourceMap': true
6+
}})
77

88
return {
99
code: res.outputText,

lib/get_cache_key.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var crypto = require('crypto')
22

3-
function getCacheKey (fileData, filename, configString) {
3+
module.exports = function getCacheKey (fileData, filename, configString) {
44
return crypto.createHash('md5')
5-
.update(fileData + filePath + configString, 'utf8')
5+
.update(fileData + filename + configString, 'utf8')
66
.digest('hex')
77
}

lib/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports.info = function info(msg) {
1+
module.exports.info = function info (msg) {
22
console.info('\n[jest-vue] Info: ' + (msg) + '\n')
33
}

lib/process.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function processScript (scriptPart) {
2121
return compileBabel(scriptPart.content)
2222
}
2323

24-
module.exports = function(src, path){
24+
module.exports = function (src, path) {
2525
var parts = vueCompiler.parseComponent(src, { pad: true })
2626
const renderFunctions = compileTemplate(parts.template)
2727

@@ -36,10 +36,10 @@ module.exports = function(src, path){
3636
'var __vue__options__ = (typeof module.exports === "function"' +
3737
'? module.exports.options' +
3838
': module.exports)\n'
39-
39+
4040
output += '__vue__options__.render = ' + renderFunctions.render + '\n' +
4141
'__vue__options__.staticRenderFns = ' + renderFunctions.staticRenderFns + '\n'
42-
42+
4343
if (map) {
4444
const beforeLines = output.split(splitRE).length
4545
addTemplateMapping(script, parts, output, map, beforeLines)
@@ -48,6 +48,6 @@ module.exports = function(src, path){
4848
if (map) {
4949
output += '\n' + convertSourceMap.fromJSON(map.toString()).toComment()
5050
}
51-
51+
5252
return output
5353
}

lib/template-compiler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ var compilePug = require('./compilers/pug-compiler')
55
var compileJade = require('./compilers/jade-compiler')
66
const throwError = require('./throw-error')
77

8-
function getTemplateContent(templatePart) {
9-
if(templatePart.lang === 'pug') {
8+
function getTemplateContent (templatePart) {
9+
if (templatePart.lang === 'pug') {
1010
return compilePug(templatePart.content)
1111
}
12-
if(templatePart.lang === 'jade') {
12+
if (templatePart.lang === 'jade') {
1313
return compileJade(templatePart.content)
1414
}
1515
return templatePart.content

lib/throw-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = function error (msg){
1+
module.exports = function error (msg) {
22
throw new Error('\n[jest-vue] Error: ' + (msg) + '\n')
33
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"vue jest preprocessor"
1616
],
1717
"scripts": {
18-
"lint": "eslint jest-vue.js test",
18+
"lint": "eslint lib jest-vue.js test",
1919
"lint:fix": "npm run lint -- --fix",
2020
"release": "build/release.sh",
2121
"release:note": "node build/gen-release-note.js",

0 commit comments

Comments
 (0)