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

Commit

Permalink
Merge 11ed102 into 7a40cf2
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed May 6, 2019
2 parents 7a40cf2 + 11ed102 commit 2da218a
Show file tree
Hide file tree
Showing 7 changed files with 1,011 additions and 521 deletions.
6 changes: 4 additions & 2 deletions lib/cli.js
Expand Up @@ -20,7 +20,7 @@ debug.setDebug(program.debug);

const isStdin = program.stdin;
const jsonConfig = config.get(program.config);
const json = Object.assign({}, jsonDefault, jsonConfig);
const json = Object.assign({}, jsonDefault, jsonConfig.data);

const settings = {
excludeFiles: json.excludeFiles,
Expand Down Expand Up @@ -71,12 +71,14 @@ if (!isStdin && !program.args.length) {
program.help();
}

report.onstart();

async.series(
isStdin ?
tasks.forStdin(settings, program.stdinFilename) :
tasks.forResources(program.args, settings),
function() {
report.onend();
report.onend(jsonConfig.relativePath);
process.exit();
}
);
7 changes: 6 additions & 1 deletion lib/config.js
Expand Up @@ -8,6 +8,7 @@ const exitCodes = require('./exit-codes');
const knownProps = require('./config-properties');
const stripJsonComments = require('strip-json-comments');
const parseJson = require('parse-json');
const path = require('path');

function loadJson(filepath, content) {
try {
Expand Down Expand Up @@ -61,8 +62,12 @@ module.exports = {
process.exit(exitCodes.ERROR_CONFIG);
}

return data || {};
return {
relativePath: path.relative('./', file || '.yaspellerrc'),
data: data || {}
};
},

/**
* Check properties in config.
*
Expand Down
9 changes: 7 additions & 2 deletions lib/report.js
Expand Up @@ -30,6 +30,11 @@ module.exports = {
}
});
},
onstart() {
reports.forEach(function(name) {
name.onstart && name.onstart();
});
},
oneach(err, data, dictionary) {
var isError = err || (!err && data.data && data.data.length);
stats.total++;
Expand All @@ -52,9 +57,9 @@ module.exports = {
});
}
},
onend() {
onend(configPath) {
reports.forEach(function(name) {
name.onend && name.onend(buffer, stats);
name.onend && name.onend(buffer, stats, configPath);
});
}
};
16 changes: 14 additions & 2 deletions lib/report/console.js
Expand Up @@ -4,6 +4,7 @@ const chalk = require('chalk');
const program = require('commander');
const utils = require('../utils');
const yaspeller = require('../yaspeller');
const packageJson = require('../../package.json');

function getTyposByCode(code, data) {
let typos = [];
Expand Down Expand Up @@ -42,6 +43,9 @@ function getTyposByCode(code, data) {
}

module.exports = {
onstart() {
console.log('Spelling check:');
},
oneach(err, data) {
const errors = [];
if (err) {
Expand Down Expand Up @@ -77,9 +81,17 @@ module.exports = {
}
}
},
onend(data, stats) {
onend(data, stats, configPath) {
if (!program.onlyErrors && stats.total) {
if (!stats.errors) {
if (stats.errors) {
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 {
console.log(chalk.green('No errors.'));
}

Expand Down

0 comments on commit 2da218a

Please sign in to comment.