-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new config maxDataLineLength
- Loading branch information
Showing
10 changed files
with
251 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { LintConfig } from '../types' | ||
import { getDataSectionsDetail, checkIsDataLine } from './getDataSectionsDetail' | ||
import { DefaultLintConfiguration } from './getLintConfig' | ||
|
||
const datalines = `GROUP_LOGIC:$3. SUBGROUP_LOGIC:$3. SUBGROUP_ID:8. VARIABLE_NM:$32. OPERATOR_NM:$10. RAW_VALUE:$4000. | ||
AND,AND,1,LIBREF,CONTAINS,"'DC'" | ||
AND,OR,2,DSN,=,"'MPE_LOCK_ANYTABLE'"` | ||
|
||
const datalinesBeginPattern1 = `datalines;` | ||
const datalinesBeginPattern2 = `datalines4;` | ||
const datalinesBeginPattern3 = `cards;` | ||
const datalinesBeginPattern4 = `cards4;` | ||
const datalinesBeginPattern5 = `parmcards;` | ||
const datalinesBeginPattern6 = `parmcards4;` | ||
|
||
const datalinesEndPattern1 = `;` | ||
const datalinesEndPattern2 = `;;;;` | ||
|
||
describe('getDataSectionsDetail', () => { | ||
const config = new LintConfig(DefaultLintConfiguration) | ||
it(`should return the detail of data section when it begins and ends with '${datalinesBeginPattern1}' and '${datalinesEndPattern1}' markers`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern1}\n${datalines}\n${datalinesEndPattern1}\n%put world;` | ||
expect(getDataSectionsDetail(text, config)).toEqual([ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
]) | ||
}) | ||
|
||
it(`should return the detail of data section when it begins and ends with '${datalinesBeginPattern2}' and '${datalinesEndPattern2}' markers`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern2}\n${datalines}\n${datalinesEndPattern2}\n%put world;` | ||
expect(getDataSectionsDetail(text, config)).toEqual([ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
]) | ||
}) | ||
|
||
it(`should return the detail of data section when it begins and ends with '${datalinesBeginPattern3}' and '${datalinesEndPattern1}' markers`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern3}\n${datalines}\n${datalinesEndPattern1}\n%put world;` | ||
expect(getDataSectionsDetail(text, config)).toEqual([ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
]) | ||
}) | ||
|
||
it(`should return the detail of data section when it begins and ends with '${datalinesBeginPattern4}' and '${datalinesEndPattern1}' markers`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern4}\n${datalines}\n${datalinesEndPattern1}\n%put world;` | ||
expect(getDataSectionsDetail(text, config)).toEqual([ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
]) | ||
}) | ||
|
||
it(`should return the detail of data section when it begins and ends with '${datalinesBeginPattern5}' and '${datalinesEndPattern1}' markers`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern5}\n${datalines}\n${datalinesEndPattern1}\n%put world;` | ||
expect(getDataSectionsDetail(text, config)).toEqual([ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
]) | ||
}) | ||
|
||
it(`should return the detail of data section when it begins and ends with '${datalinesBeginPattern6}' and '${datalinesEndPattern2}' markers`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern6}\n${datalines}\n${datalinesEndPattern2}\n%put world;` | ||
expect(getDataSectionsDetail(text, config)).toEqual([ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
]) | ||
}) | ||
}) | ||
|
||
describe('checkIsDataLine', () => { | ||
const config = new LintConfig(DefaultLintConfiguration) | ||
it(`should return true if a line index is in a range of any data section`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern1}\n${datalines}\n${datalinesEndPattern1}\n%put world;` | ||
expect( | ||
checkIsDataLine( | ||
[ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
], | ||
4 | ||
) | ||
).toBe(true) | ||
}) | ||
|
||
it(`should return false if a line index is not in a range of any of data sections`, () => { | ||
const text = `%put hello\n${datalinesBeginPattern1}\n${datalines}\n${datalinesEndPattern1}\n%put world;` | ||
expect( | ||
checkIsDataLine( | ||
[ | ||
{ | ||
start: 1, | ||
end: 5 | ||
} | ||
], | ||
8 | ||
) | ||
).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { LintConfig } from '../types' | ||
import { splitText } from './splitText' | ||
|
||
interface DataSectionsDetail { | ||
start: number | ||
end: number | ||
} | ||
|
||
export const getDataSectionsDetail = (text: string, config: LintConfig) => { | ||
const dataSections: DataSectionsDetail[] = [] | ||
const lines = splitText(text, config) | ||
|
||
const dataSectionStartRegex1 = new RegExp( | ||
'^(datalines;)|(cards;)|(cards4;)|(parmcards;)' | ||
) | ||
const dataSectionEndRegex1 = new RegExp(';') | ||
const dataSectionStartRegex2 = new RegExp('^(datalines4)|(parmcards4);') | ||
const dataSectionEndRegex2 = new RegExp(';;;;') | ||
|
||
let dataSectionStarted = false | ||
let dataSectionStartIndex = -1 | ||
let dataSectionEndRegex = dataSectionEndRegex1 | ||
|
||
lines.forEach((line, index) => { | ||
if (dataSectionStarted) { | ||
if (dataSectionEndRegex.test(line)) { | ||
dataSections.push({ start: dataSectionStartIndex, end: index }) | ||
dataSectionStarted = false | ||
} | ||
} else { | ||
if (dataSectionStartRegex1.test(line)) { | ||
dataSectionStarted = true | ||
dataSectionStartIndex = index | ||
dataSectionEndRegex = dataSectionEndRegex1 | ||
} else if (dataSectionStartRegex2.test(line)) { | ||
dataSectionStarted = true | ||
dataSectionStartIndex = index | ||
dataSectionEndRegex = dataSectionEndRegex2 | ||
} | ||
} | ||
}) | ||
|
||
return dataSections | ||
} | ||
|
||
export const checkIsDataLine = ( | ||
dataSections: DataSectionsDetail[], | ||
lineIndex: number | ||
) => { | ||
for (const dataSection of dataSections) { | ||
if (lineIndex >= dataSection.start && lineIndex <= dataSection.end) | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters