Skip to content

Commit

Permalink
Merge pull request #13 from sasjs/lint-folder-project
Browse files Browse the repository at this point in the history
feat(lint): add lintFolder and lintProject APIs
  • Loading branch information
krishna-acondy authored Mar 31, 2021
2 parents 12bfcd6 + ffcd57d commit 7aa4bfc
Show file tree
Hide file tree
Showing 23 changed files with 503 additions and 248 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@sasjs/utils": "^2.9.0"
"@sasjs/utils": "^2.10.1"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
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'
158 changes: 0 additions & 158 deletions src/lint.spec.ts

This file was deleted.

81 changes: 0 additions & 81 deletions src/lint.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/lint/index.ts
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'
69 changes: 69 additions & 0 deletions src/lint/lintFile.spec.ts
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
})
})
})
23 changes: 23 additions & 0 deletions src/lint/lintFile.ts
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]
}
Loading

0 comments on commit 7aa4bfc

Please sign in to comment.