@@ -134,6 +134,7 @@ type ValidateOptions = {
134134 isReleaseCandidate: boolean ;
135135 repoUrl: string ;
136136 tagPrefix: string ;
137+ fix: boolean ;
137138} ;
138139
139140/**
@@ -145,13 +146,15 @@ type ValidateOptions = {
145146 * @param options.isReleaseCandidate - Whether the current branch is a release candidate or not.
146147 * @param options.repoUrl - The GitHub repository URL for the current project.
147148 * @param options.tagPrefix - The prefix used in tags before the version number.
149+ * @param options.fix - Whether to attempt to fix the changelog or not.
148150 */
149151async function validate ( {
150152 changelogPath,
151153 currentVersion,
152154 isReleaseCandidate,
153155 repoUrl,
154156 tagPrefix,
157+ fix,
155158} : ValidateOptions ) {
156159 const changelogContent = await readChangelog ( changelogPath ) ;
157160
@@ -167,6 +170,11 @@ async function validate({
167170 } catch ( error ) {
168171 if ( error instanceof ChangelogFormattingError ) {
169172 const { validChangelog, invalidChangelog } = error . data ;
173+ if ( fix ) {
174+ await saveChangelog ( changelogPath , validChangelog ) ;
175+ return undefined ;
176+ }
177+
170178 const diff = generateDiff ( validChangelog , invalidChangelog ) ;
171179 return exitWithError ( `Changelog not well-formatted. Diff:\n\n${ diff } ` ) ;
172180 } else if ( error instanceof InvalidChangelogError ) {
@@ -279,6 +287,11 @@ async function main() {
279287 'The current version of the project that the changelog belongs to.' ,
280288 type : 'string' ,
281289 } )
290+ . option ( 'fix' , {
291+ default : false ,
292+ description : `Attempt to fix any formatting errors in the changelog` ,
293+ type : 'boolean' ,
294+ } )
282295 . epilog ( validateEpilog ) ,
283296 )
284297 . command ( 'init' , 'Initialize a new empty changelog' , ( _yargs ) => {
@@ -297,6 +310,7 @@ async function main() {
297310 repo : repoUrl ,
298311 root : projectRootDirectory ,
299312 tagPrefix,
313+ fix,
300314 } = argv ;
301315 let { currentVersion } = argv ;
302316
@@ -411,6 +425,7 @@ async function main() {
411425 isReleaseCandidate,
412426 repoUrl,
413427 tagPrefix,
428+ fix,
414429 } ) ;
415430 } else if ( command === 'init' ) {
416431 await init ( {
0 commit comments