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

eslint-plugin-zod-to-openapi

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-zod-to-openapi - npm Package Compare versions

Comparing version 0.0.22 to 0.0.23

77

lib-commonjs/rules/require-comment/rule.js

@@ -7,4 +7,13 @@ "use strict";

const type_1 = require("../../util/type");
const commentRegex = /\*\n\s+\* (.*)\n/;
const deprecatedTag = '@deprecated';
const commentRegex = /[\*\n\s]+(.*)[\*\s]+(.*)/;
const DEPRECATED_TAG = '@deprecated';
const EXAMPLE_TAG = '@example';
const getCommentValue = (comment) => {
const match = commentRegex.exec(comment);
const commentValue = match?.[1];
const exampleValue = match?.[2];
return commentValue
? `${commentValue}${exampleValue ? `\n${exampleValue}` : ''}`
: undefined;
};
const getCommentNode = (node) => {

@@ -22,7 +31,12 @@ if (node.parent?.type === 'ExportNamedDeclaration') {

exports.getComment = getComment;
const createCommentValue = (contents, deprecated) => `${deprecated ? `${deprecatedTag} ` : ''}${contents}`;
const createCommentValue = (contents, deprecated, example) => {
const deprecatedValue = deprecated ? `${DEPRECATED_TAG} ` : '';
const exampleValue = example ? `\n${EXAMPLE_TAG} ${example}` : '';
return `${deprecatedValue}${contents}${exampleValue}`;
};
const createFormattedComment = (contents, loc, newline) => {
const lines = contents.split('\n');
const indent = ' '.repeat(loc.start.column);
return `${newline ? `\n${indent}` : ''}/**
${indent} * ${contents}
${lines.map((line) => `${indent} * ${line}`).join('\n')}
${indent} */

@@ -56,8 +70,4 @@ ${indent}`;

property.key.type === 'Identifier' &&
property.key.name === key &&
property.value.type === 'Literal') {
return {
property,
value: property.value.value,
};
property.key.name === key) {
return property;
}

@@ -67,2 +77,30 @@ }

};
const getExampleValue = (properties, context) => {
const examples = getPropertyNode(properties, 'examples');
const example = getPropertyNode(properties, 'example');
if (examples) {
if (examples.value.type !== 'ArrayExpression') {
// This should always be an array if not ts compiler will complain
return;
}
// Because grabbing a value is difficult if it is not a literal
const arrayText = context.getSourceCode().getText(examples.value);
// Remove square brackets
return arrayText.slice(1, -1);
}
if (example) {
const text = context.getSourceCode().getText(example.value);
return text;
}
return undefined;
};
const getLiteralValue = (property) => {
if (!property) {
return undefined;
}
if (property.value.type === 'Literal') {
return property.value.value;
}
return undefined;
};
const getExpectedCommentValue = (node, context) => {

@@ -77,4 +115,4 @@ const openApiCallExpression = (0, traverse_1.findOpenApiCallExpression)(node);

}
const description = getPropertyNode(argument.properties, 'description');
if (!description) {
const descriptionProperty = getPropertyNode(argument.properties, 'description');
if (!descriptionProperty) {
return context.report({

@@ -85,3 +123,3 @@ messageId: 'required',

}
const descriptionValue = description.value;
const descriptionValue = getLiteralValue(descriptionProperty);
if (typeof descriptionValue !== 'string') {

@@ -94,8 +132,9 @@ // would be handled by ts

messageId: 'required',
node: description.property,
node: descriptionProperty,
});
}
const deprecated = getPropertyNode(argument.properties, 'deprecated');
const deprecatedValue = Boolean(deprecated?.value);
return createCommentValue(descriptionValue, deprecatedValue);
const deprecatedNode = getPropertyNode(argument.properties, 'deprecated');
const deprecatedValue = Boolean(getLiteralValue(deprecatedNode));
const exampleValue = getExampleValue(argument.properties, context);
return createCommentValue(descriptionValue, deprecatedValue, exampleValue);
};

@@ -129,3 +168,3 @@ // eslint-disable-next-line new-cap

}
const commentValue = commentRegex.exec(comment.value)?.[1];
const commentValue = getCommentValue(comment.value);
if (!commentValue || expectedCommentValue !== commentValue) {

@@ -214,3 +253,3 @@ return context.report({

}
const commentValue = commentRegex.exec(comment.value)?.[1];
const commentValue = getCommentValue(comment.value);
if (!commentValue || expectedCommentValue !== commentValue) {

@@ -217,0 +256,0 @@ return context.report({

{
"name": "eslint-plugin-zod-to-openapi",
"version": "0.0.22",
"version": "0.0.23",
"private": false,

@@ -5,0 +5,0 @@ "description": "Eslint rules for zod-to-openapi",

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