1
0
mirror of https://github.com/sasjs/lint.git synced 2025-12-10 17:34:36 +00:00
Files
lint/src/utils/getLintConfig.ts

45 lines
1.4 KiB
TypeScript

import path from 'path'
import { LintConfig } from '../types/LintConfig'
import { readFile } from '@sasjs/utils/file'
import { getProjectRoot } from './getProjectRoot'
export const getDefaultHeader = () =>
`/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
/**
* Default configuration that is used when a .sasjslint file is not found
*/
export const DefaultLintConfiguration = {
noTrailingSpaces: true,
noEncodedPasswords: true,
hasDoxygenHeader: true,
noSpacesInFileNames: true,
lowerCaseFileNames: true,
maxLineLength: 80,
maxHeaderLineLength: 80,
maxDataLineLength: 80,
noTabIndentation: true,
indentationMultiple: 2,
hasMacroNameInMend: true,
noNestedMacros: true,
hasMacroParentheses: true,
strictMacroDefinition: true,
noGremlins: true,
defaultHeader: getDefaultHeader()
}
/**
* Fetches the config from the .sasjslint file and creates a LintConfig object.
* Returns the default configuration when a .sasjslint file is unavailable.
* @returns {Promise<LintConfig>} resolves with an object representing the current lint configuration.
*/
export async function getLintConfig(): Promise<LintConfig> {
const projectRoot = await getProjectRoot()
const configuration = await readFile(
path.join(projectRoot, '.sasjslint')
).catch((_) => {
return JSON.stringify(DefaultLintConfiguration)
})
return new LintConfig(JSON.parse(configuration))
}