1
0
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:
Krishna Acondy
2021-04-19 20:06:45 +01:00
parent 031a323839
commit 33a57c3163
32 changed files with 930 additions and 318 deletions

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