mirror of
https://github.com/sasjs/lint.git
synced 2026-01-06 20:20:06 +00:00
feat: new rules noNestedMacros & hasMacroParentheses
This commit is contained in:
3
src/utils/getColNumber.ts
Normal file
3
src/utils/getColNumber.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const getColNumber = (statement: string, text: string): number => {
|
||||
return (statement.split('\n').pop() as string).indexOf(text) + 1
|
||||
}
|
||||
5
src/utils/getLineNumber.ts
Normal file
5
src/utils/getLineNumber.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const getLineNumber = (statements: string[], index: number): number => {
|
||||
const combinedCode = statements.slice(0, index).join(';')
|
||||
const lines = (combinedCode.match(/\n/g) || []).length + 1
|
||||
return lines
|
||||
}
|
||||
@@ -17,7 +17,7 @@ describe('getLintConfig', () => {
|
||||
const config = await getLintConfig()
|
||||
|
||||
expect(config).toBeInstanceOf(LintConfig)
|
||||
expect(config.fileLintRules.length).toEqual(1)
|
||||
expect(config.fileLintRules.length).toEqual(3)
|
||||
expect(config.lineLintRules.length).toEqual(5)
|
||||
expect(config.pathLintRules.length).toEqual(2)
|
||||
})
|
||||
|
||||
@@ -15,7 +15,9 @@ export const DefaultLintConfiguration = {
|
||||
maxLineLength: 80,
|
||||
noTabIndentation: true,
|
||||
indentationMultiple: 2,
|
||||
hasMacroNameInMend: false
|
||||
hasMacroNameInMend: false,
|
||||
noNestedMacros: true,
|
||||
hasMacroParentheses: true
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
19
src/utils/trimComments.ts
Normal file
19
src/utils/trimComments.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const trimComments = (
|
||||
statement: string,
|
||||
commentStarted: boolean = false
|
||||
): { statement: string; commentStarted: boolean } => {
|
||||
let trimmed = statement.trim()
|
||||
|
||||
if (commentStarted || trimmed.startsWith('/*')) {
|
||||
const parts = trimmed.split('*/')
|
||||
if (parts.length > 1) {
|
||||
return {
|
||||
statement: (parts.pop() as string).trim(),
|
||||
commentStarted: false
|
||||
}
|
||||
} else {
|
||||
return { statement: '', commentStarted: true }
|
||||
}
|
||||
}
|
||||
return { statement: trimmed, commentStarted: false }
|
||||
}
|
||||
Reference in New Issue
Block a user