Skip to content

Commit 9129c8f

Browse files
author
Kent C. Dodds
committed
fix(eslint): if no fix is necessary, do not return undefined
1 parent 6fd8f23 commit 9129c8f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ function format({
3838
options.disableLog = disableLog
3939

4040
try {
41+
// console.log('text', text)
4142
const pretty = prettify(text, prettierOptions, prettierPath)
43+
// console.log('pretty', pretty)
4244
const eslintFixed = eslintFix(pretty, eslintConfig, eslintPath)
45+
// console.log('eslintFixed', eslintFixed)
4346
return eslintFixed
4447
} finally {
4548
options.disableLog = originalLogValue
@@ -81,7 +84,9 @@ function eslintFix(text, eslintConfig, eslintPath) {
8184
const eslint = getESLintCLIEngine(eslintPath, eslintOptions)
8285
try {
8386
const report = eslint.executeOnText(text)
84-
const [{output}] = report.results
87+
// default the output to text because if there's nothing
88+
// to fix, eslint doesn't provide `output`
89+
const [{output = text}] = report.results
8590
// NOTE: We're ignoring linting errors/warnings here and
8691
// defaulting to the given text if there are any
8792
// because all we're trying to do is fix what we can.

src/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ const tests = [
4949
},
5050
output: defaultOutput(),
5151
},
52+
{
53+
title: 'with code that needs no fixing',
54+
input: {
55+
text: 'var [foo, {bar}] = window.APP;',
56+
eslintConfig: {rules: {}},
57+
},
58+
output: 'var [foo, {bar}] = window.APP;',
59+
},
5260
// if you have a bug report or something,
5361
// go ahead and add a test case here
5462
]

0 commit comments

Comments
 (0)