Skip to content

Commit

Permalink
Added -init arg & auto search for a config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Dennithorne committed Jun 27, 2017
1 parent 68cf71a commit f7cdd72
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .cflintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"output" : [ ],
"rule" : [ ],
"excludes" : [ ],
"includes" : [ { } ],
"inheritParent" : false,
"inheritPlugins" : true
}
35 changes: 35 additions & 0 deletions bin/cflint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
#! /usr/bin/env node
var shell = require("shelljs");
var findConfig = require('find-config');

// Check for the init arg.
var initIndex = process.argv.indexOf("-init");
if (initIndex !== -1) {

var fs = require('fs');

// Remove -init, it is not part of the official cflint.
process.argv.splice(initIndex);

// Add version just so it wont output the help.
process.argv.push('-version');

// Get the empty configfile data.
var cflintrcData = fs.readFileSync(__dirname + '/../.cflintrc', 'utf8');

fs.writeFileSync(process.cwd() + '/.cflintrc', cflintrcData);

console.log(`
Successfully created .cflintrc file in ${process.cwd()}
By default there are only parsing errors, all other rules are excluded.
Run 'cflint -listrulegroups' to see possible rules.
`)
}

// Collect the arguments to resend.
var userArgs = process.argv.slice(2).join(" ");

// Find the path to the nearest config file '.cflintrc'.
var configFilePath = findConfig('.cflintrc');

// If there is a config file append it.
if (configFilePath) {
userArgs += ' -configfile ' + configFilePath
}

// Execute cflint.
shell.exec('java -jar ' + __dirname + '/CFLint-1.0.1-all.jar ' + userArgs);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cflint",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -12,6 +12,7 @@
"cflint": "bin/cflint.js"
},
"dependencies": {
"find-config": "^1.0.0",
"shelljs": "^0.7.7"
}
}

0 comments on commit f7cdd72

Please sign in to comment.