1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-07 12:40:05 +00:00

feat(lint): implement v1 with 3 rules - trailing spaces, encoded passwords and Doxygen header

This commit is contained in:
Krishna Acondy
2021-03-22 20:23:10 +00:00
parent f3d7d38984
commit bf23963127
31 changed files with 5603 additions and 0 deletions

5
src/types/Diagnostic.ts Normal file
View File

@@ -0,0 +1,5 @@
export interface Diagnostic {
lineNumber: number
columnNumber: number
warning: string
}

View File

@@ -0,0 +1,61 @@
import { LintConfig } from './LintConfig'
import { LintRuleType } from './LintRuleType'
describe('LintConfig', () => {
it('should create an empty instance', () => {
const config = new LintConfig()
expect(config).toBeTruthy()
expect(config.fileLintRules.length).toEqual(0)
expect(config.lineLintRules.length).toEqual(0)
})
it('should create an instance with the noTrailingSpaces flag set', () => {
const config = new LintConfig({ noTrailingSpaces: true })
expect(config).toBeTruthy()
expect(config.lineLintRules.length).toEqual(1)
expect(config.lineLintRules[0].name).toEqual('noTrailingSpaces')
expect(config.lineLintRules[0].type).toEqual(LintRuleType.Line)
expect(config.fileLintRules.length).toEqual(0)
})
it('should create an instance with the noEncodedPasswords flag set', () => {
const config = new LintConfig({ noEncodedPasswords: true })
expect(config).toBeTruthy()
expect(config.lineLintRules.length).toEqual(1)
expect(config.lineLintRules[0].name).toEqual('noEncodedPasswords')
expect(config.lineLintRules[0].type).toEqual(LintRuleType.Line)
expect(config.fileLintRules.length).toEqual(0)
})
it('should create an instance with the hasDoxygenHeader flag set', () => {
const config = new LintConfig({ hasDoxygenHeader: true })
expect(config).toBeTruthy()
expect(config.lineLintRules.length).toEqual(0)
expect(config.fileLintRules.length).toEqual(1)
expect(config.fileLintRules[0].name).toEqual('hasDoxygenHeader')
expect(config.fileLintRules[0].type).toEqual(LintRuleType.File)
})
it('should create an instance with all flags set', () => {
const config = new LintConfig({
noTrailingSpaces: true,
noEncodedPasswords: true,
hasDoxygenHeader: true
})
expect(config).toBeTruthy()
expect(config.lineLintRules.length).toEqual(2)
expect(config.lineLintRules[0].name).toEqual('noTrailingSpaces')
expect(config.lineLintRules[0].type).toEqual(LintRuleType.Line)
expect(config.lineLintRules[1].name).toEqual('noEncodedPasswords')
expect(config.lineLintRules[1].type).toEqual(LintRuleType.Line)
expect(config.fileLintRules.length).toEqual(1)
expect(config.fileLintRules[0].name).toEqual('hasDoxygenHeader')
expect(config.fileLintRules[0].type).toEqual(LintRuleType.File)
})
})

23
src/types/LintConfig.ts Normal file
View File

@@ -0,0 +1,23 @@
import { hasDoxygenHeader } from '../rules/hasDoxygenHeader'
import { noEncodedPasswords } from '../rules/noEncodedPasswords'
import { noTrailingSpaces } from '../rules/noTrailingSpaces'
import { FileLintRule, LineLintRule } from './LintRule'
export class LintConfig {
readonly lineLintRules: LineLintRule[] = []
readonly fileLintRules: FileLintRule[] = []
constructor(json?: any) {
if (json?.noTrailingSpaces) {
this.lineLintRules.push(noTrailingSpaces)
}
if (json?.noEncodedPasswords) {
this.lineLintRules.push(noEncodedPasswords)
}
if (json?.hasDoxygenHeader) {
this.fileLintRules.push(hasDoxygenHeader)
}
}
}

19
src/types/LintRule.ts Normal file
View File

@@ -0,0 +1,19 @@
import { Diagnostic } from './Diagnostic'
import { LintRuleType } from './LintRuleType'
export interface LintRule {
type: LintRuleType
name: string
description: string
warning: string
test: (value: string, lineNumber: number) => Diagnostic[]
}
export interface LineLintRule extends LintRule {
type: LintRuleType.Line
}
export interface FileLintRule extends LintRule {
type: LintRuleType.File
test: (value: string) => Diagnostic[]
}

View File

@@ -0,0 +1,4 @@
export enum LintRuleType {
Line,
File
}