mirror of
https://github.com/sasjs/lint.git
synced 2026-01-14 15:50:05 +00:00
chore(*): organise rules into folders by type
This commit is contained in:
41
src/rules/line/indentationMultiple.ts
Normal file
41
src/rules/line/indentationMultiple.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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 = isNaN(config?.indentationMultiple as number)
|
||||
? 2
|
||||
: config!.indentationMultiple
|
||||
|
||||
if (indentationMultiple === 0) return []
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user