11import { command } from 'yargs'
2- import { logInfo , log } from '../utilities/log'
2+ import { logInfo , log , logError } from '../utilities/log'
33import { Linter , Configuration , ILinterOptions } from 'tslint'
4- import * as fs from 'fs'
5- import chalk from 'chalk'
64import { resolve } from 'path'
7-
8- const fileName = resolve ( 'src/server/server.ts' )
9- const configurationFilename = resolve ( 'tslint.json' )
10- const options : ILinterOptions = {
11- fix : false ,
12- formatter : 'json'
13- }
14-
15- const fileContents = fs . readFileSync ( fileName , 'utf8' )
16- const linter = new Linter ( options )
17- const configuration = Configuration . findConfiguration (
18- configurationFilename ,
19- fileName
20- ) . results
21- linter . lint ( fileName , fileContents , configuration )
5+ import { readFile_ } from '../utilities/rx-fs'
6+ import { take } from 'rxjs/operators'
7+ import chalk from 'chalk'
228
239command (
2410 'lint' ,
@@ -45,19 +31,41 @@ function errors(count: number) {
4531 : chalk . underline ( ` ${ str } ` )
4632}
4733
34+ function showErrorLoadingProject ( ) {
35+ logError ( 'Could not load entry file, are you in a project directory?' )
36+ }
37+
4838function lint ( ) {
49- logInfo ( 'Linter\n' )
50- const result = linter . getResult ( )
51- log ( ` Errors: ` , errors ( result . errorCount ) )
52- log ( `Warnings: ` , warnings ( result . warningCount ) , '\n' )
53-
54- result . failures . map ( obj => obj . toJson ( ) ) . forEach ( json => {
55- log (
56- `${ json . ruleSeverity } (${ json . ruleName } ): ${ json . name } (${
57- json . startPosition . line
58- } , ${ json . startPosition . character } ): ${ json . failure } `
59- )
60- } )
61-
62- log ( '\n' )
39+ const fileName = resolve ( 'src/server/server.ts' )
40+ const configurationFilename = resolve ( 'tslint.json' )
41+ const options : ILinterOptions = {
42+ fix : false ,
43+ formatter : 'json'
44+ }
45+
46+ readFile_ ( fileName )
47+ . pipe ( take ( 1 ) )
48+ . subscribe ( fileContents => {
49+ const linter = new Linter ( options )
50+ const configuration = Configuration . findConfiguration (
51+ configurationFilename ,
52+ fileName
53+ ) . results
54+ linter . lint ( fileName , fileContents . toString ( ) , configuration )
55+
56+ logInfo ( 'Linter\n' )
57+ const result = linter . getResult ( )
58+ log ( ` Errors: ` , errors ( result . errorCount ) )
59+ log ( `Warnings: ` , warnings ( result . warningCount ) , '\n' )
60+
61+ result . failures . map ( obj => obj . toJson ( ) ) . forEach ( json => {
62+ log (
63+ `${ json . ruleSeverity } (${ json . ruleName } ): ${ json . name } (${
64+ json . startPosition . line
65+ } , ${ json . startPosition . character } ): ${ json . failure } `
66+ )
67+ } )
68+
69+ log ( '\n' )
70+ } , showErrorLoadingProject )
6371}
0 commit comments