Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions es5/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ var buildVersion = JSON.parse(packageConfig).version;
_commander2.default.version(buildVersion)
// default cli behaviour will be an interactive walkthrough each error, with suggestions,
// options to replace etc.
.option('-r, --report', 'Outputs a full report which details the unique spelling errors found.').option('-n, --ignore-numbers', 'Ignores numbers.').option('--en-us', 'American English dictionary.').option('--en-gb', 'British English dictionary.').option('--en-au', 'Australian English dictionary.').option('--es-es', 'Spanish dictionary.').option('-d, --dictionary [file]', 'specify a custom dictionary file - it should not include the file extension and will load .dic and .aiff.').option('-a, --ignore-acronyms', 'Ignores acronyms.').option('-x, --no-suggestions', 'Do not suggest words (can be slow)').option('-t, --target-relative', 'Uses ".spelling" files relative to the target.').usage("[options] source-file source-file").parse(process.argv);
.option('-r, --report', 'Outputs a full report which details the unique spelling errors found')
.option('-n, --ignore-numbers', 'Ignores numbers')
.option('--en-us', 'American English dictionary')
.option('--en-gb', 'British English dictionary')
.option('--en-au', 'Australian English dictionary')
.option('--es-es', 'Spanish dictionary')
.option('-d, --dictionary [file]', 'Specify a custom dictionary file - it should not include the file extension and will load .dic and .aiff')
.option('-a, --ignore-acronyms', 'Ignores acronyms')
.option('-x, --no-suggestions', 'Do not suggest words (can be slow)')
.option('-t, --target-relative', 'Uses ".spelling" files relative to the target')
.option('-z, --no-colour','No colour output in report')
.usage("[options] source-file source-file").parse(process.argv)
;

var language = void 0;
if (_commander2.default.enUs) {
Expand All @@ -59,22 +71,29 @@ if (_commander2.default.enUs) {
language = "es-es";
}


var options = {
ignoreAcronyms: _commander2.default.ignoreAcronyms,
ignoreNumbers: _commander2.default.ignoreNumbers,
suggestions: _commander2.default.suggestions,
relativeSpellingFiles: _commander2.default.targetRelative,
colour: _commander2.default.colour,
dictionary: {
language: language,
file: _commander2.default.dictionary
}
};


if (!_commander2.default.args.length) {
_commander2.default.outputHelp();
process.exit();
} else {

if ( ! options.colour ) {
_chalk2.default.enabled = false;
}

_spellcheck2.default.initialise(options);

var inputPatterns = _commander2.default.args;
Expand All @@ -84,7 +103,7 @@ if (!_commander2.default.args.length) {
if (_commander2.default.report) {
var errors = _index2.default.spell(src, options);
if (errors.length > 0) {
console.log((0, _reportGenerator.generateFileReport)(filename, { errors: errors, src: src }));
console.log((0, _reportGenerator.generateFileReport)(filename, { errors: errors, src: src }, options));
process.exitCode = 1;
}
fileProcessed(null, errors);
Expand All @@ -95,4 +114,4 @@ if (!_commander2.default.args.length) {
}, function (e, results) {
console.log((0, _reportGenerator.generateSummaryReport)(results));
});
}
}
12 changes: 9 additions & 3 deletions es5/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getLines(src, index, noBefore, noAfter) {
}

exports.default = {
getBlock: function getBlock(src, index, length) {
getBlock: function getBlock(src, index, length, options) {
var lineInfo = getLines(src, index, 2, 2);
var lineStart = 0;
var lineEnd = lineInfo.line.length;
Expand All @@ -76,10 +76,16 @@ exports.default = {
if (lineEnd - (lineInfo.column + length) > 30) {
lineEnd = lineInfo.column + length + 30;
}
var info = lineInfo.line.substring(lineStart, lineInfo.column) + _chalk2.default.red(lineInfo.line.substr(lineInfo.column, length)) + lineInfo.line.substring(lineInfo.column + length, lineEnd);

var info = lineInfo.line.substring(lineStart, lineInfo.column) +
( options.colour ? "" : "[[[") +
_chalk2.default.red(lineInfo.line.substr(lineInfo.column, length)) +
( options.colour ? "" : "]]]") +
lineInfo.line.substring(lineInfo.column + length, lineEnd);

return {
info: info,
lineNumber: lineInfo.lineNumber
};
}
};
};
6 changes: 3 additions & 3 deletions es5/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ function generateSummaryReport(results) {
}

// Generates a report for the errors found in a single markdown file.
function generateFileReport(file, spellingInfo) {
function generateFileReport(file, spellingInfo, options) {
var report = ' ' + _chalk2.default.bold(file) + '\n';

for (var k = 0; k < spellingInfo.errors.length; k++) {
var error = spellingInfo.errors[k];
var displayBlock = _context2.default.getBlock(spellingInfo.src, error.index, error.word.length);
var displayBlock = _context2.default.getBlock(spellingInfo.src, error.index, error.word.length, options);

var lineNumber = String(displayBlock.lineNumber);
var lineNumberPadding = Array(10 - lineNumber.length).join(' ');
var linePrefix = '' + lineNumberPadding + lineNumber + ' |';
report += linePrefix + ' ' + displayBlock.info + ' \n';
}
return report;
}
}
13 changes: 9 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,28 +84,33 @@ Where `speling` will be highlighted in red.
* "Add to file ignores" will ignore the word in this file only.
* "Add to dictionary - case insensitive" will add to the dictionary for all files and match any case. E.g. with the word `Microsoft` both `Microsoft` and `microsoft` would match.
* "Add to dictionary - case sensitive" will add to the dictionary for all files and match the case that has been used. E.g. with the word `Microsoft`, the word `microsoft` will not match.

All exclusions will be stored in a `.spelling` file in the directory from which you run the command.

### Target Relative Mode

Using the `--target-relative` (`-t`) option will augment the shared `.spelling` file with a relative `.spelling` file (sibling of the `.md` file) and give you the additional options with the interactive mode:
Using the `--target-relative` (`-t`) option will augment the shared `.spelling` file with a relative `.spelling` file (sibling of the `.md` file) and give you the additional options with the interactive mode:

* "Add to file ignores" will be replaced with "[Relative] Add to file ignores". There is no need to add file ignores into the shared `.spelling` file.
* "[Relative] Add to dictionary - case insensitive" will add to the dictionary for all files within the current `.md` file and match any case.
* "[Relative] Add to dictionary - case sensitive" will add to the dictionary for all files within the folder of the current `.md` file.

### Report Mode

Using the `--report` (`-r`) option will show a report of all the spelling mistakes that have been found. This mode is useful for CI build reports.
Using the `--report` (`-r`) option will show a report of all the spelling mistakes that have been found. This mode is useful for CI build reports.

### No Colour Mode

For situations where the report colours do not show up and you can't identify the failing words, the `--no-colour` (`-z`) will turn off colour and surround the spelling mistakes with square brackets, such as `[[[mistake]]]`.


## `.spelling` files

The `.spelling` file is self documenting as it includes...

```
# markdown-spellcheck spelling configuration file
# Format - lines begining # are comments
# Format - lines beginning # are comments
# global dictionary is at the start, file overrides afterwards
# one word per line, to define a file override use ' - filename'
# where filename is relative to this configuration file
Expand Down