New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

glob-docs

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-docs - npm Package Compare versions

Comparing version 0.0.5-alpha to 0.0.6-alpha

src/doctags/option.js

4

package.json
{
"name": "glob-docs",
"version": "0.0.5-alpha",
"version": "0.0.6-alpha",
"description": "",

@@ -10,3 +10,3 @@ "main": "index.js",

"bin": {
"gdocs": "./bin/cli.js"
"glb-docs": "./bin/cli.js"
},

@@ -13,0 +13,0 @@ "author": "",

@@ -18,2 +18,3 @@ /*!

CODE: require('./doctags/code'),
OPTION: require('./doctags/option'),
TODO: require('./doctags/todo'),

@@ -65,3 +66,2 @@ INSERT: require('./doctags/insert'),

this.allDocTags.push(docTag);
// merges siblings if applicable

@@ -103,3 +103,2 @@ docTag.merge({

let parentDocTag = null;
let lastDocTag = null;
this._docTagsByFilename[filename].forEach((docTag) => {

@@ -123,4 +122,2 @@ const currentDocTag = this._docTagsById[docTag.id];

}
lastDocTag = docTag;
});

@@ -152,2 +149,3 @@ }

}
return renders

@@ -154,0 +152,0 @@ }

@@ -18,3 +18,2 @@ const utils = require('./utils');

jumpLines: 0,
highlight: '1',
showSourceFile: true,

@@ -21,0 +20,0 @@ ...utils.parseTagParams(value)

@@ -9,72 +9,16 @@ const utils = require('./utils');

function merge({docTag, blobDocs}) {
const { lineNum, sourceFile } = docTag.node;
// The first line (starting from 0-n) that @DOC| tag was found.
const firstDocTagLineIndex = lineNum - 1;
// It creates a list of lines from source file.
const sourceCodeLines = sourceFile.sourceCodeLines;
const firstDocTagLine = sourceCodeLines[firstDocTagLineIndex];
/**
* Note: To make all comments more clear, please consider
* 'firstDocTagLine' with value exactly like line below:
* var firstDocTagLine = '// @DOC| My comment.';
*/
/**
* It returns "index" where @DOC| starts.
* // @DOC| My comment.
* // πŸ’₯DOC| My comment. // index=3
*/
const docTagStartsAtIndex = firstDocTagLine.indexOf(DOC_TAG);
/**
* It returns sum of string lenght before docTag + doc tag size.
* // @DOC| My comment.
* πŸ€πŸ€πŸ€πŸŽΎπŸŽΎπŸŽΎπŸŽΎπŸŽΎ My comment.
*/
const docTypeSize = docTagStartsAtIndex + DOC_TAG.length;
const firstLineCommentSize = firstDocTagLine.length;
/**
* It returns list comment string after docTag type.
* // [' ', 'M', 'y', ' ', 'c', 'o', 'm', ...]
*/
const commentLetterList = firstDocTagLine.slice(docTypeSize, firstLineCommentSize).split('');
/***
* The index where the comment text (not DocTag) starts.
*/
let commentStartAt = docTypeSize;
for(let letter of commentLetterList) {
if (letter !== " ") {
break;
const comments = utils.parseMultilineComments({
docTag,
blobDocs,
commentCondiction: (comment, indentation) => {
const indentSize = indentation.length;
const indentToken = " ".repeat(indentSize);
const validCommentPrefix = (comment[0] && comment[0] != " " && comment[0] != "");
const validIndentation = (indentation === indentToken);
return validCommentPrefix && validIndentation;
}
commentStartAt++;
}
});
/***
* Gets first line comment only (no DocTags).
*/
const commentLines = [
firstDocTagLine.slice(commentStartAt, firstDocTagLine.length)
];
docTag.setValue('comments', comments.join(' '));
/**
* Gets the next lines till end of comments.
*/
for(let i=(firstDocTagLineIndex + 1); i < sourceCodeLines.length; i++) {
const nextComment = sourceCodeLines[i];
const commentIndentation = nextComment.slice(docTagStartsAtIndex, commentStartAt);
const comment = nextComment.slice(commentStartAt, nextComment.length);
const validCommentPrefix = (comment[0] && comment[0] != " " && comment[0] != "");
const validIndentation = (commentIndentation === " ".repeat(commentIndentation.length));
if (validCommentPrefix && validIndentation) {
commentLines.push(comment);
} else {
break;
}
}
docTag.setValue('comments', commentLines.join(' '));
// Adds only root elements

@@ -81,0 +25,0 @@ if (!docTag.parentId) {

@@ -0,1 +1,3 @@

const DOC_TAG = '@DOC|';
module.exports.toId = (text) => {

@@ -70,1 +72,70 @@ return text

}
module.exports.parseMultilineComments = ({docTag, commentCondiction}) => {
const { lineNum, sourceFile } = docTag.node;
// The first line (starting from 0-n) that @DOC| tag was found.
const firstDocTagLineIndex = lineNum - 1;
// It creates a list of lines from source file.
const sourceCodeLines = sourceFile.sourceCodeLines;
const firstDocTagLine = sourceCodeLines[firstDocTagLineIndex];
/**
* Note: To make all comments more clear, please consider
* 'firstDocTagLine' with value exactly like line below:
* var firstDocTagLine = '// @DOC| My comment.';
*/
/**
* It returns "index" where @DOC| starts.
* // @DOC| My comment.
* // πŸ’₯DOC| My comment. // index=3
*/
const docTagStartsAtIndex = firstDocTagLine.indexOf(DOC_TAG);
/**
* It returns sum of string lenght before docTag + doc tag size.
* // @DOC| My comment.
* πŸ€πŸ€πŸ€πŸŽΎπŸŽΎπŸŽΎπŸŽΎπŸŽΎ My comment.
*/
const docTypeSize = docTagStartsAtIndex + DOC_TAG.length;
const firstLineCommentSize = firstDocTagLine.length;
/**
* It returns list comment string after docTag type.
* // [' ', 'M', 'y', ' ', 'c', 'o', 'm', ...]
*/
const commentLetterList = firstDocTagLine.slice(docTypeSize, firstLineCommentSize).split('');
/***
* The index where the comment text (not DocTag) starts.
*/
let commentStartAt = docTypeSize;
for(let letter of commentLetterList) {
if (letter !== " ") {
break;
}
commentStartAt++;
}
/***
* Gets first line comment only (no DocTags).
*/
const commentLines = [
firstDocTagLine.slice(commentStartAt, firstDocTagLine.length)
];
/**
* Gets the next lines till end of comments.
*/
for(let i=(firstDocTagLineIndex + 1); i < sourceCodeLines.length; i++) {
const nextComment = sourceCodeLines[i];
const commentIndentation = nextComment.slice(docTagStartsAtIndex, commentStartAt);
const comment = nextComment.slice(commentStartAt, nextComment.length);
if (commentCondiction(comment, commentIndentation)) {
commentLines.push(comment);
} else {
break;
}
}
return commentLines;
}

@@ -0,2 +1,28 @@

function createLink(childTag, label, options) {
const {node} = childTag;
let sourceLink = [
options.sourceFileLinkPrefix,
node.relativeFilepath
].join('');
return `<a href="${sourceLink}#L${node.lineNum}">${label}</a>`;
}
module.exports = {
OPTION: ({ options, docTag }) => {
if (docTag.options.root) {
let table = [
' Option | Description',
'--------|------------'
];
docTag.children.forEach(childTag => {
const {tagValue, comments} = childTag.metatags;
const filelink = createLink(childTag, tagValue, options);
table.push(`${filelink} | ${comments}`);
});
return table.join('\n');
}
return '';
},
/***

@@ -6,4 +32,3 @@ * It renders syntax highligh code.

CODE: ({ options, docTag }) => {
let fileLink = [];
let fileLink = '';
if (options.code.showSourceFile && docTag.options.params.showSourceFile) {

@@ -14,14 +39,6 @@ let sourceLabel = [

].join(':');
fileLink = `<sub>File: ${createLink(docTag, sourceLabel, options)}</sub>\n`;
}
let sourceLink = [
options.sourceFileLinkPrefix,
docTag.node.relativeFilepath
].join('');
fileLink.push(
`File: [${sourceLabel}](${sourceLink}#L${docTag.node.lineNum})`,
);
}
return [
...fileLink,
return fileLink + [
`\`\`\`${docTag.options.params.lang}`,

@@ -52,3 +69,3 @@ docTag.metatags.codeSource,

},
SECTION: ({ docTag }) => {
SECTION: ({ docTag, index }) => {
const header = '#'.repeat(docTag.options.level + 1);

@@ -55,0 +72,0 @@ return `${header} ${docTag.options.title}`;

<!-- @DOC|INSERT:START(type=TODO) -->
## TODO
- [x] - [ It should do something like that 1](test/fixtures/demo-terraform.tf#L1)
- [ ] - [ It should do something like that 1](test/fixtures/demo-terraform.tf#L1)
- [x] - [ It should do something like that 1](test/fixtures/demo-terraform.tf#L2)

@@ -5,0 +5,0 @@ - [x] - [ It should do something like that 1](test/fixtures/demo-terraform.tf#L3)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc