mirror of
https://github.com/sasjs/lint.git
synced 2026-01-10 05:50:05 +00:00
fix(*): Add severity, start and end column numbers for diagnostics, change warning to message
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import * as fileModule from '@sasjs/utils/file'
|
||||
import { LintConfig } from '../types/LintConfig'
|
||||
import { getLintConfig } from './getLintConfig'
|
||||
|
||||
@@ -7,4 +8,16 @@ describe('getLintConfig', () => {
|
||||
|
||||
expect(config).toBeInstanceOf(LintConfig)
|
||||
})
|
||||
|
||||
it('should get the default config when a .sasjslint file is unavailable', async () => {
|
||||
jest
|
||||
.spyOn(fileModule, 'readFile')
|
||||
.mockImplementationOnce(() => Promise.reject())
|
||||
|
||||
const config = await getLintConfig()
|
||||
|
||||
expect(config).toBeInstanceOf(LintConfig)
|
||||
expect(config.fileLintRules.length).toEqual(1)
|
||||
expect(config.lineLintRules.length).toEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,14 +10,15 @@ const defaultConfiguration = {
|
||||
}
|
||||
/**
|
||||
* 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((e) => {
|
||||
console.error('Error reading .sasjslint file', e)
|
||||
).catch((_) => {
|
||||
console.warn('Unable to load .sasjslint file. Using default configuration.')
|
||||
return JSON.stringify(defaultConfiguration)
|
||||
})
|
||||
return new LintConfig(JSON.parse(configuration))
|
||||
|
||||
Reference in New Issue
Block a user