Skip to content

Commit

Permalink
💄 Add prettier (#148)
Browse files Browse the repository at this point in the history
* adding prettier

* auto prettier/standard on tsc builds

* remove standard config (not needed)
  • Loading branch information
GantMan authored Dec 21, 2017
1 parent 0f0331a commit d55a791
Show file tree
Hide file tree
Showing 45 changed files with 303 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json,js,jsx,html,css}]
[*.{json,js,jsx,html,css,ts,tsx}]
indent_style = space
indent_size = 2

Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
readme.md
dist/
3 changes: 2 additions & 1 deletion .vscode/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"newclear",
"shipit",
"snapupdate",
"tempy"
"tempy",
"updtr"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
Expand Down
20 changes: 9 additions & 11 deletions __tests__/__mocks__/mockContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,45 @@ const noConfigSolidarity = {
printResults: jest.fn(),
setSolidaritySettings: jest.fn(),
updateRequirement: jest.fn(),
updateVersions: jest.fn(() => Promise.resolve())
updateVersions: jest.fn(() => Promise.resolve()),
}

const mockContext = {
...realThing,
outputMode: null,
system: {
startTimer: jest.fn(() => jest.fn())
startTimer: jest.fn(() => jest.fn()),
},
print: {
error: jest.fn(),
success: jest.fn(),
info: jest.fn(),
spin: jest.fn(() => ({
stop: jest.fn()
stop: jest.fn(),
})),
table: jest.fn(),
xmark: jest.fn(),
checkmark: jest.fn(),
color: {
green: jest.fn(),
red: jest.fn(),
blue: jest.fn()
blue: jest.fn(),
},
colors: {
green: jest.fn(),
red: jest.fn(),
blue: jest.fn()
}
blue: jest.fn(),
},
},
printSeparator: jest.fn(),
_pluginsList: [],
parameters: {
options: {}
options: {},
},
prompt: {
ask: jest.fn(
() => Promise.resolve({ createFile: true })
)
ask: jest.fn(() => Promise.resolve({ createFile: true })),
},
solidarity: noConfigSolidarity
solidarity: noConfigSolidarity,
}

module.exports = mockContext
14 changes: 9 additions & 5 deletions __tests__/command_helpers/checkCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import checkCLI from '../../src/extensions/functions/checkCLI'
import solidarityExtension from '../../src/extensions/solidarity-extension'

const doesNotExistCLI = {
binary: 'no_way_this_should_be_real'
binary: 'no_way_this_should_be_real',
}

const alwaysExistCLI = {
binary: 'node'
binary: 'node',
}

const outOfDateCLI = {
binary: 'node',
semver: '10.99'
semver: '10.99',
}

const context = require('gluegun')

test('error on missing binary', async () => {
expect(await checkCLI(doesNotExistCLI, context)).toBe(`Binary '${doesNotExistCLI.binary}' not found`)
expect(await checkCLI(doesNotExistCLI, context)).toBe(
`Binary '${doesNotExistCLI.binary}' not found`
)
})

