File size: 1,491 Bytes
1477a90 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import { createRule, paramMessage, getDoc } from '@typespec/compiler'
export const docDecoratorRule = createRule({
name: 'doc-decorator',
severity: 'warning',
description: 'Ensure documentation.',
messages: {
default: paramMessage`Missing documentation for ${'name'} ${'type'}`,
},
create: (context) => ({
model: (target) => {
if (target.name && !getDoc(context.program, target)) {
context.reportDiagnostic({
target,
format: {
name: target.name,
},
})
}
if (target.name.endsWith('Response')) {
return
}
for (const [name, property] of target.properties) {
if (
target.name &&
name &&
!['_', 'contentType'].includes(name) &&
!getDoc(context.program, property)
) {
context.reportDiagnostic({
target: property,
format: {
name: `${target.name}.${name}`,
},
})
}
}
},
enum: (target) => {
if (target.name && !getDoc(context.program, target)) {
context.reportDiagnostic({
target,
format: {
name: target.name,
},
})
}
},
union: (target) => {
if (target.name && !getDoc(context.program, target)) {
context.reportDiagnostic({
target,
format: {
name: target.name,
},
})
}
},
}),
})
|