Skip to content

Commit

Permalink
Merge pull request #24 from sasjs/assorted-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krishna-acondy authored Apr 7, 2021
2 parents 64c413d + 5c130c7 commit cc33ebb
Show file tree
Hide file tree
Showing 16 changed files with 414 additions and 175 deletions.
1 change: 1 addition & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ What code changes have been made to achieve the intent.
- [ ] Any new functionality has been unit tested.
- [ ] All unit tests are passing (`npm test`).
- [ ] All CI checks are green.
- [ ] sasjslint-schema.json is updated with any new / changed functionality
- [ ] JSDoc comments have been added or updated.
- [ ] Reviewer is assigned.
76 changes: 53 additions & 23 deletions sasjslint-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"title": "SASjs Lint Config File",
"description": "The SASjs Lint Config file provides the settings for customising SAS code style in your project.",
"default": {
"noTrailingSpaces": true,
"noEncodedPasswords": true,
"hasDoxygenHeader": true,
"noSpacesInFileNames": true,
"hasMacroNameInMend": false,
"hasMacroParentheses": true,
"indentationMultiple": 2,
"lowerCaseFileNames": true,
"maxLineLength": 80,
"noNestedMacros": true,
"noSpacesInFileNames": true,
"noTabIndentation": true,
"indentationMultiple": 2
"noTrailingSpaces": true
},
"examples": [
{
Expand All @@ -23,18 +26,13 @@
"lowerCaseFileNames": true,
"maxLineLength": 80,
"noTabIndentation": true,
"indentationMultiple": 4
"indentationMultiple": 4,
"hasMacroNameInMend": true,
"noNestedMacros": true,
"hasMacroParentheses": true
}
],
"properties": {
"noTrailingSpaces": {
"$id": "#/properties/noTrailingSpaces",
"type": "boolean",
"title": "noTrailingSpaces",
"description": "Enforces no trailing spaces in lines of SAS code. Shows a warning when they are present.",
"default": true,
"examples": [true, false]
},
"noEncodedPasswords": {
"$id": "#/properties/noEncodedPasswords",
"type": "boolean",
Expand All @@ -51,14 +49,30 @@
"default": true,
"examples": [true, false]
},
"noSpacesInFileNames": {
"$id": "#/properties/noSpacesInFileNames",
"hasMacroNameInMend": {
"$id": "#/properties/hasMacroNameInMend",
"type": "boolean",
"title": "noSpacesInFileNames",
"description": "Enforces no spaces in file names. Shows a warning when they are present.",
"title": "hasMacroNameInMend",
"description": "Enforces the presence of macro names in %mend statements. Shows a warning for %mend statements with missing or mismatched macro names.",
"default": false,
"examples": [true, false]
},
"hasMacroParentheses": {
"$id": "#/properties/hasMacroParentheses",
"type": "boolean",
"title": "hasMacroParentheses",
"description": "Enforces the presence of parentheses in macro definitions. Shows a warning for each macro defined without parentheses, or with spaces between the macro name and the opening parenthesis.",
"default": true,
"examples": [true, false]
},
"indentationMultiple": {
"$id": "#/properties/indentationMultiple",
"type": "number",
"title": "indentationMultiple",
"description": "Enforces a configurable multiple for the number of spaces for indentation. Shows a warning for lines that are not indented by a multiple of this number.",
"default": 2,
"examples": [2, 3, 4]
},
"lowerCaseFileNames": {
"$id": "#/properties/lowerCaseFileNames",
"type": "boolean",
Expand All @@ -75,6 +89,22 @@
"default": 80,
"examples": [60, 80, 120]
},
"noNestedMacros": {
"$id": "#/properties/noNestedMacros",
"type": "boolean",
"title": "noNestedMacros",
"description": "Enforces the absence of nested macro definitions. Shows a warning for each nested macro definition.",
"default": true,
"examples": [true, false]
},
"noSpacesInFileNames": {
"$id": "#/properties/noSpacesInFileNames",
"type": "boolean",
"title": "noSpacesInFileNames",
"description": "Enforces no spaces in file names. Shows a warning when they are present.",
"default": true,
"examples": [true, false]
},
"noTabIndentation": {
"$id": "#/properties/noTabIndentation",
"type": "boolean",
Expand All @@ -83,13 +113,13 @@
"default": true,
"examples": [true, false]
},
"indentationMultiple": {
"$id": "#/properties/indentationMultiple",
"type": "number",
"title": "indentationMultiple",
"description": "Enforces a configurable multiple for the number of spaces for indentation. Shows a warning for lines that are not indented by a multiple of this number.",
"default": 2,
"examples": [2, 3, 4]
"noTrailingSpaces": {
"$id": "#/properties/noTrailingSpaces",
"type": "boolean",
"title": "noTrailingSpaces",
"description": "Enforces no trailing spaces in lines of SAS code. Shows a warning when they are present.",
"default": true,
"examples": [true, false]
}
}
}
74 changes: 65 additions & 9 deletions src/rules/hasMacroNameInMend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - somemacro',
lineNumber: 4,
startColumnNumber: 3,
endColumnNumber: 9,
Expand All @@ -37,6 +37,44 @@ describe('hasMacroNameInMend', () => {
])
})

