UNPKG

8.45 kBMarkdownView Raw
1yaspeller
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
11This README is also available [in Russian](./README.ru.md).
12
13Search tool typos in the text, files and websites.
14
15Used API [Yandex.Speller](https://tech.yandex.ru/speller/doc/dg/concepts/About-docpage/).
16
17![yaspeller](https://raw.githubusercontent.com/hcodes/yaspeller/master/images/cli.en.png)
18
19## Installation
20`npm install yaspeller -g`
21
22## Using CLI
23`yaspeller [options] <file-or-directory-or-link...>`
24
25## Using with [pre-commit](https://pre-commit.com/)
26
27Add this to your `.pre-commit-config.yaml`:
28
29```yaml
30- repo: https://github.com/hcodes/yaspeller.git
31 rev: '' # Use the sha / tag you want to point at
32 hooks:
33 - id: yaspeller
34```
35
36
37### Examples
38+ `yaspeller README.md` — search typos in the file.
39+ `yaspeller "*.md"` — node glob syntax for Windows.
40+ `yaspeller -e ".md,.html,.txt" ./texts/` — finding typos in files in the folder.
41+ `yaspeller https://ru.wikipedia.org/wiki/%D0%9E%D0%BF%D0%B5%D1%87%D0%B0%D1%82%D0%BA%D0%B0` — search typos in the page.
42+ `yaspeller http://bem.info/sitemap.xml` — search typos at the addresses specified in the sitemap.xml.
43+ `echo "Hello, world!" | yaspeller --stdin`
44+ `echo "Hello, world!" | yaspeller --stdin --stdin-filename hello.txt`
45
46### Options
47
48#### `-f, --format <value>`
49Formats: `plain`, `html`, `markdown` or `auto`.<br/>
50Default: `auto`.
51
52#### `-l, --lang <value>`
53Languages: `en`, `ru` or `uk`.<br/>
54Default: `en,ru`.
55
56#### `-c, --config <path>`
57Configuration file path.
58
59#### `-e, --file-extensions <value>`
60Set file extensions to search for files in a folder.<br/>
61Example: `.md,.htm,.txt`.
62
63#### `--dictionary <file>`
64JSON file for own dictionary.
65```js
66[
67 "someword1", // someword1 = someword1 and Someword1
68 "Someword2", // Someword2 = Someword2
69 "someword3"
70]
71```
72
73Regular expressions are supported:
74```js
75[
76 "unknownword",
77 "unknown(W|w)ord[12]?", // unknown(W|w)ord[12]? = unknown(W|w)ord[12]? and Unknown(W|w)ord[12]?
78 "Unknown(W|w)ord[34]?" // Unknown(W|w)ord[34]? = Unknown(W|w)ord[34]?
79]
80```
81
82Examples:<br/>
83`yaspeller --dictionary my_dict.json .`<br/>
84`yaspeller --dictionary my_dict.json:my_dict2.json .`
85
86
87#### `--report <type>`
88Set type of report: `console`, `html`, `markdown`, `junit` or `json`.<br/>
89Default: `console`<br/>
90Example: `console,html,custom_report.js`
91
92#### `--check-yo`
93Check the correctness of using the letter “Ё” (Yo) in Russian texts.
94
95#### `--by-words`
96Do not use a dictionary environment (context) during the scan.<br/>
97This is useful in cases where the service is transmitted to the input of a list of individual words.
98
99#### `--find-repeat-words`
100Highlight repetitions of words, consecutive. For example, `I flew to to to Cyprus`.
101
102#### `--flag-latin`
103Flag words, written in Latin, as erroneous.
104
105#### `--ignore-tags <tags>`
106Ignore HTML tags.<br/>
107Default: `code,kbd,object,samp,script,style,var`<br/>
108Option to formats `html` and` markdown`.
109
110#### `--ignore-text <regexp>`
111Remove the text from the scan using regular expressions.
112
113#### `--ignore-capitalization`
114Ignore the incorrect use of UPPERCASE / lowercase letters, for example, in the word `moscow`.
115
116#### `--ignore-digits`
117Ignore words with numbers, such as `avp17h4534`.
118
119#### `--ignore-latin`
120Ignore words, written in Latin, for example, `madrid`.
121
122#### `--ignore-roman-numerals`
123Ignore Roman numerals `I, II, III, ...`.
124
125#### `--ignore-uppercase`
126Ignore words written in capital letters.
127
128#### `--ignore-urls`
129Ignore Internet addresses, email addresses and filenames.
130
131#### `--max-requests <value>`
132Max count of requests in parallel.<br/>
133Default: `2`.
134
135#### `--no-colors`
136Clean output without colors.
137
138#### `--only-errors`
139Output only errors.
140
141#### `--stdin`
142Process files on `<STDIN>`. Default: false
143
144#### `--stdin-filename <file>`
145Specify filename to process `<STDIN>` as. Used in reports.
146
147#### `--debug`
148Debug mode.
149
150## Configuration
151`npm install yaspeller --save-dev`
152
153Add the text in `package.json` / `scripts`:<br/>
154` "yaspeller": "yaspeller .",`
155
156To run the linter:<br/>
157`npm run yaspeller`
158
159`yaspeller` is configured using JSON file at the root of the project:
160
161- `.yaspellerrc`
162- `.yaspellerrc.js`
163- `.yaspellerrc.json`
164- `.yaspeller.json`
165- `package.json`, field `yaspeller`
166
167```JSON
168{
169 "excludeFiles": [
170 ".git",
171 "libs",
172 "node_modules",
173 "yaspeller"
174 ],
175 "lang": "ru",
176 "fileExtensions": [
177 ".md",
178 ".css"
179 ],
180 "dictionary": [
181 "someword1"
182 ]
183}
184```
185
186**Advanced example:**
187```js
188{
189 "excludeFiles": [
190 ".git",
191 "yaspeller",
192 "node_modules",
193 "libs"
194 ],
195 "format": "html",
196 "lang": "en",
197 "fileExtensions": [
198 ".md",
199 ".css"
200 ],
201 "report": ["console", "html"],
202 "dictionary": [
203 // JSON comments
204 "someword1", // someword1 = someword1 and Someword1
205 "Someword2", // Someword2 = Someword2
206 "some(w|W)ord[23]", // some(w|W)ord[23] = some(w|W)ord[23] and Some(w|W)ord[23]
207 "Some(w|W)ord" // Some(w|W)ord = Some(w|W)ord
208 ],
209 "ignoreText": [
210 "<php\?[^]*?\?>", // Shortly
211 ["<php\?[^]*?\?>", "g"] // Longly
212 ],
213 "ignoreTags": ["code", "script"],
214 "ignoreUrls": true,
215 "findRepeatWords": true,
216 "maxRequests": 5
217}
218```
219
220| Property | Type | Details |
221|----------|------|---------|
222| `format` | `String` | [`--format`](#-f---format-value) |
223| `lang` | `String` | [`--lang`](#-l---lang-value) |
224| `excludeFiles` | `Array` | |
225| `fileExtensions` | `Array` | [`--file-extension`](#--file-extensions-value) |
226| `dictionary` | `Array` | [`--dictionary`](#--dictionary-file) |
227| `report` | `Array` | [`--report`](#--report-type) |
228| `checkYo` | `Boolean` | [`--check-yo`](#--check-yo) |
229| `byWords` | `Boolean` | [`--by-words`](#--by-words) |
230| `findRepeatWords` | `Boolean` | [`--find-repeat-words`](#--find-repeat-words) |
231| `flagLatin` | `Boolean` | [`--flag-latin`](#--flag-latin) |
232| `ignoreTags` | `Array` | [`--ignore-tags`](#--ignore-tags-tags) |
233| `ignoreText` | `Array` | [`--ignore-text`](#--ignore-text-regexp) |
234| `ignoreCapitalization` | `Boolean` | [`--ignore-capitalization`](#--ignore-capitalization) |
235| `ignoreDigits` | `Boolean` | [`--ignore-digits`](#--ignore-digits) |
236| `ignoreLatin` | `Boolean` | [`--ignore-latin`](#--ignore-latin) |
237| `ignoreRomanNumerals` | `Boolean` | [`--ignore-roman-numerals`](#--ignore-roman-numerals) |
238| `ignoreUppercase` | `Boolean` | [`--ignore-uppercase`](#--ignore-uppercase) |
239| `ignoreUrls` | `Boolean` | [`--ignore-urls`](#--ignore-urls) |
240| `maxRequests` | `Number` | [`--max-requests`](#--max-requests-value) |
241
242## Ignore text from checking
243### Ignore a line
244```js
245var re = /a-z/; // yaspeller ignore
246```
247```js
248var re = /a-z/; /* yaspeller ignore */
249```
250```html
251<span>a-z</span> <!-- yaspeller ignore -->
252```
253
254### Ignore a block
255```js
256/* yaspeller ignore:start */
257var reUpper = /A-Z/,
258 reLower = /a-z/;
259/* yaspeller ignore:end */
260```
261
262```html
263<!-- yaspeller ignore:start -->
264<span>A-Z</span>
265<div>a-z</div>
266<!-- yaspeller ignore:end -->
267```
268
269## [Gulp](http://gulpjs.com) plugin
270```js
271var gulp = require('gulp'),
272 run = require('gulp-run'); // npm install gulp-run --save-dev
273
274gulp.task('yaspeller', function (cb) {
275 run('./node_modules/.bin/yaspeller .').exec()
276 .on('error', function (err) {
277 console.error(err.message);
278 cb();
279 })
280 .on('finish', cb);
281});
282```
283
284## [Grunt](http://gruntjs.com) plugin
285```js
286module.exports = function(grunt) {
287 grunt.loadNpmTasks('grunt-shell'); // npm install grunt-shell --save-dev
288 grunt.initConfig({
289 shell: {
290 yaspeller: {
291 options: {stderr: false},
292 command: './node_modules/.bin/yaspeller .'
293 }
294 }
295 });
296 grunt.registerTask('lint', ['shell:yaspeller']);
297};
298```
299
300## [Restrictions API Yandex.Speller](http://legal.yandex.ru/speller_api/)
301
302## Links
303- [Yaspeller for CI](https://github.com/ai/yaspeller-ci)
304
305## [License](./LICENSE.md)
306MIT License