Skip to content

Commit c37df35

Browse files
committedOct 29, 2020
standard
1 parent 93906eb commit c37df35

File tree

5 files changed

+56
-56
lines changed

5 files changed

+56
-56
lines changed
 

‎bin/cmd.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
module.exports = Cli
44

5-
var minimist = require('minimist')
6-
var getStdin = require('get-stdin')
5+
const minimist = require('minimist')
6+
const getStdin = require('get-stdin')
77

88
function Cli (opts) {
9-
var Linter = require('../').linter
10-
var standard = opts.linter || new Linter(opts)
9+
const Linter = require('../').linter
10+
const standard = opts.linter || new Linter(opts)
1111

1212
opts = Object.assign({
1313
cmd: 'standard-engine',
1414
tagline: 'JavaScript Custom Style',
1515
version: '0.0.0'
1616
}, opts)
1717

18-
var argv = minimist(process.argv.slice(2), {
18+
const argv = minimist(process.argv.slice(2), {
1919
alias: {
2020
global: 'globals',
2121
plugin: 'plugins',
@@ -83,7 +83,7 @@ Flags (advanced):
8383
return
8484
}
8585

86-
var lintOpts = {
86+
const lintOpts = {
8787
fix: argv.fix,
8888
extensions: argv.ext,
8989
globals: argv.global,
@@ -92,7 +92,7 @@ Flags (advanced):
9292
parser: argv.parser
9393
}
9494

95-
var stdinText
95+
let stdinText
9696

9797
if (argv.stdin) {
9898
getStdin().then(function (text) {
@@ -124,7 +124,7 @@ Flags (advanced):
124124
console.error('%s: %s (%s)', opts.cmd, opts.tagline, opts.homepage)
125125

126126
// Are any fixable rules present?
127-
var isFixable = result.results.some(function (result) {
127+
const isFixable = result.results.some(function (result) {
128128
return result.messages.some(function (message) {
129129
return !!message.fix
130130
})

‎index.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ module.exports.cli = require('./bin/cmd')
33

44
module.exports.linter = Linter
55

6-
var os = require('os')
7-
var path = require('path')
8-
var pkgConf = require('pkg-conf')
9-
var fs = require('fs')
6+
const os = require('os')
7+
const path = require('path')
8+
const pkgConf = require('pkg-conf')
9+
const fs = require('fs')
1010

11-
var CACHE_HOME = require('xdg-basedir').cache || os.tmpdir()
11+
const CACHE_HOME = require('xdg-basedir').cache || os.tmpdir()
1212

13-
var DEFAULT_EXTENSIONS = [
13+
const DEFAULT_EXTENSIONS = [
1414
'.js',
1515
'.jsx',
1616
'.mjs',
1717
'.cjs'
1818
]
1919

20-
var DEFAULT_IGNORE = [
20+
const DEFAULT_IGNORE = [
2121
'**/*.min.js',
2222
'coverage/**',
2323
'node_modules/**',
@@ -36,11 +36,11 @@ function Linter (opts) {
3636
this.cwd = opts.cwd || process.cwd()
3737
this.customParseOpts = opts.parseOpts
3838

39-
var m = opts.version && opts.version.match(/^(\d+)\./)
40-
var majorVersion = (m && m[1]) || '0'
39+
const m = opts.version && opts.version.match(/^(\d+)\./)
40+
const majorVersion = (m && m[1]) || '0'
4141

4242
// Example cache location: ~/.cache/standard/v12/
43-
var cacheLocation = path.join(CACHE_HOME, this.cmd, `v${majorVersion}/`)
43+
const cacheLocation = path.join(CACHE_HOME, this.cmd, `v${majorVersion}/`)
4444

4545
this.eslintConfig = Object.assign({
4646
cache: true,
@@ -80,7 +80,7 @@ Linter.prototype.lintTextSync = function (text, opts) {
8080

8181
Linter.prototype.lintText = function (text, opts, cb) {
8282
if (typeof opts === 'function') return this.lintText(text, null, opts)
83-
var result
83+
let result
8484
try {
8585
result = this.lintTextSync(text, opts)
8686
} catch (err) {
@@ -105,14 +105,14 @@ Linter.prototype.lintText = function (text, opts, cb) {
105105
* @param {function(Error, Object)} cb callback
106106
*/
107107
Linter.prototype.lintFiles = function (files, opts, cb) {
108-
var self = this
108+
const self = this
109109
if (typeof opts === 'function') return self.lintFiles(files, null, opts)
110110
opts = self.parseOpts(opts)
111111

112112
if (typeof files === 'string') files = [files]
113113
if (files.length === 0) files = ['.']
114114

115-
var result
115+
let result
116116
try {
117117
result = new self.eslint.CLIEngine(opts.eslintConfig).executeOnFiles(files)
118118
} catch (err) {
@@ -127,7 +127,7 @@ Linter.prototype.lintFiles = function (files, opts, cb) {
127127
}
128128

129129
Linter.prototype.parseOpts = function (opts) {
130-
var self = this
130+
const self = this
131131

132132
opts = {
133133
eslintConfig: { ...self.eslintConfig },
@@ -148,8 +148,8 @@ Linter.prototype.parseOpts = function (opts) {
148148
opts.eslintConfig.cwd = opts.cwd
149149
opts.eslintConfig.fix = opts.fix
150150

151-
var packageOpts = {}
152-
var rootPath = null
151+
let packageOpts = {}
152+
let rootPath = null
153153

154154
if (opts.usePackageJson || opts.useGitIgnore) {
155155
packageOpts = pkgConf.sync(self.cmd, { cwd: opts.cwd })
@@ -199,9 +199,9 @@ Linter.prototype.parseOpts = function (opts) {
199199
setParser(packageOpts.parser || opts.parser)
200200

201201
if (self.customParseOpts) {
202-
var rootDir
202+
let rootDir
203203
if (opts.usePackageJson) {
204-
var filePath = pkgConf.filepath(packageOpts)
204+
const filePath = pkgConf.filepath(packageOpts)
205205
rootDir = filePath ? path.dirname(filePath) : opts.cwd
206206
} else {
207207
rootDir = opts.cwd

‎test/api.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var eslint = require('eslint')
2-
var Linter = require('../').linter
3-
var path = require('path')
4-
var test = require('tape')
1+
const eslint = require('eslint')
2+
const Linter = require('../').linter
3+
const path = require('path')
4+
const test = require('tape')
55

66
function getStandard () {
77
return new Linter({
@@ -14,7 +14,7 @@ function getStandard () {
1414

1515
test('api: lintFiles', function (t) {
1616
t.plan(3)
17-
var standard = getStandard()
17+
const standard = getStandard()
1818
standard.lintFiles([], { cwd: path.join(__dirname, '../bin') }, function (err, result) {
1919
t.error(err, 'no error while linting')
2020
t.equal(typeof result, 'object', 'result is an object')
@@ -24,7 +24,7 @@ test('api: lintFiles', function (t) {
2424

2525
test('api: lintText', function (t) {
2626
t.plan(3)
27-
var standard = getStandard()
27+
const standard = getStandard()
2828
standard.lintText('console.log("hi there")\n', function (err, result) {
2929
t.error(err, 'no error while linting')
3030
t.equal(typeof result, 'object', 'result is an object')
@@ -34,24 +34,24 @@ test('api: lintText', function (t) {
3434

3535
test('api: lintTextSync', function (t) {
3636
t.plan(2)
37-
var standard = getStandard()
38-
var result = standard.lintTextSync('console.log("hi there")\n')
37+
const standard = getStandard()
38+
const result = standard.lintTextSync('console.log("hi there")\n')
3939
t.equal(typeof result, 'object', 'result is an object')
4040
t.equal(result.errorCount, 1, 'should have used single quotes')
4141
})
4242

4343
test('api: parseOpts -- avoid self.eslintConfig parser mutation', function (t) {
4444
t.plan(2)
45-
var standard = getStandard()
46-
var opts = standard.parseOpts({ parser: 'blah' })
45+
const standard = getStandard()
46+
const opts = standard.parseOpts({ parser: 'blah' })
4747
t.equal(opts.parser, 'blah')
4848
t.equal(standard.eslintConfig.parser, undefined)
4949
})
5050

5151
test('api: parseOpts -- avoid self.eslintConfig global mutation', function (t) {
5252
t.plan(2)
53-
var standard = getStandard()
54-
var opts = standard.parseOpts({ globals: ['what'] })
53+
const standard = getStandard()
54+
const opts = standard.parseOpts({ globals: ['what'] })
5555
t.deepEqual(opts.globals, ['what'])
5656
t.deepEqual(standard.eslintConfig.globals, [])
5757
})

‎test/clone.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
22

3-
var crossSpawn = require('cross-spawn')
4-
var fs = require('fs')
5-
var path = require('path')
6-
var test = require('tape')
3+
const crossSpawn = require('cross-spawn')
4+
const fs = require('fs')
5+
const path = require('path')
6+
const test = require('tape')
77

8-
var GIT = 'git'
9-
var STANDARD = path.join(__dirname, 'lib', 'standard-cmd.js')
10-
var TMP = path.join(__dirname, '..', 'tmp')
8+
const GIT = 'git'
9+
const STANDARD = path.join(__dirname, 'lib', 'standard-cmd.js')
10+
const TMP = path.join(__dirname, '..', 'tmp')
1111

1212
const pkg = {
1313
name: 'standard',
@@ -19,9 +19,9 @@ test('test `standard` repo', function (t) {
1919

2020
fs.mkdirSync(TMP, { recursive: true })
2121

22-
var name = pkg.name
23-
var url = pkg.repo + '.git'
24-
var folder = path.join(TMP, name)
22+
const name = pkg.name
23+
const url = pkg.repo + '.git'
24+
const folder = path.join(TMP, name)
2525
fs.access(path.join(TMP, name), fs.R_OK | fs.W_OK, function (err) {
2626
downloadPackage(function (err) {
2727
if (err) throw err
@@ -34,26 +34,26 @@ test('test `standard` repo', function (t) {
3434
}
3535

3636
function gitClone (cb) {
37-
var args = ['clone', '--depth', 1, url, path.join(TMP, name)]
37+
const args = ['clone', '--depth', 1, url, path.join(TMP, name)]
3838
spawn(GIT, args, { stdio: 'ignore' }, function (err) {
3939
if (err) err.message += ' (git clone) (' + name + ')'
4040
cb(err)
4141
})
4242
}
4343

4444
function gitPull (cb) {
45-
var args = ['pull']
45+
const args = ['pull']
4646
spawn(GIT, args, { cwd: folder, stdio: 'ignore' }, function (err) {
4747
if (err) err.message += ' (git pull) (' + name + ')'
4848
cb(err)
4949
})
5050
}
5151

5252
function runStandard () {
53-
var args = ['--verbose']
53+
const args = ['--verbose']
5454
if (pkg.args) args.push.apply(args, pkg.args)
5555
spawn(STANDARD, args, { cwd: folder }, function (err) {
56-
var str = name + ' (' + pkg.repo + ')'
56+
const str = name + ' (' + pkg.repo + ')'
5757
if (err) { t.fail(str) } else { t.pass(str) }
5858
})
5959
}
@@ -63,7 +63,7 @@ test('test `standard` repo', function (t) {
6363
function spawn (command, args, opts, cb) {
6464
if (!opts.stdio) opts.stdio = 'inherit'
6565

66-
var child = crossSpawn(command, args, opts)
66+
const child = crossSpawn(command, args, opts)
6767
child.on('error', cb)
6868
child.on('close', function (code) {
6969
if (code !== 0) return cb(new Error('non-zero exit code: ' + code))

‎test/lib/standard-cmd.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
2-
var path = require('path')
3-
var eslint = require('eslint')
4-
var opts = {
2+
const path = require('path')
3+
const eslint = require('eslint')
4+
const opts = {
55
cmd: 'pocketlint',
66
version: '0.0.0',
77
eslint,

0 commit comments

Comments
 (0)
Please sign in to comment.