mirror of
https://github.com/sasjs/lint.git
synced 2025-12-10 17:34:36 +00:00
fix(*): add missing text check to getColumnNumber, rename function and file
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
export const getColNumber = (statement: string, text: string): number => {
|
||||
return (statement.split('\n').pop() as string).indexOf(text) + 1
|
||||
}
|
||||
13
src/utils/getColumnNumber.spec.ts
Normal file
13
src/utils/getColumnNumber.spec.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { getColumnNumber } from './getColumnNumber'
|
||||
|
||||
describe('getColumnNumber', () => {
|
||||
it('should return the column number of the specified string within a line of text', () => {
|
||||
expect(getColumnNumber('foo bar', 'bar')).toEqual(5)
|
||||
})
|
||||
|
||||
it('should throw an error when the specified string is not found within the text', () => {
|
||||
expect(() => getColumnNumber('foo bar', 'baz')).toThrowError(
|
||||
"String 'baz' was not found in statement 'foo bar'"
|
||||
)
|
||||
})
|
||||
})
|
||||
9
src/utils/getColumnNumber.ts
Normal file
9
src/utils/getColumnNumber.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export const getColumnNumber = (statement: string, text: string): number => {
|
||||
const index = (statement.split('\n').pop() as string).indexOf(text)
|
||||
if (index < 0) {
|
||||
throw new Error(
|
||||
`String '${text}' was not found in statement '${statement}'`
|
||||
)
|
||||
}
|
||||
return (statement.split('\n').pop() as string).indexOf(text) + 1
|
||||
}
|
||||
Reference in New Issue
Block a user