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