Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #139 from hcodes/warning_typo
Browse files Browse the repository at this point in the history
Print a typo warning at the end if there are typos
  • Loading branch information
hcodes committed Mar 23, 2020
2 parents 7635299 + 68b7727 commit bc6d5b4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v6.0.3
- Fix: print a typo warning at the end if there are typos #121.
- Updated deps in package.json.

## v6.0.2
- Updated deps in package.json.

Expand Down
24 changes: 15 additions & 9 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const program = require('commander');
const pth = require('path');

const stats = {
errors: 0,
hasTypos: false,
ok: 0,
total: 0,
errors: 0,
ok: 0
};
const reports = [];
const reportNames = {};
Expand Down Expand Up @@ -35,25 +36,30 @@ module.exports = {
name.onstart && name.onstart();
});
},
oneach(err, data, dictionary) {
var isError = err || (!err && data.data && data.data.length);
oneach(hasError, data, dictionary) {
const hasTypos = Boolean(data && data.data && data.data.length);

stats.total++;

if (isError) {
if (hasError || hasTypos) {
stats.errors++;

buffer.push([err, data]);
if (hasTypos) {
stats.hasTypos = true;
}

buffer.push([hasError, data]);
} else {
stats.ok++;

if (!program.onlyErrors) {
buffer.push([err, data]);
buffer.push([hasError, data]);
}
}

if ((program.onlyErrors && isError) || !program.onlyErrors) {
if (!program.onlyErrors || hasError || hasTypos) {
reports.forEach(function(name) {
name.oneach && name.oneach(err, data, dictionary);
name.oneach && name.oneach(hasError, data, dictionary);
});
}
},
Expand Down
10 changes: 7 additions & 3 deletions lib/report/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,23 @@ module.exports = {
},
onend(data, stats, configPath) {
if (!program.onlyErrors && stats.total) {
if (stats.errors) {
if (stats.hasTypos) {
let path = configPath + ' (';
if (configPath.search(/package\.json/) !== -1) {
path += '"yaspeller"→';
}

path += '"dictionary" property)';
console.log(chalk.yellow(`Fix typo or add word to dictionary at ${path} if you are sure about spelling. Docs: ${packageJson.homepage}#configuration`));
} else {
}

if (!stats.errors) {
console.log(chalk.green('No errors.'));
}

console.log(chalk.magenta('Checking finished: ' + utils.uptime()));
if (program.debug) {
console.log(chalk.magenta('Checking finished: ' + utils.uptime()));
}
}
}
};
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
}
}
} else {
throw new Error(file + ': is not utf-8.');
throw new Error(file + ': is not UTF-8.');
}
} else if (throwIfFileNotExists) {
throw new Error(file + ': is not exists.');
Expand Down
2 changes: 1 addition & 1 deletion lib/yaspeller.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function checkFile(file, callback, settings) {
);
}, settings);
} else {
callback(true, Error(file + ': is not utf-8'));
callback(true, Error(file + ': is not UTF-8'));
}
} else {
callback(true, Error(file + ': is not file'));
Expand Down

0 comments on commit bc6d5b4

Please sign in to comment.