Skip to content

Commit

Permalink
Increased eslint strictness some more
Browse files Browse the repository at this point in the history
  • Loading branch information
redien committed May 30, 2016
1 parent a2f38eb commit b69cff6
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 120 deletions.
51 changes: 28 additions & 23 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ rules:
max-nested-callbacks: error
max-params: error
max-statements: 'off'
max-statements-per-line: 'off'
max-statements-per-line: error
new-parens: error
newline-after-var: 'off'
newline-before-return: 'off'
newline-per-chained-call: 'off'
no-alert: 'off'
newline-per-chained-call: error
no-alert: error
no-array-constructor: error
no-bitwise: 'off'
no-bitwise: error
no-caller: error
no-catch-shadow: error
no-confusing-arrow: error
Expand All @@ -88,19 +88,20 @@ rules:
no-div-regex: error
no-duplicate-imports: error
no-else-return: 'off'
no-empty-function: 'off'
no-eq-null: 'off'
no-empty-function: error
no-eq-null: error
no-eval:
- error
- allowIndirect: true
no-extend-native: 'off'
no-extra-semi: error
no-extra-bind: error
no-extra-label: error
no-extra-parens: 'off'
no-extra-parens: error
no-floating-decimal: error
no-implicit-globals: 'off'
no-implied-eval: 'off'
no-inline-comments: 'off'
no-implicit-globals: error
no-implied-eval: error
no-inline-comments: error
no-inner-declarations:
- error
- functions
Expand All @@ -113,7 +114,7 @@ rules:
no-loop-func: error
no-magic-numbers: 'off'
no-mixed-requires: error
no-multi-spaces: 'off'
no-multi-spaces: error
no-multi-str: error
no-multiple-empty-lines: error
no-native-reassign: error
Expand Down Expand Up @@ -142,19 +143,19 @@ rules:
no-sequences: error
no-shadow: 'off'
no-shadow-restricted-names: error
no-spaced-func: 'off'
no-spaced-func: error
no-sync: 'off'
no-ternary: 'off'
no-ternary: error
no-throw-literal: error
no-trailing-spaces: 'off'
no-trailing-spaces: error
no-undef-init: error
no-undefined: 'off'
no-underscore-dangle: 'off'
no-underscore-dangle: error
no-unmodified-loop-condition: error
no-unneeded-ternary: error
no-unsafe-finally: error
no-unused-expressions: 'off'
no-use-before-define: 'off'
no-unused-expressions: error
no-use-before-define: error
no-useless-call: error
no-useless-computed-key: error
no-useless-concat: error
Expand All @@ -170,11 +171,11 @@ rules:
object-property-newline: 'off'
object-shorthand: 'off'
one-var: 'off'
one-var-declaration-per-line: 'off'
one-var-declaration-per-line: error
operator-assignment:
- error
- always
operator-linebreak: 'off'
operator-linebreak: error
padded-blocks: 'off'
prefer-arrow-callback: 'off'
prefer-const: error
Expand All @@ -183,16 +184,20 @@ rules:
prefer-spread: 'off'
prefer-template: 'off'
quote-props: 'off'
quotes: 'off'
quotes:
- error
- single
- avoidEscape: true
allowTemplateLiterals: true
radix: error
require-jsdoc: 'off'
require-yield: error
semi: 'off'
semi-spacing: 'off'
semi: error
semi-spacing: error
sort-imports: error
sort-vars: 'off'
space-before-blocks: 'off'
space-before-function-paren: 'off'
space-before-function-paren: error
space-in-parens:
- error
- never
Expand Down
40 changes: 20 additions & 20 deletions cli/limbus-buildgen-cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// limbus-buildgen - A "build anywhere" C/C++ makefile/project generator.
// limbus-buildgen - A 'build anywhere' C/C++ makefile/project generator.
// Written in 2014-2016 by Jesper Oskarsson jesosk@gmail.com
//
// To the extent possible under law, the author(s) have dedicated all copyright
Expand All @@ -17,6 +17,14 @@ var exitWithError = function (error) {
process.exit(-1);
};

var getFlagValue = function (flags, index) {
if (index + 1 >= flags.length) {
exitWithError('Flag ' + flags[index] + ' is missing a value');
}

return flags[index + 1];
};

