11#!/usr/bin/env node
22/* eslint-disable import/order */
33'use strict' ;
4- var debug = require ( 'debug' ) ( 'xo' ) ;
4+ const debug = require ( 'debug' ) ( 'xo' ) ;
55
66// Prefer the local installation of XO.
7- var resolveCwd = require ( 'resolve-cwd' ) ;
8- var hasFlag = require ( 'has-flag' ) ;
7+ const resolveCwd = require ( 'resolve-cwd' ) ;
8+ const hasFlag = require ( 'has-flag' ) ;
99
10- var localCLI = resolveCwd ( 'xo/cli' ) ;
10+ const localCLI = resolveCwd ( 'xo/cli' ) ;
1111
1212if ( ! hasFlag ( 'no-local' ) && localCLI && localCLI !== __filename ) {
1313 debug ( 'Using local install of XO.' ) ;
1414 require ( localCLI ) ;
1515 return ;
1616}
1717
18- var path = require ( 'path' ) ;
19- var spawn = require ( 'child_process' ) . spawn ;
20- var updateNotifier = require ( 'update-notifier' ) ;
21- var getStdin = require ( 'get-stdin' ) ;
22- var meow = require ( 'meow' ) ;
23- var formatterPretty = require ( 'eslint-formatter-pretty' ) ;
24- var xo = require ( './' ) ;
25-
26- var cli = meow ( {
27- help : [
28- 'Usage' ,
29- ' $ xo [<file|glob> ...]' ,
30- '' ,
31- 'Options' ,
32- ' --init Add XO to your project' ,
33- ' --fix Automagically fix issues' ,
34- ' --reporter Reporter to use' ,
35- ' --stdin Validate code from stdin' ,
36- ' --esnext Enforce ES2015+ rules' ,
37- ' --env Environment preset [Can be set multiple times]' ,
38- ' --global Global variable [Can be set multiple times]' ,
39- ' --ignore Additional paths to ignore [Can be set multiple times]' ,
40- ' --space Use space indent instead of tabs [Default: 2]' ,
41- ' --no-semicolon Prevent use of semicolons' ,
42- ' --plugin Include third-party plugins [Can be set multiple times]' ,
43- ' --extend Extend defaults with a custom config [Can be set multiple times]' ,
44- ' --open Open files with issues in your editor' ,
45- ' --quiet Show only errors and no warnings' ,
46- '' ,
47- 'Examples' ,
48- ' $ xo' ,
49- ' $ xo index.js' ,
50- ' $ xo *.js !foo.js' ,
51- ' $ xo --esnext --space' ,
52- ' $ xo --env=node --env=mocha' ,
53- ' $ xo --init --esnext' ,
54- ' $ xo --plugin=react' ,
55- '' ,
56- 'Tips' ,
57- ' Put options in package.json instead of using flags so other tools can read it.'
58- ]
59- } , {
18+ const path = require ( 'path' ) ;
19+ const spawn = require ( 'child_process' ) . spawn ;
20+ const updateNotifier = require ( 'update-notifier' ) ;
21+ const getStdin = require ( 'get-stdin' ) ;
22+ const meow = require ( 'meow' ) ;
23+ const formatterPretty = require ( 'eslint-formatter-pretty' ) ;
24+ const xo = require ( './' ) ;
25+
26+ const cli = meow ( `
27+ Usage
28+ $ xo [<file|glob> ...]
29+
30+ Options
31+ --init Add XO to your project
32+ --fix Automagically fix issues
33+ --reporter Reporter to use
34+ --stdin Validate code from stdin
35+ --esnext Enforce ES2015+ rules
36+ --env Environment preset [Can be set multiple times]
37+ --global Global variable [Can be set multiple times]
38+ --ignore Additional paths to ignore [Can be set multiple times]
39+ --space Use space indent instead of tabs [Default: 2]
40+ --no-semicolon Prevent use of semicolons
41+ --plugin Include third-party plugins [Can be set multiple times]
42+ --extend Extend defaults with a custom config [Can be set multiple times]
43+ --open Open files with issues in your editor
44+ --quiet Show only errors and no warnings
45+
46+ Examples
47+ $ xo
48+ $ xo index.js
49+ $ xo *.js !foo.js
50+ $ xo --esnext --space
51+ $ xo --env=node --env=mocha
52+ $ xo --init --esnext
53+ $ xo --plugin=react
54+
55+ Tips
56+ Put options in package.json instead of using flags so other tools can read it.
57+ ` , {
6058 string : [
6159 '_'
6260 ] ,
@@ -71,8 +69,8 @@ var cli = meow({
7169
7270updateNotifier ( { pkg : cli . pkg } ) . notify ( ) ;
7371
74- var input = cli . input ;
75- var opts = cli . flags ;
72+ const input = cli . input ;
73+ const opts = cli . flags ;
7674
7775function log ( report ) {
7876 // legacy
@@ -81,7 +79,7 @@ function log(report) {
8179 opts . reporter = 'compact' ;
8280 }
8381
84- var reporter = opts . reporter ? xo . getFormatter ( opts . reporter ) : formatterPretty ;
82+ const reporter = opts . reporter ? xo . getFormatter ( opts . reporter ) : formatterPretty ;
8583
8684 process . stdout . write ( reporter ( report . results ) ) ;
8785 process . exit ( report . errorCount === 0 ? 0 : 1 ) ;
@@ -92,33 +90,29 @@ function open(report) {
9290 return ;
9391 }
9492
95- var editor = process . env . EDITOR ;
93+ const editor = process . env . EDITOR ;
9694
9795 if ( ! editor ) {
98- console . log ( [
99- '' ,
100- '`open` option was used, but your $EDITOR environment variable is empty.' ,
101- 'Fix it by setting path to your editor of choice in ~/.bashrc or ~/.zshrc:' ,
102- '' ,
103- ' export EDITOR=atom' ,
104- ''
105- ] . join ( '\n' ) ) ;
96+ console . log ( `
97+ \`open\` option was used, but your $EDITOR environment variable is empty.
98+ Fix it by setting path to your editor of choice in ~/.bashrc or ~/.zshrc:
99+
100+ export EDITOR=atom
101+ ` ) ;
106102 return ;
107103 }
108104
109- var executableName = editor . split ( path . sep ) . pop ( ) ;
105+ const executableName = editor . split ( path . sep ) . pop ( ) ;
110106
111107 function lineColumn ( message ) {
112- return message . line + ':' + message . column ;
108+ return ` ${ message . line } : ${ message . column } ` ;
113109 }
114110
115- var args = [ ] ;
111+ const args = [ ] ;
116112
117113 report . results
118- . filter ( function ( file ) {
119- return file . errorCount > 0 ;
120- } )
121- . forEach ( function ( file ) {
114+ . filter ( file => file . errorCount > 0 )
115+ . forEach ( file => {
122116 // Sublime Text and Atom support opening file at exact position
123117 if ( [ 'subl' , 'atom' ] . indexOf ( executableName ) >= 0 ) {
124118 args . push ( file . filePath + ':' + lineColumn ( file . messages [ 0 ] ) ) ;
@@ -155,7 +149,7 @@ if (input[0] === '-') {
155149if ( opts . init ) {
156150 require ( 'xo-init' ) ( ) ;
157151} else if ( opts . stdin ) {
158- getStdin ( ) . then ( function ( str ) {
152+ getStdin ( ) . then ( str => {
159153 if ( opts . fix ) {
160154 console . error ( 'The `fix` option is not supported on stdin' ) ;
161155 process . exit ( 1 ) ;
@@ -169,7 +163,7 @@ if (opts.init) {
169163 log ( xo . lintText ( str , opts ) ) ;
170164 } ) ;
171165} else {
172- xo . lintFiles ( input , opts ) . then ( function ( report ) {
166+ xo . lintFiles ( input , opts ) . then ( report => {
173167 if ( opts . fix ) {
174168 xo . outputFixes ( report ) ;
175169 }
0 commit comments