1
0
mirror of https://github.com/sasjs/lint.git synced 2025-12-10 17:34:36 +00:00
Files
lint/src/rules/line/noTrailingSpaces.ts

39 lines
989 B
TypeScript

import { LintConfig } from '../../types'
import { LineLintRule } from '../../types/LintRule'
import { LintRuleType } from '../../types/LintRuleType'
import { Severity } from '../../types/Severity'
const name = 'noTrailingSpaces'
const description = 'Disallow trailing spaces on lines.'
const message = 'Line contains trailing spaces'
const test = (value: string, lineNumber: number, config?: LintConfig) => {
const severity = config?.severityLevel[name] || Severity.Warning
return value.trimEnd() === value
? []
: [
{
message,
lineNumber,
startColumnNumber: value.trimEnd().length + 1,
endColumnNumber: value.length,
severity
}
]
}
const fix = (value: string) => value.trimEnd()
/**
* Lint rule that checks for the presence of trailing space(s) in a given line of text.
*/
export const noTrailingSpaces: LineLintRule = {
type: LintRuleType.Line,
name,
description,
message,
test,
fix
}