mirror of
https://github.com/sasjs/lint.git
synced 2026-01-12 06:40:06 +00:00
Revert "feat(*): add line endings rule, add automatic formatting for fixable violations"
This reverts commit 33a57c3163.
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
@@ -1,7 +0,0 @@
|
||||
import { getLintConfig } from '../utils'
|
||||
import { processText } from './shared'
|
||||
|
||||
export const formatText = async (text: string) => {
|
||||
const config = await getLintConfig()
|
||||
return processText(text, config)
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { LintConfig } from '../types'
|
||||
import { LineEndings } from '../types/LineEndings'
|
||||
import { splitText } from '../utils/splitText'
|
||||
|
||||
export const processText = (text: string, config: LintConfig) => {
|
||||
const processedText = processContent(config, text)
|
||||
const lines = splitText(processedText, config)
|
||||
const formattedLines = lines.map((line) => {
|
||||
return processLine(config, line)
|
||||
})
|
||||
|
||||
const configuredLineEnding =
|
||||
config.lineEndings === LineEndings.LF ? '\n' : '\r\n'
|
||||
return formattedLines.join(configuredLineEnding)
|
||||
}
|
||||
|
||||
const processContent = (config: LintConfig, content: string): string => {
|
||||
let processedContent = content
|
||||
config.fileLintRules
|
||||
.filter((r) => !!r.fix)
|
||||
.forEach((rule) => {
|
||||
processedContent = rule.fix!(processedContent)
|
||||
})
|
||||
|
||||
return processedContent
|
||||
}
|
||||
|
||||
export const processLine = (config: LintConfig, line: string): string => {
|
||||
let processedLine = line
|
||||
config.lineLintRules
|
||||
.filter((r) => !!r.fix)
|
||||
.forEach((rule) => {
|
||||
processedLine = rule.fix!(line)
|
||||
})
|
||||
|
||||
return processedLine
|
||||
}
|
||||
Reference in New Issue
Block a user