Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
chore(lint): use prettier standard to format code
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Jun 22, 2017
1 parent d14e98e commit 57aeb8e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 58 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"deps": "deps-ok && dependency-check --no-dev --no-default-entries --entry src/index.js .",
"issues": "git-issues",
"license": "license-checker --production --onlyunknown --csv",
"pretty": "prettier-standard 'src/*.js'",
"prelint": "npm run pretty",
"lint": "standard --verbose --fix src/*.js",
"pretest": "npm run lint",
"secure": "nsp check",
Expand All @@ -72,9 +74,10 @@
"mocha": "3.4.2",
"nsp": "2.6.3",
"pre-git": "3.15.0",
"prettier-standard": "5.1.0",
"semantic-release": "^6.3.6",
"snap-shot": "2.17.0",
"standard": "10.0.2",
"semantic-release": "^6.3.6"
"standard": "10.0.2"
},
"dependencies": {
"check-more-types": "2.24.0",
Expand Down
36 changes: 12 additions & 24 deletions src/get-os-info-spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const {getOsVersion, getPlatformInfo, versionRegex} = require('./get-os-info')
const { getOsVersion, getPlatformInfo, versionRegex } = require('./get-os-info')
const la = require('lazy-ass')
const is = require('check-more-types')
const snapshot = require('snap-shot')
Expand All @@ -11,36 +11,24 @@ describe('get-os-info', () => {
const linuxVersion = 'Version: Ubuntu Linux - 12.04'

it('gets OS', () =>
getOsVersion()
.then(os =>
la(is.unemptyString(os), 'missing OS', os)
)
)
getOsVersion().then(os => la(is.unemptyString(os), 'missing OS', os)))

it('gets platform information', () =>
getPlatformInfo()
.then(info =>
la(is.unemptyString(info), 'missing platform info', info)
)
)
getPlatformInfo().then(info =>
la(is.unemptyString(info), 'missing platform info', info)
))

it('has version regex', () =>
la(is.regexp(versionRegex))
)
it('has version regex', () => la(is.regexp(versionRegex)))

it('can parse mac version', () =>
la(versionRegex.test(macVersion))
)
it('can parse mac version', () => la(versionRegex.test(macVersion)))

it('can replace mac version', () =>
it('can replace mac version', function () {
snapshot(macVersion.replace(versionRegex, 'a version'))
)
})

it('can parse linux version', () =>
la(versionRegex.test(linuxVersion))
)
it('can parse linux version', () => la(versionRegex.test(linuxVersion)))

it('can replace linux version', () =>
it('can replace linux version', function () {
snapshot(linuxVersion.replace(versionRegex, 'a version'))
)
})
})
11 changes: 5 additions & 6 deletions src/get-os-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ function formatOSVersion (osInfo) {

function getOsVersion () {
if (os.platform() === 'linux') {
return getos()
.then(formatOSVersion)
.catch(() => os.release())
return getos().then(formatOSVersion).catch(() => os.release())
} else {
return Promise.resolve(os.release())
}
}

function getPlatformInfo () {
return getOsVersion()
.then((version) => stripIndent`
return getOsVersion().then(
version => stripIndent`
Platform: ${os.platform()}
Version: ${version}
`)
`
)
}

const platformRegex = /Platform: \w+/
Expand Down
28 changes: 10 additions & 18 deletions src/index-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const {formErrorText} = require('.')
const {platformRegex, versionRegex} = require('./get-os-info')
const { formErrorText } = require('.')
const { platformRegex, versionRegex } = require('./get-os-info')
const la = require('lazy-ass')
const is = require('check-more-types')
const snapshot = require('snap-shot')
Expand All @@ -14,7 +14,8 @@ describe('formErrorText', () => {
}
const error = new Error('exception message')

const normalizePlatform = text => text.replace(platformRegex, 'Platform: name')
const normalizePlatform = text =>
text.replace(platformRegex, 'Platform: name')
const normalizeVersion = text => text.replace(versionRegex, 'Version: number')

it('is a function', () => {
Expand All @@ -26,24 +27,15 @@ describe('formErrorText', () => {
})

it('has platform name string', () =>
formErrorText(info)(error).then(text =>
la(platformRegex.test(text), text)
)
)
formErrorText(info)(error).then(text => la(platformRegex.test(text), text)))

it('has version string', () =>
formErrorText(info)(error).then(text =>
la(versionRegex.test(text), text)
)
)
formErrorText(info)(error).then(text => la(versionRegex.test(text), text)))

it('forms full error message', () =>
snapshot(
formErrorText(info)(error)
.then(normalizePlatform)
.then(normalizeVersion)
)
)
formErrorText(info)(error).then(normalizePlatform).then(normalizeVersion)
))

describe('throws an error if', () => {
it('error is missing', () => {
Expand All @@ -55,11 +47,11 @@ describe('formErrorText', () => {
})

it('info is missing description', () => {
la(is.raises(() => formErrorText({solution: 'do something'})))
la(is.raises(() => formErrorText({ solution: 'do something' })))
})

it('info is missing solution', () => {
la(is.raises(() => formErrorText({description: 'hmm'})))
la(is.raises(() => formErrorText({ description: 'hmm' })))
})
})
})
17 changes: 9 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

const { stripIndents } = require('common-tags')
const { merge } = require('ramda')
const {getOsVersion, getPlatformInfo} = require('./get-os-info')
const { getOsVersion, getPlatformInfo } = require('./get-os-info')
const la = require('lazy-ass')
const is = require('check-more-types')

function addPlatformInformation (info) {
return getPlatformInfo()
.then((platform) => merge(info, { platform }))
return getPlatformInfo().then(platform => merge(info, { platform }))
}

function formError (info, error) {
return addPlatformInformation(info)
.then((info) => merge(info, { message: error.message, stack: error.stack }))
return addPlatformInformation(info).then(info =>
merge(info, { message: error.message, stack: error.stack })
)
}

const utils = {
Expand All @@ -35,8 +35,8 @@ function formErrorText (info) {
la(is.error(error), 'expected error object', error)

const hr = '----------'
return formError(info, error)
.then((extended) => stripIndents`
return formError(info, error).then(
extended => stripIndents`
${hr}
${info.description}
${info.solution}
Expand All @@ -46,7 +46,8 @@ function formErrorText (info) {
${info.printStack ? extended.stack : ''}
${hr}
${extended.platform}
`)
`
)
}
}

Expand Down

0 comments on commit 57aeb8e

Please sign in to comment.