mirror of
https://github.com/sasjs/lint.git
synced 2025-12-11 01:44:36 +00:00
Merge pull request #210 from sasjs/issue-209
feat: support a user-level ~/.sasjslint
This commit is contained in:
@@ -8,11 +8,12 @@ import { formatFolder } from './formatFolder'
|
|||||||
* @returns {Promise<FormatResult>} Resolves successfully when all SAS files in the current project have been formatted.
|
* @returns {Promise<FormatResult>} Resolves successfully when all SAS files in the current project have been formatted.
|
||||||
*/
|
*/
|
||||||
export const formatProject = async (): Promise<FormatResult> => {
|
export const formatProject = async (): Promise<FormatResult> => {
|
||||||
const projectRoot =
|
const projectRoot = (await getProjectRoot()) || process.currentDir
|
||||||
(await getProjectRoot()) || process.projectDir || process.currentDir
|
|
||||||
if (!projectRoot) {
|
if (!projectRoot) {
|
||||||
throw new Error('SASjs Project Root was not found.')
|
throw new Error('SASjs Project Root was not found.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info(`Formatting all .sas files under ${projectRoot}`)
|
||||||
|
|
||||||
return await formatFolder(projectRoot)
|
return await formatFolder(projectRoot)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,12 @@ import { lintFolder } from './lintFolder'
|
|||||||
* @returns {Promise<Map<string, Diagnostic[]>>} Resolves with a map with array of diagnostic objects, each containing a warning, line number and column number, and grouped by file path.
|
* @returns {Promise<Map<string, Diagnostic[]>>} 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 () => {
|
export const lintProject = async () => {
|
||||||
const projectRoot =
|
const projectRoot = (await getProjectRoot()) || process.currentDir
|
||||||
(await getProjectRoot()) || process.projectDir || process.currentDir
|
|
||||||
if (!projectRoot) {
|
if (!projectRoot) {
|
||||||
throw new Error('SASjs Project Root was not found.')
|
throw new Error('SASjs Project Root was not found.')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info(`Linting all .sas files under ${projectRoot}`)
|
||||||
|
|
||||||
return await lintFolder(projectRoot)
|
return await lintFolder(projectRoot)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import os from 'os'
|
||||||
import { LintConfig } from '../types/LintConfig'
|
import { LintConfig } from '../types/LintConfig'
|
||||||
import { readFile } from '@sasjs/utils/file'
|
import { readFile } from '@sasjs/utils/file'
|
||||||
import { getProjectRoot } from './getProjectRoot'
|
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 the default configuration when a .sasjslint file is unavailable.
|
||||||
* @returns {Promise<LintConfig>} resolves with an object representing the current lint configuration.
|
* @returns {Promise<LintConfig>} resolves with an object representing the current lint configuration.
|
||||||
*/
|
*/
|
||||||
export async function getLintConfig(): Promise<LintConfig> {
|
export async function getLintConfig(): Promise<LintConfig> {
|
||||||
const projectRoot = await getProjectRoot()
|
const projectRoot = await getProjectRoot()
|
||||||
|
const lintFileLocation = projectRoot || os.homedir()
|
||||||
const configuration = await readFile(
|
const configuration = await readFile(
|
||||||
path.join(projectRoot, '.sasjslint')
|
path.join(lintFileLocation, '.sasjslint')
|
||||||
).catch((_) => {
|
).catch((_) => {
|
||||||
return JSON.stringify(DefaultLintConfiguration)
|
return JSON.stringify(DefaultLintConfiguration)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import os from 'os'
|
||||||
import { fileExists } from '@sasjs/utils/file'
|
import { fileExists } from '@sasjs/utils/file'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,10 +12,11 @@ export async function getProjectRoot(): Promise<string> {
|
|||||||
let rootFound = false
|
let rootFound = false
|
||||||
let i = 1
|
let i = 1
|
||||||
let currentLocation = process.cwd()
|
let currentLocation = process.cwd()
|
||||||
|
const homeDir = os.homedir()
|
||||||
|
|
||||||
const maxLevels = currentLocation.split(path.sep).length
|
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'))
|
const isRoot = await fileExists(path.join(currentLocation, '.sasjslint'))
|
||||||
|
|
||||||
if (isRoot) {
|
if (isRoot) {
|
||||||
|
|||||||
Reference in New Issue
Block a user