1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-05 03:30:06 +00:00

feat(format): add the ability to format files, folders and projects

This commit is contained in:
Krishna Acondy
2021-04-19 22:13:53 +01:00
parent d28d32d441
commit bcb50b9968
11 changed files with 320 additions and 17 deletions

22
src/format/formatFile.ts Normal file
View File

@@ -0,0 +1,22 @@
import { createFile, readFile } from '@sasjs/utils/file'
import { LintConfig } from '../types/LintConfig'
import { getLintConfig } from '../utils/getLintConfig'
import { processText } from './shared'
/**
* Applies automatic formatting to the file at the given path.
* @param {string} filePath - the path to the file to be formatted.
* @param {LintConfig} configuration - an optional configuration. When not passed in, this is read from the .sasjslint file.
* @returns {Promise<void>} Resolves successfully when the file has been formatted.
*/
export const formatFile = async (
filePath: string,
configuration?: LintConfig
) => {
const config = configuration || (await getLintConfig())
const text = await readFile(filePath)
const formattedText = processText(text, config)
await createFile(filePath, formattedText)
}