1- import { RuleModule } from 'eslint-plugin-yml/lib/types.js' ;
1+ import type { RuleModule } from 'eslint-plugin-yml/lib/types.js' ;
22import { createRule } from 'eslint-plugin-yml/lib/utils' ;
33
4- import { isNullable , isPairWithKey } from '../utils.js' ;
4+ import { isBlockScalar , isMapping , isNullable , isPairWithKey , isScalar } from '../utils.js' ;
55
66export function createOutOfLineRule ( {
77 property,
@@ -24,6 +24,8 @@ export function createOutOfLineRule({
2424 } ,
2525 messages : {
2626 [ messageId ] : message ,
27+ nullDescription : 'description must not be present for `null` type' ,
28+ descriptionLevel : 'description must not be next to the property' ,
2729 } ,
2830 type : 'layout' ,
2931 schema : [ ] ,
@@ -38,6 +40,29 @@ export function createOutOfLineRule({
3840 if ( ! isPairWithKey ( node , property ) ) {
3941 return ;
4042 }
43+
44+ // the 'null' must not have a description otherwise it will generate a model for it
45+ if (
46+ property === 'oneOf' &&
47+ isNullable ( node . value ) &&
48+ node . value . entries . some (
49+ ( entry ) =>
50+ isMapping ( entry ) &&
51+ isPairWithKey ( entry . pairs [ 0 ] , 'type' ) &&
52+ isScalar ( entry . pairs [ 0 ] . value ) &&
53+ ! isBlockScalar ( entry . pairs [ 0 ] . value ) &&
54+ entry . pairs [ 0 ] . value . raw === "'null'" &&
55+ entry . pairs . length > 1 ,
56+ )
57+ ) {
58+ context . report ( {
59+ node : node . value ,
60+ messageId : 'nullDescription' ,
61+ } ) ;
62+
63+ return ;
64+ }
65+
4166 // parent is mapping, and parent is real parent that must be to the far left
4267 if ( node . parent . parent . loc . start . column === 0 ) {
4368 return ;
0 commit comments