diff --git a/src/format/formatProject.ts b/src/format/formatProject.ts index 7c8033d..abc9cc7 100644 --- a/src/format/formatProject.ts +++ b/src/format/formatProject.ts @@ -8,11 +8,12 @@ import { formatFolder } from './formatFolder' * @returns {Promise} Resolves successfully when all SAS files in the current project have been formatted. */ export const formatProject = async (): Promise => { - const projectRoot = - (await getProjectRoot()) || process.projectDir || process.currentDir + const projectRoot = (await getProjectRoot()) || process.currentDir if (!projectRoot) { throw new Error('SASjs Project Root was not found.') } + console.info(`Formatting all .sas files under ${projectRoot}`) + return await formatFolder(projectRoot) } diff --git a/src/lint/lintProject.ts b/src/lint/lintProject.ts index 89eeafd..4738b80 100644 --- a/src/lint/lintProject.ts +++ b/src/lint/lintProject.ts @@ -6,10 +6,12 @@ import { lintFolder } from './lintFolder' * @returns {Promise>} Resolves with a map with array of diagnostic objects, each containing a warning, line number and column number, and grouped by file path. */ export const lintProject = async () => { - const projectRoot = - (await getProjectRoot()) || process.projectDir || process.currentDir + const projectRoot = (await getProjectRoot()) || process.currentDir if (!projectRoot) { throw new Error('SASjs Project Root was not found.') } + + console.info(`Linting all .sas files under ${projectRoot}`) + return await lintFolder(projectRoot) } diff --git a/src/utils/getLintConfig.ts b/src/utils/getLintConfig.ts index ab96bca..737d6c0 100644 --- a/src/utils/getLintConfig.ts +++ b/src/utils/getLintConfig.ts @@ -1,4 +1,5 @@ import path from 'path' +import os from 'os' import { LintConfig } from '../types/LintConfig' import { readFile } from '@sasjs/utils/file' import { getProjectRoot } from './getProjectRoot' @@ -31,14 +32,15 @@ export const DefaultLintConfiguration = { } /** - * Fetches the config from the .sasjslint file and creates a LintConfig object. + * Fetches the config from the .sasjslint file (at project root or home directory) and creates a LintConfig object. * Returns the default configuration when a .sasjslint file is unavailable. * @returns {Promise} resolves with an object representing the current lint configuration. */ export async function getLintConfig(): Promise { const projectRoot = await getProjectRoot() + const lintFileLocation = projectRoot || os.homedir() const configuration = await readFile( - path.join(projectRoot, '.sasjslint') + path.join(lintFileLocation, '.sasjslint') ).catch((_) => { return JSON.stringify(DefaultLintConfiguration) }) diff --git a/src/utils/getProjectRoot.ts b/src/utils/getProjectRoot.ts index 73db38e..cc04978 100644 --- a/src/utils/getProjectRoot.ts +++ b/src/utils/getProjectRoot.ts @@ -1,4 +1,5 @@ import path from 'path' +import os from 'os' import { fileExists } from '@sasjs/utils/file' /** @@ -11,10 +12,11 @@ export async function getProjectRoot(): Promise { let rootFound = false let i = 1 let currentLocation = process.cwd() + const homeDir = os.homedir() const maxLevels = currentLocation.split(path.sep).length - while (i <= maxLevels && !rootFound) { + while (i <= maxLevels && !rootFound && currentLocation !== homeDir) { const isRoot = await fileExists(path.join(currentLocation, '.sasjslint')) if (isRoot) {