How to use returnsTag method in storybook-root

Best JavaScript code snippet using storybook-root

valid-jsdoc.js

Source:valid-jsdoc.js Github

copy

Full Screen

1/**2 * @fileoverview Validates JSDoc comments are syntactically correct3 * @author Nicholas C. Zakas4 */5"use strict";6//------------------------------------------------------------------------------7// Requirements8//------------------------------------------------------------------------------9const doctrine = require("doctrine");10//------------------------------------------------------------------------------11// Rule Definition12//------------------------------------------------------------------------------13module.exports = {14 meta: {15 docs: {16 description: "enforce valid JSDoc comments",17 category: "Possible Errors",18 recommended: false19 },20 schema: [21 {22 type: "object",23 properties: {24 prefer: {25 type: "object",26 additionalProperties: {27 type: "string"28 }29 },30 preferType: {31 type: "object",32 additionalProperties: {33 type: "string"34 }35 },36 requireReturn: {37 type: "boolean"38 },39 requireParamDescription: {40 type: "boolean"41 },42 requireReturnDescription: {43 type: "boolean"44 },45 matchDescription: {46 type: "string"47 },48 requireReturnType: {49 type: "boolean"50 }51 },52 additionalProperties: false53 }54 ]55 },56 create(context) {57 const options = context.options[0] || {},58 prefer = options.prefer || {},59 sourceCode = context.getSourceCode(),60 // these both default to true, so you have to explicitly make them false61 requireReturn = options.requireReturn !== false,62 requireParamDescription = options.requireParamDescription !== false,63 requireReturnDescription = options.requireReturnDescription !== false,64 requireReturnType = options.requireReturnType !== false,65 preferType = options.preferType || {},66 checkPreferType = Object.keys(preferType).length !== 0;67 //--------------------------------------------------------------------------68 // Helpers69 //--------------------------------------------------------------------------70 // Using a stack to store if a function returns or not (handling nested functions)71 const fns = [];72 /**73 * Check if node type is a Class74 * @param {ASTNode} node node to check.75 * @returns {boolean} True is its a class76 * @private77 */78 function isTypeClass(node) {79 return node.type === "ClassExpression" || node.type === "ClassDeclaration";80 }81 /**82 * When parsing a new function, store it in our function stack.83 * @param {ASTNode} node A function node to check.84 * @returns {void}85 * @private86 */87 function startFunction(node) {88 fns.push({89 returnPresent: (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") ||90 isTypeClass(node)91 });92 }93 /**94 * Indicate that return has been found in the current function.95 * @param {ASTNode} node The return node.96 * @returns {void}97 * @private98 */99 function addReturn(node) {100 const functionState = fns[fns.length - 1];101 if (functionState && node.argument !== null) {102 functionState.returnPresent = true;103 }104 }105 /**106 * Check if return tag type is void or undefined107 * @param {Object} tag JSDoc tag108 * @returns {boolean} True if its of type void or undefined109 * @private110 */111 function isValidReturnType(tag) {112 return tag.type === null || tag.type.name === "void" || tag.type.type === "UndefinedLiteral";113 }114 /**115 * Check if type should be validated based on some exceptions116 * @param {Object} type JSDoc tag117 * @returns {boolean} True if it can be validated118 * @private119 */120 function canTypeBeValidated(type) {121 return type !== "UndefinedLiteral" && // {undefined} as there is no name property available.122 type !== "NullLiteral" && // {null}123 type !== "NullableLiteral" && // {?}124 type !== "FunctionType" && // {function(a)}125 type !== "AllLiteral"; // {*}126 }127 /**128 * Extract the current and expected type based on the input type object129 * @param {Object} type JSDoc tag130 * @returns {Object} current and expected type object131 * @private132 */133 function getCurrentExpectedTypes(type) {134 let currentType;135 if (type.name) {136 currentType = type.name;137 } else if (type.expression) {138 currentType = type.expression.name;139 }140 const expectedType = currentType && preferType[currentType];141 return {142 currentType,143 expectedType144 };145 }146 /**147 * Validate type for a given JSDoc node148 * @param {Object} jsdocNode JSDoc node149 * @param {Object} type JSDoc tag150 * @returns {void}151 * @private152 */153 function validateType(jsdocNode, type) {154 if (!type || !canTypeBeValidated(type.type)) {155 return;156 }157 const typesToCheck = [];158 let elements = [];159 switch (type.type) {160 case "TypeApplication": // {Array.<String>}161 elements = type.applications[0].type === "UnionType" ? type.applications[0].elements : type.applications;162 typesToCheck.push(getCurrentExpectedTypes(type));163 break;164 case "RecordType": // {{20:String}}165 elements = type.fields;166 break;167 case "UnionType": // {String|number|Test}168 case "ArrayType": // {[String, number, Test]}169 elements = type.elements;170 break;171 case "FieldType": // Array.<{count: number, votes: number}>172 if (type.value) {173 typesToCheck.push(getCurrentExpectedTypes(type.value));174 }175 break;176 default:177 typesToCheck.push(getCurrentExpectedTypes(type));178 }179 elements.forEach(validateType.bind(null, jsdocNode));180 typesToCheck.forEach(typeToCheck => {181 if (typeToCheck.expectedType &&182 typeToCheck.expectedType !== typeToCheck.currentType) {183 context.report({184 node: jsdocNode,185 message: "Use '{{expectedType}}' instead of '{{currentType}}'.",186 data: {187 currentType: typeToCheck.currentType,188 expectedType: typeToCheck.expectedType189 }190 });191 }192 });193 }194 /**195 * Validate the JSDoc node and output warnings if anything is wrong.196 * @param {ASTNode} node The AST node to check.197 * @returns {void}198 * @private199 */200 function checkJSDoc(node) {201 const jsdocNode = sourceCode.getJSDocComment(node),202 functionData = fns.pop(),203 params = Object.create(null),204 paramsTags = [];205 let hasReturns = false,206 returnsTag,207 hasConstructor = false,208 isInterface = false,209 isOverride = false,210 isAbstract = false;211 // make sure only to validate JSDoc comments212 if (jsdocNode) {213 let jsdoc;214 try {215 jsdoc = doctrine.parse(jsdocNode.value, {216 strict: true,217 unwrap: true,218 sloppy: true219 });220 } catch (ex) {221 if (/braces/i.test(ex.message)) {222 context.report({ node: jsdocNode, message: "JSDoc type missing brace." });223 } else {224 context.report({ node: jsdocNode, message: "JSDoc syntax error." });225 }226 return;227 }228 jsdoc.tags.forEach(tag => {229 switch (tag.title.toLowerCase()) {230 case "param":231 case "arg":232 case "argument":233 paramsTags.push(tag);234 break;235 case "return":236 case "returns":237 hasReturns = true;238 returnsTag = tag;239 break;240 case "constructor":241 case "class":242 hasConstructor = true;243 break;244 case "override":245 case "inheritdoc":246 isOverride = true;247 break;248 case "abstract":249 case "virtual":250 isAbstract = true;251 break;252 case "interface":253 isInterface = true;254 break;255 // no default256 }257 // check tag preferences258 if (prefer.hasOwnProperty(tag.title) && tag.title !== prefer[tag.title]) {259 context.report({ node: jsdocNode, message: "Use @{{name}} instead.", data: { name: prefer[tag.title] } });260 }261 // validate the types262 if (checkPreferType && tag.type) {263 validateType(jsdocNode, tag.type);264 }265 });266 paramsTags.forEach(param => {267 if (!param.type) {268 context.report({ node: jsdocNode, message: "Missing JSDoc parameter type for '{{name}}'.", data: { name: param.name } });269 }270 if (!param.description && requireParamDescription) {271 context.report({ node: jsdocNode, message: "Missing JSDoc parameter description for '{{name}}'.", data: { name: param.name } });272 }273 if (params[param.name]) {274 context.report({ node: jsdocNode, message: "Duplicate JSDoc parameter '{{name}}'.", data: { name: param.name } });275 } else if (param.name.indexOf(".") === -1) {276 params[param.name] = 1;277 }278 });279 if (hasReturns) {280 if (!requireReturn && !functionData.returnPresent && (returnsTag.type === null || !isValidReturnType(returnsTag)) && !isAbstract) {281 context.report({282 node: jsdocNode,283 message: "Unexpected @{{title}} tag; function has no return statement.",284 data: {285 title: returnsTag.title286 }287 });288 } else {289 if (requireReturnType && !returnsTag.type) {290 context.report({ node: jsdocNode, message: "Missing JSDoc return type." });291 }292 if (!isValidReturnType(returnsTag) && !returnsTag.description && requireReturnDescription) {293 context.report({ node: jsdocNode, message: "Missing JSDoc return description." });294 }295 }296 }297 // check for functions missing @returns298 if (!isOverride && !hasReturns && !hasConstructor && !isInterface &&299 node.parent.kind !== "get" && node.parent.kind !== "constructor" &&300 node.parent.kind !== "set" && !isTypeClass(node)) {301 if (requireReturn || functionData.returnPresent) {302 context.report({303 node: jsdocNode,304 message: "Missing JSDoc @{{returns}} for function.",305 data: {306 returns: prefer.returns || "returns"307 }308 });309 }310 }311 // check the parameters312 const jsdocParams = Object.keys(params);313 if (node.params) {314 node.params.forEach((param, i) => {315 if (param.type === "AssignmentPattern") {316 param = param.left;317 }318 const name = param.name;319 // TODO(nzakas): Figure out logical things to do with destructured, default, rest params320 if (param.type === "Identifier") {321 if (jsdocParams[i] && (name !== jsdocParams[i])) {322 context.report({323 node: jsdocNode,324 message: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.",325 data: {326 name,327 jsdocName: jsdocParams[i]328 }329 });330 } else if (!params[name] && !isOverride) {331 context.report({332 node: jsdocNode,333 message: "Missing JSDoc for parameter '{{name}}'.",334 data: {335 name336 }337 });338 }339 }340 });341 }342 if (options.matchDescription) {343 const regex = new RegExp(options.matchDescription);344 if (!regex.test(jsdoc.description)) {345 context.report({ node: jsdocNode, message: "JSDoc description does not satisfy the regex pattern." });346 }347 }348 }349 }350 //--------------------------------------------------------------------------351 // Public352 //--------------------------------------------------------------------------353 return {354 ArrowFunctionExpression: startFunction,355 FunctionExpression: startFunction,356 FunctionDeclaration: startFunction,357 ClassExpression: startFunction,358 ClassDeclaration: startFunction,359 "ArrowFunctionExpression:exit": checkJSDoc,360 "FunctionExpression:exit": checkJSDoc,361 "FunctionDeclaration:exit": checkJSDoc,362 "ClassExpression:exit": checkJSDoc,363 "ClassDeclaration:exit": checkJSDoc,364 ReturnStatement: addReturn365 };366 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { returnsTag } = require('storybook-root');2const { returnsTag } = require('storybook-root');3const { returnsTag } = require('storybook-root');4const { returnsTag } = require('storybook-root');5const { returnsTag } = require('storybook-root');6const { returnsTag } = require('storybook-root');7const { returnsTag } = require('storybook-root');8const { returnsTag } = require('storybook-root');9const { returnsTag } = require('storybook-root');10const { returnsTag } = require('storybook-root');11const { returnsTag } = require('storybook-root');12const { returnsTag } = require('storybook-root');13const { returnsTag } = require('storybook-root');14const { returnsTag } = require('storybook-root');15const { returnsTag } = require('storybook-root');16const { returnsTag } = require('storybook-root');17const { returnsTag } = require('storybook-root');18const { returnsTag } = require('storybook-root');19const { returnsTag } = require('storybook-root');20const { returnsTag } = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1const { returnsTag } = require('storybook-root');2const { returnsTag } = require('storybook-root');3const { returnsTag } = require('storybook-root');4const { returnsTag } = require('storybook-root');5const { returnsTag } = require('storybook-root');6const { returnsTag } = require('storybook-root');7const { returnsTag } = require('storybook-root');8const { returnsTag } = require('storybook-root');9const { returnsTag } = require('storybook-root');10const { returnsTag } = require('storybook-root');11const { returnsTag } = require('storybook-root');12const { returnsTag } = require('storybook-root');13const { returnsTag } = require('storybook-root');14const { returnsTag } = require('storybook-root');15const { returnsTag } = require('storybook

