Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share CLIEngine per worker #61

Merged
merged 1 commit into from
Jul 6, 2017
Merged
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: 1 addition & 2 deletions src/LintRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ export default class LintRunner {
this.workers = promisify(workers);
}

run(config, files) {
run(files) {
const that = this;
return Promise.all(
files.map((file) => {
return that.workers({
config: config,
fileArg: file
});
})
Expand Down
13 changes: 4 additions & 9 deletions src/LintWorker.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { CLIEngine } from 'eslint';

const lintFile = (config, fileArg) => {
const eslint = new CLIEngine({ cwd: process.cwd() });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to instantiate the cwd as process.cwd()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, technically no - since the code in CLIEngine already does this


const lintFile = (fileArg) => {
if (!Array.isArray(fileArg)) {
fileArg = [fileArg];
}

const eslint = new CLIEngine(config);
const report = eslint.executeOnFiles(fileArg);

// autofix if possible (experimental)
if (config.fix) {
CLIEngine.outputFixes(report);
}
return report.results;
};

module.exports = (options, callback) => {
const results = lintFile(options.config, options.fileArg);
const results = lintFile(options.fileArg);
callback(null, results);
};
2 changes: 1 addition & 1 deletion src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default class Server {
}
this.filesToProcess++;
const that = this;
this.lintRunner.run({ cwd: ROOT_DIR }, [file])
this.lintRunner.run([file])
.then(function(results) {
const record = results.records[0];
if (record) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const check = (options) => {
const rcDir = path.dirname(rcPath);
const eslint = new CLIEngine({ cwd: rcDir });

const filePaths = flatten(paths.map(globPath => glob.sync(globPath, { cwd: rcDir })));
const filePaths = flatten(paths.map(globPath => glob.sync(globPath, { cwd: rcDir, absolute: true })));
// filter out the files that we tell eslint to ignore
const nonIgnoredFilePaths = filePaths.filter((filePath) => {
return !(eslint.isPathIgnored(path.join(rcDir, filePath)) || filePath.indexOf('eslint') !== -1);
return !(eslint.isPathIgnored(filePath) || filePath.indexOf('eslint') !== -1);
});

lintRunner.run({ cwd: rcDir }, nonIgnoredFilePaths)
lintRunner.run(nonIgnoredFilePaths)
.then((results) => {
const records = results.records.filter((record) => {
return record.warningCount > 0 || record.errorCount > 0;
Expand Down