Skip to content

Commit

Permalink
Fix EOL issues
Browse files Browse the repository at this point in the history
  • Loading branch information
piascikj committed Aug 13, 2019
1 parent 06155f3 commit c563e44
Show file tree
Hide file tree
Showing 6 changed files with 2,391 additions and 2,408 deletions.
32 changes: 13 additions & 19 deletions lib/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var _ = require("lodash"),
util = require('util'),
path = require('path'),
fm = require('front-matter'),
eol = require('eol'),
tools = require('./tools'),
marked = tools.marked,
log = require('debug')('imdone-core:File'),
Expand All @@ -16,7 +17,6 @@ var ERRORS = {
NOT_A_TASK: "task must be of type Task"
};

const EOL = /\r\n|\r|\n/
const escapeRegExp = tools.escapeRegExp

/**
Expand Down Expand Up @@ -310,7 +310,7 @@ File.prototype.getRawDescription = function(config, content) {

File.prototype.getCommentsAfterLine = function(config, comment) {
const commentLines = []
let lines = comment.split(EOL);
let lines = eol.split(comment);
const lang = this.getLang()
const singleLineComment = lines[0].indexOf(lang.symbol) > -1
for(let i=1; i < lines.length; i++) {
Expand All @@ -328,6 +328,7 @@ File.prototype.getCommentsAfterLine = function(config, comment) {
// DOING: This is adding spaces where they shouldn't be. gh:199 id:61
// - [ ] Compare each line of the description after trimming spaces to determine if it should be replaced
// - [ ] for additional lines use space and leading characters of previous lines
//
File.prototype.modifyDescription = function(task, config) {
log(`modifying description: ${task.rawTask}`)
log(`line: ${task.line}`)
Expand Down Expand Up @@ -465,7 +466,7 @@ File.prototype.isInCodeBlock = function(content) {
}

File.prototype.isSingleLineBlockComment = function (content) {
return content.split(EOL).length === 1
return eol.split(content).length === 1
}

File.prototype.extractCodeStyleTasks = function(config, pos, content) {
Expand Down Expand Up @@ -604,10 +605,13 @@ File.getUnixContent = function(content) {
return content.replace(/\r\n|\r/g, '\n');
};

// DOING: There has to be an easier way yto find Line Pos
// - count characters
// - split
File.prototype.getLinePos = function(lineNo) {
var re = /^/gm;
var line = 1;
var content = File.getUnixContent(this.getContent());
var content = eol.lf(this.getContent());
var result;
while ((result = re.exec(content)) !== null) {
if (line == lineNo) {
Expand All @@ -621,21 +625,10 @@ File.prototype.getLinePos = function(lineNo) {

File.getLineNumber = function(content, pos) {
const beforePos = content.substring(0,pos)
const lines = beforePos.split(EOL)
const lines = eol.split(beforePos)
return lines.length
};

// File.getLineNumber = function(content, pos) {
// var unixContent = File.getUnixContent(content);
// var extraChars = (File.hasWindowsEOL(content)) ? 1 : 0;
// var lines = unixContent.split(/^/gm);
// var len = 0;
// for (var i = 0; i < lines.length; i++) {
// len = len + lines[i].length + extraChars;
// if (len > pos) return i+1;
// }
// };

File.prototype.getLineNumber = function(pos) {
return File.getLineNumber(this.getContent(), pos);
};
Expand Down Expand Up @@ -798,8 +791,9 @@ File.prototype.modifyCodeOrHashTask = function(re, task, config) {
if (/[a-z]/.test(task.list)) task.type = Task.Types.HASHTAG;
var hash = task.type === Task.Types.HASHTAG ? "#" : "";
var order = task.order === "" ? "" : util.format( "%d", task.order );
// DOING: Fix issue with single line block comments id:41 gh:168
// - [x] another line
// DOING: Fix issue with single line block comments id:41 gh:168!
// - [ ] another line
// - [ ] and another
var taskContent = util.format("%s%s%s%s %s", hash, task.list, task.hasColon ? ":" : "", order, text);
task.line = this.getLineNumber(index)
task.id = getTaskId(self.getPath(), task.line, task.text);
Expand Down Expand Up @@ -878,7 +872,7 @@ File.prototype.modifyTaskFromHtml = function(task, html) {
};

File.prototype.modifyTaskFromContent = function(task, content, config) {
let lines = content.split(EOL);
let lines = eol.split(content);
task.updatedText = lines.shift()
if (lines.length > 0) task.description = lines
this.modifyTask(task, config)
Expand Down
1 change: 1 addition & 0 deletions notes/2019-01/2019-01-27.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#DOING: Monitor NPM security vulnerabilities id:71 gh:210
- [ ] do it
- do it good
1 change: 1 addition & 0 deletions notes/2019-08/2019-08-05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions notes/2019-08/2019-08-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#DOING: a new card

Loading

0 comments on commit c563e44

Please sign in to comment.