yaml-eslint-parser
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -17,5 +17,10 @@ "use strict"; | ||
}); | ||
const stripCommentCode = comments.reduce((text, comment) => text.slice(0, comment.range[0]) + | ||
text.slice(...comment.range).replace(/\S/gu, " ") + | ||
text.slice(comment.range[1]), code); | ||
let stripCommentCode = ""; | ||
let startIndex = 0; | ||
for (const comment of comments) { | ||
stripCommentCode += code.slice(startIndex, comment.range[0]); | ||
stripCommentCode += code.slice(...comment.range).replace(/\S/gu, " "); | ||
startIndex = comment.range[1]; | ||
} | ||
stripCommentCode += code.slice(startIndex); | ||
const tokens = []; | ||
@@ -26,9 +31,9 @@ const ast = Object.assign({ type: "Program", body: [], comments, sourceType: "module", tokens, parent: null }, getConvertLocation(node)); | ||
} | ||
const stripTokensCode = tokens.reduce((text, token) => text.slice(0, token.range[0]) + | ||
text.slice(...token.range).replace(/\S/gu, " ") + | ||
text.slice(token.range[1]), stripCommentCode); | ||
const useRanges = sort(tokens).map((t) => t.range); | ||
let range = useRanges.shift(); | ||
let line = 1; | ||
let column = 0; | ||
for (let index = 0; index < stripTokensCode.length; index++) { | ||
const c = stripTokensCode[index]; | ||
const len = stripCommentCode.length; | ||
for (let index = 0; index < len; index++) { | ||
const c = stripCommentCode[index]; | ||
if (c === "\n") { | ||
@@ -39,36 +44,29 @@ line++; | ||
} | ||
else if (c.trim()) { | ||
if (isPunctuator(c)) { | ||
addToken(tokens, "Punctuator", { | ||
range: [index, index + 1], | ||
loc: { | ||
start: { | ||
line, | ||
column, | ||
}, | ||
end: { | ||
line, | ||
column: column + 1, | ||
}, | ||
}, | ||
}, stripTokensCode); | ||
if (range) { | ||
while (range && range[1] <= index) { | ||
range = useRanges.shift(); | ||
} | ||
if (range && range[0] <= index) { | ||
column++; | ||
continue; | ||
} | ||
} | ||
if (isPunctuator(c)) { | ||
addToken(tokens, "Punctuator", { | ||
range: [index, index + 1], | ||
loc: { | ||
start: { | ||
line, | ||
column, | ||
}, | ||
end: { | ||
line, | ||
column: column + 1, | ||
}, | ||
}, | ||
}, stripCommentCode); | ||
} | ||
column++; | ||
} | ||
tokens.sort((a, b) => { | ||
if (a.range[0] > b.range[0]) { | ||
return 1; | ||
} | ||
if (a.range[0] < b.range[0]) { | ||
return -1; | ||
} | ||
if (a.range[1] > b.range[1]) { | ||
return 1; | ||
} | ||
if (a.range[1] < b.range[1]) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
sort(tokens); | ||
return ast; | ||
@@ -86,3 +84,2 @@ /** | ||
c === "]" || | ||
// | ||
c === "?"); | ||
@@ -729,1 +726,21 @@ } | ||
} | ||
/** | ||
* Sort tokens | ||
*/ | ||
function sort(tokens) { | ||
return tokens.sort((a, b) => { | ||
if (a.range[0] > b.range[0]) { | ||
return 1; | ||
} | ||
if (a.range[0] < b.range[0]) { | ||
return -1; | ||
} | ||
if (a.range[1] > b.range[1]) { | ||
return 1; | ||
} | ||
if (a.range[1] < b.range[1]) { | ||
return -1; | ||
} | ||
return 0; | ||
}); | ||
} |
{ | ||
"name": "yaml-eslint-parser", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "A YAML parser that produces output compatible with ESLint", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48265
1333