mirror of
https://github.com/sasjs/lint.git
synced 2026-01-16 16:50:05 +00:00
chore: getLineNumber utility removed
This commit is contained in:
@@ -3,7 +3,6 @@ import { FileLintRule } from '../types/LintRule'
|
|||||||
import { LintRuleType } from '../types/LintRuleType'
|
import { LintRuleType } from '../types/LintRuleType'
|
||||||
import { Severity } from '../types/Severity'
|
import { Severity } from '../types/Severity'
|
||||||
import { trimComments } from '../utils/trimComments'
|
import { trimComments } from '../utils/trimComments'
|
||||||
import { getLineNumber } from '../utils/getLineNumber'
|
|
||||||
import { getColumnNumber } from '../utils/getColumnNumber'
|
import { getColumnNumber } from '../utils/getColumnNumber'
|
||||||
|
|
||||||
const name = 'hasMacroNameInMend'
|
const name = 'hasMacroNameInMend'
|
||||||
@@ -17,7 +16,7 @@ const test = (value: string) => {
|
|||||||
|
|
||||||
const declaredMacros: { name: string; lineNumber: number }[] = []
|
const declaredMacros: { name: string; lineNumber: number }[] = []
|
||||||
let isCommentStarted = false
|
let isCommentStarted = false
|
||||||
lines.forEach((line, index) => {
|
lines.forEach((line, lineIndex) => {
|
||||||
const { statement: trimmedLine, commentStarted } = trimComments(
|
const { statement: trimmedLine, commentStarted } = trimComments(
|
||||||
line,
|
line,
|
||||||
isCommentStarted
|
isCommentStarted
|
||||||
@@ -39,7 +38,7 @@ const test = (value: string) => {
|
|||||||
.split('(')[0]
|
.split('(')[0]
|
||||||
declaredMacros.push({
|
declaredMacros.push({
|
||||||
name: macroName,
|
name: macroName,
|
||||||
lineNumber: getLineNumber(lines, index + 1)
|
lineNumber: lineIndex + 1
|
||||||
})
|
})
|
||||||
} else if (trimmedStatement.startsWith('%mend')) {
|
} else if (trimmedStatement.startsWith('%mend')) {
|
||||||
const declaredMacro = declaredMacros.pop()
|
const declaredMacro = declaredMacros.pop()
|
||||||
@@ -52,7 +51,7 @@ const test = (value: string) => {
|
|||||||
message: `%mend statement is missing macro name - ${
|
message: `%mend statement is missing macro name - ${
|
||||||
declaredMacro!.name
|
declaredMacro!.name
|
||||||
}`,
|
}`,
|
||||||
lineNumber: getLineNumber(lines, index + 1),
|
lineNumber: lineIndex + 1,
|
||||||
startColumnNumber: getColumnNumber(line, '%mend'),
|
startColumnNumber: getColumnNumber(line, '%mend'),
|
||||||
endColumnNumber: getColumnNumber(line, '%mend') + 6,
|
endColumnNumber: getColumnNumber(line, '%mend') + 6,
|
||||||
severity: Severity.Warning
|
severity: Severity.Warning
|
||||||
@@ -62,7 +61,7 @@ const test = (value: string) => {
|
|||||||
message: `%mend statement has mismatched macro name, it should be '${
|
message: `%mend statement has mismatched macro name, it should be '${
|
||||||
declaredMacro!.name
|
declaredMacro!.name
|
||||||
}'`,
|
}'`,
|
||||||
lineNumber: getLineNumber(lines, index + 1),
|
lineNumber: lineIndex + 1,
|
||||||
startColumnNumber: getColumnNumber(line, macroName),
|
startColumnNumber: getColumnNumber(line, macroName),
|
||||||
endColumnNumber:
|
endColumnNumber:
|
||||||
getColumnNumber(line, macroName) + macroName.length - 1,
|
getColumnNumber(line, macroName) + macroName.length - 1,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { FileLintRule } from '../types/LintRule'
|
|||||||
import { LintRuleType } from '../types/LintRuleType'
|
import { LintRuleType } from '../types/LintRuleType'
|
||||||
import { Severity } from '../types/Severity'
|
import { Severity } from '../types/Severity'
|
||||||
import { trimComments } from '../utils/trimComments'
|
import { trimComments } from '../utils/trimComments'
|
||||||
import { getLineNumber } from '../utils/getLineNumber'
|
|
||||||
import { getColumnNumber } from '../utils/getColumnNumber'
|
import { getColumnNumber } from '../utils/getColumnNumber'
|
||||||
|
|
||||||
const name = 'hasMacroParentheses'
|
const name = 'hasMacroParentheses'
|
||||||
@@ -14,7 +13,7 @@ const test = (value: string) => {
|
|||||||
|
|
||||||
const lines: string[] = value ? value.split('\n') : []
|
const lines: string[] = value ? value.split('\n') : []
|
||||||
let isCommentStarted = false
|
let isCommentStarted = false
|
||||||
lines.forEach((line, index) => {
|
lines.forEach((line, lineIndex) => {
|
||||||
const { statement: trimmedLine, commentStarted } = trimComments(
|
const { statement: trimmedLine, commentStarted } = trimComments(
|
||||||
line,
|
line,
|
||||||
isCommentStarted
|
isCommentStarted
|
||||||
@@ -40,7 +39,7 @@ const test = (value: string) => {
|
|||||||
if (!macroName)
|
if (!macroName)
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
message: 'Macro definition contains space(s)',
|
message: 'Macro definition contains space(s)',
|
||||||
lineNumber: getLineNumber(lines, index + 1),
|
lineNumber: lineIndex + 1,
|
||||||
startColumnNumber: getColumnNumber(line, '%macro'),
|
startColumnNumber: getColumnNumber(line, '%macro'),
|
||||||
endColumnNumber:
|
endColumnNumber:
|
||||||
getColumnNumber(line, '%macro') + trimmedStatement.length,
|
getColumnNumber(line, '%macro') + trimmedStatement.length,
|
||||||
@@ -49,7 +48,7 @@ const test = (value: string) => {
|
|||||||
else if (macroNameDefinitionParts.length === 1)
|
else if (macroNameDefinitionParts.length === 1)
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
message,
|
message,
|
||||||
lineNumber: getLineNumber(lines, index + 1),
|
lineNumber: lineIndex + 1,
|
||||||
startColumnNumber: getColumnNumber(line, macroNameDefinition),
|
startColumnNumber: getColumnNumber(line, macroNameDefinition),
|
||||||
endColumnNumber:
|
endColumnNumber:
|
||||||
getColumnNumber(line, macroNameDefinition) +
|
getColumnNumber(line, macroNameDefinition) +
|
||||||
@@ -60,7 +59,7 @@ const test = (value: string) => {
|
|||||||
else if (macroName !== macroName.trim())
|
else if (macroName !== macroName.trim())
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
message: 'Macro definition contains space(s)',
|
message: 'Macro definition contains space(s)',
|
||||||
lineNumber: getLineNumber(lines, index + 1),
|
lineNumber: lineIndex + 1,
|
||||||
startColumnNumber: getColumnNumber(line, macroNameDefinition),
|
startColumnNumber: getColumnNumber(line, macroNameDefinition),
|
||||||
endColumnNumber:
|
endColumnNumber:
|
||||||
getColumnNumber(line, macroNameDefinition) +
|
getColumnNumber(line, macroNameDefinition) +
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { FileLintRule } from '../types/LintRule'
|
|||||||
import { LintRuleType } from '../types/LintRuleType'
|
import { LintRuleType } from '../types/LintRuleType'
|
||||||
import { Severity } from '../types/Severity'
|
import { Severity } from '../types/Severity'
|
||||||
import { trimComments } from '../utils/trimComments'
|
import { trimComments } from '../utils/trimComments'
|
||||||
import { getLineNumber } from '../utils/getLineNumber'
|
|
||||||
import { getColumnNumber } from '../utils/getColumnNumber'
|
import { getColumnNumber } from '../utils/getColumnNumber'
|
||||||
|
|
||||||
const name = 'noNestedMacros'
|
const name = 'noNestedMacros'
|
||||||
@@ -15,7 +14,7 @@ const test = (value: string) => {
|
|||||||
|
|
||||||
const lines: string[] = value ? value.split('\n') : []
|
const lines: string[] = value ? value.split('\n') : []
|
||||||
let isCommentStarted = false
|
let isCommentStarted = false
|
||||||
lines.forEach((line, index) => {
|
lines.forEach((line, lineIndex) => {
|
||||||
const { statement: trimmedLine, commentStarted } = trimComments(
|
const { statement: trimmedLine, commentStarted } = trimComments(
|
||||||
line,
|
line,
|
||||||
isCommentStarted
|
isCommentStarted
|
||||||
@@ -41,7 +40,7 @@ const test = (value: string) => {
|
|||||||
message: message
|
message: message
|
||||||
.replace('{macro}', macroName)
|
.replace('{macro}', macroName)
|
||||||
.replace('{parent}', parentMacro!),
|
.replace('{parent}', parentMacro!),
|
||||||
lineNumber: getLineNumber(lines, index + 1),
|
lineNumber: lineIndex + 1,
|
||||||
startColumnNumber: getColumnNumber(line, '%macro'),
|
startColumnNumber: getColumnNumber(line, '%macro'),
|
||||||
endColumnNumber:
|
endColumnNumber:
|
||||||
getColumnNumber(line, '%macro') + trimmedStatement.length - 1,
|
getColumnNumber(line, '%macro') + trimmedStatement.length - 1,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ describe('getColumnNumber', () => {
|
|||||||
|
|
||||||
it('should throw an error when the specified string is not found within the text', () => {
|
it('should throw an error when the specified string is not found within the text', () => {
|
||||||
expect(() => getColumnNumber('foo bar', 'baz')).toThrowError(
|
expect(() => getColumnNumber('foo bar', 'baz')).toThrowError(
|
||||||
"String 'baz' was not found in statement 'foo bar'"
|
"String 'baz' was not found in line 'foo bar'"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
export const getColumnNumber = (statement: string, text: string): number => {
|
export const getColumnNumber = (line: string, text: string): number => {
|
||||||
const index = (statement.split('\n').pop() as string).indexOf(text)
|
const index = (line.split('\n').pop() as string).indexOf(text)
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
throw new Error(
|
throw new Error(`String '${text}' was not found in line '${line}'`)
|
||||||
`String '${text}' was not found in statement '${statement}'`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
return (statement.split('\n').pop() as string).indexOf(text) + 1
|
return (line.split('\n').pop() as string).indexOf(text) + 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export const getLineNumber = (lines: string[], index: number): number => {
|
|
||||||
const combinedCode = lines.slice(0, index).join('\n')
|
|
||||||
return (combinedCode.match(/\n/g) || []).length + 1
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user