Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Fix TypeError #201

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v10.0.1
- Fix `TypeError: Cannot read properties of undefined (reading 'length')` #199

## v10.0.0
- Update major `yandex-speller` package.
- Remove unsupported options of new API Yandex Speller: `flagLatin`, `ignoreLatin`, `byWords`, `ignoreRomanNumerals` and `ignoreUppercase`.
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ To run the linter:<br/>
| `ignoreText` | `Array` | [`--ignore-text`](#--ignore-text-regexp) |
| `ignoreCapitalization` | `Boolean` | [`--ignore-capitalization`](#--ignore-capitalization) |
| `ignoreDigits` | `Boolean` | [`--ignore-digits`](#--ignore-digits) |
(#--ignore-roman-numerals) |
| `ignoreUppercase` | `Boolean` | [`--ignore-uppercase`](#--ignore-uppercase) |
| `ignoreUrls` | `Boolean` | [`--ignore-urls`](#--ignore-urls) |
| `maxRequests` | `Number` | [`--max-requests`](#--max-requests-value) |

Expand Down
25 changes: 25 additions & 0 deletions lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ function onResource(err, data, originalText) {
data.data = dictionary.removeDictionaryWordsFromData(data.data);
data.data = yaspeller.removeDuplicates(data.data);

/* TODO: Incorrect API response
1. Japanese and Chinese characters are not supported.
2. In response with code ERROR_TOO_MANY_ERRORS, the whole text is returned instead of the word.

{
"err": false,
"data": [
{
"code": 4,
"pos": 0,
"row": 0,
"col": 0,
"len": 10,
"word": " こんにちは、世界!",
"s": [
" こんにちは、世界!"
]
}
]
}

Temporarily ignoring this type of error.
*/
data.data = yaspeller.filterIncorrectTypos(data.data);

yaspeller.addPositions(originalText, data.data);
yaspeller.sortByPositions(data.data);

Expand Down
8 changes: 8 additions & 0 deletions lib/yaspeller.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,15 @@ function getErrors() {
});
}

function filterIncorrectTypos(data) {
return data.filter(item => {
const isIncorrectTypo = Boolean(item.code === yaspellerApi.ERROR_TOO_MANY_ERRORS && item.word);
return !isIncorrectTypo;
});
}

module.exports = {
filterIncorrectTypos,
addPositions,
errors: getErrors(),
checkFile,
Expand Down
Loading
Loading