-
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.
feat(lint): add rule for indentation multiple
- Loading branch information
1 parent
8fc3c39
commit f1adcb8
Showing
10 changed files
with
188 additions
and
53 deletions.
There are no files selected for viewing
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
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,18 @@ | ||
|
||
|
||
%macro mf_getuniquelibref(prefix=mclib,maxtries=1000); | ||
%local x libref; | ||
%let x={SAS002}; | ||
%do x=0 %to &maxtries; | ||
%if %sysfunc(libref(&prefix&x)) ne 0 %then %do; | ||
%let libref=&prefix&x; | ||
%let rc=%sysfunc(libname(&libref,%sysfunc(pathname(work)))); | ||
%if &rc %then %put %sysfunc(sysmsg()); | ||
&prefix&x | ||
%*put &sysmacroname: Libref &libref assigned as WORK and returned; | ||
%return; | ||
%end; | ||
%end; | ||
%put unable to find available libref in range &prefix.0-&maxtries; | ||
%mend; | ||
|
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
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
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,68 @@ | ||
import { LintConfig, Severity } from '../types' | ||
import { indentationMultiple } from './indentationMultiple' | ||
|
||
describe('indentationMultiple', () => { | ||
it('should return an empty array when the line is indented by two spaces', () => { | ||
const line = " %put 'hello';" | ||
const config = new LintConfig({ indentationMultiple: 2 }) | ||
expect(indentationMultiple.test(line, 1, config)).toEqual([]) | ||
}) | ||
|
||
it('should return an empty array when the line is indented by a multiple of 2 spaces', () => { | ||
const line = " %put 'hello';" | ||
const config = new LintConfig({ indentationMultiple: 2 }) | ||
expect(indentationMultiple.test(line, 1, config)).toEqual([]) | ||
}) | ||
|
||
it('should return an empty array when the line is not indented', () => { | ||
const line = "%put 'hello';" | ||
const config = new LintConfig({ indentationMultiple: 2 }) | ||
expect(indentationMultiple.test(line, 1, config)).toEqual([]) | ||
}) | ||
|
||
it('should return an array with a single diagnostic when the line is indented incorrectly', () => { | ||
const line = " %put 'hello';" | ||
const config = new LintConfig({ indentationMultiple: 2 }) | ||
expect(indentationMultiple.test(line, 1, config)).toEqual([ | ||
{ | ||
message: `Line has incorrect indentation - 3 spaces`, | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
} | ||
]) | ||
}) | ||
|
||
it('should return an array with a single diagnostic when the line is indented incorrectly', () => { | ||
const line = " %put 'hello';" | ||
const config = new LintConfig({ indentationMultiple: 3 }) | ||
expect(indentationMultiple.test(line, 1, config)).toEqual([ | ||
{ | ||
message: `Line has incorrect indentation - 2 spaces`, | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
} | ||
]) | ||
}) | ||
|
||
it('should fall back to a default of 2 spaces', () => { | ||
const line = " %put 'hello';" | ||
expect(indentationMultiple.test(line, 1)).toEqual([ | ||
{ | ||
message: `Line has incorrect indentation - 1 space`, | ||
lineNumber: 1, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
} | ||
]) | ||
}) | ||
|
||
it('should return an empty array for lines within the default indentation', () => { | ||
const line = " %put 'hello';" | ||
expect(indentationMultiple.test(line, 1)).toEqual([]) | ||
}) | ||
}) |
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,37 @@ | ||
import { LintConfig } from '../types' | ||
import { LineLintRule } from '../types/LintRule' | ||
import { LintRuleType } from '../types/LintRuleType' | ||
import { Severity } from '../types/Severity' | ||
|
||
const name = 'indentationMultiple' | ||
const description = 'Ensure indentation by a multiple of the configured number.' | ||
const message = 'Line has incorrect indentation' | ||
const test = (value: string, lineNumber: number, config?: LintConfig) => { | ||
if (!value.startsWith(' ')) return [] | ||
|
||
const indentationMultiple = config?.indentationMultiple || 2 | ||
const numberOfSpaces = value.search(/\S|$/) | ||
if (numberOfSpaces % indentationMultiple === 0) return [] | ||
return [ | ||
{ | ||
message: `${message} - ${numberOfSpaces} ${ | ||
numberOfSpaces === 1 ? 'space' : 'spaces' | ||
}`, | ||
lineNumber, | ||
startColumnNumber: 1, | ||
endColumnNumber: 1, | ||
severity: Severity.Warning | ||
} | ||
] | ||
} | ||
|
||
/** | ||
* Lint rule that checks if a line is indented by a multiple of the configured indentation multiple. | ||
*/ | ||
export const indentationMultiple: LineLintRule = { | ||
type: LintRuleType.Line, | ||
name, | ||
description, | ||
message, | ||
test | ||
} |
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
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
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