yaspeller
Средство поиска опечаток в тексте, в файлах и на сайтах.
Используется API Yandex.Speller.
Установка
npm install yaspeller -g
Командная строка
yaspeller [options] <file-or-directory-or-link...>
pre-commit
Используйте сДобавте в ваш .pre-commit-config.yaml
:
- repo: https://github.com/hcodes/yaspeller.git
rev: '' # Use the sha / tag you want to point at
hooks:
- id: yaspeller
Примеры
yaspeller README.md
— поиск опечаток в файле.yaspeller -e ".md,.html" ./texts/
— поиск опечаток в файлах в папке.yaspeller https://ru.wikipedia.org/wiki/%D0%9E%D0%BF%D0%B5%D1%87%D0%B0%D1%82%D0%BA%D0%B0
— поиск опечаток на странице сайта.yaspeller http://bem.info/sitemap.xml
— поиск опечаток в адресах, перечисленных в sitemap.xml.echo "Hello, world!" | yaspeller
Опции
-f, --format <value>
Форматы: plain
, html
, markdown
или auto
.
По умолчанию: plain
.
-l, --lang <value>
Языки: en
, ru
or uk
.
По умолчанию: en,ru
.
-c, --config <path>
Конфигурационный файл.
-e, --file-extensions <value>
Поиск файлов в папке по расширениям.
Пример: .md,.htm,.txt
.
--dictionary <file>
JSON-файл собственного словаря.
[
"someword1", // someword1 = someword1 and Someword1
"Someword2", // Someword2 = Someword2
"someword3"
]
Поддерживаются регулярные выражения:
[
"unknownword",
"unknown(W|w)ord[12]?", // unknown(W|w)ord[12]? = unknown(W|w)ord[12]? and Unknown(W|w)ord[12]?
"Unknown(W|w)ord[34]?" // Unknown(W|w)ord[34]? = Unknown(W|w)ord[34]?
]
Примеры использования:
yaspeller --dictionary my_dict.json .
yaspeller --dictionary my_dict.json:my_dict2.json .
--report <type>
Задать вид отчёта: console
, html
, markdown
или json
.
По умолчанию: console
Пример: console,html,custom_report.js
--check-yo
Проверять корректность использования буквы «ё» в русских текстах.
--by-words
Не использовать словарное окружение (контекст) при проверке.
Опция полезна в случаях, когда на вход сервиса передаётся список отдельных слов.
--find-repeat-words
Находить повторы слов, идущие подряд. Например, я полетел на на Кипр
.
--flag-latin
Отмечать слова, написанные латиницей, как ошибочные.
--ignore-tags <tags>
Игнорировать HTML-теги.
По умолчанию: code,kbd,object,samp,script,style,var
Опция для форматов html
и markdown
.
--ignore-text <regexp>
Удалить текст из проверки с помощью регулярных выражений.
--ignore-capitalization
Игнорировать неверное употребление ПРОПИСНЫХ/строчных букв, например, в слове москва
.
--ignore-digits
Пропускать слова с цифрами, например, авп17х4534
.
--ignore-latin
Пропускать слова, написанные латиницей, например, madrid
.
--ignore-roman-numerals
Игнорировать римские цифры I, II, III, ...
.
--ignore-uppercase
Пропускать слова, написанные заглавными буквами, например, ВПК
.
--ignore-urls
Пропускать интернет-адреса, почтовые адреса и имена файлов.
--max-requests <value>
Одновременное количество запросов к API Yandex.Speller.
По умолчанию: 2
.
--no-colors
Консольный вывод без цвета.
--only-errors
Выводить только ошибки.
--stdin
Обработка файлов через <STDIN>
. По умолчанию: false
--stdin-filename <file>
Имя файла, отправленного на <STDIN>
, используется в отчётах.
--debug
Режим отладки.
Установка в проект
npm install yaspeller --save-dev
Необходимо добавить в package.json
/ scripts
:
"yaspeller": "yaspeller .",
Для запуска в качестве линтера:
npm run yaspeller
yaspeller
настраивается, используя JSON-файл, расположенный в корне проекта:
.yaspellerrc
.yaspellerrc.js
.yaspellerrc.json
.yaspeller.json
package.json
, полеyaspeller
{
"excludeFiles": [
".git",
"yaspeller",
"node_modules",
"libs"
],
"lang": "ru",
"fileExtensions": [
".md",
".txt"
],
"dictionary": [
"someword1"
]
}
Расширенный пример:
{
"excludeFiles": [
".git",
"yaspeller",
"node_modules",
"libs"
],
"format": "html",
"lang": "en",
"fileExtensions": [
".md",
".txt"
],
"report": ["console", "html"],
"dictionary": [
// JSON comments
"someword1", // someword1 = someword1 and Someword1
"Someword2", // Someword2 = Someword2
"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
],
"ignoreTags": ["code", "script"],
"ignoreText": [
"<php\?[^]*?\?>", // Короткая запись
["<php\?[^]*?\?>", "g"] // Длинная запись
],
"ignoreUrls": true,
"findRepeatWords": true,
"maxRequests": 5
}
Свойство | Тип | Подробности |
---|---|---|
format |
String |
--format |
lang |
String |
--lang |
excludeFiles |
Array |
|
fileExtensions |
Array |
--file-extension |
dictionary |
Array |
--dictionary |
report |
Array |
--report |
checkYo |
Boolean |
--check-yo |
byWords |
Boolean |
--by-words |
findRepeatWords |
Boolean |
--find-repeat-words |
flagLatin |
Boolean |
--flag-latin |
ignoreTags |
Array |
--ignore-tags |
ignoreText |
Array |
--ignore-text |
ignoreCapitalization |
Boolean |
--ignore-capitalization |
ignoreDigits |
Boolean |
--ignore-digits |
ignoreLatin |
Boolean |
--ignore-latin |
ignoreRomanNumerals |
Boolean |
--ignore-roman-numerals |
ignoreUppercase |
Boolean |
--ignore-uppercase |
ignoreUrls |
Boolean |
--ignore-urls |
maxRequests |
Number |
--max-requests |
Исключение части текста из проверки
Исключить строку
var re = /А-ЯЁ/; // yaspeller ignore
var re = /А-ЯЁ/; /* yaspeller ignore */
<span>А-ЯЁ</span> <!-- yaspeller ignore -->
Исключить блок
/* yaspeller ignore:start */
var reUpper = /А-ЯЁ/,
reLower = /а-яё/;
/* yaspeller ignore:end */
<!-- yaspeller ignore:start -->
<span>А-ЯЁ</span>
<div>а-яё</div>
<!-- yaspeller ignore:end -->
Gulp
Плагин дляvar gulp = require('gulp'),
run = require('gulp-run'); // npm install gulp-run --save-dev
gulp.task('yaspeller', function (cb) {
run('./node_modules/.bin/yaspeller ./').exec()
.on('error', function (err) {
console.error(err.message);
cb();
})
.on('finish', cb);
});
Grunt
Плагин дляmodule.exports = function(grunt) {
grunt.loadNpmTasks('grunt-shell'); // npm install grunt-shell --save-dev
grunt.initConfig({
shell: {
yaspeller: {
options: {stderr: false},
command: './node_modules/.bin/yaspeller .'
}
}
});
grunt.registerTask('lint', ['shell:yaspeller']);
};
Ограничения API Яндекс.Спеллера
Ссылки
Лицензия
MIT License