mirror of
https://github.com/sasjs/lint.git
synced 2025-12-11 01:44:36 +00:00
fix(parseMacros): avoid statement break on html encoded semi colon
This commit is contained in:
@@ -121,6 +121,9 @@ describe('strictMacroDefinition', () => {
|
||||
it('should return an empty array when the content has correct macro definition syntax', () => {
|
||||
const content = `%macro mp_ds2cards(base_ds=, tgt_ds=\n ,cards_file="%sysfunc(pathname(work))/cardgen.sas"\n ,maxobs=max\n ,random_sample=NO\n ,showlog=YES\n ,outencoding=\n ,append=NO\n)/*/STORE SOURCE*/;`
|
||||
expect(strictMacroDefinition.test(content)).toEqual([])
|
||||
|
||||
const content2 = `%macro mm_createapplication(\n tree=/User Folders/sasdemo\n ,name=myApp\n ,ClassIdentifier=mcore\n ,desc=Created by mm_createapplication\n ,params= param1=1
param2=blah\n ,version=\n ,frefin=mm_in\n ,frefout=mm_out\n ,mDebug=1\n );`
|
||||
expect(strictMacroDefinition.test(content2)).toEqual([])
|
||||
})
|
||||
|
||||
it('should return an array with a single diagnostic when Macro definition has space in param', () => {
|
||||
|
||||
@@ -277,5 +277,38 @@ describe('parseMacros', () => {
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
})
|
||||
|
||||
it('should return an array with a single macro having semi-colon in params', () => {
|
||||
const text = `\n%macro mm_createapplication(\n tree=/User Folders/sasdemo\n ,name=myApp\n ,ClassIdentifier=mcore\n ,desc=Created by mm_createapplication\n ,params= param1=1
param2=blah\n ,version=\n ,frefin=mm_in\n ,frefout=mm_out\n ,mDebug=1\n );`
|
||||
|
||||
const macros = parseMacros(text, new LintConfig())
|
||||
|
||||
expect(macros.length).toEqual(1)
|
||||
expect(macros).toContainEqual({
|
||||
name: 'mm_createapplication',
|
||||
declarationLines: [
|
||||
`%macro mm_createapplication(`,
|
||||
` tree=/User Folders/sasdemo`,
|
||||
` ,name=myApp`,
|
||||
` ,ClassIdentifier=mcore`,
|
||||
` ,desc=Created by mm_createapplication`,
|
||||
` ,params= param1=1
param2=blah`,
|
||||
` ,version=`,
|
||||
` ,frefin=mm_in`,
|
||||
` ,frefout=mm_out`,
|
||||
` ,mDebug=1`,
|
||||
` );`
|
||||
],
|
||||
terminationLine: '',
|
||||
declaration:
|
||||
'%macro mm_createapplication( tree=/User Folders/sasdemo ,name=myApp ,ClassIdentifier=mcore ,desc=Created by mm_createapplication ,params= param1=1
param2=blah ,version= ,frefin=mm_in ,frefout=mm_out ,mDebug=1 )',
|
||||
termination: '',
|
||||
startLineNumbers: [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
endLineNumber: null,
|
||||
parentMacro: '',
|
||||
hasMacroNameInMend: false,
|
||||
mismatchedMendMacroName: ''
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -38,6 +38,19 @@ export const parseMacros = (text: string, config?: LintConfig): Macro[] => {
|
||||
|
||||
const statements: string[] = trimmedLine.split(';')
|
||||
|
||||
if (isReadingMacroDefinition) {
|
||||
statements.forEach((statement, statementIndex) => {
|
||||
if (/&[^\s]{1,5}$/.test(statement)) {
|
||||
const next = statements[statementIndex]
|
||||
const updatedStatement = `${statement};${
|
||||
statements[statementIndex + 1]
|
||||
}`
|
||||
statements.splice(statementIndex, 1, updatedStatement)
|
||||
statements.splice(statementIndex + 1, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
statements.forEach((statement, statementIndex) => {
|
||||
const { statement: trimmedStatement, commentStarted } = trimComments(
|
||||
statement,
|
||||
|
||||
Reference in New Issue
Block a user