it('should return an array with a single diagnostic when a macro is missing an %mend statement', () => {
const content = `%macro somemacro;
%put &sysmacroname;`

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: 'Missing %mend statement for macro - somemacro',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
}
])
})

it('should return an array with a diagnostic for each macro missing an %mend statement', () => {
const content = `%macro somemacro;
%put &sysmacroname;
%macro othermacro`

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: 'Missing %mend statement for macro - somemacro',
lineNumber: 1,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
},
{
message: 'Missing %mend statement for macro - othermacro',
lineNumber: 3,
startColumnNumber: 1,
endColumnNumber: 1,
severity: Severity.Warning
}
])
})

it('should return an array with a single diagnostic when %mend has incorrect macro name', () => {
const content = `
%macro somemacro;
Expand All @@ -45,7 +83,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: 'mismatch macro name in %mend statement',
message: `%mend statement has mismatched macro name, it should be 'somemacro'`,
lineNumber: 4,
startColumnNumber: 9,
endColumnNumber: 24,
Expand All @@ -54,6 +92,24 @@ describe('hasMacroNameInMend', () => {
])
})

it('should return an array with a single diagnostic when extra %mend statement is present', () => {
const content = `
%macro somemacro;
%put &sysmacroname;
%mend somemacro;
%mend something;`

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend statement is redundant',
lineNumber: 5,
startColumnNumber: 3,
endColumnNumber: 18,
severity: Severity.Warning
}
])
})

it('should return an empty array when the file is undefined', () => {
const content = undefined

Expand Down Expand Up @@ -88,7 +144,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - inner',
lineNumber: 6,
startColumnNumber: 5,
endColumnNumber: 11,
Expand All @@ -110,7 +166,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - outer',
lineNumber: 9,
startColumnNumber: 3,
endColumnNumber: 9,
Expand All @@ -132,14 +188,14 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - inner',
lineNumber: 6,
startColumnNumber: 5,
endColumnNumber: 11,
severity: Severity.Warning
},
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - outer',
lineNumber: 9,
startColumnNumber: 3,
endColumnNumber: 9,
Expand Down Expand Up @@ -197,7 +253,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - examplemacro',
lineNumber: 29,
startColumnNumber: 5,
endColumnNumber: 11,
Expand All @@ -216,7 +272,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: 'mismatch macro name in %mend statement',
message: `%mend statement has mismatched macro name, it should be 'somemacro'`,
lineNumber: 6,
startColumnNumber: 14,
endColumnNumber: 29,
Expand All @@ -233,7 +289,7 @@ describe('hasMacroNameInMend', () => {

expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend missing macro name',
message: '%mend statement is missing macro name - somemacro',
lineNumber: 4,
startColumnNumber: 5,
endColumnNumber: 11,
Expand Down
Loading

0 comments on commit cc33ebb

Please sign in to comment.