diff --git a/es5/cli.js b/es5/cli.js index 6a03604..549098c 100644 --- a/es5/cli.js +++ b/es5/cli.js @@ -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) { @@ -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; @@ -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); @@ -95,4 +114,4 @@ if (!_commander2.default.args.length) { }, function (e, results) { console.log((0, _reportGenerator.generateSummaryReport)(results)); }); -} \ No newline at end of file +} diff --git a/es5/context.js b/es5/context.js index e91b976..1a59dc4 100644 --- a/es5/context.js +++ b/es5/context.js @@ -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; @@ -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 }; } -}; \ No newline at end of file +}; diff --git a/es5/report-generator.js b/es5/report-generator.js index 4ae6e59..3609898 100644 --- a/es5/report-generator.js +++ b/es5/report-generator.js @@ -35,12 +35,12 @@ 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(' '); @@ -48,4 +48,4 @@ function generateFileReport(file, spellingInfo) { report += linePrefix + ' ' + displayBlock.info + ' \n'; } return report; -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index dfd1579..755a4f4 100644 --- a/readme.md +++ b/readme.md @@ -84,12 +84,12 @@ 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. @@ -97,7 +97,12 @@ Using the `--target-relative` (`-t`) option will augment the shared `.spelling` ### 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 @@ -105,7 +110,7 @@ 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