Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# eslint-parallel
Tiny eslint wrapper to allow executing javascript linting in parallel.

This is a fork of the original project, in order to update the version of eslint being used.
As there are a number of PRs that have been waiting to be merged for a while in the original,
I decided to publish this as I need it.

## Install

```command
Expand All @@ -17,6 +21,10 @@ node_modules/.bin/eslint-parallel src/js/**

See [ESLint Docs](http://eslint.org/docs/user-guide/command-line-interface) for all the options

### CPU Count

If you need to override the CPU count (e.g. on CI), you can use the environment variable `ESLINT_CPU_COUNT`.

## API Usage

```javascript
Expand Down
9 changes: 9 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
["@babel/preset-env", {
"targets": {
"node": true
},
"loose": true
}]]
}
29 changes: 17 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
{
"name": "eslint-parallel",
"version": "1.0.0",
"name": "@chooban/eslint-parallel",
"version": "2.0.1",
"main": "lib/linter.js",
"description": "Tiny eslint wrapper to allow executing javascript linting in parallel.",
"author": "Alan Souza",
"contributors": [
"Ross Hendry <[email protected]>"
],
"homepage": "http://eslint.org",
"bugs": "https://github.com/alansouzati/eslint-parallel/issues",
"bugs": "https://github.com/chooban/eslint-parallel/issues",
"license": "Apache-2.0",
"private": false,
"repository": {
"type": "git",
"url": "https://github.com/alansouzati/eslint-parallel.git"
"url": "https://github.com/chooban/eslint-parallel.git"
},
"bin": {
"eslint-parallel": "./lib/cli.js"
},
"dependencies": {
"babel-core": "^6.20.0",
"chalk": "^1.1.3",
"eslint": "^5.0.0",
"@babel/register": "^7.10.5",
"chalk": "^4.1.0",
"strip-ansi": "^6.0.0",
"text-table": "^0.2.0"
},
"devDependencies": {
"babel-cli": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-preset-es2015": "^6.9.0"
"@babel/cli": "^7.10.5",
"@babel/core": "^7.10.5",
"@babel/preset-env": "^7.10.4",
"eslint": "^7.5.0"
},
"peerDependencies": {
"eslint": ">=5.0.0"
"eslint": ">=7.0.0"
},
"scripts": {
"build": "node_modules/.bin/babel src --out-dir lib --copy-files --loose-mode",
"build": "node_modules/.bin/babel src --out-dir lib --copy-files",
"prepublishOnly": "npm run build"
}
}
9 changes: 5 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
require('babel-register');
require('@babel/register');

/**
* NPM dependencies
Expand Down Expand Up @@ -31,7 +31,8 @@ function translateOptions(cliOptions) {
cacheFile: cliOptions.cacheFile,
cacheLocation: cliOptions.cacheLocation,
fix: cliOptions.fix,
allowInlineConfig: cliOptions.inlineConfig
allowInlineConfig: cliOptions.inlineConfig,
reportUnusedDisableDirectives: cliOptions.reportUnusedDisableDirectives
};
}

Expand All @@ -44,10 +45,10 @@ if (cliOptions.version) {
} else {
new Linter(translateOptions(cliOptions)).execute(cliOptions._).then(
(result) => {
const failed = result.errorCount || result.warningCount;
const failed = result.errorCount || (!cliOptions.quiet && result.warningCount);
console.log(formatTotal(result));

if (failed) {
console.log(formatTotal(result));
process.exit(1);
} else {
process.exit(0);
Expand Down
10 changes: 5 additions & 5 deletions src/formatter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import chalk from 'chalk';
import stripAnsi from 'strip-ansi';
import table from 'text-table';

export function formatTotal(results) {
const total = results.errorCount + results.warningCount;
const problemLabel = total && total === 1 ? 'problem' : 'problems';
const errorLabel = total && total === 1 ? 'error' : 'errors';
const warningLabel = total && total === 1 ? 'warning' : 'warnings';
return chalk.red.bold(
`\u2716 ${total} ${problemLabel} (${results.errorCount} ${errorLabel}, ${results.warningCount} ${warningLabel})\n`
);
const text = `${total} ${problemLabel} (${results.errorCount} ${errorLabel}, ${results.warningCount} ${warningLabel})\n`;
return results.errorCount > 0 ? chalk.red.bold(`\u2716 ${text}`) : results.warningCount > 0 ? chalk.yellow.bold(`\u2716 ${text}`) : ` ${text}`;
}

export function formatResults(results) {
Expand Down Expand Up @@ -46,13 +46,13 @@ export function formatResults(results) {
{
align: ['', 'r', 'l'],
stringLength(str) {
return chalk.stripColor(str).length;
return stripAnsi(str).length;
}
}
).split('\n').map(el => el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.dim(`${p1}:${p2}`))).join('\n')}\n\n`;
});

return output;
};
}

export default { formatResults, formatTotal };
28 changes: 21 additions & 7 deletions src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
**/
import fs from 'fs';
import path from 'path';
import os from 'os';
import { fork } from 'child_process';

/**
* NPM dependencies
**/
import { CLIEngine } from 'eslint';
import { listFilesToProcess } from 'eslint/lib/util/glob-utils.js';
import glob from 'glob';
import { FileEnumerator } from 'eslint/lib/cli-engine/file-enumerator';
import { CascadingConfigArrayFactory } from 'eslint/lib/cli-engine/cascading-config-array-factory';

/**
* Local dependencies
**/
import { formatResults } from './formatter';

const cpuCount = os.cpus().length;
const cpuCount = Number(process.env.ESLINT_CPU_COUNT) ?? os.cpus().length;

function listFilesToProcess(patterns, options) {
return Array.from(
new FileEnumerator({
...options,
configArrayFactory: new CascadingConfigArrayFactory({
...options,

// Disable "No Configuration Found" error.
useEslintrc: false
})
}).iterateFiles(patterns),
({ filePath, ignored }) => ({ filename: filePath, ignored })
);
}

function hasEslintCache(options) {
const cacheLocation = (
Expand Down Expand Up @@ -86,7 +100,7 @@ export default class Linter {
errorCount: 0,
warningCount: 0
};
const chunckedPromises = [];
const chunkedPromises = [];
const chunkSize = Math.ceil(files.length / cpuCount);
for (let i = 0; i < files.length; i += chunkSize) {
const chunkedPaths = files.slice(i, i + chunkSize);
Expand All @@ -97,9 +111,9 @@ export default class Linter {
totalCount.errorCount += report.errorCount;
totalCount.warningCount += report.warningCount;
});
chunckedPromises.push(chunckedPromise);
chunkedPromises.push(chunckedPromise);
}
Promise.all(chunckedPromises).then(() => {
Promise.all(chunkedPromises).then(() => {
resolve(totalCount);
});
} else {
Expand Down
Loading