Skip to content

Commit

Permalink
Merge pull request #27 from sasjs/issue-26
Browse files Browse the repository at this point in the history
fix(hasMacroNameInMend): default sets to true
  • Loading branch information
krishna-acondy authored Apr 16, 2021
2 parents 031a323 + fe97405 commit c2209cb
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .sasjslint
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lowerCaseFileNames": true,
"noTabIndentation": true,
"indentationMultiple": 2,
"hasMacroNameInMend": false,
"hasMacroNameInMend": true,
"noNestedMacros": true,
"hasMacroParentheses": true
}
133 changes: 76 additions & 57 deletions src/lint/lintFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,87 @@ import { lintFile } from './lintFile'
import { Severity } from '../types/Severity'
import path from 'path'

const expectedDiagnostics = [
{
message: 'Line contains trailing spaces',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 2,
severity: Severity.Warning
},
{
message: 'Line contains trailing spaces',
lineNumber: 2,
startColumnNumber: 1,
endColumnNumber: 2,
severity: Severity.Warning
},
{
message: 'File name contains spaces',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'File name contains uppercase characters',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'File missing Doxygen header',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'Line contains encoded password',
lineNumber: 5,
startColumnNumber: 10,
endColumnNumber: 18,
severity: Severity.Error
},
{
message: 'Line is indented with a tab',
lineNumber: 7,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'Line has incorrect indentation - 3 spaces',
lineNumber: 6,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: '%mend statement is missing macro name - mf_getuniquelibref',
lineNumber: 17,
startColumnNumber: 3,
endColumnNumber: 9,
severity: Severity.Warning
}
]

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
})
expect(results.length).toEqual(expectedDiagnostics.length)
expect(results).toContainEqual(expectedDiagnostics[0])
expect(results).toContainEqual(expectedDiagnostics[1])
expect(results).toContainEqual(expectedDiagnostics[2])
expect(results).toContainEqual(expectedDiagnostics[3])
expect(results).toContainEqual(expectedDiagnostics[4])
expect(results).toContainEqual(expectedDiagnostics[5])
expect(results).toContainEqual(expectedDiagnostics[6])
expect(results).toContainEqual(expectedDiagnostics[7])
expect(results).toContainEqual(expectedDiagnostics[8])
})
})
136 changes: 78 additions & 58 deletions src/lint/lintFolder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,90 @@ import { lintFolder } from './lintFolder'
import { Severity } from '../types/Severity'
import path from 'path'

const expectedFilesCount = 1
const expectedDiagnostics = [
{
message: 'Line contains trailing spaces',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 2,
severity: Severity.Warning
},
{
message: 'Line contains trailing spaces',
lineNumber: 2,
startColumnNumber: 1,
endColumnNumber: 2,
severity: Severity.Warning
},
{
message: 'File name contains spaces',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'File name contains uppercase characters',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'File missing Doxygen header',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'Line contains encoded password',
lineNumber: 5,
startColumnNumber: 10,
endColumnNumber: 18,
severity: Severity.Error
},
{
message: 'Line is indented with a tab',
lineNumber: 7,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'Line has incorrect indentation - 3 spaces',
lineNumber: 6,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: '%mend statement is missing macro name - mf_getuniquelibref',
lineNumber: 17,
startColumnNumber: 3,
endColumnNumber: 9,
severity: Severity.Warning
}
]

describe('lintFolder', () => {
it('should identify lint issues in a given folder', async () => {
const results = await lintFolder(path.join(__dirname, '..'))

expect(results.size).toEqual(1)
expect(results.size).toEqual(expectedFilesCount)
const diagnostics = results.get(
path.join(__dirname, '..', 'Example File.sas')
)!
expect(diagnostics.length).toEqual(8)
expect(diagnostics).toContainEqual({
message: 'Line contains trailing spaces',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 2,
severity: Severity.Warning
})
expect(diagnostics).toContainEqual({
message: 'Line contains trailing spaces',
lineNumber: 2,
startColumnNumber: 1,
endColumnNumber: 2,
severity: Severity.Warning
})
expect(diagnostics).toContainEqual({
message: 'File name contains spaces',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
})
expect(diagnostics).toContainEqual({
message: 'File name contains uppercase characters',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
})
expect(diagnostics).toContainEqual({
message: 'File missing Doxygen header',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
})
expect(diagnostics).toContainEqual({
message: 'Line contains encoded password',
lineNumber: 5,
startColumnNumber: 10,
endColumnNumber: 18,
severity: Severity.Error
})
expect(diagnostics).toContainEqual({
message: 'Line is indented with a tab',
lineNumber: 7,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
})
expect(diagnostics).toContainEqual({
message: 'Line has incorrect indentation - 3 spaces',
lineNumber: 6,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
})
expect(diagnostics.length).toEqual(expectedDiagnostics.length)
expect(diagnostics).toContainEqual(expectedDiagnostics[0])
expect(diagnostics).toContainEqual(expectedDiagnostics[1])
expect(diagnostics).toContainEqual(expectedDiagnostics[2])
expect(diagnostics).toContainEqual(expectedDiagnostics[3])
expect(diagnostics).toContainEqual(expectedDiagnostics[4])
expect(diagnostics).toContainEqual(expectedDiagnostics[5])
expect(diagnostics).toContainEqual(expectedDiagnostics[6])
expect(diagnostics).toContainEqual(expectedDiagnostics[7])
expect(diagnostics).toContainEqual(expectedDiagnostics[8])
})
})
Loading

0 comments on commit c2209cb

Please sign in to comment.