Skip to content
Open
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
23 changes: 15 additions & 8 deletions es5/spell-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var _async = require('async');

var _async2 = _interopRequireDefault(_async);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var globalDictionary = [];
Expand Down Expand Up @@ -134,16 +138,18 @@ function addToGlobalDictionary(word, relative) {
spelling.isDirty = true;
spelling.lastLineOfGlobalSpellings++;
for (var filename in fileDictionary) {
if (fileDictionary.hasOwnProperty(filename)) {
fileDictionary[filename].index++;
var normalizedPath = _path2.default.normalize(filename);
if (fileDictionary.hasOwnProperty(normalizedPath)) {
fileDictionary[normalizedPath].index++;
}
}
}

function addToFileDictionary(filename, word, relative) {
var normalizedPath = _path2.default.normalize(filename);
var spelling = relative ? relativeSpelling : sharedSpelling;
if (fileDictionary.hasOwnProperty(filename)) {
var fileDict = fileDictionary[filename];
if (fileDictionary.hasOwnProperty(normalizedPath)) {
var fileDict = fileDictionary[normalizedPath];
spelling.fileLines.splice(fileDict.index, 0, word);
spelling.isDirty = true;
for (var dictionaryFilename in fileDictionary) {
Expand All @@ -153,9 +159,9 @@ function addToFileDictionary(filename, word, relative) {
}
fileDict.words.push(word);
} else {
spelling.fileLines.splice(spelling.fileLines.length - 1, 0, " - " + filename, word);
spelling.fileLines.splice(spelling.fileLines.length - 1, 0, " - " + normalizedPath, word);
spelling.isDirty = true;
fileDictionary[filename] = {
fileDictionary[normalizedPath] = {
index: spelling.fileLines.length - 1,
words: [word]
};
Expand All @@ -167,8 +173,9 @@ function getGlobalWords() {
}

function getFileWords(filename) {
if (fileDictionary.hasOwnProperty(filename)) {
return fileDictionary[filename].words;
var normalizedPath = _path2.default.normalize(filename);
if (fileDictionary.hasOwnProperty(normalizedPath)) {
return fileDictionary[normalizedPath].words;
}
return [];
}
Expand Down
20 changes: 12 additions & 8 deletions es6/spell-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import async from 'async';
import path from 'path';

let globalDictionary = [];
let fileDictionary = {};
Expand Down Expand Up @@ -133,16 +134,18 @@ function addToGlobalDictionary(word, relative) {
spelling.isDirty = true;
spelling.lastLineOfGlobalSpellings++;
for (let filename in fileDictionary) {
if (fileDictionary.hasOwnProperty(filename)) {
fileDictionary[filename].index++;
const normalizedPath = path.normalize(filename)
if (fileDictionary.hasOwnProperty(normalizedPath)) {
fileDictionary[normalizedPath].index++;
}
}
}

function addToFileDictionary(filename, word, relative) {
const normalizedPath = path.normalize(filename)
const spelling = relative ? relativeSpelling : sharedSpelling;
if (fileDictionary.hasOwnProperty(filename)) {
let fileDict = fileDictionary[filename];
if (fileDictionary.hasOwnProperty(normalizedPath)) {
let fileDict = fileDictionary[normalizedPath];
spelling.fileLines.splice(fileDict.index, 0, word);
spelling.isDirty = true;
for (let dictionaryFilename in fileDictionary) {
Expand All @@ -154,9 +157,9 @@ function addToFileDictionary(filename, word, relative) {
fileDict.words.push(word);
}
else {
spelling.fileLines.splice(spelling.fileLines.length - 1, 0, " - " + filename, word);
spelling.fileLines.splice(spelling.fileLines.length - 1, 0, " - " + normalizedPath, word);
spelling.isDirty = true;
fileDictionary[filename] = {
fileDictionary[normalizedPath] = {
index: spelling.fileLines.length - 1,
words: [word]
};
Expand All @@ -168,8 +171,9 @@ function getGlobalWords() {
}

function getFileWords(filename) {
if (fileDictionary.hasOwnProperty(filename)) {
return fileDictionary[filename].words;
const normalizedPath = path.normalize(filename)
if (fileDictionary.hasOwnProperty(normalizedPath)) {
return fileDictionary[normalizedPath].words;
}
return [];
}
Expand Down
13 changes: 12 additions & 1 deletion test/spell-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ describe("Spell-Config", () => {
expect(initDone.calledOnce).to.equal(true);
});

it("should match path regardless of dot slash", () => {
const FILE1 = "relative/blog.md";
const FILE2 = "./" + FILE1;
const initDone = sinon.stub();
const spellConfig = getSpellConfig();
spellConfig.initialise("./.spelling", initDone);
spellConfig.addToFileDictionary(FILE1, "aaaaa", false);
expect(spellConfig.getFileWords(FILE2).length).to.equal(1);
expect(initDone.calledOnce).to.equal(true);
});

it("should add file words from relative or shared into array", () => {
const FILE = "/relative/blog.md";
const initDone = sinon.stub();
Expand Down Expand Up @@ -78,4 +89,4 @@ describe("Spell-Config", () => {
expect(writeDirtyFileDone.calledOnce).to.equal(true);
});

});
});