1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-07 20:50:04 +00:00

feat: add a new config attribute for allowedGremlins

This commit is contained in:
2023-01-09 17:13:19 +05:00
parent 9984a373df
commit 844f1ad154
4 changed files with 54 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import { Severity } from '../../types/Severity'
import { noGremlins } from './noGremlins'
import { noGremlins, charFromHex } from './noGremlins'
import { LintConfig } from '../../types'
describe('noTabs', () => {
it('should return an empty array when the line does not have any gremlin', () => {
@@ -8,8 +8,19 @@ describe('noTabs', () => {
})
it('should return a diagnostic array when the line contains gremlins', () => {
const line = " %put 'hello';"
const line = `${charFromHex('0x0080')} ${charFromHex(
'0x3000'
)} %put 'hello';`
const diagnostics = noGremlins.test(line, 1)
expect(diagnostics.length).toEqual(2)
})
it('should return an empty array when the line contains gremlins but those gremlins are allowed', () => {
const config = new LintConfig({ allowedGremlins: ['0x0080', '0x3000'] })
const line = `${charFromHex('0x0080')} ${charFromHex(
'0x3000'
)} %put 'hello';`
const diagnostics = noGremlins.test(line, 1, config)
expect(diagnostics.length).toEqual(0)
})
})

View File

@@ -10,15 +10,18 @@ const message = 'Line contains a gremlin'
const test = (value: string, lineNumber: number, config?: LintConfig) => {
const severity = config?.severityLevel[name] || Severity.Warning
const allowedGremlins = config?.allowedGremlins || []
const diagnostics: Diagnostic[] = []
const gremlins: any = {}
for (const [hexCode, config] of Object.entries(gremlinCharacters)) {
gremlins[charFromHex(hexCode)] = Object.assign({}, config, {
hexCode
})
for (const [hexCode, gremlinConfig] of Object.entries(gremlinCharacters)) {
if (!allowedGremlins.includes(hexCode)) {
gremlins[charFromHex(hexCode)] = Object.assign({}, gremlinConfig, {
hexCode
})
}
}
const regexpWithAllChars = new RegExp(
@@ -56,4 +59,5 @@ export const noGremlins: LineLintRule = {
test
}
const charFromHex = (hexCode: string) => String.fromCodePoint(parseInt(hexCode))
export const charFromHex = (hexCode: string) =>
String.fromCodePoint(parseInt(hexCode))