Full Screen

Using AI Code Generation

copy

Full Screen

1const { returnsTag } = require('storybook-root');2const { returnsTag } = require('storybook-root');3const { returnsTag } = require('storybook-root');4const { returnsTag } = require('storybook-root');5const { returnsTag } = require('storybook-root');6const { returnsTag } = require('storybook-root');7const { returnsTag } = require('storybook-root');8const { returnsTag } = require('storybook-root');9const { returnsTag } = require('storybook-root');10const { returnsTag } = require('storybook-root');11const { returnsTag } = require('storybook-root');12const { returnsTag } = require('storybook-root');13const { returnsTag } = require('storybook-root');14const { returnsTag } = require('storybook-root');15const { returnsTag } = require('storybook

Full Screen

Using AI Code Generation

copy

Full Screen

1import { returnsTag } from 'storybook-root';2import { returnsTag } from 'storybook-root';3import { returnsTag } from 'storybook-root';4import { returnsTag } from 'storybook-root';5import { returnsTag } from 'storybook-root';6import { returnsTag } from 'storybook-root';7import { returnsTag } from 'storybook-root';8import { returnsTag } from 'storybook-root';9import { returnsTag } from 'storybook-root';10import { returnsTag } from 'storybook-root';11import { returnsTag } from 'storybook-root';12import { returnsTag } from 'storybook-root';13import { returnsTag } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withRootDecorator } from 'storybook-root-decorator';5import { Button } from '../src/Button';6storiesOf('Button', module)7 .addDecorator(withRootDecorator)8 .add(9 withInfo({10 })(() => <Button>Default</Button>)11 .add(12 withInfo({13 })(() => <Button primary>Primary</Button>)14 );15import React from 'react';16import { addDecorator } from '@storybook/react';17import { withInfo } from '@storybook/addon-info';18import { withRootDecorator } from 'storybook-root-decorator';19import { Button } from '../src/Button';20addDecorator(withRootDecorator);21export default {22};23export const Default = () => <Button>Default</Button>;24export const Primary = () => <Button primary>Primary</Button>;25export const Secondary = () => <Button secondary>Secondary</Button>;26export const Tertiary = () => <Button tertiary>Tertiary</Button>;27export const Quaternary = () => <Button quaternary>Quaternary</Button>;28export const Quinary = () => <Button quinary>Quinary</Button>;29export const Senary = () => <Button senary>Se to test a method that is imported

Full Screen

Using AI Code Generation

copy

Full Screen

1const { returnsTag } = require('storybook-root');2const returnsTagResult = returnsTag();3console.log(returnsTagResult);4conButptth =orequire('path');5nodule.>xpor;s = {6 webpackFinal: async (config, { configType }) => {7 config.resolve.alias['storybook-root'] = pat.resolve(__dirname, '../');8 return config;9 },10};11const path = require('path');12mule.exports = {13 webpackFinal: async (config, { configType }) => {14 config.resolve.alias['storybook-root']= pa.resolve(__dirnme, '../');15 reurn config;16 },17};18const path = requre('path');19odule.exs = {20 wbpackFinal: async (config, { configType }) => {21 config.resolve.alias['storybook-root'] = path.resolve(__irname, '../');22 return config;23 },24};25const path = require('path');26module.exports = {27 webpackFinal: async (config, { configType }) => {28 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');29 return config;30 },31};32const path = require('path');33module.exports = {34 webpackFinal: async (config, { configType }) => {35 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');36 return config;37 },38};39const path = require('path');40module.exports = {41 webpackFinal: async (config, { configType }) => {42 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');43 return config;44 },45};46const path = require('path');47module.exports = {48 webpackFinal: async (config, { configType }) => {49 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');50 return config;51 },52};

