-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from sasjs/lint-folder-project
feat(lint): add lintFolder and lintProject APIs
- Loading branch information
Showing
23 changed files
with
503 additions
and
248 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,6 @@ | |
"typescript": "^4.2.3" | ||
}, | ||
"dependencies": { | ||
"@sasjs/utils": "^2.9.0" | ||
"@sasjs/utils": "^2.10.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { lintText, lintFile } from './lint' | ||
export * from './lint' | ||
export * from './types' | ||
export * from './utils' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './lintText' | ||
export * from './lintFile' | ||
export * from './lintFolder' | ||
export * from './lintProject' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { lintFile } from './lintFile' | ||
import { Severity } from '../types/Severity' | ||
import path from 'path' | ||
|
||
describe('lintFile', () => { | ||
it('should identify lint issues in a given file', async () => { | ||
const results = await lintFile( | ||
path.join(__dirname, '..', 'Example File.sas') | ||
) | ||
|
||
expect(results.length).toEqual(8) | ||
expect(results).toContainEqual({ | ||
message: 'Line contains trailing spaces', | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 2, | ||
severity: Severity.Warning | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'Line contains trailing spaces', | ||
lineNumber: 2, | ||
startColumnNumber: 1, | ||
endColumnNumber: 2, | ||
severity: Severity.Warning | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'File name contains spaces', | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'File name contains uppercase characters', | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'File missing Doxygen header', | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'Line contains encoded password', | ||
lineNumber: 5, | ||
startColumnNumber: 10, | ||
endColumnNumber: 18, | ||
severity: Severity.Error | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'Line is indented with a tab', | ||
lineNumber: 7, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
}) | ||
expect(results).toContainEqual({ | ||
message: 'Line has incorrect indentation - 3 spaces', | ||
lineNumber: 6, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { readFile } from '@sasjs/utils/file' | ||
import { LintConfig } from '../types/LintConfig' | ||
import { getLintConfig } from '../utils/getLintConfig' | ||
import { processFile, processText } from './shared' | ||
|
||
/** | ||
* Analyses and produces a set of diagnostics for the file at the given path. | ||
* @param {string} filePath - the path to the file to be linted. | ||
* @param {LintConfig} configuration - an optional configuration. When not passed in, this is read from the .sasjslint file. | ||
* @returns {Diagnostic[]} array of diagnostic objects, each containing a warning, line number and column number. | ||
*/ | ||
export const lintFile = async ( | ||
filePath: string, | ||
configuration?: LintConfig | ||
) => { | ||
const config = configuration || (await getLintConfig()) | ||
const text = await readFile(filePath) | ||
|
||
const fileDiagnostics = processFile(filePath, config) | ||
const textDiagnostics = processText(text, config) | ||
|
||
return [...fileDiagnostics, ...textDiagnostics] | ||
} |
Oops, something went wrong.