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

chore: eslint instead of jscs #183

Merged
merged 1 commit into from
Aug 8, 2018
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
52 changes: 52 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"parserOptions": {
"ecmaVersion": 2017
},
"env": {
"node": true,
"es6": true
},
"rules": {
"array-bracket-spacing": [2, "never"],
"block-scoped-var": 2,
"brace-style": 2,
"camelcase": 1,
"comma-dangle": ["error", "always-multiline"],
"computed-property-spacing": [2, "never"],
"curly": 2,
"eol-last": 2,
"eqeqeq": [2, "smart"],
"guard-for-in": 2,
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"max-depth": [1, 5],
"max-len": [1, 120],
"max-statements": [1, 100],
"new-cap": 0,
"no-caller": 2,
"no-else-return": 2,
"no-extend-native": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-unused-vars": 1,
"no-use-before-define": [2, "nofunc"],
"object-curly-spacing": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"keyword-spacing": [2, {"before": true, "after": true}],
"space-before-function-paren": [
2,
{
"anonymous": "ignore",
"named": "never"
}
],
"space-unary-ops": 2
}
}
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To release a major you need to add `BREAKING CHANGE: ` to the start of the body

## Code standards

Ensure that your code adheres to the included `.jshintrc` and `.jscsrc` configs.
Ensure that your code adheres to the included `.eslintrc` config by running `npm run lint`.

## Sending pull requests

Expand All @@ -42,4 +42,4 @@ Ensure that your code adheres to the included `.jshintrc` and `.jscsrc` configs.

*Important:* when fixing a bug, please commit a **failing test** first so that Travis CI (or I can) can show the code failing. Once that commit is in place, then commit the bug fix, so that we can test *before* and *after*.

Remember that you're developing for multiple platforms and versions of node, so if the tests pass on your Mac or Linux or Windows machine, it *may* not pass elsewhere.
Remember that you're developing for multiple platforms and versions of node, so if the tests pass on your Mac or Linux or Windows machine, it *may* not pass elsewhere.
14 changes: 0 additions & 14 deletions .jscsrc

This file was deleted.

16 changes: 0 additions & 16 deletions .jshintrc

This file was deleted.

6 changes: 4 additions & 2 deletions cli/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ alias.t = 'test';
function dashToCamelCase(dash) {
return dash.indexOf('-') < 0
? dash
: dash.replace(/-[a-z]/g, function (m) {return m[1].toUpperCase()})
: dash.replace(/-[a-z]/g, function (m) {
return m[1].toUpperCase();
});
}

function args(processargv) {
Expand Down Expand Up @@ -43,7 +45,7 @@ function args(processargv) {
}

return acc;
}, { _: [] });
}, {_: []});

// by passing `-d` to the cli, we enable the debugging output, but this must
// be as early as possible in the cli logic to capture all the output
Expand Down
31 changes: 15 additions & 16 deletions cli/commands/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module.exports = ignore;
var debug = require('debug')('snyk');
var policy = require('snyk-policy');
var chalk = require('chalk');
var snyk = require('../../lib');
var authorization = require('../../lib/authorization');
var auth = require('./auth');

Expand Down Expand Up @@ -39,23 +38,23 @@ function ignore(options) {
options.id, options.reason, options.expiry
);
return policy.load(options['policy-path'])
.catch(function (error) {
if (error.code === 'ENOENT') { // file does not exist - create it
return policy.create();
}
throw Error('policyFile');
})
.then(function ignoreIssue(pol) {
pol.ignore[options.id] = [
{
'*':
.catch(function (error) {
if (error.code === 'ENOENT') { // file does not exist - create it
return policy.create();
}
throw Error('policyFile');
})
.then(function ignoreIssue(pol) {
pol.ignore[options.id] = [
{
'*':
{
reason: options.reason,
expires: options.expiry,
},
},
];
policy.save(pol, options['policy-path']);
});
})
},
];
policy.save(pol, options['policy-path']);
});
});
}
186 changes: 95 additions & 91 deletions cli/commands/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,115 +34,119 @@ function monitor() {
}