var flagHandlers = {
'--toolchain': function (result, processArguments, index) {
result.toolchain = getFlagValue(processArguments, index);
Expand All @@ -25,15 +33,15 @@ var flagHandlers = {
result.outputPath = getFlagValue(processArguments, index);
},
'--help': function () {
console.log("\n" +
"Usage: limbus-buildgen [flags] <path to JSON configuration file>\n" +
"\n" +
"Options:\n" +
"\n" +
" --help output usage information\n" +
" --toolchain <toolchain> override the configured target toolchain\n" +
" --outputPath <path> specify the path where build files are written\n" +
" to (default: .)");
console.log('\n' +
'Usage: limbus-buildgen [flags] <path to JSON configuration file>\n' +
'\n' +
'Options:\n' +
'\n' +
' --help output usage information\n' +
' --toolchain <toolchain> override the configured target toolchain\n' +
' --outputPath <path> specify the path where build files are written\n' +
' to (default: .)');
process.exit(0);
}
};
Expand All @@ -42,14 +50,6 @@ var argumentIsFlag = function (argument) {
return argument.substr(0, 2) === '--';
};

var getFlagValue = function (flags, index) {
if (index + 1 >= flags.length) {
exitWithError('Flag ' + flags[index] + ' is missing a value');
}

return flags[index + 1];
}

var parseArguments = function (processArguments) {
var result = {};

Expand All @@ -70,13 +70,13 @@ var parseArguments = function (processArguments) {
if (flagHandler) {
flagHandler(result, processArguments, index);
} else {
exitWithError("Unknown flag '" + argument + "'");
exitWithError('Unknown flag "' + argument + '"');
}
}
}

if (!result.configPath) {
exitWithError("No configuration file");
exitWithError('No configuration file');
}

return result;
Expand Down
14 changes: 11 additions & 3 deletions features/compiling.feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ var minimal = require('../source/minimal-configuration');

describe('Compiling', function () {
beforeEach(function () {
return util.beforeEach().then(function () {
return util.beforeEach()
.then(function () {
return shell.mkdir('temp/some_directory');
}).then(function () {
})
.then(function () {
return shell.cp('temp/main.c', 'temp/some_directory/');
});
});
Expand All @@ -28,11 +30,17 @@ describe('Compiling', function () {
});

it('should pass compiler flags as is', function () {
var flags = '-S';

if (util.toolchainCompiler === 'cl') {
flags = '/X';
}

return util.testConfiguration(minimal.projectWith({
toolchain: util.toolchain,
artifacts: [
minimal.artifactWith({
compilerFlags: util.toolchainCompiler === 'cl' ? '/X' : '-S'
compilerFlags: flags
})
]
})).should.be.rejected();
Expand Down
27 changes: 18 additions & 9 deletions features/configuration-validation.feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('Configuration Validation', function () {
});

var configShouldFailWith = function (config, expectedError, property) {
return util.testConfiguration(config).then(function () {
return util.testConfiguration(config)
.then(function () {
return Promise.reject(new Error('Did not fail'));
}, function (error) {
return Promise.all([
Expand Down Expand Up @@ -190,15 +191,18 @@ describe('Configuration Validation', function () {

describe('File extensions', function () {
it('should give error "no extension" with property "files" when a file in files has no extension', function () {
return Promise.resolve().then(function () {
return Promise.resolve()
.then(function () {
return configShouldFailWith(minimal.projectWithArtifactWith({
files: ['other-file']
}), /no extension/i, /files/);
}).then(function () {
})
.then(function () {
return configShouldFailWith(minimal.projectWithArtifactWith({
files: ['main.c', 'other-file']
}), /no extension/i, /files/);
}).then(function () {
})
.then(function () {
return configShouldFailWith(minimal.projectWithArtifactWith({
files: ['main.']
}), /no extension/i, /files/);
Expand All @@ -212,15 +216,20 @@ describe('Configuration Validation', function () {
}), /cannot be path/i, /outputName/);
};

return Promise.resolve().then(function () {
return Promise.resolve()
.then(function () {
return invalidOutputName('app/');
}).then(function () {
})
.then(function () {
return invalidOutputName('/app');
}).then(function () {
})
.then(function () {
return invalidOutputName('/');
}).then(function () {
})
.then(function () {
return invalidOutputName('.');
}).then(function () {
})
.then(function () {
return invalidOutputName('..');
});
});
Expand Down
6 changes: 3 additions & 3 deletions features/front-end.feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ describe('Front-end', function () {
).should.be.rejected();
});

it('should fail with "Unknown flag \'<flag>\'" if given an unknown flag', function () {
it('should fail with \'Unknown flag "<flag>"\' if given an unknown flag', function () {
return util.writeConfiguration(minimal.project())
.then(util.generateWithParameters('--some-flag value'))
.then(function () {
return Promise.reject(new Error('Did not fail'));
}, function (error) {
return error.message.should.containEql("Unknown flag '--some-flag'");
})
return error.message.should.containEql('Unknown flag "--some-flag"');
});
});
});
6 changes: 4 additions & 2 deletions features/linking.feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ var minimal = require('../source/minimal-configuration');

describe('Linking', function () {
beforeEach(function () {
return util.beforeEach().then(function () {
return util.beforeEach()
.then(function () {
return shell.mkdir('temp/include');
}).then(function () {
})
.then(function () {
return shell.copyFiles([
'linked.c',
'linked_dynamic.c',
Expand Down
16 changes: 10 additions & 6 deletions features/readme-examples.feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ var usageInformation = '';
var readme = fs.readFileSync('README.md').toString();

readme.replace(/```javascript([\s\S]+?)```/gi, function (match, example) {
example = example.replace(/require\('limbus\-buildgen'\)/g, "require('../source/limbus-buildgen')");
example = example.replace(/require\('limbus\-buildgen'\)/g, 'require("../source/limbus-buildgen")');
javascriptExamples.push(example);
return match;
});
readme.replace(/```json([\s\S]+?)```/gi, function (match, example) {
jsonExamples.push(example);
jsonExampleExpressions.push("require('../source/limbus-buildgen').generate(" + example + ");");
jsonExampleExpressions.push('require("../source/limbus-buildgen").generate(' + example + ');');
return match;
});
readme.replace(/```(\s+Usage:[\s\S]+?)```/, function (match, info) {
Expand All @@ -38,9 +38,11 @@ readme.replace(/```(\s+Usage:[\s\S]+?)```/, function (match, info) {
});

var generateWithExample = function (example) {
return Promise.resolve().then(function () {
return Promise.resolve()
.then(function () {
return util.writeFile('temp/example.js', Promise.resolve(example));
}).then(function () {
})
.then(function () {
return shell.exec('node ' + shell.path('example.js'), {cwd: './temp'});
});
};
Expand All @@ -59,7 +61,8 @@ var generateExamples = function (examples) {

describe('README Examples', function () {
beforeEach(function () {
return util.beforeEach().then(function () {
return util.beforeEach()
.then(function () {
return shell.copyFiles([
'main.c'
], 'features/readme-examples/', 'temp/');
Expand Down Expand Up @@ -92,7 +95,8 @@ describe('README Examples', function () {
var usageCommand = shell.path('generated/limbus-buildgen') + ' --help';

it('should match the output of `' + usageCommand + '`', function () {
return shell.exec(usageCommand).then(function (result) {
return shell.exec(usageCommand)
.then(function (result) {
return usageInformation.replace(/\r\n/g, '\n').should.containEql(result.stdout.replace(/\r\n/g, '\n'));
});
});
Expand Down
16 changes: 11 additions & 5 deletions features/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ var pathModule = require('path');
var childProcess = require('child_process');

exports.path = function (path) {
return path ? path.replace(/\//g, pathModule.sep) : path;
if (path) {
return path.replace(/\//g, pathModule.sep);
} else {
return undefined;
}
};

exports.exec = function (command, options) {
return new Promise(function(resolve, reject) {
var currentWorkingDirectory = '.';
if (options && options.cwd) {
currentWorkingDirectory = exports.path(options.cwd);
}
return new Promise(function (resolve, reject) {
childProcess.exec(
command,
{
cwd: (options && options.cwd) ? exports.path(options.cwd) : undefined
},
{ cwd: currentWorkingDirectory },
function (error, stdout, stderr) {
if (error) {
error.message += stdout + stderr;
Expand Down
Loading

0 comments on commit b69cff6

Please sign in to comment.