1 | yaspeller
|
2 | =========
|
3 | [![NPM version](https://img.shields.io/npm/v/yaspeller.svg)](https://www.npmjs.com/package/yaspeller)
|
4 | [![NPM Downloads](https://img.shields.io/npm/dm/yaspeller.svg?style=flat)](https://www.npmjs.org/package/yaspeller)
|
5 | [![Coverage Status](https://img.shields.io/coveralls/hcodes/yaspeller.svg)](https://coveralls.io/r/hcodes/yaspeller)
|
6 | [![Dependency Status](https://img.shields.io/david/hcodes/yaspeller.svg)](https://david-dm.org/hcodes/yaspeller)
|
7 |
|
8 | <img align="right" width="200" src="https://raw.githubusercontent.com/hcodes/yaspeller/master/images/logo.png" />
|
9 |
|
10 | Средство поиска опечаток в тексте, в файлах и на сайтах.
|
11 |
|
12 | Используется API [Yandex.Speller](https://tech.yandex.ru/speller/doc/dg/concepts/About-docpage/).
|
13 |
|
14 | ![yaspeller](https://raw.githubusercontent.com/hcodes/yaspeller/master/images/cli.ru.png)
|
15 |
|
16 | ## Установка
|
17 | `npm install yaspeller -g`
|
18 |
|
19 | ## Командная строка
|
20 | `yaspeller [options] <file-or-directory-or-link...>`
|
21 |
|
22 | ## Используйте с [pre-commit](https://pre-commit.com/)
|
23 |
|
24 | Добавте в ваш `.pre-commit-config.yaml`:
|
25 |
|
26 | ```yaml
|
27 | - repo: https://github.com/hcodes/yaspeller.git
|
28 | rev: '' # Use the sha / tag you want to point at
|
29 | hooks:
|
30 | - id: yaspeller
|
31 | ```
|
32 |
|
33 | ### Примеры
|
34 | + `yaspeller README.md` — поиск опечаток в файле.
|
35 | + `yaspeller -e ".md,.html" ./texts/` — поиск опечаток в файлах в папке.
|
36 | + `yaspeller https://ru.wikipedia.org/wiki/%D0%9E%D0%BF%D0%B5%D1%87%D0%B0%D1%82%D0%BA%D0%B0` — поиск опечаток на странице сайта.
|
37 | + `yaspeller http://bem.info/sitemap.xml` — поиск опечаток в адресах, перечисленных в sitemap.xml.
|
38 | + `echo "Hello, world!" | yaspeller`
|
39 |
|
40 | ### Опции
|
41 |
|
42 | #### `-f, --format <value>`
|
43 | Форматы: `plain`, `html`, `markdown` или `auto`.<br/>
|
44 | По умолчанию: `plain`.
|
45 |
|
46 | #### `-l, --lang <value>`
|
47 | Языки: `en`, `ru` or `uk`.<br/>
|
48 | По умолчанию: `en,ru`.
|
49 |
|
50 | #### `-c, --config <path>`
|
51 | Конфигурационный файл.
|
52 |
|
53 | #### `-e, --file-extensions <value>`
|
54 | Поиск файлов в папке по расширениям.<br/>
|
55 | Пример: `.md,.htm,.txt`.
|
56 |
|
57 | #### `--dictionary <file>`
|
58 | JSON-файл собственного словаря.
|
59 | ```js
|
60 | [
|
61 | "someword1", // someword1 = someword1 and Someword1
|
62 | "Someword2", // Someword2 = Someword2
|
63 | "someword3"
|
64 | ]
|
65 | ```
|
66 | Поддерживаются регулярные выражения:
|
67 | ```js
|
68 | [
|
69 | "unknownword",
|
70 | "unknown(W|w)ord[12]?", // unknown(W|w)ord[12]? = unknown(W|w)ord[12]? and Unknown(W|w)ord[12]?
|
71 | "Unknown(W|w)ord[34]?" // Unknown(W|w)ord[34]? = Unknown(W|w)ord[34]?
|
72 | ]
|
73 | ```
|
74 | Примеры использования:<br/>
|
75 | `yaspeller --dictionary my_dict.json .`<br/>
|
76 | `yaspeller --dictionary my_dict.json:my_dict2.json .`
|
77 |
|
78 | #### `--report <type>`
|
79 | Задать вид отчёта: `console`, `html`, `markdown`, `junit` или `json`.<br/>
|
80 | По умолчанию: `console`<br/>
|
81 | Пример: `console,html,custom_report.js`
|
82 |
|
83 | #### `--check-yo`
|
84 | Проверять корректность использования буквы «ё» в русских текстах.
|
85 |
|
86 | #### `--by-words`
|
87 | Не использовать словарное окружение (контекст) при проверке.<br/>
|
88 | Опция полезна в случаях, когда на вход сервиса передаётся список отдельных слов.
|
89 |
|
90 | #### `--find-repeat-words`
|
91 | Находить повторы слов, идущие подряд. Например, `я полетел на на Кипр`.
|
92 |
|
93 | #### `--flag-latin`
|
94 | Отмечать слова, написанные латиницей, как ошибочные.
|
95 |
|
96 | #### `--ignore-tags <tags>`
|
97 | Игнорировать HTML-теги.<br/>
|
98 | По умолчанию: `code,kbd,object,samp,script,style,var`<br/>
|
99 | Опция для форматов `html` и `markdown`.
|
100 |
|
101 | #### `--ignore-text <regexp>`
|
102 | Удалить текст из проверки с помощью регулярных выражений.
|
103 |
|
104 | #### `--ignore-capitalization`
|
105 | Игнорировать неверное употребление ПРОПИСНЫХ/строчных букв, например, в слове `москва`.
|
106 |
|
107 | #### `--ignore-digits`
|
108 | Пропускать слова с цифрами, например, `авп17х4534`.
|
109 |
|
110 | #### `--ignore-latin`
|
111 | Пропускать слова, написанные латиницей, например, `madrid`.
|
112 |
|
113 | #### `--ignore-roman-numerals`
|
114 | Игнорировать римские цифры `I, II, III, ...`.
|
115 |
|
116 | #### `--ignore-uppercase`
|
117 | Пропускать слова, написанные заглавными буквами, например, `ВПК`.
|
118 |
|
119 | #### `--ignore-urls`
|
120 | Пропускать интернет-адреса, почтовые адреса и имена файлов.
|
121 |
|
122 | #### `--max-requests <value>`
|
123 | Одновременное количество запросов к API Yandex.Speller.<br/>
|
124 | По умолчанию: `2`.
|
125 |
|
126 | #### `--no-colors`
|
127 | Консольный вывод без цвета.
|
128 |
|
129 | #### `--only-errors`
|
130 | Выводить только ошибки.
|
131 |
|
132 | #### `--stdin`
|
133 | Обработка файлов через `<STDIN>`. По умолчанию: false
|
134 |
|
135 | #### `--stdin-filename <file>`
|
136 | Имя файла, отправленного на `<STDIN>`, используется в отчётах.
|
137 |
|
138 | #### `--debug`
|
139 | Режим отладки.
|
140 |
|
141 | ## Установка в проект
|
142 | `npm install yaspeller --save-dev`
|
143 |
|
144 | Необходимо добавить в `package.json` / `scripts`:<br/>
|
145 | ` "yaspeller": "yaspeller .",`
|
146 |
|
147 | Для запуска в качестве линтера:<br/>
|
148 | `npm run yaspeller`
|
149 |
|
150 | `yaspeller` настраивается, используя JSON-файл, расположенный в корне проекта:
|
151 |
|
152 | - `.yaspellerrc`
|
153 | - `.yaspellerrc.js`
|
154 | - `.yaspellerrc.json`
|
155 | - `.yaspeller.json`
|
156 | - `package.json`, поле `yaspeller`
|
157 |
|
158 | ```JSON
|
159 | {
|
160 | "excludeFiles": [
|
161 | ".git",
|
162 | "yaspeller",
|
163 | "node_modules",
|
164 | "libs"
|
165 | ],
|
166 | "lang": "ru",
|
167 | "fileExtensions": [
|
168 | ".md",
|
169 | ".txt"
|
170 | ],
|
171 | "dictionary": [
|
172 | "someword1"
|
173 | ]
|
174 | }
|
175 | ```
|
176 |
|
177 | **Расширенный пример:**
|
178 | ```js
|
179 | {
|
180 | "excludeFiles": [
|
181 | ".git",
|
182 | "yaspeller",
|
183 | "node_modules",
|
184 | "libs"
|
185 | ],
|
186 | "format": "html",
|
187 | "lang": "en",
|
188 | "fileExtensions": [
|
189 | ".md",
|
190 | ".txt"
|
191 | ],
|
192 | "report": ["console", "html"],
|
193 | "dictionary": [
|
194 | // JSON comments
|
195 | "someword1", // someword1 = someword1 and Someword1
|
196 | "Someword2", // Someword2 = Someword2
|
197 | "some(w|W)ord[23]", // some(w|W)ord[23] = some(w|W)ord[23] and Some(w|W)ord[23]
|
198 | "Some(w|W)ord" // Some(w|W)ord = Some(w|W)ord
|
199 | ],
|
200 | "ignoreTags": ["code", "script"],
|
201 | "ignoreText": [
|
202 | "<php\?[^]*?\?>", // Короткая запись
|
203 | ["<php\?[^]*?\?>", "g"] // Длинная запись
|
204 | ],
|
205 | "ignoreUrls": true,
|
206 | "findRepeatWords": true,
|
207 | "maxRequests": 5
|
208 | }
|
209 | ```
|
210 |
|
211 | | Свойство | Тип | Подробности |
|
212 | |----------|------|---------|
|
213 | | `format` | `String` | [`--format`](#-f---format-value) |
|
214 | | `lang` | `String` | [`--lang`](#-l---lang-value) |
|
215 | | `excludeFiles` | `Array` | |
|
216 | | `fileExtensions` | `Array` | [`--file-extension`](#--file-extensions-value) |
|
217 | | `dictionary` | `Array` | [`--dictionary`](#--dictionary-file) |
|
218 | | `report` | `Array` | [`--report`](#--report-type) |
|
219 | | `checkYo` | `Boolean` | [`--check-yo`](#--check-yo) |
|
220 | | `byWords` | `Boolean` | [`--by-words`](#--by-words) |
|
221 | | `findRepeatWords` | `Boolean` | [`--find-repeat-words`](#--find-repeat-words) |
|
222 | | `flagLatin` | `Boolean` | [`--flag-latin`](#--flag-latin) |
|
223 | | `ignoreTags` | `Array` | [`--ignore-tags`](#--ignore-tags-tags) |
|
224 | | `ignoreText` | `Array` | [`--ignore-text`](#--ignore-text-regexp) |
|
225 | | `ignoreCapitalization` | `Boolean` | [`--ignore-capitalization`](#--ignore-capitalization) |
|
226 | | `ignoreDigits` | `Boolean` | [`--ignore-digits`](#--ignore-digits) |
|
227 | | `ignoreLatin` | `Boolean` | [`--ignore-latin`](#--ignore-latin) |
|
228 | | `ignoreRomanNumerals` | `Boolean` | [`--ignore-roman-numerals`](#--ignore-roman-numerals) |
|
229 | | `ignoreUppercase` | `Boolean` | [`--ignore-uppercase`](#--ignore-uppercase) |
|
230 | | `ignoreUrls` | `Boolean` | [`--ignore-urls`](#--ignore-urls) |
|
231 | | `maxRequests` | `Number` | [`--max-requests`](#--max-requests-value) |
|
232 |
|
233 | ## Исключение части текста из проверки
|
234 | ### Исключить строку
|
235 | ```js
|
236 | var re = /А-ЯЁ/; // yaspeller ignore
|
237 | ```
|
238 | ```js
|
239 | var re = /А-ЯЁ/; /* yaspeller ignore */
|
240 | ```
|
241 | ```html
|
242 | <span>А-ЯЁ</span> <!-- yaspeller ignore -->
|
243 | ```
|
244 |
|
245 | ### Исключить блок
|
246 | ```js
|
247 | /* yaspeller ignore:start */
|
248 | var reUpper = /А-ЯЁ/,
|
249 | reLower = /а-яё/;
|
250 | /* yaspeller ignore:end */
|
251 | ```
|
252 |
|
253 | ```html
|
254 | <!-- yaspeller ignore:start -->
|
255 | <span>А-ЯЁ</span>
|
256 | <div>а-яё</div>
|
257 | <!-- yaspeller ignore:end -->
|
258 | ```
|
259 |
|
260 | ## Плагин для [Gulp](http://gulpjs.com)
|
261 | ```js
|
262 | var gulp = require('gulp'),
|
263 | run = require('gulp-run'); // npm install gulp-run --save-dev
|
264 |
|
265 | gulp.task('yaspeller', function (cb) {
|
266 | run('./node_modules/.bin/yaspeller ./').exec()
|
267 | .on('error', function (err) {
|
268 | console.error(err.message);
|
269 | cb();
|
270 | })
|
271 | .on('finish', cb);
|
272 | });
|
273 | ```
|
274 |
|
275 | ## Плагин для [Grunt](http://gruntjs.com)
|
276 | ```js
|
277 | module.exports = function(grunt) {
|
278 | grunt.loadNpmTasks('grunt-shell'); // npm install grunt-shell --save-dev
|
279 | grunt.initConfig({
|
280 | shell: {
|
281 | yaspeller: {
|
282 | options: {stderr: false},
|
283 | command: './node_modules/.bin/yaspeller .'
|
284 | }
|
285 | }
|
286 | });
|
287 | grunt.registerTask('lint', ['shell:yaspeller']);
|
288 | };
|
289 | ```
|
290 |
|
291 | ## [Ограничения API Яндекс.Спеллера](http://legal.yandex.ru/speller_api/)
|
292 |
|
293 | ## Ссылки
|
294 | - [Yaspeller для CI](https://github.com/ai/yaspeller-ci)
|
295 |
|
296 | ## [Лицензия](./LICENSE.md)
|
297 | MIT License
|