Merge pull request #16 from curbengh/lint

test: lint using Javascript Standard Style
This commit is contained in:
curbengh 2019-08-06 12:02:41 +09:30 committed by GitHub
commit 79308b2d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 32 deletions

View File

@ -1,19 +1,23 @@
dist: bionic
sudo: false
language: node_js
node_js:
- "node" # latest stable Node.js release
- "node"
cache:
directories:
- "node_modules" # cache the modules for faster build
npm: true
script:
- npm install -g snyk
- npm install # install node modules
- npm install snyk
- snyk auth $SNYK_TOKEN
- snyk test # Check node modules for vulnerability
- snyk protect # Patch node modules (if available)
- snyk monitor # Update dependencies to snyk
- npm install standard
- standard
branches:
only:
- master # Only build master branch

View File

@ -33,10 +33,10 @@ function logicHtml (str, data) {
// Return if a path matches exclusion pattern
if (isMatch(path, exclude, globOptions)) return str
let result = Htmlminifier(str, options)
let saved = ((str.length - result.length) / str.length * 100).toFixed(2)
const result = Htmlminifier(str, options)
const saved = ((str.length - result.length) / str.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the html: %s [%s saved]', path, saved + '%')
}
return result
@ -60,10 +60,10 @@ function logicCss (str, data) {
return new Promise((resolve, reject) => {
new CleanCSS(options).minify(str, (err, result) => {
if (err) return reject(err)
let saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2)
const saved = ((str.length - result.styles.length) / str.length * 100).toFixed(2)
resolve(result.styles)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the css: %s [%s saved]', path, saved + '%')
}
})
@ -92,10 +92,10 @@ function logicJs (str, data) {
delete jsOptions.logger
delete jsOptions.globOptions
let result = Terser.minify(str, jsOptions)
let saved = ((str.length - result.code.length) / str.length * 100).toFixed(2)
const result = Terser.minify(str, jsOptions)
const saved = ((str.length - result.code.length) / str.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the js: %s [%s saved]', path, saved + '%')
}
return result.code
@ -107,9 +107,9 @@ function logicSvg () {
// Return if disabled.
if (options.enable === false) return
let route = hexo.route
let routeList = route.list()
let include = options.include
const route = hexo.route
const routeList = route.list()
const include = options.include
const globOptions = options.globOptions
let includeString = include
@ -119,7 +119,7 @@ function logicSvg () {
return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => {
// Grab all assets using hexo router
let assetPath = route.get(path)
const assetPath = route.get(path)
let assetTxt = ''
// Extract the content
assetPath.on('data', (chunk) => (assetTxt += chunk))
@ -130,9 +130,9 @@ function logicSvg () {
// Replace the original file with the minified.
route.set(path, result.data)
// Logging
let saved = ((assetTxt.length - result.data.length) / assetTxt.length * 100).toFixed(2)
const saved = ((assetTxt.length - result.data.length) / assetTxt.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Minify the svg: %s [%s saved]', path, saved + '%')
}
resolve(assetTxt)
@ -149,9 +149,9 @@ function logicGzip () {
// Return if disabled.
if (options.enable === false) return
let route = hexo.route
let routeList = route.list()
let include = options.include
const route = hexo.route
const routeList = route.list()
const include = options.include
const globOptions = options.globOptions
let includeString = include
@ -161,7 +161,7 @@ function logicGzip () {
return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => {
// Grab all assets using hexo router
let assetPath = route.get(path)
const assetPath = route.get(path)
let assetTxt = ''
// Extract the content
assetPath.on('data', (chunk) => (assetTxt += chunk))
@ -173,9 +173,9 @@ function logicGzip () {
// Save the compressed file to .gz
route.set(path + '.gz', Input)
// Logging
let saved = ((assetTxt.length - Input.toString().length) / assetTxt.length * 100).toFixed(2)
const saved = ((assetTxt.length - Input.toString().length) / assetTxt.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Gzip-compressed %s [%s saved]', path, saved + '%')
}
resolve(assetTxt)
@ -195,9 +195,9 @@ function logicBrotli () {
// Return if disabled.
if (options.enable === false) return
let route = hexo.route
let routeList = route.list()
let include = options.include
const route = hexo.route
const routeList = route.list()
const include = options.include
const globOptions = options.globOptions
let includeString = include
@ -207,23 +207,23 @@ function logicBrotli () {
return Promise.all((micromatch(routeList, include, globOptions)).map(path => {
return new Promise((resolve, reject) => {
// Grab all assets using hexo router
let assetPath = route.get(path)
const assetPath = route.get(path)
let assetTxt = ''
// Extract the content
assetPath.on('data', (chunk) => (assetTxt += chunk))
assetPath.on('end', () => {
if (assetTxt.length) {
// Input has to be buffer for brotli
let input = Buffer.from(assetTxt, 'utf-8')
const input = Buffer.from(assetTxt, 'utf-8')
// brotli defaults to max compression level
br.compress(input, (err, output) => {
if (!err) {
// Save the compressed file to .br
route.set(path + '.br', output)
// Logging
let saved = ((input.length - output.toString().length) / input.length * 100).toFixed(2)
const saved = ((input.length - output.toString().length) / input.length * 100).toFixed(2)
if (options.logger) {
let log = hexo.log || console.log
const log = hexo.log || console.log
log.log('Brotli-compressed %s [%s saved]', path, saved + '%')
}
resolve(assetTxt)