Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Offering to the ESLint gods
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoffner committed Jul 11, 2017
1 parent 604cc31 commit 0d3d897
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@ rules:
no-unused-vars:
- error
- args: none
no-useless-escape:
- off
no-regex-spaces:
- off
27 changes: 12 additions & 15 deletions lib/runners/java.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var shovel = require('../shovel'),
exec = require('child_process').exec,
execSync = require('child_process').execSync,
util = require('../util'),
tagHelpers = require('../utils/tag-helpers'),
manipulateFileSync = require('../utils/manipulate-file-sync'),
Expand All @@ -11,17 +9,16 @@ module.exports.run = function run(opts, cb) {
let buildGradle = '';

shovel.start(opts, cb, {
solutionOnly: function (runCode, fail) {
solutionOnly: function(runCode, fail) {
fs.emptydirSync(`${opts.dir}/src`);

const names = extractNames(opts.solution, 'Solution');
const solutionFile = util.codeWriteSync(null, opts.solution, `${opts.dir}/src/main/java`, names.file);

util.codeWriteSync(null, opts.solution, `${opts.dir}/src/main/java`, names.file);
util.codeWriteSync(null, javaMain(names.full), `${opts.dir}/src/test/java`, 'Start.java');

buildAndTest(runCode);
},
testIntegration: function (runCode, fail) {
testIntegration: function(runCode, fail) {
fs.emptydirSync(`${opts.dir}/src`);

const fixtures = [];
Expand Down Expand Up @@ -62,7 +59,7 @@ module.exports.run = function run(opts, cb) {

buildAndTest(runCode);
},
transformBuffer: function (buffer) {
transformBuffer: function(buffer) {
var stdout = "", stderr = "", buildLines = [];

// both types of streams will be embedded within the gradle output, so lets break them out
Expand All @@ -82,9 +79,9 @@ module.exports.run = function run(opts, cb) {
// attach build output to beginning of stdout, also attach dependencies so everyone knows whats available
// TODO: eventually we want to support this as its own buffer property, for now we are just embedding it
// within the output in case its helpful for troubleshooting
buildOutput = `Dependencies:\n\n${loadedDependencies()}\n\nTasks:\n\n`;
let buildOutput = `Dependencies:\n\n${loadedDependencies()}\n\nTasks:\n\n`;
buildOutput += buildLines.join("\n").replace(/^Start > start.*/gm, '');
buildOutput = tagHelpers.log('-Build Output', buildOutput)
buildOutput = tagHelpers.log('-Build Output', buildOutput);
buffer.stdout = buildOutput + stdout;

buffer.stderr += stderr;
Expand Down Expand Up @@ -192,7 +189,7 @@ module.exports.run = function run(opts, cb) {
.join('\n') + '\n';
}

function extractNames (code, defaultClassName) {
function extractNames(code, defaultClassName) {
const packageName = (code.match(/\bpackage\s+([A-Z|a-z](?:[a-z|A-Z|0-9|_]|\.[A-Z|a-z])*)\W/) || [])[1];
const className = (code.match(/\bclass\s+([A-Z][a-z|A-Z|0-9|_]*)\W/) || [])[1] || defaultClassName;

Expand All @@ -206,7 +203,7 @@ module.exports.run = function run(opts, cb) {

// hacky solution for starting the dynamic main class. We need to use test mode since thats currently how we
// have STDOUT/ERR setup to output anything
function javaMain (mainClass) {
function javaMain(mainClass) {
const importClass = mainClass.indexOf('.') > 0 ? `import ${mainClass};` : '';
return `
import org.junit.Test;
Expand All @@ -218,12 +215,12 @@ module.exports.run = function run(opts, cb) {
${mainClass}.main(null);
}
}
`
`;
}

// Our hacky way of running tests with our custom listener.
// TODO: this is configurable via gradle, we just need to take the time to figure that bit out.
function javaTestRunner (fixtures) {
function javaTestRunner(fixtures) {
// add any imports needed, use a set to make sure we have unique values
let imports = new Set(fixtures.filter(f => f.indexOf('.') > 0).map(f => `import ${f};\n`));
let runs = fixtures.map(f => `runner.run(${f}.class);\n`);
Expand All @@ -242,5 +239,5 @@ module.exports.run = function run(opts, cb) {
}
}
`;
};
}
}
};
4 changes: 2 additions & 2 deletions lib/utils/manipulate-file-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function manipulateFileSync(src, dest, options) {
fs.outputFileSync(dest, content, options.write);

return content;
}
};

/**
* Instead of replacing content, this method tries to determine which content should be kept
Expand All @@ -45,7 +45,7 @@ module.exports = function manipulateFileSync(src, dest, options) {
* @returns String transformed content
*/
function keep(content, options) {
const targets = options.target ? content.match(options.target) : null
const targets = options.target ? content.match(options.target) : null;
let targetContent = targets && targets.length ? targets[0] : content;

if (targetContent) {
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/split-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param regex defaults to a regex that supports `// @config: split-file File.ext`
* @returns {{root: string, files: {}, splits: number}}
*/
module.exports = function splitFiles(content, regex = /^[ \t#|\/]* ?@config[: ] ?split-file (.*$)/gm) {
module.exports = function splitFiles(content, regex = /^[ #|\/]* ?@config[: ] ?split-file (.*$)/gm) {
const parts = content.split(regex),
result = {root: '', files: {}, splits: 0};

Expand All @@ -26,4 +26,4 @@ module.exports = function splitFiles(content, regex = /^[ \t#|\/]* ?@config[: ]
});

return result;
}
};
2 changes: 1 addition & 1 deletion lib/utils/tag-helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports.log = function log(label, value) {
return `<LOG::${label}>${(value || '').replace(/\n/g, "<:LF:>")}\n`;
}
};
2 changes: 1 addition & 1 deletion lib/utils/wrap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function wrap(value) {
return Array.isArray(value) ? value : [value];
}
};

0 comments on commit 0d3d897

Please sign in to comment.