From 8fafe4f5903bea4eac325dff8f0b9d368322168c Mon Sep 17 00:00:00 2001 From: Denis Seleznev Date: Thu, 9 Aug 2018 09:27:55 +0300 Subject: [PATCH 1/4] Fixed checking substrings --- lib/dictionary.js | 10 +++++- test/test.dictionary.js | 70 +++++++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/lib/dictionary.js b/lib/dictionary.js index c37a3f1..cc5dc24 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -168,7 +168,15 @@ module.exports = { // unknownWord(s)? = unknownWord(s)? and UnknownWord(s)? // UnknownWord(s)? = UnknownWord(s)? - const preparedWord = word.replace(rePrepare, ($, $1, $2) => '[' + $1 + $1.toUpperCase() + ']' + $2); + let preparedWord = word.replace(rePrepare, ($, $1, $2) => '[' + $1 + $1.toUpperCase() + ']' + $2); + + if (preparedWord.search(/\^/) !== 0) { + preparedWord = '^' + preparedWord; + } + + if (preparedWord.search(/\$/) !== preparedWord.length - 1) { + preparedWord += '$'; + } try { result.push(new RegExp(preparedWord)); diff --git a/test/test.dictionary.js b/test/test.dictionary.js index 7561eb5..b8ebcf0 100644 --- a/test/test.dictionary.js +++ b/test/test.dictionary.js @@ -53,17 +53,53 @@ describe('Dictionary', function() { }); it('isTypo()', function() { - const dict = dictionary.prepareDictionary([ - 'контрол' - ]); - - assert.isFalse(dictionary.isTypo('Контрол', dict)); - - const dict2 = dictionary.prepareDictionary([ - 'Контрол' - ]); - - assert.isTrue(dictionary.isTypo('контрол', dict2)); + [ + { + dict: [ + 'контрол' + ], + word: 'Контрол', + result: false + }, + { + dict: [ + 'Контрол' + ], + word: 'контрол', + result: true + }, + { + dict: [ + 'митап' + ], + word: 'митап', + result: false + }, + { + dict: [ + 'митап' + ], + word: 'тестмитап', + result: true + }, + { + dict: [ + 'митап' + ], + word: 'немитап', + result: true + }, + { + dict: [ + 'митап' + ], + word: 'багмитапбаг', + result: true + } + ].forEach(item => { + const dict = dictionary.prepareDictionary(item.dict); + assert.equal(item.result, dictionary.isTypo(item.word, dict), item.word); + }); }); it('removeDuplicates()', function() { @@ -101,17 +137,17 @@ describe('Dictionary', function() { it('set(), dictionary from config', function() { dictionary.set([], ['a']); - assert.deepEqual(dictionary._dict, [/[aA]/]); + assert.deepEqual(dictionary._dict, [/^[aA]$/]); }); it('set()', function() { dictionary.set(['test/dict/a.json', 'test/dict/b.json'], ['a']); assert.deepEqual(dictionary._dict, [ - /[aA]/, - /[xX]yz/, - /[aA]bc/, - /CLI/, - /[dD]eps/ + /^[aA]$/, + /^[xX]yz$/, + /^[aA]bc$/, + /^CLI$/, + /^[dD]eps$/ ]); }); From d6f8a02a80cccad0ba8be55c5abdd761f6be6ded Mon Sep 17 00:00:00 2001 From: Denis Seleznev Date: Thu, 9 Aug 2018 09:28:15 +0300 Subject: [PATCH 2/4] Fixed comments in JSON --- lib/config.js | 15 +++++++++++++++ test/test.config.js | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/lib/config.js b/lib/config.js index 47ced86..9fdbdc3 100644 --- a/lib/config.js +++ b/lib/config.js @@ -6,6 +6,17 @@ const debug = require('./debug'); const printDebug = debug.print; const exitCodes = require('./exit-codes'); const knownProps = require('./config-properties'); +const stripJsonComments = require('strip-json-comments'); +const parseJson = require('parse-json'); + +function loadJson(filepath, content) { + try { + return parseJson(stripJsonComments(content)); + } catch (err) { + err.message = `JSON Error in ${filepath}:\n${err.message}`; + throw err; + } +} module.exports = { /** @@ -16,6 +27,10 @@ module.exports = { */ get(file) { const explorer = cosmiconfig('yaspeller', { + loaders: { + '.json': loadJson, + noExt: loadJson + }, searchPlaces: [ 'package.json', '.yaspellerrc', diff --git a/test/test.config.js b/test/test.config.js index f9413d8..84b84a7 100644 --- a/test/test.config.js +++ b/test/test.config.js @@ -19,6 +19,10 @@ describe('Config', function() { it('get, custom config', function() { assert.deepEqual(config.get('./test/json/no_comment.json'), ['1']); }); + + it('get, custom config with comments', function() { + assert.deepEqual(config.get('./test/json/comment.json'), ['1']); + }); it('get, default config', function() { assert.ok(Object.keys(config.get(null)).length); From 15c883d1e9dc2c02c190ef164d54acfdd55c0c7f Mon Sep 17 00:00:00 2001 From: Denis Seleznev Date: Thu, 9 Aug 2018 09:28:44 +0300 Subject: [PATCH 3/4] :arrow_up: --- package-lock.json | 38 +++++++++++++++++++------------------- package.json | 9 +++++---- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a20129..171338a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -378,9 +378,9 @@ } }, "commander": { - "version": "2.16.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.16.0.tgz", - "integrity": "sha512-sVXqklSaotK9at437sFlFpyOcJonxe0yST/AG9DkQKUdIE6IqGIMv4SfAQSKaJbSdVEJYItASCrBiVQHq1HQew==" + "version": "2.17.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", + "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==" }, "concat-map": { "version": "0.0.1", @@ -578,9 +578,9 @@ } }, "eslint": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.1.0.tgz", - "integrity": "sha512-DyH6JsoA1KzA5+OSWFjg56DFJT+sDLO0yokaPZ9qY0UEmYrPA1gEX/G1MnVkmRDsksG4H1foIVz2ZXXM3hHYvw==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.3.0.tgz", + "integrity": "sha512-N/tCqlMKkyNvAvLu+zI9AqDasnSLt00K+Hu8kdsERliC9jYEc8ck12XtjvOXrBKu8fK6RrBcN9bat6Xk++9jAg==", "dev": true, "requires": { "ajv": "^6.5.0", @@ -599,7 +599,7 @@ "functional-red-black-tree": "^1.0.1", "glob": "^7.1.2", "globals": "^11.7.0", - "ignore": "^3.3.3", + "ignore": "^4.0.2", "imurmurhash": "^0.1.4", "inquirer": "^5.2.0", "is-resolvable": "^1.1.0", @@ -614,7 +614,7 @@ "path-is-inside": "^1.0.2", "pluralize": "^7.0.0", "progress": "^2.0.0", - "regexpp": "^1.1.0", + "regexpp": "^2.0.0", "require-uncached": "^1.0.3", "semver": "^5.5.0", "string.prototype.matchall": "^2.0.0", @@ -1038,9 +1038,9 @@ } }, "ignore": { - "version": "3.3.10", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", - "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.3.tgz", + "integrity": "sha512-Z/vAH2GGIEATQnBVXMclE2IGV6i0GyVngKThcGZ5kHgHMxLo9Ow2+XHRq1aEKEej5vOF1TPJNbvX6J/anT0M7A==", "dev": true }, "imurmurhash": { @@ -1764,9 +1764,9 @@ } }, "regexpp": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", - "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.0.tgz", + "integrity": "sha512-g2FAVtR8Uh8GO1Nv5wpxW7VFVwHcCEr4wyA8/MHiRkO8uHoR5ntAA8Uq3P1vvMTX/BeQiRVSpDGLd+Wn5HNOTA==", "dev": true }, "repeat-string": { @@ -1940,17 +1940,17 @@ "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, "sinon": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-6.1.3.tgz", - "integrity": "sha512-yeTza8xIZZdiXntCHJAzKll/sSYE+DuJOS8hiSapzaLqdW8eCNVVC9je9SZYYTkPm2bLts9x6UYxwuMAVVrM6Q==", + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-6.1.4.tgz", + "integrity": "sha512-NFEts+4D4jp2sBjL94fQpZk5o73kzn/g58+I9Dp15i9vsnT4Lk1UEyUf2jACODWLG6Pz/llF0sArYUw47Aarmg==", "dev": true, "requires": { "@sinonjs/formatio": "^2.0.0", "@sinonjs/samsam": "^2.0.0", "diff": "^3.5.0", "lodash.get": "^4.4.2", - "lolex": "^2.4.2", - "nise": "^1.3.3", + "lolex": "^2.7.1", + "nise": "^1.4.2", "supports-color": "^5.4.0", "type-detect": "^4.0.8" } diff --git a/package.json b/package.json index 2736c96..dd2a629 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "yaspeller": "./bin/yaspeller" }, "description": "Search tool typos in the text, files and websites", - "version": "4.2.1", + "version": "5.0.0", "license": "MIT", "homepage": "https://github.com/hcodes/yaspeller", "repository": { @@ -34,7 +34,7 @@ "dependencies": { "async": "^2.6.1", "chalk": "^2.4.1", - "commander": "^2.15.1", + "commander": "^2.17.1", "cosmiconfig": "^5.0.5", "entities": "^1.1.1", "escape-html": "^1.0.3", @@ -50,10 +50,11 @@ }, "devDependencies": { "chai": "^4.1.0", - "eslint": "^5.0.0", + "eslint": "^5.3.0", "istanbul": "^0.4.5", "mocha": "^5.2.0", - "sinon": "^6.0.1" + "parse-json": "^4.0.0", + "sinon": "^6.1.4" }, "engines": { "node": ">=4" From ba11c3dc80d2f50a08471a613dc4671beafeb097 Mon Sep 17 00:00:00 2001 From: Denis Seleznev Date: Thu, 9 Aug 2018 09:36:58 +0300 Subject: [PATCH 4/4] Update CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb910a4..8172857 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v5.0.0 +- FIX: **Breaking changes**: Incorrect work of dictionary words in substrings #106. +- FIX: Comments in JSON #108. + ## v4.2.1 FIX: TypeError: Cannot destructure property config of 'undefined' or 'null' #103.