UNPKG

1.12 kBJavaScriptView Raw
1#!/usr/bin/env node
2// Copyright IBM Corp. and LoopBack contributors 2019,2020. All Rights Reserved.
3// Node module: @loopback/build
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6
7/*
8========
9
10Usage:
11 node ./bin/run-eslint
12
13========
14*/
15
16'use strict';
17
18function run(argv, options) {
19 const utils = require('./utils');
20
21 const eslintOpts = argv.slice(2);
22
23 const isConfigSet = utils.isOptionSet(eslintOpts, '-c', '--config');
24 const isExtSet = utils.isOptionSet(eslintOpts, '--ext');
25
26 const eslintConfigFile = isConfigSet
27 ? null
28 : utils.getConfigFile('.eslintrc.js', '.eslintrc.json');
29
30 const eslintIgnoreFile = utils.getConfigFile('.eslintignore');
31
32 const args = [];
33 if (eslintConfigFile) {
34 args.push('-c', eslintConfigFile);
35 }
36 if (eslintIgnoreFile) {
37 args.push('--ignore-path', eslintIgnoreFile);
38 }
39
40 if (!isExtSet) {
41 args.push('--ext', '.js,.ts');
42 }
43 args.push(...eslintOpts);
44
45 return utils.runCLI('eslint/bin/eslint', args, options);
46}
47
48module.exports = run;
49if (require.main === module) run(process.argv);