Skip to content

Commit 0e40d2c

Browse files
sudo-suhasokonet
authored andcommitted
style: Use dedent for prettier multi-line template literals (#242)
1 parent 3fa4f6d commit 0e40d2c

File tree

7 files changed

+72
-64
lines changed

7 files changed

+72
-64
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"chalk": "^2.1.0",
3232
"commander": "^2.11.0",
3333
"cosmiconfig": "^3.1.0",
34+
"dedent": "^0.7.0",
3435
"execa": "^0.8.0",
3536
"is-glob": "^4.0.0",
3637
"jest-validate": "^21.1.0",

src/getConfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ function unknownValidationReporter(config, example, option, options) {
5959
* a typical mistake of mixing simple and advanced configs
6060
*/
6161
if (isGlob(option)) {
62+
// prettier-ignore
6263
const message = ` Unknown option ${chalk.bold(`"${option}"`)} with value ${chalk.bold(
63-
format(config[option], { inlineCharacterLimit: Number.POSITIVE_INFINITY })
64-
)} was found in the config root.
64+
format(config[option], { inlineCharacterLimit: Number.POSITIVE_INFINITY })
65+
)} was found in the config root.
6566
6667
You are probably trying to mix simple and advanced config formats. Adding
6768

src/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict'
44

55
const appRoot = require('app-root-path')
6+
const dedent = require('dedent')
67
const cosmiconfig = require('cosmiconfig')
78
const stringifyObject = require('stringify-object')
89
const getConfig = require('./getConfig').getConfig
@@ -44,10 +45,8 @@ module.exports = function lintStaged(injectedLogger, configPath) {
4445
const config = validateConfig(getConfig(result.config))
4546

4647
if (config.verbose) {
47-
logger.log(`
48-
Running lint-staged with the following config:
49-
${stringifyObject(config)}
50-
`)
48+
logger.log('Running lint-staged with the following config:')
49+
logger.log(stringifyObject(config, { indent: ' ' }))
5150
}
5251

5352
const scripts = packageJson.scripts || {}
@@ -68,15 +67,18 @@ ${stringifyObject(config)}
6867
logger.error(`${err.message}.`)
6968
} else {
7069
// It was probably a parsing error
71-
logger.error(`Could not parse lint-staged config.
70+
logger.error(dedent`
71+
Could not parse lint-staged config.
7272
73-
${err}`)
73+
${err}
74+
`)
7475
}
76+
logger.error() // empty line
7577
// Print helpful message for all errors
76-
logger.error(`
77-
Please make sure you have created it correctly.
78-
See https://github.com/okonet/lint-staged#configuration.
79-
`)
78+
logger.error(dedent`
79+
Please make sure you have created it correctly.
80+
See https://github.com/okonet/lint-staged#configuration.
81+
`)
8082
process.exitCode = 1
8183
})
8284
}

src/runScript.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const chunk = require('lodash/chunk')
4+
const dedent = require('dedent')
45
const execa = require('execa')
56
const logSymbols = require('log-symbols')
67
const pMap = require('p-map')
@@ -46,18 +47,22 @@ module.exports = function runScript(commands, pathsToLint, scripts, config) {
4647
return pMap(filePathChunks, mapper, { concurrency })
4748
.catch(err => {
4849
/* This will probably never be called. But just in case.. */
49-
throw new Error(`${logSymbols.error} ${linter} got an unexpected error.
50-
${err.message}`)
50+
throw new Error(dedent`
51+
${logSymbols.error} ${linter} got an unexpected error.
52+
${err.message}
53+
`)
5154
})
5255
.then(() => {
5356
if (errors.length === 0) return `${logSymbols.success} ${linter} passed!`
5457

5558
const errStdout = errors.map(err => err.stdout).join('')
5659
const errStderr = errors.map(err => err.stderr).join('')
5760

58-
throw new Error(`${logSymbols.error} ${linter} found some errors. Please fix them and try committing again.
59-
${errStdout}
60-
${errStderr}`)
61+
throw new Error(dedent`
62+
${logSymbols.error} ${linter} found some errors. Please fix them and try committing again.
63+
${errStdout}
64+
${errStderr}
65+
`)
6166
})
6267
} catch (err) {
6368
throw err

test/__snapshots__/index.spec.js.snap

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,52 @@
22

33
exports[`lintStaged should load config file when specified 1`] = `
44
"
5-
LOG
6-
Running lint-staged with the following config:
7-
{
8-
verbose: true,
9-
linters: {
10-
'*': 'mytask'
11-
},
12-
concurrent: true,
13-
chunkSize: 9007199254740991,
14-
gitDir: '.',
15-
globOptions: {
16-
matchBase: true,
17-
dot: true
18-
},
19-
subTaskConcurrency: 1,
20-
renderer: 'verbose'
21-
}
22-
"
5+
LOG Running lint-staged with the following config:
6+
LOG {
7+
verbose: true,
8+
linters: {
9+
'*': 'mytask'
10+
},
11+
concurrent: true,
12+
chunkSize: 9007199254740991,
13+
gitDir: '.',
14+
globOptions: {
15+
matchBase: true,
16+
dot: true
17+
},
18+
subTaskConcurrency: 1,
19+
renderer: 'verbose'
20+
}"
2321
`;
2422

2523
exports[`lintStaged should not output config in non verbose mode 1`] = `""`;
2624

2725
exports[`lintStaged should output config in verbose mode 1`] = `
2826
"
29-
LOG
30-
Running lint-staged with the following config:
31-
{
32-
verbose: true,
33-
linters: {
34-
'*': 'mytask'
35-
},
36-
concurrent: true,
37-
chunkSize: 9007199254740991,
38-
gitDir: '.',
39-
globOptions: {
40-
matchBase: true,
41-
dot: true
42-
},
43-
subTaskConcurrency: 1,
44-
renderer: 'verbose'
45-
}
46-
"
27+
LOG Running lint-staged with the following config:
28+
LOG {
29+
verbose: true,
30+
linters: {
31+
'*': 'mytask'
32+
},
33+
concurrent: true,
34+
chunkSize: 9007199254740991,
35+
gitDir: '.',
36+
globOptions: {
37+
matchBase: true,
38+
dot: true
39+
},
40+
subTaskConcurrency: 1,
41+
renderer: 'verbose'
42+
}"
4743
`;
4844

4945
exports[`lintStaged should print helpful error message when config file is not found 1`] = `
5046
"
5147
ERROR Config could not be found.
5248
ERROR
53-
Please make sure you have created it correctly.
54-
See https://github.com/okonet/lint-staged#configuration.
55-
"
49+
ERROR Please make sure you have created it correctly.
50+
See https://github.com/okonet/lint-staged#configuration."
5651
`;
5752

5853
exports[`lintStaged should print helpful error message when explicit config file is not found 1`] = `
@@ -61,7 +56,6 @@ ERROR Could not parse lint-staged config.
6156
6257
Error: ENOENT: no such file or directory, open 'fake-config-file.yml'
6358
ERROR
64-
Please make sure you have created it correctly.
59+
ERROR Please make sure you have created it correctly.
6560
See https://github.com/okonet/lint-staged#configuration.
66-
6761
`;

test/runScript-mock-pMap.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dedent from 'dedent'
12
import pMapMock from 'p-map'
23
import logSymbols from 'log-symbols'
34
import runScript from '../src/runScript'
@@ -39,8 +40,10 @@ describe('runScript', () => {
3940
try {
4041
await res[0].task()
4142
} catch (err) {
42-
expect(err.message).toMatch(`${logSymbols.error} test got an unexpected error.
43-
Unexpected Error`)
43+
expect(err.message).toMatch(dedent`
44+
${logSymbols.error} test got an unexpected error.
45+
Unexpected Error
46+
`)
4447
}
4548
})
4649
})

test/runScript.spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dedent from 'dedent'
12
import mockFn from 'execa'
23
import logSymbols from 'log-symbols'
34
import runScript from '../src/runScript'
@@ -140,10 +141,11 @@ describe('runScript', () => {
140141
try {
141142
await taskPromise
142143
} catch (err) {
143-
expect(err.message)
144-
.toMatch(`${logSymbols.error} mock-fail-linter found some errors. Please fix them and try committing again.
145-
${linterErr.stdout}
146-
${linterErr.stderr}`)
144+
expect(err.message).toMatch(dedent`
145+
${logSymbols.error} mock-fail-linter found some errors. Please fix them and try committing again.
146+
${linterErr.stdout}
147+
${linterErr.stderr}
148+
`)
147149
}
148150
})
149151
})

0 commit comments

Comments
 (0)