Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
v0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brentlintner committed Aug 10, 2017
1 parent 8c679cf commit 3357ad0
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 343 deletions.
45 changes: 27 additions & 18 deletions lib/cli/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ var logger = require("./../logger");
var plugin = require("./../plugin");
var upload = require("./analyze/upload");
var log_helper = require("./analyze/log_helper");
var DEFAULT_IGNORE_DIRS = [
".git",
"node_modules"
];
var plugin_map = require("./init/map");
var DEFAULT_IGNORE_DIRS = plugin_map.ignore;
var log = logger.create("cli");
var log_and_exit = function (error) {
log.error(_.get(error, "stack", error));
log.error("\n", _.get(error, "stack", error));
process.exit(1);
};
var add_default_ignores = function (vile_yml) {
Expand All @@ -31,6 +29,7 @@ var analyze = function (opts, paths) {
dont_post_process: opts.dontPostProcess,
format: opts.format,
plugins: custom_plugins,
skip_core_plugins: opts.withoutCorePlugins,
skip_snippets: opts.skipSnippets,
spinner: !(opts.quiet || !opts.decorations)
};
Expand Down Expand Up @@ -71,6 +70,25 @@ var analyze = function (opts, paths) {
exec();
}
};
var configure = function (opts) {
var issue_levels = _.compact(_.split(opts.issueLog, ","));
logger.enable(opts.decorations, issue_levels);
config.load(opts.config);
if (opts.log)
logger.level(opts.log);
var disable_logger = opts.quiet ||
opts.format == "json" ||
opts.format == "syntastic";
if (disable_logger)
logger.disable();
if (!disable_logger && opts.decorations) {
logger.start_spinner();
}
};
var action = function (paths, opts) {
configure(opts);
analyze(opts, paths);
};
var create = function (cli) {
return cli
.command("analyze [paths...]")
Expand All @@ -85,23 +103,14 @@ var create = function (cli) {
"example: [src:lib,...] or [src.ts:lib.js,...]")
.option("-t, --terminal-snippets [path]", "show generated code snippets in the terminal")
.option("-s, --skip-snippets", "don't generate code snippets")
.option("-d, --dont-post-process", "don't post process data in any way (ex: adding ok issues)- " +
"useful for per file checking- don't use with --upload")
.option("-g, --git-diff [rev]", "only check files patched in latest HEAD commit, or rev")
.option("-d, --dont-post-process", "don't post process data in any way (ex: adding ok issues)- " +
"useful for per file checking")
.option("-w, --without-core-plugins", "don't use plugins bundled with core lib")
.option("-l, --log [level]", "specify the log level (info=default|warn|error)")
.option("-i, --issue-log [level]", "specify issue types to log (ex: '-i security,dependency')")
.option("-q, --quiet", "log nothing")
.option("-n, --no-decorations", "disable color and progress bar")
.action(function (paths, opts) {
var issue_levels = _.compact(_.split(opts.issueLog, ","));
logger.enable(opts.decorations, issue_levels);
config.load(opts.config);
if (opts.log)
logger.level(opts.log);
if (opts.quiet || opts.format == "json" ||
opts.format == "syntastic")
logger.disable();
analyze(opts, paths);
});
.action(action);
};
module.exports = { create: create };
5 changes: 2 additions & 3 deletions lib/cli/analyze/log_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ var to_console = function (issue, format) {
var loc = h_line || h_char ?
"" + (h_line ? "line " + h_line + ", " : "") +
("" + (h_char ? "col " + h_char + ", " : "")) : "";
var msg = issue.path + ": " + loc + details;
return msg;
var issue_path = _.isEmpty(issue.path) ? "" : issue.path + ": ";
return "" + issue_path + loc + details;
}
};
var to_console_duplicate = function (issue) {
Expand Down Expand Up @@ -197,7 +197,6 @@ var log_issue_messages = function (issues, showsnippets, nocolors) {
nlog.info_issue(to_console_cov(issue) + msg_postfix);
}
else if (issue.type == util.OK) {
nlog.info_issue(issue.path + msg_postfix);
}
else {
nlog.info_issue(to_console(issue) + msg_postfix);
Expand Down
14 changes: 7 additions & 7 deletions lib/cli/analyze/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ var wait_for_done_status_and_log = function (commit_id, auth) {
wait_for(COMMIT_STATUS_INTERVAL_TIME, function (timer) {
service
.commit_status(commit_id, auth)
.then(function (http) {
var api_body = _.get(http, "body");
var response = _.get(http, "response", { message: null });
.then(function (msg) {
var api_body = _.get(msg, "body");
var response = _.get(msg, "response", { message: null });
var status_code = _.get(response, "statusCode");
var body_json = _.attempt(JSON.parse.bind(null, api_body));
var message = _.get(body_json, "message");
Expand Down Expand Up @@ -50,11 +50,11 @@ var commit = function (issues, cli_time, opts) {
auth.project = opts.upload;
return service
.commit(issues, cli_time, auth)
.then(function (http) {
if (_.get(http, "response.statusCode") != 200) {
upload_error(_.get(http, "body", "[no body]"));
.then(function (msg) {
if (_.get(msg, "response.statusCode") != 200) {
upload_error(_.get(msg, "body", "[no body]"));
}
var body_json = _.attempt(JSON.parse.bind(null, _.get(http, "body", "{}")));
var body_json = _.attempt(JSON.parse.bind(null, _.get(msg, "body", "{}")));
var commit_state = _.get(body_json, "message");
var commit_id = _.get(body_json, "data.commit_id", null);
log.info("Commit " + commit_id + " " + commit_state);
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var create = function (cli) {
.command("auth")
.action(function () {
log.info("To authenticate, first go to " +
"https://vile.io and get a user token.");
"https://vile.io/auth_tokens and get an All token.");
log.info();
log.info("Then:");
log.info();
Expand Down
6 changes: 1 addition & 5 deletions lib/cli/init.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
"use strict";
var _ = require("lodash");
var plugin_map = require("./init/map");
var pre = require("./init/pre");
var language = require("./init/language");
var framework = require("./init/framework");
var ignore = require("./init/ignore");
var coverage = require("./init/coverage");
var post = require("./init/post");
var vile_config_base = function () {
return {
vile: {
allow: [],
ignore: [],
plugins: _.get(plugin_map.frameworks, "core")
plugins: []
}
};
};
Expand All @@ -21,7 +18,6 @@ var initialize_vile_project = function (cli) {
.then(ignore.init)
.then(language.init)
.then(framework.init)
.then(coverage.init)
.then(post.init);
};
var create = function (cli) {
Expand Down
2 changes: 2 additions & 0 deletions lib/cli/init/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var check_for_project_frameworks = function (config) {
}
if (exists("coffeelint.json"))
frameworks.push("coffeelint");
if (exists("tslint.json"))
frameworks.push("tslint");
if (exists(".sass-lint.yml"))
frameworks.push("sass-lint");
if (exists(".rubocop.yml"))
Expand Down
77 changes: 23 additions & 54 deletions lib/cli/init/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,51 @@ var inquirer = require("inquirer");
var fs = require("fs");
var Bluebird = require("bluebird");
var _ = require("lodash");
var IGNORE_DIRECTORIES = [
"node_modules",
"app/assets/images",
"bower_components",
"typings",
var fs_readdir = Bluebird.promisify(fs.readdir);
var EXTRA_IGNORE_DIRECTORIES = [
"bin",
".bin",
"build",
".build",
"public",
".test",
".git",
"tmp",
"vendor",
"coverage"
".tmp",
"typings"
];
var get_chosen_ignored_directories = function (dirs) {
if (_.isEmpty(dirs))
return Bluebird.resolve(dirs);
var choices = _.map(dirs, function (dir) {
return { name: dir };
});
return inquirer.prompt({
choices: choices,
message: "Select any directories or files to ignore.",
name: "dirs",
type: "checkbox",
validate: function (answer) { return true; }
})
.then(function (answers) { return answers.dirs; });
return new Bluebird(function (resolve, reject) {
inquirer.prompt({
choices: choices,
message: "Select any extra directories or files to ignore.",
name: "dirs",
type: "checkbox",
validate: function () { return true; }
})
.then(function (answers) {
resolve(answers.dirs);
});
});
};
var ignored_directories = function (directory) {
return fs.readdirAsync(directory)
return fs_readdir(directory)
.then(function (targets) {
return _.filter(targets, function (target) {
return fs.statSync(target).isDirectory() &&
_.some(IGNORE_DIRECTORIES, function (dir) { return dir == target; });
_.some(EXTRA_IGNORE_DIRECTORIES, function (dir) { return dir == target; });
});
})
.then(get_chosen_ignored_directories);
};
var get_any_extra_directories_from_user = function () {
return inquirer.prompt([
{
message: "Enter paths (separate with commas):",
name: "extra_ignore_dirs",
type: "input"
}
])
.then(function (answers) {
var dirs = answers.extra_ignore_dirs;
return _.compact(_.toString(dirs).split(","));
});
};
var get_any_extra_directories = function () {
return inquirer.prompt([
{
default: true,
message: "Would you like to manually add paths to ignore?",
name: "get_extra_dirs",
type: "confirm"
}
]).then(function (answers) {
if (answers.get_extra_dirs) {
return get_any_extra_directories_from_user();
}
else {
return Bluebird.resolve([]);
}
});
};
var check_for_ignored_directories = function (config) {
return ignored_directories(process.cwd())
.then(function (ignored_dirs) {
return get_any_extra_directories()
.then(function (dirs) {
config.vile.ignore = _.uniq(_.concat("node_modules", ignored_dirs, dirs));
return config;
});
config.vile.ignore = _.uniq(ignored_dirs);
return config;
});
};
module.exports = {
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/init/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ var check_for_project_languages = function (config) {
.then(function () {
var uniq_langs = _.chain(_.filter(_.uniq(langs)))
.map(function (lang) { return lang.toLowerCase(); })
.filter(function (lang) {
return _.some(_.keys(plugin_map.langs), function (l) { return l == lang; });
})
.value();
if (_.isEmpty(uniq_langs))
return Bluebird.resolve(config);
return inquirer.prompt({
choices: _.map(uniq_langs, function (lang) {
return { name: lang };
}),
message: "It appears you speak our language. Select any that apply!",
message: "Found some available plugins. Select any languages that apply!",
name: "langs",
type: "checkbox",
validate: function (answer) { return true; }
Expand Down
43 changes: 29 additions & 14 deletions lib/cli/init/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,60 @@ var frameworks = {
brakeman: ["brakeman"],
bundler: ["bundler-outdated", "bundler-audit"],
coffeelint: ["coffeelint"],
core: ["stat"],
coverage: ["coverage"],
editorconfig: ["eclint"],
eslint: ["eslint"],
git: ["git"],
jshint: ["jshint"],
nodejs: ["retire", "ncu"],
nodejs: ["nsp"],
rails: ["brakeman", "rails-best-practices"],
retirejs: ["retire"],
rubocop: ["rubocop"],
sass_lint: ["sass-lint"],
slim_lint: ["slim-lint"]
slim_lint: ["slim-lint"],
tslint: ["tslint"]
};
var langs = {
coffeescript: ["coffeelint"],
haskell: ["hlint"],
javascript: ["escomplex"],
php: ["phpmd"],
ruby: ["rubocop", "rubycritic"],
ruby: ["rubocop"],
sass: ["sass-lint"],
scss: ["scss-lint"],
slim: ["slim-lint"],
typescript: ["tslint"]
scss: ["sass-lint"],
slim: ["slim-lint"]
};
var peer = {
"brakeman": { gem: "brakeman" },
"bundler-audit": { gem: ["bundler", "bundler-audit"] },
"bundler-outdated": { gem: "bundler" },
"hlint": { cabal: "hlint" },
"ncu": { npm: "npm-check-updates" },
"rails-best-practices": { gem: "rails_best_practices" },
"retire": { npm: "retire" },
"rubocop": { gem: "rubocop" },
"sass-lint": { npm: "sass-lint" },
"scss-lint": { gem: "scss_lint" },
"slim-lint": { gem: "slim_lint" }
};
var DEFAULT_IGNORE_DIRS = [
"app/assets/images",
"app/assets/videos",
"bin",
"bower_components",
".bundle",
"cabal.sandbox.config",
".cabal-sandbox",
"coverage",
"db",
"doc",
"dist",
".git",
".gitmodules",
".gitattributes",
"log",
"node_modules",
".nyc_output",
"tmp",
"tags",
"vendor"
];
var PLUGIN_MAP = {
frameworks: frameworks,
ignore: DEFAULT_IGNORE_DIRS,
langs: langs,
peer: peer
};
Expand Down
Loading

0 comments on commit 3357ad0

Please sign in to comment.