1
0
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:
Saad Jutt
2021-04-06 19:45:42 +05:00
parent 3970f05dc9
commit 3530badf49
12 changed files with 221 additions and 38 deletions

View File

@@ -0,0 +1,3 @@
export const getColNumber = (statement: string, text: string): number => {
return (statement.split('\n').pop() as string).indexOf(text) + 1
}

View 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
}

View File

@@ -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)
})

View File

@@ -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
View 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 }
}