fileoverview author Yann Braga
  import { getMetaObjectExpression } from '../utils' ; import { isLiteral } from '../utils/ast' ; import { CategoryId } from '../utils/constants' ; import { createStorybookRule } from '../utils/create-storybook-rule' ; export = createStorybookRule ( { name : 'hierarchy-separator' , defaultOptions : [ ] , meta : { type : 'problem' , fixable : 'code' , hasSuggestions : true , docs : { description : 'Deprecated hierachy separator in title property' , categories : [ CategoryId . CSF , CategoryId . RECOMMENDED ] , recommended : 'warn' , } , messages : { useCorrectSeparators : 'Use correct separators' , deprecatedHierarchySeparator : 'Deprecated hierachy separator in title property: {{metaTitle}}.' , } , schema : [ ] , } , create : function ( context ) { return { ExportDefaultDeclaration : function ( node ) { const meta = getMetaObjectExpression ( node , context ) ; if ( ! meta ) { return null ; } const titleNode = meta . properties . find ( ( prop ) => prop . key . name === 'title' ) ; if ( ! titleNode || ! isLiteral ( titleNode . value ) ) { return ; } const metaTitle = titleNode . value . raw || '' ; if ( metaTitle . includes ( '|' ) ) { context . report ( { node : titleNode , messageId : 'deprecatedHierarchySeparator' , data : { metaTitle } , fix : function ( fixer ) { return fixer . replaceTextRange ( titleNode . value . range , metaTitle . replace ( /\|/g , '/' ) ) ; } , suggest : [ { messageId : 'useCorrectSeparators' , fix : function ( fixer ) { return fixer . replaceTextRange ( titleNode . value . range , metaTitle . replace ( /\|/g , '/' ) ) ; } , } , ] , } ) ; } } , } ; } , } ) ;