api-doc-validator
Advanced tools
Comparing version 2.18.0 to 2.19.0
@@ -9,15 +9,20 @@ const fs = require('fs'); | ||
const propRule = /^[\r\n\t\s]*((?:class\s+|var\s+|let\s+|const\s+|async\s+|static\s+|function\s+)*)([$\w]+)(\s*[:=]\s*async\b)?/; | ||
const varRule = /var|let|const/; | ||
const prefixRule = /^class|var|let|const|async|static|function$/; | ||
module.exports = function parseComments(file) { | ||
var stream = fs.createReadStream(file); | ||
const stream = fs.createReadStream(file); | ||
var state = TEXT; | ||
var comment = ''; | ||
var loc = null; | ||
var line = 1; | ||
var column = 0; | ||
var list = []; | ||
let state = TEXT; | ||
let comment = ''; | ||
let loc = null; | ||
let line = 1; | ||
let column = 0; | ||
var updatePos = function (text) { | ||
var l = countLines(text); | ||
const list = []; | ||
const updatePos = function (text) { | ||
const l = countLines(text); | ||
line += l; | ||
@@ -32,14 +37,12 @@ | ||
var slice = function (text, start) { | ||
var offset = text.slice(0, start); | ||
const slice = function (text, start) { | ||
updatePos(text.slice(0, start)); | ||
updatePos(offset); | ||
return text.slice(start); | ||
}; | ||
var handle = function (text) { | ||
const handle = function (text) { | ||
while (text.length > 0) { | ||
if (state === TEXT) { | ||
let start = text.indexOf('/'); | ||
const start = text.indexOf('/'); | ||
@@ -82,4 +85,4 @@ if (start === -1) { | ||
if (state === COMMENT_TEXT) { | ||
let nl = text.indexOf("\n"); | ||
let end = text.indexOf("*/"); | ||
const nl = text.indexOf("\n"); | ||
const end = text.indexOf("*/"); | ||
@@ -105,3 +108,3 @@ if (nl === -1 && end === -1) { | ||
if (state === COMMENT_NL) { | ||
let spaces = text.match(/^[\s\t\r\n]+/); | ||
const spaces = text.match(/^[\s\t\r\n]+/); | ||
@@ -114,5 +117,5 @@ if (spaces) { | ||
if (text.charAt(1) === '/') { | ||
state = TEXT; | ||
text = slice(text, 2); | ||
list.push({ | ||
const item = { | ||
value: comment, | ||
@@ -124,5 +127,42 @@ start: loc, | ||
} | ||
}); | ||
}; | ||
state = TEXT; | ||
comment = ''; | ||
loc = null; | ||
const match = text.match(propRule); | ||
if (match && !prefixRule.test(match[2])) { | ||
const prefix = match[1] || ''; | ||
const suffix = match[3] || ''; | ||
const target = { | ||
name: match[2], | ||
}; | ||
if (varRule.test(prefix)) { | ||
target.var = prefix.trim(); | ||
} | ||
if (prefix.includes('class')) { | ||
target.class = true; | ||
} | ||
if (prefix.includes('async') || suffix.includes('async')) { | ||
target.async = true; | ||
} | ||
if (prefix.includes('static')) { | ||
target.static = true; | ||
} | ||
if (prefix.includes('function')) { | ||
target.function = true; | ||
} | ||
item.target = target; | ||
} | ||
list.push(item); | ||
} | ||
@@ -157,3 +197,3 @@ else { | ||
function countLines(text) { | ||
var match = text.match(/\n/g); | ||
const match = text.match(/\n/g); | ||
@@ -164,5 +204,5 @@ return match ? match.length : 0; | ||
function countColumns(text) { | ||
var match = text.match(/\n?(.+)$/); | ||
const match = text.match(/\n?(.+)$/); | ||
return match ? match[1].length : 0; | ||
} |
{ | ||
"name": "api-doc-validator", | ||
"version": "2.18.0", | ||
"version": "2.19.0", | ||
"description": "api doc and validator", | ||
@@ -5,0 +5,0 @@ "main": "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
64964
1834