return apiTokenExists('snyk monitor')
.then(function () {
return args.reduce(function (acc, path) {
return acc.then(function () {
return fs.exists(path).then(function (exists) {
if (!exists && !options.docker) {
throw new Error(
'snyk monitor should be pointed at an existing project');
}
.then(function () {
return args.reduce(function (acc, path) {
return acc.then(function () {
return fs.exists(path).then(function (exists) {
if (!exists && !options.docker) {
throw new Error(
'snyk monitor should be pointed at an existing project');
}

var packageManager = detect.detectPackageManager(path, options);
var packageManager = detect.detectPackageManager(path, options);

var targetFile = options.docker
? undefined
: (options.file || detect.detectPackageFile(path));
var targetFile = options.docker
? undefined
: (options.file || detect.detectPackageFile(path));


var plugin = plugins.loadPlugin(packageManager, options);
var plugin = plugins.loadPlugin(packageManager, options);

var moduleInfo = ModuleInfo(plugin, options.policy);
var moduleInfo = ModuleInfo(plugin, options.policy);

var displayPath = pathUtil.relative(
'.', pathUtil.join(path, targetFile || ''));
var displayPath = pathUtil.relative(
'.', pathUtil.join(path, targetFile || ''));

var analysisType = options.docker ? 'docker' : packageManager;
var analysisType = options.docker ? 'docker' : packageManager;

var analyzingDepsSpinnerLabel =
var analyzingDepsSpinnerLabel =
'Analyzing ' + analysisType + ' dependencies for ' + displayPath;

var postingMonitorSpinnerLabel =
var postingMonitorSpinnerLabel =
'Posting monitor snapshot for ' + displayPath + ' ...';

return spinner(analyzingDepsSpinnerLabel)
.then(function () {
return moduleInfo.inspect(path, targetFile, options)
})
.then(spinner.clear(analyzingDepsSpinnerLabel))
.then(function (info) {
return spinner(postingMonitorSpinnerLabel)
.then(function () { return info });
})
.then(function (info) {
if (_.get(info, 'plugin.packageManager')) {
packageManager = info.plugin.packageManager;
}
var meta = {
method: 'cli',
packageManager: packageManager,
'policy-path': options['policy-path'],
'project-name':
return spinner(analyzingDepsSpinnerLabel)
.then(function () {
return moduleInfo.inspect(path, targetFile, options);
})
.then(spinner.clear(analyzingDepsSpinnerLabel))
.then(function (info) {
return spinner(postingMonitorSpinnerLabel)
.then(function () {
return info;
});
})
.then(function (info) {
if (_.get(info, 'plugin.packageManager')) {
packageManager = info.plugin.packageManager;
}
var meta = {
method: 'cli',
packageManager: packageManager,
'policy-path': options['policy-path'],
'project-name':
options['project-name'] || config['PROJECT_NAME'],
isDocker: !!options.docker,
};
return snyk.monitor(path, meta, info);
})
.then(spinner.clear(postingMonitorSpinnerLabel))
.then(function (res) {
res.path = path;
var endpoint = url.parse(config.API);
var leader = '';
if (res.org) {
leader = '/org/' + res.org;
}
endpoint.pathname = leader + '/manage';
var manageUrl = url.format(endpoint);

endpoint.pathname = leader + '/monitor/' + res.id;
var output = formatMonitorOutput(
packageManager, res,
manageUrl, options.json
);
// push a good result
results.push({ok: true, data: output, path: path});
});
}).catch(function (err) {
isDocker: !!options.docker,
};
return snyk.monitor(path, meta, info);
})
.then(spinner.clear(postingMonitorSpinnerLabel))
.then(function (res) {
res.path = path;
var endpoint = url.parse(config.API);
var leader = '';
if (res.org) {
leader = '/org/' + res.org;
}
endpoint.pathname = leader + '/manage';
var manageUrl = url.format(endpoint);

endpoint.pathname = leader + '/monitor/' + res.id;
var output = formatMonitorOutput(
packageManager, res,
manageUrl, options.json
);
// push a good result
results.push({ok: true, data: output, path: path});
});
}).catch(function (err) {
// push this error so the promise chain continues
results.push({ok: false, data: err, path: path});
results.push({ok: false, data: err, path: path});
});
});
});
}, Promise.resolve())
.then(function () {
if (options.json) {
var dataToSend = results.map(function (result) {
if (result.ok) {
return JSON.parse(result.data)
}, Promise.resolve())
.then(function () {
if (options.json) {
var dataToSend = results.map(function (result) {
if (result.ok) {
return JSON.parse(result.data);
}
return {ok: false, error: result.data.message, path: result.path};
});
// backwards compat - strip array if only one result
dataToSend = dataToSend.length === 1 ? dataToSend[0] : dataToSend;
var json = JSON.stringify(dataToSend, null, 2);

if (results.every(function (res) {
return res.ok;
})) {
return json;
}

throw new Error(json);
}
return {ok: false, error: result.data.message, path: result.path}

return results.map(function (res) {
if (res.ok) {
return res.data;
}
if (res.data && res.data.cliMessage) {
return chalk.bold.red(res.data.cliMessage);
}
return 'For path `' + res.path + '`, ' + res.data.message;
}).join('\n');
});
// backwards compat - strip array if only one result
dataToSend = dataToSend.length === 1 ? dataToSend[0] : dataToSend;
var json = JSON.stringify(dataToSend, null, 2);

if (results.every(function (res) { return res.ok; })) {
return json
}

throw new Error(json);
}

return results.map(function (res) {
if (res.ok) {
return res.data;
}
if (res.data && res.data.cliMessage) {
return chalk.bold.red(res.data.cliMessage)
}
return 'For path `' + res.path + '`, ' + res.data.message;
}).join('\n');
});
});
}

function formatMonitorOutput(packageManager, res, manageUrl, isJson) {
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ function displayPolicy(path) {
}
throw e;
});
}
}
Loading