Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Determine fix results based on exit code
Browse files Browse the repository at this point in the history
Perhaps in the past ESLint threw an error if `--fix` did not fix all of
the errors in a file.  Or, maybe this logic was flawed from the start.
Either way, this change just looks at the exit code (`0` if there are 
no linting errors left, `1` if there are), and returns an appropriate
string.  Both cases are really success messages, there were no errors.

If there was an error for some reason, we need to print the `err.message`
string, because `addWarning` expects a string, not an error object.
  • Loading branch information
IanVS committed Jan 5, 2017
1 parent 73a9c1e commit 913d0e1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
8 changes: 6 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ module.exports = {
config: atom.config.get('linter-eslint'),
filePath,
projectPath
}).catch(response => atom.notifications.addWarning(response));
}).catch(err => {
atom.notifications.addWarning(err.message);
});
}
});
}));
Expand Down Expand Up @@ -87,7 +89,9 @@ module.exports = {
config: atom.config.get('linter-eslint'),
filePath,
projectPath
}).then(response => atom.notifications.addSuccess(response)).catch(response => atom.notifications.addWarning(response));
}).then(response => atom.notifications.addSuccess(response)).catch(err => {
atom.notifications.addWarning(err.message);
});
}
}));

Expand Down
9 changes: 4 additions & 5 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ function lintJob(argv, contents, eslint, configPath, config) {
}

function fixJob(argv, eslint) {
try {
eslint.execute(argv);
return 'Linter-ESLint: Fix Complete';
} catch (err) {
throw new Error('Linter-ESLint: Fix Attempt Completed, Linting Errors Remain');
const exit = eslint.execute(argv);
if (exit === 0) {
return 'Linter-ESLint: Fix complete.';
}
return 'Linter-ESLint: Fix attempt complete, but linting errors remain.';
}

(0, _processCommunication.create)().onRequest('job', (_ref, job) => {
Expand Down
2 changes: 1 addition & 1 deletion spec/linter-eslint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ describe('The eslint provider for Linter', () => {
return fix(textEditor)
.then((messagesAfterSave) => {
// Linter reports a successful fix
expect(messagesAfterSave).toBe('Linter-ESLint: Fix Complete')
expect(messagesAfterSave).toBe('Linter-ESLint: Fix complete.')
})
}
// Create a subscription to watch when the editor changes (from the fix)
Expand Down
12 changes: 6 additions & 6 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ module.exports = {
config: atom.config.get('linter-eslint'),
filePath,
projectPath
}).catch(response =>
atom.notifications.addWarning(response)
)
}).catch((err) => {
atom.notifications.addWarning(err.message)
})
}
})
}))
Expand Down Expand Up @@ -87,9 +87,9 @@ module.exports = {
projectPath
}).then(response =>
atom.notifications.addSuccess(response)
).catch(response =>
atom.notifications.addWarning(response)
)
).catch((err) => {
atom.notifications.addWarning(err.message)
})
}
}))

Expand Down
9 changes: 4 additions & 5 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ function lintJob(argv, contents, eslint, configPath, config) {
}

function fixJob(argv, eslint) {
try {
eslint.execute(argv)
return 'Linter-ESLint: Fix Complete'
} catch (err) {
throw new Error('Linter-ESLint: Fix Attempt Completed, Linting Errors Remain')
const exit = eslint.execute(argv)
if (exit === 0) {
return 'Linter-ESLint: Fix complete.'
}
return 'Linter-ESLint: Fix attempt complete, but linting errors remain.'
}

create().onRequest('job', ({ contents, type, config, filePath, projectPath, rules }, job) => {
Expand Down

0 comments on commit 913d0e1

Please sign in to comment.