diff --git a/.yaspellerrc b/.yaspellerrc index 5f7fb76..fb95263 100644 --- a/.yaspellerrc +++ b/.yaspellerrc @@ -30,6 +30,7 @@ "svg", "Seleznev", "sitemap", + "stdin", "sublicense", "yaspeller", "yo" diff --git a/README.md b/README.md index e2b77e0..93b1c9b 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,9 @@ Ignore HTML tags.
Default: `code,kbd,object,samp,script,style,var`
Option to formats `html` and` markdown`. +#### `--ignore-text ` +Removes the text from the scan using regular expressions. + #### `--ignore-capitalization` Ignore the incorrect use of UPPERCASE / lowercase letters, for example, in the word `moscow`. @@ -178,6 +181,10 @@ Yaspeller is configured using `.yaspellerrc` JSON file at the root of the projec "some(w|W)ord[23]", // some(w|W)ord[23] = some(w|W)ord[23] and Some(w|W)ord[23] "Some(w|W)ord" // Some(w|W)ord = Some(w|W)ord ], + "ignoreText": [ + "", // Shortly + ["", "g"] // Longly + ], "ignoreTags": ["code", "script"], "ignoreUrls": true, "findRepeatWords": true, @@ -198,6 +205,7 @@ Yaspeller is configured using `.yaspellerrc` JSON file at the root of the projec | `findRepeatWords` | `Boolean` | [`--find-repeat-words`](#--find-repeat-words) | | `flagLatin` | `Boolean` | [`--flag-latin`](#--flag-latin) | | `ignoreTags` | `Array` | [`--ignore-tags`](#--ignore-tags-tags) | +| `ignoreText` | `Array` | [`--ignore-text`](#--ignore-text-regexp) | | `ignoreCapitalization` | `Boolean` | [`--ignore-capitalization`](#--ignore-capitalization) | | `ignoreDigits` | `Boolean` | [`--ignore-digits`](#--ignore-digits) | | `ignoreLatin` | `Boolean` | [`--ignore-latin`](#--ignore-latin) | diff --git a/README.ru.md b/README.ru.md index 7431567..9aa90e2 100644 --- a/README.ru.md +++ b/README.ru.md @@ -88,6 +88,9 @@ JSON-файл собственного словаря. По умолчанию: `code,kbd,object,samp,script,style,var`
Опция для форматов `html` и `markdown`. +#### `--ignore-text ` +Удалять текст из проверки с помощью регулярных выражений. + #### `--ignore-capitalization` Игнорировать неверное употребление ПРОПИСНЫХ/строчных букв, например, в слове `москва`. @@ -174,6 +177,10 @@ JSON-файл собственного словаря. "Some(w|W)ord" // Some(w|W)ord = Some(w|W)ord ], "ignoreTags": ["code", "script"], + "ignoreText": [ + "", // Короткая запись + ["", "g"] // Длинная запись + ], "ignoreUrls": true, "findRepeatWords": true, "maxRequests": 5 @@ -193,6 +200,7 @@ JSON-файл собственного словаря. | `findRepeatWords` | `Boolean` | [`--find-repeat-words`](#--find-repeat-words) | | `flagLatin` | `Boolean` | [`--flag-latin`](#--flag-latin) | | `ignoreTags` | `Array` | [`--ignore-tags`](#--ignore-tags-tags) | +| `ignoreText` | `Array` | [`--ignore-text`](#--ignore-text-regexp) | | `ignoreCapitalization` | `Boolean` | [`--ignore-capitalization`](#--ignore-capitalization) | | `ignoreDigits` | `Boolean` | [`--ignore-digits`](#--ignore-digits) | | `ignoreLatin` | `Boolean` | [`--ignore-latin`](#--ignore-latin) | diff --git a/lib/cli.js b/lib/cli.js index 83fa20d..b3ae3d7 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -9,6 +9,7 @@ var async = require('async'), report = require('./report'), tasks = require('./tasks'), utils = require('./utils'), + ignore = require('./ignore'), _ = require('lodash'), isTTY = process.stdin.isTTY, json, @@ -32,10 +33,20 @@ var settings = { options: json.options || {} }; -['checkYo', 'fileExtensions', 'format', 'ignoreTags', 'lang', 'maxRequests'].forEach(function(key) { +[ + 'checkYo', + 'fileExtensions', + 'format', + 'ignoreTags', + 'ignoreText', + 'lang', + 'maxRequests' +].forEach(function(key) { settings[key] = program[key] || json[key]; }); +settings.ignoreText = ignore.prepareRegExpToIgnoreText(settings.ignoreText); + programOptions.apiOptions.forEach(function(el) { var key = el[0]; if(program[key]) { diff --git a/lib/debug.js b/lib/debug.js index 7cc67fe..90fc589 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -1,3 +1,5 @@ +'use strict'; + var chalk = require('chalk'), _ = require('lodash'), isDebug = false; diff --git a/lib/dictionary.js b/lib/dictionary.js index f18a9a1..59f6415 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -1,3 +1,5 @@ +'use strict'; + var chalk = require('chalk'), _ = require('lodash'), debug = require('./debug'), diff --git a/lib/exit-codes.js b/lib/exit-codes.js index abef70e..3e7cd7e 100644 --- a/lib/exit-codes.js +++ b/lib/exit-codes.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { HAS_TYPOS: 1, ERROR_LOADING: 2, diff --git a/lib/format.js b/lib/format.js index 03c5487..eaf721c 100644 --- a/lib/format.js +++ b/lib/format.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { /** * Is HTML? diff --git a/lib/ignore.js b/lib/ignore.js index 2ee997d..7f4de32 100644 --- a/lib/ignore.js +++ b/lib/ignore.js @@ -1,3 +1,7 @@ +'use strict'; + +var chalk = require('chalk'); + // jshint maxlen: 256 module.exports = { /** @@ -74,5 +78,35 @@ module.exports = { }); return text; + }, + /** + * Prepares regular expressions to remove text. + * + * @param {Array|undefined} data + * + * @return {Array} + */ + prepareRegExpToIgnoreText: function(data) { + var result = []; + + if(typeof data === 'string') { + data = [data]; + } + + Array.isArray(data) && data.forEach(function(re) { + try { + if(typeof re === 'string') { + result.push(new RegExp(re, 'g')); + } + + if(Array.isArray(re)) { + result.push(new RegExp(re[0], typeof re[1] === 'undefined' ? 'g' : re[1])); + } + } catch(e) { + console.error(chalk.red('Error in RegExp "' + re.toString() + '": ' + e)); + } + }); + + return result; } }; diff --git a/lib/options.js b/lib/options.js index 3a57b11..e007eb8 100644 --- a/lib/options.js +++ b/lib/options.js @@ -1,3 +1,5 @@ +'use strict'; + /*jshint maxlen:1000 */ var program = require('commander'), _ = require('lodash'); @@ -27,6 +29,7 @@ module.exports = { .option('--ignore-tags ', 'ignore tags. Default: "' + prefs.defaultIgnoreTags + '"', splitByCommas, null) + .option('--ignore-text ', 'ignore text using RegExp') .option('--max-requests ', 'max count of requests at a time. Default: 2', parseInt, 0) .option('--only-errors', 'output only errors') .option('--debug', 'debug mode') diff --git a/lib/report.js b/lib/report.js index 2ed2dbc..5596ad9 100644 --- a/lib/report.js +++ b/lib/report.js @@ -1,3 +1,5 @@ +'use strict'; + var chalk = require('chalk'), program = require('commander'), pth = require('path'), diff --git a/lib/report/console.js b/lib/report/console.js index ba665d2..826985d 100644 --- a/lib/report/console.js +++ b/lib/report/console.js @@ -1,3 +1,5 @@ +'use strict'; + var chalk = require('chalk'), program = require('commander'), utils = require('../utils'), diff --git a/lib/report/error_dictionary.js b/lib/report/error_dictionary.js index a35083a..31bf513 100644 --- a/lib/report/error_dictionary.js +++ b/lib/report/error_dictionary.js @@ -1,3 +1,5 @@ +'use strict'; + var fs = require('fs'), chalk = require('chalk'), _ = require('lodash'); diff --git a/lib/report/example.js b/lib/report/example.js index 99c733f..4e3378b 100644 --- a/lib/report/example.js +++ b/lib/report/example.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { oneach: function(err, data) { console.log('oneach: ', err, data); diff --git a/lib/report/html.js b/lib/report/html.js index 9049c68..8d117d8 100644 --- a/lib/report/html.js +++ b/lib/report/html.js @@ -1,3 +1,5 @@ +'use strict'; + /*jshint maxlen:1000 */ var fs = require('fs'), pth = require('path'), diff --git a/lib/report/html/template.js b/lib/report/html/template.js index 64b9e9d..a40cb68 100644 --- a/lib/report/html/template.js +++ b/lib/report/html/template.js @@ -1,3 +1,5 @@ +'use strict'; + var App = { init: function() { this.events(); diff --git a/lib/report/json.js b/lib/report/json.js index f477517..8697a38 100644 --- a/lib/report/json.js +++ b/lib/report/json.js @@ -1,3 +1,5 @@ +'use strict'; + var fs = require('fs'), chalk = require('chalk'); diff --git a/lib/report/markdown.js b/lib/report/markdown.js index 1d6502a..0658a0c 100644 --- a/lib/report/markdown.js +++ b/lib/report/markdown.js @@ -1,3 +1,5 @@ +'use strict'; + var fs = require('fs'), pth = require('path'), chalk = require('chalk'), @@ -5,7 +7,7 @@ var fs = require('fs'), yaspeller = require('../yaspeller'), _ = require('lodash'), buffer = []; - + function prepareResource(resource) { var relativeFile = resource; if(!utils.isUrl(resource)) { diff --git a/lib/utils.js b/lib/utils.js index 95ae493..31733bf 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,3 +1,5 @@ +'use strict'; + var chalk = require('chalk'), fs = require('fs'), isutf8 = require('isutf8'), diff --git a/lib/yaspeller.js b/lib/yaspeller.js index 18b04bc..e81684b 100644 --- a/lib/yaspeller.js +++ b/lib/yaspeller.js @@ -1,3 +1,5 @@ +'use strict'; + /* jshint maxlen: 300 */ var async = require('async'), entities = require('entities'), @@ -42,6 +44,7 @@ function stripTags(html) { * @param {Object} [settings] * @param {string} [settings.format] Text format: plain or html. * @param {string|Array} [settings.lang] Language: en, ru or uk. + * @param {Array} [settings.ignoreText] * @param {Object} [settings.options] */ function checkText(text, callback, settings) { @@ -51,6 +54,10 @@ function checkText(text, callback, settings) { apiSettings.lang = Array.isArray(lang) ? lang.join(',') : lang; + apiSettings.ignoreText && apiSettings.ignoreText.forEach(function(re) { + text = text.replace(re, ''); + }); + if(ignore.hasIgnoredText(text)) { text = ignore.lines(text); text = ignore.blocks(text); diff --git a/test/test.ignore.js b/test/test.ignore.js index 94f2fec..31e8aaf 100644 --- a/test/test.ignore.js +++ b/test/test.ignore.js @@ -1,5 +1,6 @@ // jshint maxlen:1024 var yaspeller = require('../lib/yaspeller'), + ignore = require('../lib/ignore'), assert = require('chai').assert; describe('Ignore text', function() { @@ -56,4 +57,39 @@ describe('Ignore text', function() { done(); }, {lang: 'ru'}); }); + + it('with regExp, long', function(done) { + var text = 'Moscaw1\nMoscaw2\nMoscaw3\nMoscaw4'; + yaspeller.checkText(text, function(err, data) { + assert.equal(data.length, 2); + done(); + }, { + lang: 'en', + ignoreText: ignore.prepareRegExpToIgnoreText([ + ['[^]*?', 'gi'] + ]) + }); + }); + + it('with regExp, short1', function(done) { + var text = 'Moscaw1\nMoscaw2\nMoscaw3\nMoscaw4'; + yaspeller.checkText(text, function(err, data) { + assert.equal(data.length, 2); + done(); + }, { + lang: 'en', + ignoreText: ignore.prepareRegExpToIgnoreText(['[^]*?']) + }); + }); + + it('with regExp, short2', function(done) { + var text = 'Moscaw1\nMoscaw2\nMoscaw3\nMoscaw4'; + yaspeller.checkText(text, function(err, data) { + assert.equal(data.length, 2); + done(); + }, { + lang: 'en', + ignoreText: ignore.prepareRegExpToIgnoreText('[^]*?') + }); + }); });