Full Screen

Using AI Code Generation

copy

Full Screen

1import { returnsTag } from 'storybook-root';2const test = () => {3 const tag = returnsTag();4};5test();6import { returnsTag } from 'storybook-root';7const test = () => {8 const tag = returnsTag();9};10test();11import { returnsTag } from 'storybook-root';12const test = () => {13 const tag = returnsTag();14};15test();16import { returnsTag } from 'storybook-root';17const test = () => {18 const tag = returnsTag();19};20test();21import { returnsTag } from 'storybook-root';22const test = () => {23 const tag = returnsTag();24};25test();26import { returnsTag } from 'storybook-root';27const test = () => {28 const tag = returnsTag();29};30test();31import { returnsTag } from 'storybook-root';32const test = () => {33 const tag = returnsTag();34};35test();36import { returnsTag } from 'storybook-root';37const test = () => {38 const tag = returnsTag();39};40test();41import { returnsTag } from 'storybook-root';42const test = () => {43 const tag = returnsTag();44};45test();46import { returnsTag } from 'storybook-root';47export const Septenary = () => <Button septenary>Septenary</Button>;48export const Octonary = () => <Button octonary>Octonary</Button>;49export const Nonary = () => <Button nonary>Nonary</Button>;50export const Denary = () => <Button denary>Denary</Button>;51export const Undenary = () => <Button undenary>Undenary</Button>;52export const Duodenary = () => <Button duodenary>Duodenary</Button>;53export const Treddenary = () => <Button treddenary>Treddenary</Button>;

Full Screen

Using AI Code Generation

copy

Full Screen

1import {returnsTag} from 'storybook-root';2import {returnsTag} from 'storybook-root';3describe('returnsTag', () => {4 it('should return the string passed as argument', () => {5 expect(returnsTag('test')).toEqual('test');6 });7});8This is a very basic example but it shows how to test a method that is imported

Full Screen

Using AI Code Generation

copy

Full Screen

1const { returnsTag } = require('storybook-root');2const returnsTagResult = returnsTag();3console.log(returnsTagResult);4const path = require('path');5module.exports = {6 webpackFinal: async (config, { configType }) => {7 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');8 return config;9 },10};11const path = require('path');12module.exports = {13 webpackFinal: async (config, { configType }) => {14 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');15 return config;16 },17};18const path = require('path');19module.exports = {20 webpackFinal: async (config, { configType }) => {21 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');22 return config;23 },24};25const path = require('path');26module.exports = {27 webpackFinal: async (config, { configType }) => {28 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');29 return config;30 },31};32const path = require('path');33module.exports = {34 webpackFinal: async (config, { configType }) => {35 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');36 return config;37 },38};39const path = require('path');40module.exports = {41 webpackFinal: async (config, { configType }) => {42 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');43 return config;44 },45};46const path = require('path');47module.exports = {48 webpackFinal: async (config, { configType }) => {49 config.resolve.alias['storybook-root'] = path.resolve(__dirname, '../');50 return config;51 },52};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful