Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './serve'
import './favicon'
import './config'
import './update'
import './lint'
import { argv } from 'yargs'

argv
63 changes: 63 additions & 0 deletions src/commands/lint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { command } from 'yargs'
import { logInfo, log } from '../utilities/log'
import { Linter, Configuration, ILinterOptions } from 'tslint'
import * as fs from 'fs'
import chalk from 'chalk'
import { resolve } from 'path'

const fileName = resolve('src/server/server.ts')
const configurationFilename = resolve('tslint.json')
const options: ILinterOptions = {
fix: false,
formatter: 'json'
}

const fileContents = fs.readFileSync(fileName, 'utf8')
const linter = new Linter(options)
const configuration = Configuration.findConfiguration(
configurationFilename,
fileName
).results
linter.lint(fileName, fileContents, configuration)

command(
'lint',
'check your code quality',
args => {
return args
},
args => {
lint()
}
)

function warnings(count: number) {
const str = count.toString()
return count > 0
? chalk.underline(chalk.bgYellow(` ${str} `))
: chalk.underline(` ${str} `)
}

function errors(count: number) {
const str = count.toString()
return count > 0
? chalk.underline(chalk.bgRed(` ${str} `))
: chalk.underline(` ${str} `)
}

function lint() {
logInfo('Linter\n')
const result = linter.getResult()
log(` Errors: `, errors(result.errorCount))
log(`Warnings: `, warnings(result.warningCount), '\n')

result.failures.map(obj => obj.toJson()).forEach(json => {
log(
`${json.ruleSeverity}(${json.ruleName}): ${json.name} (${
json.startPosition.line
}, ${json.startPosition.character}): ${json.failure}`
)
})

log('\n')
}
2 changes: 1 addition & 1 deletion src/utilities/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function logErrorWithPrefix(msg: any) {
log(chalk.bgRedBright(`Error: ${msg}`))
}

export function logInfo(msg: any) {
export function logInfo(msg: string) {
log(chalk.blue(msg))
}

Expand Down