fileoverview author Yann Braga
  import { getMetaObjectExpression } from '../utils' ; import { CategoryId } from '../utils/constants' ; import { createStorybookRule } from '../utils/create-storybook-rule' ; export = createStorybookRule ( { name : 'meta-inline-properties' , defaultOptions : [ { csfVersion : 3 } ] , meta : { type : 'problem' , docs : { description : 'Meta should only have inline properties' , categories : [ CategoryId . CSF , CategoryId . RECOMMENDED ] , excludeFromConfig : true , recommended : 'error' , } , messages : { metaShouldHaveInlineProperties : 'Meta should only have inline properties: {{property}}' , } , schema : [ { type : 'object' , properties : { csfVersion : { type : 'number' , } , } , additionalProperties : false , } , ] , } , create ( context ) { const isInline = ( node ) => { return ( node . value . type === 'ObjectExpression' || node . value . type === 'Literal' || node . value . type === 'ArrayExpression' ) ; } ; return { ExportDefaultDeclaration ( node ) { const meta = getMetaObjectExpression ( node , context ) ; if ( ! meta ) { return null ; } const ruleProperties = [ 'title' , 'args' ] ; let dynamicProperties = [ ] ; const metaNodes = meta . properties . filter ( ( prop ) => ruleProperties . includes ( prop . key . name ) ) ; metaNodes . forEach ( ( metaNode ) => { if ( ! isInline ( metaNode ) ) { dynamicProperties . push ( metaNode ) ; } } ) ; if ( dynamicProperties . length > 0 ) { dynamicProperties . forEach ( ( propertyNode ) => { context . report ( { node : propertyNode , messageId : 'metaShouldHaveInlineProperties' , data : { property : propertyNode . key . name , } , } ) ; } ) ; } } , } ; } , } ) ;