Socket
Socket
Sign inDemoInstall

@closeio/best-practices-documentation

Package Overview
Dependencies
2
Maintainers
8
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.1 to 0.4.2

24

lib/cjs/utils/replace.js

@@ -72,2 +72,3 @@ "use strict";

const replaceBestPractices = (filename, lines, index, getBestPracticeLines) => {
const [startRe, endRe] = getInsertREs(filename);
let inBestPractice = false;

@@ -80,3 +81,3 @@ let lineNumber = 0;

if (inBestPractice) {
if (INSERT_END_RE.test(line)) {
if (endRe.test(line)) {
inBestPractice = false;

@@ -90,5 +91,5 @@ // Do not continue, we want to write out the end line

newLines.push(line);
if (INSERT_START_RE.test(line)) {
if (startRe.test(line)) {
inBestPractice = true;
const [, bestPracticeId] = INSERT_START_RE.exec(line);
const [, bestPracticeId] = startRe.exec(line);
if (!index.has(bestPracticeId)) {

@@ -104,3 +105,16 @@ throw new Error(`Missing best practice: file ${filename} at line ${lineNumber} expects best practice ID: ${bestPracticeId}. No best practice with this ID was found.`);

exports.replaceBestPractices = replaceBestPractices;
const INSERT_START_RE = /^\s*<!-- @BestPractice.insert (\S+) -->$/;
const INSERT_END_RE = /^\s*<!-- @BestPractice.end -->$/;
/**
* Get the regexp to match insertion comments in a documentation file.
*
* .mdx files use jsx comments rather than html comments.
*/
const getInsertREs = (filename) => {
if (/\.mdx$/.test(filename)) {
return [MDX_INSERT_START_RE, MDX_INSERT_END_RE];
}
return [MD_INSERT_START_RE, MD_INSERT_END_RE];
};
const MD_INSERT_START_RE = /^\s*<!-- @BestPractice.insert (\S+) -->$/;
const MD_INSERT_END_RE = /^\s*<!-- @BestPractice.end -->$/;
const MDX_INSERT_START_RE = /^\s*{\/\* @BestPractice.insert (\S+) \*\/}$/;
const MDX_INSERT_END_RE = /^\s*{\/\* @BestPractice.end \*\/}$/;

@@ -43,2 +43,3 @@ "use strict";

const replaceBestPractices = (filename, lines, index, getBestPracticeLines) => {
const [startRe, endRe] = getInsertREs(filename);
let inBestPractice = false;

@@ -51,3 +52,3 @@ let lineNumber = 0;

if (inBestPractice) {
if (INSERT_END_RE.test(line)) {
if (endRe.test(line)) {
inBestPractice = false;

@@ -61,5 +62,5 @@ // Do not continue, we want to write out the end line

newLines.push(line);
if (INSERT_START_RE.test(line)) {
if (startRe.test(line)) {
inBestPractice = true;
const [, bestPracticeId] = INSERT_START_RE.exec(line);
const [, bestPracticeId] = startRe.exec(line);
if (!index.has(bestPracticeId)) {

@@ -75,3 +76,16 @@ throw new Error(`Missing best practice: file ${filename} at line ${lineNumber} expects best practice ID: ${bestPracticeId}. No best practice with this ID was found.`);

exports.replaceBestPractices = replaceBestPractices;
const INSERT_START_RE = /^\s*<!-- @BestPractice.insert (\S+) -->$/;
const INSERT_END_RE = /^\s*<!-- @BestPractice.end -->$/;
/**
* Get the regexp to match insertion comments in a documentation file.
*
* .mdx files use jsx comments rather than html comments.
*/
const getInsertREs = (filename) => {
if (/\.mdx$/.test(filename)) {
return [MDX_INSERT_START_RE, MDX_INSERT_END_RE];
}
return [MD_INSERT_START_RE, MD_INSERT_END_RE];
};
const MD_INSERT_START_RE = /^\s*<!-- @BestPractice.insert (\S+) -->$/;
const MD_INSERT_END_RE = /^\s*<!-- @BestPractice.end -->$/;
const MDX_INSERT_START_RE = /^\s*{\/\* @BestPractice.insert (\S+) \*\/}$/;
const MDX_INSERT_END_RE = /^\s*{\/\* @BestPractice.end \*\/}$/;
{
"name": "@closeio/best-practices-documentation",
"version": "0.4.1",
"version": "0.4.2",
"description": "Tooling to document best practices in your code base.",

@@ -5,0 +5,0 @@ "author": "Trey Cucco",

@@ -30,4 +30,3 @@ # Close Best Practices Documentation

You can tag blocks of code as best practices with specially formatted
comments:
You can tag blocks of code as best practices with specially formatted comments:

@@ -112,2 +111,7 @@ ```tsx

If your file is a `.mdx` Markdown file, use `JSX` style comments instead:
{/* @BestPractice.insert insertIntoStaticDocs */}
{/* @BestPractice.end */}
It's important to have both the start and end lines, as these will be used as

@@ -114,0 +118,0 @@ boundaries of the program to know where to replace the code.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc