1
- import { RuleModule } from 'eslint-plugin-yml/lib/types.js' ;
1
+ import type { RuleModule } from 'eslint-plugin-yml/lib/types.js' ;
2
2
import { createRule } from 'eslint-plugin-yml/lib/utils' ;
3
3
4
- import { isNullable , isPairWithKey } from '../utils.js' ;
4
+ import { isBlockScalar , isMapping , isNullable , isPairWithKey , isScalar } from '../utils.js' ;
5
5
6
6
export function createOutOfLineRule ( {
7
7
property,
@@ -24,6 +24,8 @@ export function createOutOfLineRule({
24
24
} ,
25
25
messages : {
26
26
[ messageId ] : message ,
27
+ nullDescription : 'description must not be present for `null` type' ,
28
+ descriptionLevel : 'description must not be next to the property' ,
27
29
} ,
28
30
type : 'layout' ,
29
31
schema : [ ] ,
@@ -38,6 +40,29 @@ export function createOutOfLineRule({
38
40
if ( ! isPairWithKey ( node , property ) ) {
39
41
return ;
40
42
}
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
+
41
66
// parent is mapping, and parent is real parent that must be to the far left
42
67
if ( node . parent . parent . loc . start . column === 0 ) {
43
68
return ;
0 commit comments