mirror of
https://github.com/sasjs/lint.git
synced 2025-12-10 17:34:36 +00:00
39 lines
976 B
TypeScript
39 lines
976 B
TypeScript
import { LintConfig } from '../../types'
|
|
import { LineLintRule } from '../../types/LintRule'
|
|
import { LintRuleType } from '../../types/LintRuleType'
|
|
import { Severity } from '../../types/Severity'
|
|
import { getIndicesOf } from '../../utils'
|
|
|
|
const name = 'noTabs'
|
|
const alias = 'noTabIndentation'
|
|
const description = 'Disallow indenting with tabs.'
|
|
const message = 'Line contains a tab character (09x)'
|
|
|
|
const test = (value: string, lineNumber: number, config?: LintConfig) => {
|
|
const severity =
|
|
config?.severityLevel[name] ||
|
|
config?.severityLevel[alias] ||
|
|
Severity.Warning
|
|
|
|
const indices = getIndicesOf('\t', value)
|
|
|
|
return indices.map((index) => ({
|
|
message,
|
|
lineNumber,
|
|
startColumnNumber: index + 1,
|
|
endColumnNumber: index + 2,
|
|
severity
|
|
}))
|
|
}
|
|
|
|
/**
|
|
* Lint rule that checks if a given line of text is indented with a tab.
|
|
*/
|
|
export const noTabs: LineLintRule = {
|
|
type: LintRuleType.Line,
|
|
name,
|
|
description,
|
|
message,
|
|
test
|
|
}
|