Skip to content

Commit

Permalink
CB-12895 : added eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyso committed Aug 22, 2017
1 parent d27736a commit 34ae0bb
Show file tree
Hide file tree
Showing 39 changed files with 1,065 additions and 1,100 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.yml
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
7 changes: 0 additions & 7 deletions .jshintrc

This file was deleted.

18 changes: 13 additions & 5 deletions package.json
Expand Up @@ -9,9 +9,12 @@
"dependencies": {
"chalk": "~0.4",
"co": "~4.0",
"co-stream": "0.1.1",
"glob": "^5.0.14",
"gnode": "^0.1.0",
"inquirer": "2.0.0",
"jasmine": "^2.5.3",
"jira-client": "4.2.0",
"jira-linkify": "^2.3.0",
"nlf": "^1.4.3",
"opener": "^1.4.1",
Expand All @@ -21,12 +24,16 @@
"semver": "^4.2.0",
"shelljs": "0.1.4",
"treeify": "^1.0.1",
"jira-client": "4.2.0",
"inquirer": "2.0.0",
"xml2js": "0.4.17",
"co-stream": "0.1.1"
"xml2js": "0.4.17"
},
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-node": "^5.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"nsp": ">=2.0.1",
"tap-dot": "^1.0.0",
"tap-spec": "^4.0.0",
Expand All @@ -37,7 +44,8 @@
"oldtest": "node test/test.js | tap-spec",
"test": "npm run jasmine",
"cover": "istanbul cover --root src --print detail jasmine",
"jasmine": "jasmine --captureExceptions --color"
"jasmine": "jasmine --captureExceptions --color",
"eslint": "eslint test && eslint src"
},
"repository": {
"type": "git",
Expand Down
20 changes: 10 additions & 10 deletions src/apputil.js
Expand Up @@ -24,31 +24,31 @@ var shell = require('shelljs');
var origWorkingDir = path.resolve(process.cwd());
var baseWorkingDir = origWorkingDir;

exports.resolveUserSpecifiedPath = function(p) {
exports.resolveUserSpecifiedPath = function (p) {
return path.resolve(origWorkingDir, p);
};

exports.initWorkingDir = function(chdir) {
if(chdir) {
exports.initWorkingDir = function (chdir) {
if (chdir) {
var newDir = path.resolve(__dirname, '..', '..');
process.chdir(newDir);
baseWorkingDir = newDir;
}
console.log('Running from ' + baseWorkingDir);
}
};

exports.getBaseDir = function() {
exports.getBaseDir = function () {
return baseWorkingDir;
}
};

exports.fatal = function() {
exports.fatal = function () {
console.error.apply(console, arguments);
process.exit(1);
};

exports.prefixLength = 30;

exports.print = function() {
exports.print = function () {
var newArgs = Array.prototype.slice.call(arguments);
// Prefix any prints() to distinguish them from command output.
if (newArgs.length > 1 || newArgs[0]) {
Expand All @@ -61,11 +61,11 @@ exports.print = function() {
}
var prefix = chalk.magenta.bold(curDir) + chalk.yellow(banner);
newArgs.unshift(prefix);
newArgs = newArgs.map(function(val) { return val.replace(/\n/g, '\n' + prefix + ' ') });
newArgs = newArgs.map(function (val) { return val.replace(/\n/g, '\n' + prefix + ' '); });
}

console.log.apply(console, newArgs);
}
};

exports.setShellSilent = function (func) {
var origShellSilent = shell.config.silent;
Expand Down
41 changes: 20 additions & 21 deletions src/audit-license-headers.js
Expand Up @@ -18,7 +18,6 @@ under the License.
*/

var fs = require('fs');
var os = require('os');
var path = require('path');
var chalk = require('chalk');
var shelljs = require('shelljs');
Expand Down Expand Up @@ -47,52 +46,52 @@ var COMMON_RAT_EXCLUDES = [
'.jshintrc',
'*.xcworkspacedata',
'*.xccheckout',
'*.xcscheme',
'*.xcscheme'
];

var RAT_IGNORE_PATH = '.ratignore';
var RAT_IGNORE_PATH = '.ratignore';
var RATIGNORE_COMMENT_PREFIX = '#';

var RAT_NAME = 'apache-rat-0.12';
var RAT_URL = 'https://dist.apache.org/repos/dist/release/creadur/apache-rat-0.12/apache-rat-0.12-bin.tar.gz';
var RAT_URL = 'https://dist.apache.org/repos/dist/release/creadur/apache-rat-0.12/apache-rat-0.12-bin.tar.gz';

function startsWith(string, prefix) {
function startsWith (string, prefix) {
return string.indexOf(prefix) === 0;
}

function isComment(pattern) {
function isComment (pattern) {
return startsWith(pattern.trim(), RATIGNORE_COMMENT_PREFIX);
}

module.exports = function*() {
module.exports = function * () {

var opt = flagutil.registerRepoFlag(optimist);
opt = flagutil.registerHelpFlag(opt);
opt = flagutil.registerHelpFlag(opt);

opt.usage('Uses Apache RAT to audit source files for license headers.\n' +
'\n' +
'Usage: $0 audit-license-headers --repo=name [-r repos]')
argv = opt.argv;
'Usage: $0 audit-license-headers --repo=name [-r repos]');
argv = opt.argv; // eslint-disable-line no-undef

if (argv.h) {
if (argv.h) { // eslint-disable-line no-undef
optimist.showHelp();
process.exit(1);
}

var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true}); // eslint-disable-line no-undef
yield module.exports.scrubRepos(repos);
}
};

module.exports.scrubRepos = function*(repos, silent, ignoreError, win, fail) {
module.exports.scrubRepos = function * (repos, silent, ignoreError, win, fail) {
// Check that RAT command exists.
var ratPath;
yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function*() {
ratPath = path.join(process.cwd(), RAT_NAME, RAT_NAME+'.jar');
yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function * () {
ratPath = path.join(process.cwd(), RAT_NAME, RAT_NAME + '.jar');
});

if (!fs.existsSync(ratPath)) {
console.log('RAT tool not found, downloading to: ' + ratPath);
yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function*() {
yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function * () {
// TODO: this will not work on windows right?
if (shelljs.which('curl')) {
yield executil.execHelper(['sh', '-c', 'curl "' + RAT_URL + '" | tar xz']);
Expand All @@ -109,13 +108,13 @@ module.exports.scrubRepos = function*(repos, silent, ignoreError, win, fail) {

// NOTE:
// the CWD in a callback is the directory for its respective repo
yield repoutil.forEachRepo(repos, function*(repo) {
yield repoutil.forEachRepo(repos, function * (repo) {
var excludePatterns = COMMON_RAT_EXCLUDES;

// read in exclude patterns from repo's .ratignore, one pattern per line
if (fs.existsSync(RAT_IGNORE_PATH)) {

var ratignoreFile = fs.readFileSync(RAT_IGNORE_PATH);
var ratignoreFile = fs.readFileSync(RAT_IGNORE_PATH);
var ratignoreLines = ratignoreFile.toString().trim().split('\n');

// add only non-empty and non-comment lines
Expand All @@ -133,8 +132,8 @@ module.exports.scrubRepos = function*(repos, silent, ignoreError, win, fail) {
});

// run Rat
yield executil.execHelper(executil.ARGS('java -jar', ratPath, '-d', '.').concat(excludeFlags), silent, ignoreError, function(stdout) {
yield executil.execHelper(executil.ARGS('java -jar', ratPath, '-d', '.').concat(excludeFlags), silent, ignoreError, function (stdout) {
if (win) win(repo, stdout);
});
});
}
};

0 comments on commit 34ae0bb

Please sign in to comment.