Skip to content

Commit

Permalink
🚨 Remove linter warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
linhe0x0 committed Mar 15, 2017
1 parent 3253e21 commit a69065b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/commands/hook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const chalk = require('chalk')
const util = require('../utils/util')

/**
Expand Down Expand Up @@ -42,9 +41,11 @@ const init = function init(options) {
// Add gitmit hook to file "prepare-commit-msg"
return util.writeFile(hookFilePath, hookFileContent, { mode: 0o775, flag: 'a+' })
}).then(() => {
console.log(`${chalk.yellow('gitmoji')} commit hook created succesfully.`)
util.print('gitmit commit hook created succesfully.', 'success')
})
.catch((err) => {
util.print(err, 'error')
})
.catch(console.error)
}

/**
Expand All @@ -58,8 +59,10 @@ const remove = function remove() {

return util.writeFile(hookFilePath, cont)
}).then(() => {
console.log('Remove gitmit hook succesfully.')
}).catch(console.error)
util.print('Remove gitmit hook succesfully.', 'success')
}).catch((err) => {
util.print(err, 'error')
})
}

/**
Expand All @@ -75,7 +78,7 @@ const hook = function hook(options) {
// Remove gitmit from git commit hook.
remove()
} else {
console.log('You need to run this command with --init or --remove.')
util.print('You need to run this command with --init or --remove.', 'error')
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/commands/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,11 @@ const main = function main(options) {
}).then((result) => {
// Variable result will have value when exec git command.
if (result) {
console.log()
console.log(chalk.green(result.stdout))
util.print(result.stdout, 'success')
}
}, (err) => {
console.log(chalk.red(err.stdout || err))
}).catch((err) => {
util.print(err.message, 'error')
})
.catch(console.error)
}

module.exports = main
1 change: 1 addition & 0 deletions src/commands/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { gitmojis } = require('../data/gitmojis')
*/
const printMojiList = function printMojiList(data) {
data.forEach((item) => {
/* eslint no-console: ["error", { allow: ["log"] }] */
console.log(`${item.emoji} - ${chalk.blue(item.code)} - ${item.description}`)
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const fs = require('fs')
const axios = require('axios')
const ora = require('ora')
const util = require('../utils/util')

const rawUrl = 'https://raw.githubusercontent.com/sqrthree/gitmit/master/src/data/gitmojis.json'
const cacheFile = path.resolve(__dirname, '../data/gitmojis.json')
Expand All @@ -26,7 +27,7 @@ const update = function update() {
})
}).catch((err) => {
spinner.fail('Failed to fetch data.')
console.error(err)
util.print(err, 'error')
})
}

Expand Down
19 changes: 19 additions & 0 deletions src/utils/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs')
const p = require('path')
const chalk = require('chalk')

/**
* Verify whether the specified file exists.
Expand Down Expand Up @@ -105,3 +106,21 @@ exports.isGitRepo = function isGitDirectory(dir) {

return exports.exists(dirname)
}

exports.print = function print(message, type = 'defaults') {
const TEST_ENV = (process.env.NODE_ENV === 'testing')

if (TEST_ENV) return message

const types = {
defaults: 'gray',
primary: 'blue',
success: 'green',
warning: 'yellow',
error: 'red',
}

/* eslint no-console: ["error", { allow: ["log"] }] */
console.log()
return console.log(chalk[types[type]](message))
}

0 comments on commit a69065b

Please sign in to comment.