From 6350d32d0c3e472302a722a78f419b456dcead89 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Tue, 30 Mar 2021 09:24:03 +0100 Subject: [PATCH] fix(has-doxygen-header): fix logic to handle files with comment blocks --- src/rules/hasDoxygenHeader.spec.ts | 21 +++++++++++++++++++++ src/rules/hasDoxygenHeader.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/rules/hasDoxygenHeader.spec.ts b/src/rules/hasDoxygenHeader.spec.ts index 477969d..4229c59 100644 --- a/src/rules/hasDoxygenHeader.spec.ts +++ b/src/rules/hasDoxygenHeader.spec.ts @@ -34,6 +34,27 @@ describe('hasDoxygenHeader', () => { ]) }) + it('should return an array with a single diagnostic when the file has comment blocks but no header', () => { + const content = ` + %macro mf_getuniquelibref(prefix=mclib,maxtries=1000); + %local x libref; + %let x={SAS002}; + /** Comment Line 1 + * Comment Line 2 + */ + %do x=0 %to &maxtries;` + + expect(hasDoxygenHeader.test(content)).toEqual([ + { + message: 'File missing Doxygen header', + lineNumber: 1, + startColumnNumber: 1, + endColumnNumber: 1, + severity: Severity.Warning + } + ]) + }) + it('should return an array with a single diagnostic when the file is undefined', () => { const content = undefined diff --git a/src/rules/hasDoxygenHeader.ts b/src/rules/hasDoxygenHeader.ts index 3563154..0a367ab 100644 --- a/src/rules/hasDoxygenHeader.ts +++ b/src/rules/hasDoxygenHeader.ts @@ -8,7 +8,7 @@ const description = const message = 'File missing Doxygen header' const test = (value: string) => { try { - const hasFileHeader = value.split('/**')[0] !== value + const hasFileHeader = value.trimStart().startsWith('/*') if (hasFileHeader) return [] return [ {