mirror of
https://github.com/sasjs/lint.git
synced 2026-01-05 03:30:06 +00:00
feat(*): add line endings rule, add automatic formatting for fixable violations
This commit is contained in:
48
src/format/formatText.spec.ts
Normal file
48
src/format/formatText.spec.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { formatText } from './formatText'
|
||||
import * as getLintConfigModule from '../utils/getLintConfig'
|
||||
import { LintConfig } from '../types'
|
||||
jest.mock('../utils/getLintConfig')
|
||||
|
||||
describe('formatText', () => {
|
||||
it('should format the given text based on configured rules', async () => {
|
||||
jest
|
||||
.spyOn(getLintConfigModule, 'getLintConfig')
|
||||
.mockImplementationOnce(() =>
|
||||
Promise.resolve(
|
||||
new LintConfig(getLintConfigModule.DefaultLintConfiguration)
|
||||
)
|
||||
)
|
||||
const text = `%macro test
|
||||
%put 'hello';\r\n%mend; `
|
||||
|
||||
const expectedOutput = `/**
|
||||
@file
|
||||
@brief <Your brief here>
|
||||
**/\n%macro test
|
||||
%put 'hello';\n%mend;`
|
||||
|
||||
const output = await formatText(text)
|
||||
|
||||
expect(output).toEqual(expectedOutput)
|
||||
})
|
||||
|
||||
it('should use CRLF line endings when configured', async () => {
|
||||
jest
|
||||
.spyOn(getLintConfigModule, 'getLintConfig')
|
||||
.mockImplementationOnce(() =>
|
||||
Promise.resolve(
|
||||
new LintConfig({
|
||||
...getLintConfigModule.DefaultLintConfiguration,
|
||||
lineEndings: 'crlf'
|
||||
})
|
||||
)
|
||||
)
|
||||
const text = `%macro test\n %put 'hello';\r\n%mend; `
|
||||
|
||||
const expectedOutput = `/**\r\n @file\r\n @brief <Your brief here>\r\n**/\r\n%macro test\r\n %put 'hello';\r\n%mend;`
|
||||
|
||||
const output = await formatText(text)
|
||||
|
||||
expect(output).toEqual(expectedOutput)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user