test('fine on existing binary', async () => {
Expand All @@ -27,7 +29,9 @@ test('fine on existing binary', async () => {
test('returns message on improper version', async () => {
solidarityExtension(context)
context.solidarity.getVersion = () => '1'
const message = `${outOfDateCLI.binary}: you have '1', but the project requires '${outOfDateCLI.semver}'`
const message = `${outOfDateCLI.binary}: you have '1', but the project requires '${
outOfDateCLI.semver
}'`

expect(await checkCLI(outOfDateCLI, context)).toBe(message)
})
12 changes: 6 additions & 6 deletions __tests__/command_helpers/checkCLIForUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const rule = {
rule: 'cli',
binary: 'bananas',
semver: '1.1.0',
version: '--version'
version: '--version',
}

const ruleNoSemver = {
rule: 'cli',
binary: 'yarn'
binary: 'yarn',
}

describe('checkCLIForUpdates', () => {
Expand All @@ -26,14 +26,14 @@ describe('checkCLIForUpdates', () => {
rule.binary = 'yarn'
context.print = {
color: {
green: jest.fn((string) => string)
}
green: jest.fn(string => string),
},
}
})

it('pads zeros for non-semver versions', async () => {
context.solidarity = {
getVersion: jest.fn(() => '1.0')
getVersion: jest.fn(() => '1.0'),
}

const result = await checkCLIForUpdates(rule, context)
Expand All @@ -43,7 +43,7 @@ describe('checkCLIForUpdates', () => {

it('does nothing if there was no original semver', async () => {
context.solidarity = {
getVersion: jest.fn(() => '1.0')
getVersion: jest.fn(() => '1.0'),
}

const result = await checkCLIForUpdates(ruleNoSemver, context)
Expand Down
6 changes: 3 additions & 3 deletions __tests__/command_helpers/checkDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ test('checkDir detects an existing dir', () => {
// Check for a known directory
const location = './src'
// Use checkDir to make sure it exists
expect(checkDir({location}, context)).toBeTruthy()
expect(checkDir({ location }, context)).toBeTruthy()
})

test('checkDir can fail', () => {
// Use checkDir to make sure a non-existant directory returns false
expect(checkDir({location: 'DOES_NOT_EXIST'}, context)).toBeFalsy()
expect(checkDir({ location: 'DOES_NOT_EXIST' }, context)).toBeFalsy()
})

test('checkDir returns false for a file that exists', () => {
// Use checkDir to make sure a known file returns false since it's not a directory
expect(checkDir({location: './package.json'}, context)).toBeFalsy()
expect(checkDir({ location: './package.json' }, context)).toBeFalsy()
})

test('checkDir returns false if no location is set', () => {
Expand Down
7 changes: 4 additions & 3 deletions __tests__/command_helpers/checkENV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ test('checkENV detects set ENV', async () => {
i++
}
// Use checkENV to make sure it exists
expect(await checkENV({variable: someRealEnvVar})).toBeTruthy()
} else {}
expect(await checkENV({ variable: someRealEnvVar })).toBeTruthy()
} else {
}
})

test('checkENV can fail', async () => {
// Use checkENV to make sure it exists
expect(await checkENV({variable: 'THIS_SHOULD_NOT_EXIST_VERIFIER'})).toBeFalsy()
expect(await checkENV({ variable: 'THIS_SHOULD_NOT_EXIST_VERIFIER' })).toBeFalsy()
})

test('checkENV fails if no variable is set', async () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/command_helpers/checkFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ test('checkFile detects an existing file', () => {
// known file
const location = './package.json'
// Use checkFile to make sure it exists
expect(checkFile({location}, context)).toBeTruthy()
expect(checkFile({ location }, context)).toBeTruthy()
})

test('checkFile can fail', () => {
// Use checkFile to make sure it does not exist
expect(checkFile({location: 'DOES_NOT_EXIST'}, context)).toBeFalsy()
expect(checkFile({ location: 'DOES_NOT_EXIST' }, context)).toBeFalsy()
})

test('checkFile returns false for a dir that exists', () => {
// Use checkFile to make sure a known dir returns false since it's not a file
expect(checkFile({location: './src'}, context)).toBeFalsy()
expect(checkFile({ location: './src' }, context)).toBeFalsy()
})

test('checkFile returns false with no location', () => {
Expand Down
49 changes: 24 additions & 25 deletions __tests__/command_helpers/checkRequirement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const checkFile = require('../../src/extensions/functions/checkFile')
const context = require('gluegun')

const badRule = toPairs({
YARN: [{ rule: 'knope', binary: 'yarn' }]
YARN: [{ rule: 'knope', binary: 'yarn' }],
})[0]

let fail
Expand All @@ -39,28 +39,28 @@ describe('checkRequirement', () => {
const spinner = {
fail,
stop,
succeed
succeed,
}

solidarityExtension(context)
context.print = {
spin: jest.fn(() => spinner),
error: jest.fn()
error: jest.fn(),
}
context.strings = strings
context.system = {
spawn: jest.fn().mockReturnValue(Promise.resolve({
stdout: 'you did it!',
status: 0,
}))
spawn: jest.fn().mockReturnValue(
Promise.resolve({
stdout: 'you did it!',
status: 0,
})
),
}
})

test('there is a spinner message', async () => {
const result = await checkRequirement(badRule, context)
expect(context.print.spin.mock.calls).toEqual([
['Verifying YARN']
])
expect(context.print.spin.mock.calls).toEqual([['Verifying YARN']])
})

test('when an invalid rule is given', async () => {
Expand All @@ -75,7 +75,7 @@ describe('checkRequirement', () => {
checkCLI.mockImplementation(async () => 'Everything is broken')

const rule = toPairs({
YARN: [{ rule: 'cli', binary: 'yarn' }]
YARN: [{ rule: 'cli', binary: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual(['Everything is broken'])
Expand All @@ -85,7 +85,7 @@ describe('checkRequirement', () => {
checkCLI.mockImplementation(async () => false)

const rule = toPairs({
YARN: [{ rule: 'cli', binary: 'yarn' }]
YARN: [{ rule: 'cli', binary: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual([[]])
Expand All @@ -99,7 +99,7 @@ describe('checkRequirement', () => {
checkDir.mockImplementation(() => 'It worked!')

const rule = toPairs({
YARN: [{ rule: 'dir', location: 'yarn' }]
YARN: [{ rule: 'dir', location: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual([[]])
Expand All @@ -109,7 +109,7 @@ describe('checkRequirement', () => {
checkDir.mockImplementation(() => 'It worked!')

const rule = toPairs({
YARN: [{ rule: 'directory', location: 'yarn' }]
YARN: [{ rule: 'directory', location: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual([[]])
Expand All @@ -119,7 +119,7 @@ describe('checkRequirement', () => {
checkDir.mockImplementation(() => false)

const rule = toPairs({
YARN: [{ rule: 'dir', location: 'yarn' }]
YARN: [{ rule: 'dir', location: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual(["'yarn' directory not found"])
Expand All @@ -133,7 +133,7 @@ describe('checkRequirement', () => {
checkENV.mockImplementation(async () => 'It worked!')

const rule = toPairs({
YARN: [{ rule: 'env', variable: 'yarn' }]
YARN: [{ rule: 'env', variable: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual([[]])
Expand All @@ -143,7 +143,7 @@ describe('checkRequirement', () => {
checkENV.mockImplementation(async () => undefined)

const rule = toPairs({
YARN: [{ rule: 'env', variable: 'yarn' }]
YARN: [{ rule: 'env', variable: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual(["'$yarn' environment variable not found"])
Expand All @@ -157,7 +157,7 @@ describe('checkRequirement', () => {
checkFile.mockImplementation(() => 'It worked!')

const rule = toPairs({
YARN: [{ rule: 'file', location: 'yarn' }]
YARN: [{ rule: 'file', location: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual([[]])
Expand All @@ -167,7 +167,7 @@ describe('checkRequirement', () => {
checkFile.mockImplementation(() => undefined)

const rule = toPairs({
YARN: [{ rule: 'file', location: 'yarn' }]
YARN: [{ rule: 'file', location: 'yarn' }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual(["'yarn' file not found"])
Expand All @@ -181,7 +181,7 @@ describe('checkRequirement', () => {
checkCLI.mockClear()
checkCLI.mockImplementation(() => true)
const rule = toPairs({
YARN: [{ rule: 'cli', binary: 'gazorpazorp', error: customError }]
YARN: [{ rule: 'cli', binary: 'gazorpazorp', error: customError }],
})[0]

const result = await checkRequirement(rule, context)
Expand All @@ -190,7 +190,7 @@ describe('checkRequirement', () => {

test('failed ENV rule with custom message', async () => {
const rule = toPairs({
YARN: [{ rule: 'env', variable: 'gazorpazorp', error: customError }]
YARN: [{ rule: 'env', variable: 'gazorpazorp', error: customError }],
})[0]

const result = await checkRequirement(rule, context)
Expand All @@ -199,7 +199,7 @@ describe('checkRequirement', () => {

test('failed DIR rule with custom message', async () => {
const rule = toPairs({
YARN: [{ rule: 'dir', location: 'gazorpazorp', error: customError }]
YARN: [{ rule: 'dir', location: 'gazorpazorp', error: customError }],
})[0]

const result = await checkRequirement(rule, context)
Expand All @@ -208,7 +208,7 @@ describe('checkRequirement', () => {

test('failed FILE rule with custom message', async () => {
const rule = toPairs({
YARN: [{ rule: 'file', location: 'gazorpazorp', error: customError }]
YARN: [{ rule: 'file', location: 'gazorpazorp', error: customError }],
})[0]

const result = await checkRequirement(rule, context)
Expand All @@ -217,11 +217,10 @@ describe('checkRequirement', () => {

test('failed SHELL rule with custom message', async () => {
const rule = toPairs({
YARN: [{ rule: 'shell', match: 'hello', command: 'mocked', error: customError }]
YARN: [{ rule: 'shell', match: 'hello', command: 'mocked', error: customError }],
})[0]
const result = await checkRequirement(rule, context)
expect(result).toEqual([customError])
})

})
})
Loading

0 comments on commit d55a791

Please sign in to comment.