Skip to content

Commit

Permalink
use ora to show progress
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Jun 10, 2017
1 parent a3f990b commit debe5cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
36 changes: 17 additions & 19 deletions lib/linter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
'use strict'

var fs = require('fs')

var async = require('async')
var flatten = require('lodash.flatten')
var standard = require('standard')

var extractCodeBlocks = require('./codeBlockUtils').extractCodeBlocks

var disabledRules = ['no-undef', 'no-unused-vars', 'no-lone-blocks', 'no-labels']
var eslintDisable = '/* eslint-disable ' + disabledRules.join(', ') + ' */\n'

var linter = module.exports = {}
const fs = require('fs')
const async = require('async')
const flatten = require('lodash.flatten')
const standard = require('standard')
const ora = require('ora')
const extractCodeBlocks = require('./codeBlockUtils').extractCodeBlocks
const disabledRules = [
'no-undef',
'no-unused-vars',
'no-lone-blocks',
'no-labels'
]
const eslintDisable = '/* eslint-disable ' + disabledRules.join(', ') + ' */\n'
const linter = module.exports = {}

function removeParensWrappingOrphanedObject (block) {
return block.replace(
Expand Down Expand Up @@ -65,18 +67,14 @@ linter.lintText = function (text, standardOptions, done) {

linter.lintFiles = function (files, standardOptions, done) {
var index = 0
const spinner = (files.length > 3) ? ora().start() : null

if (typeof standardOptions === 'function') {
done = standardOptions
standardOptions = {}
}
async.map(files, function (file, callback) {
// Inform the user of progress
if (process.stdout.clearLine && process.stdout.cursorTo) {
process.stdout.clearLine()
process.stdout.cursorTo(0)
}

process.stdout.write('Linting file ' + (index++ + 1) + ' of ' + files.length)
if (spinner) spinner.text('Linting file ' + (index++ + 1) + ' of ' + files.length)

linter.lintText(fs.readFileSync(file, 'utf8'), standardOptions, function (err, errors, outputText) {
if (err) return callback(err)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"globby": "^6.0.0",
"lodash.flatten": "^4.2.0",
"lodash.range": "^3.1.5",
"ora": "^1.2.0",
"standard": "^8.6.0"
},
"devDependencies": {
Expand Down

0 comments on commit debe5cd

Please sign in to comment.