Skip to content

Commit

Permalink
Export and use a new function: fixNibbles() (#91)
Browse files Browse the repository at this point in the history
Commit dfd4439 added support for ESLint 8. `nibbleOnFile()` was updated to add in the roll-up statistics, but that change missed the fact that `eslint-filtered-fix.fix()` also no longer includes the roll-up statistics.

This PR exports a new function called `fixNibbles()` which calls `fix()` and then adds in the roll-up statistics using the existing `calculateStatsPerRun()` function. The call to `fix()` could have been kept within the `cli` module, but that would have required bigger changes to copy/move/export `calculateStatsPerRun()` for use in there, so this seems like the simplest solution.

This wasn't picked up by the tests as auto-fix is only available in interactive mode, and there are no tests for interactive mode. Adding support for testing interactive mode would require investigation and more time than I have available, so there are still no tests for this. This change can be tested easily by running `eslint-nibble` interactively against a file with auto-fixable errors.

Fixes #90
  • Loading branch information
IanVS authored Jan 20, 2022
2 parents 65079a3 + 222dec4 commit 8a547fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const nibbler = require('./nibbler');
const fmt = require('./config/formatters');
const chalk = require('chalk');
const inquirer = require('inquirer');
const { fix } = require('eslint-filtered-fix');
const options = require('./config/options');
const { version } = require('../package.json');

Expand Down Expand Up @@ -180,7 +179,7 @@ const cli = {
rules : isMulti ? answers.rule : [answers.rule],
warnings: answers.fixWarnings
};
const fixedReport = await fix(files, fixOptions, configuration);
const fixedReport = await nibbler.fixNibbles(files, fixOptions, configuration);
const ruleResults = nibbler.getRuleResults(fixedReport, answers.rule);
if (ruleResults.errorCount > 0 || ruleResults.warningCount > 0) {
const detailed = await nibbler.getFormattedResults(ruleResults, fmt.detailed);
Expand Down
10 changes: 10 additions & 0 deletions src/nibbler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { ESLint } = require('eslint');
const { fix } = require('eslint-filtered-fix');
let cli = new ESLint({});

function getCounts(messages) {
Expand Down Expand Up @@ -119,6 +120,15 @@ module.exports = {
return report;
},

async fixNibbles(files, fixOptions, configuration) {
const results = await fix(files, fixOptions, configuration);
const report = {
results,
...calculateStatsPerRun(results)
};
return report;
},

getFatalResults(report) {
const fatalResults = filterResults(report, 'fatal', { present: true });
if (fatalResults.errorCount > 0) {
Expand Down

0 comments on commit 8a547fc

Please sign in to comment.