UNPKG

1.81 kBJavaScriptView Raw
1"use strict";
2
3var _path = _interopRequireDefault(require("path"));
4
5var _crossSpawn = _interopRequireDefault(require("cross-spawn"));
6
7var _yargsParser = _interopRequireDefault(require("yargs-parser"));
8
9var _utils = require("../utils");
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13const unnecessaryArgumentsCount = 2;
14let args = process.argv.slice(unnecessaryArgumentsCount);
15
16const here = p => _path.default.join(__dirname, p);
17
18const hereRelative = p => here(p).replace(process.cwd(), ".");
19
20const parsedArgs = (0, _yargsParser.default)(args);
21const useBuiltinConfig = !args.includes("--config") && !(0, _utils.hasFile)(".eslintrc") && !(0, _utils.hasFile)(".eslintrc.js") && !(0, _utils.hasPkgProp)("eslintConfig");
22const config = useBuiltinConfig ? ["--config", hereRelative("../config/eslintrc.js")] : [];
23const cache = args.includes("--no-cache") ? [] : ["--cache"];
24const filesGiven = parsedArgs._.length > 0;
25const filesToApply = filesGiven ? [] : ["."];
26const extensions = ["--ext", ".js,.ts"];
27const cacheLocation = ["--cache-location", "node_modules/.cache/.eslintcache"];
28
29const isLintable = file => file.endsWith(".js") || file.endsWith(".ts");
30
31if (filesGiven) {
32 // we need to take all the flag-less arguments (the files that should be linted)
33 // and filter out the ones that aren't js files. Otherwise json or css files
34 // may be passed through
35 args = args.filter(a => !parsedArgs._.includes(a) || isLintable(a));
36}
37
38const lintArguments = [...config, ...extensions, ...cacheLocation, ...cache, ...args, ...filesToApply];
39(0, _utils.logScriptMessage)("LINT");
40
41const result = _crossSpawn.default.sync((0, _utils.resolveBin)("eslint"), lintArguments, {
42 stdio: "inherit"
43});
44
45process.exit(result.status);
46//# sourceMappingURL=lint.js.map
\No newline at end of file