@@ -14,6 +14,7 @@ import { allConfig, allRules, customRules } from '../lib/helpers/get-rules.js'
14
14
import { customConfig , githubDocsFrontmatterConfig } from '../style/github-docs.js'
15
15
import { defaultConfig } from '../lib/default-markdownlint-options.js'
16
16
import { prettyPrintResults } from './pretty-print-results.js'
17
+ import { printAnnotationResults } from '../lib/helpers/print-annotations.js'
17
18
18
19
program
19
20
. description ( 'Run GitHub Docs Markdownlint rules.' )
@@ -45,6 +46,7 @@ program
45
46
. addOption (
46
47
new Option ( '-o, --output-file <filepath>' , `Outputs the errors/warnings to the filepath.` ) ,
47
48
)
49
+ . option ( '--print-annotations' , 'Print annotations for GitHub Actions check runs.' , false )
48
50
. parse ( process . argv )
49
51
50
52
const {
@@ -56,6 +58,7 @@ const {
56
58
outputFile,
57
59
verbose,
58
60
precommit : isPrecommit ,
61
+ printAnnotations,
59
62
} = program . opts ( )
60
63
61
64
const ALL_CONTENT_DIR = [ 'content' , 'data' ]
@@ -91,7 +94,7 @@ async function main() {
91
94
customRules : configuredRules . data ,
92
95
} )
93
96
94
- // Run Markdownlint for data directory
97
+ // Run Markdownlint for content directory (frontmatter only)
95
98
const resultFrontmatter = await markdownlint . promises . markdownlint ( {
96
99
frontMatter : null ,
97
100
files : files . content ,
@@ -154,6 +157,18 @@ async function main() {
154
157
} )
155
158
}
156
159
}
160
+
161
+ if ( printAnnotations ) {
162
+ printAnnotationResults ( formattedResults , {
163
+ skippableRules : [
164
+ // As of Feb 2024, this rule is quite noisy. It's present in
165
+ // many files and is not always a problem. And besides, when it
166
+ // does warn, it's usually a very long one.
167
+ 'code-fence-line-length' , // a.k.a. GHD030
168
+ ] ,
169
+ } )
170
+ }
171
+
157
172
const end = Date . now ( )
158
173
// Ensure previous console logging is not truncated
159
174
console . log ( '\n' )
@@ -214,9 +229,15 @@ async function main() {
214
229
}
215
230
216
231
if ( errorFileCount ) {
217
- process . exit ( 1 )
232
+ if ( printAnnotations ) {
233
+ console . warn ( 'When printing annotations, the exit code is always 0' )
234
+ process . exit ( 0 )
235
+ } else {
236
+ process . exit ( 1 )
237
+ }
238
+ } else {
239
+ spinner . succeed ( 'No errors found' )
218
240
}
219
- spinner . succeed ( 'No errors found' )
220
241
}
221
242
222
243
function pluralize ( things , word , pluralForm = null ) {
0 commit comments