1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-08 21:10:05 +00:00

feat: add a new config maxHeaderLineLength

This commit is contained in:
2023-01-10 14:48:18 +05:00
parent 4cb2fe8a69
commit b6e9ee0825
10 changed files with 107 additions and 10 deletions

View File

@@ -0,0 +1,21 @@
import { LintConfig } from '../types'
import { getHeaderLinesCount } from './getHeaderLinesCount'
import { DefaultLintConfiguration } from './getLintConfig'
const sasCodeWithHeader = `/**
@file
@brief <Your brief here>
<h4> SAS Macros </h4>
**/
%put hello world;
`
const sasCodeWithoutHeader = `%put hello world;`
describe('getHeaderLinesCount', () => {
it('should return the number of line header spans upon', () => {
const config = new LintConfig(DefaultLintConfiguration)
expect(getHeaderLinesCount(sasCodeWithHeader, config)).toEqual(5)
expect(getHeaderLinesCount(sasCodeWithoutHeader, config)).toEqual(0)
})
})

View File

@@ -0,0 +1,25 @@
import { LintConfig } from '../types'
import { splitText } from './splitText'
/**
* This funtion returns the number of lines header spans upon.
*/
export const getHeaderLinesCount = (text: string, config: LintConfig) => {
text = text.replace('/*', '/**')
text = text.replace('*/', '**/')
let count = 0
if (text.trimStart().startsWith('/**')) {
const lines = splitText(text, config)
for (const line of lines) {
count++
if (line.match(/\*\*\//)) {
break
}
}
}
return count
}

View File

@@ -16,6 +16,7 @@ export const DefaultLintConfiguration = {
noSpacesInFileNames: true,
lowerCaseFileNames: true,
maxLineLength: 80,
maxHeaderLineLength: 80,
noTabIndentation: true,
indentationMultiple: 2,
hasMacroNameInMend: true,

View File

@@ -6,3 +6,4 @@ export * from './isIgnored'
export * from './listSasFiles'
export * from './splitText'
export * from './getIndicesOf'
export * from './getHeaderLinesCount'