Skip to content

Commit 6b07f17

Browse files
committed
Added ability to use a .buddyrc file
1 parent 962db22 commit 6b07f17

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ Options:
114114
-C, --no-color disables colors
115115
```
116116

117+
If a `.buddyrc` file is located in the project directory, its values will be
118+
used in place of the defaults listed above. For example:
119+
120+
``` javascript
121+
{
122+
"enforceConst": false,
123+
"ignore": [0, 1, 2], // Use empty array to disable ignore
124+
"reporter": "detailed"
125+
}
126+
```
127+
117128
## Integration
118129

119130
You can easily run Buddy on your library source as part of your build. It will

bin/buddy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env node
22

3+
var fs = require('fs');
4+
var path = require('path');
5+
var strip = require('strip-json-comments');
36
var chalk = require('chalk');
47
var filepaths = require('node-filepaths');
58
var program = require('commander');
@@ -17,6 +20,27 @@ program
1720
.option('-C, --no-color', 'disables colors')
1821
.parse(process.argv);
1922

23+
// Check and parse .buddyrc file, if it exists
24+
var rcPath, rcContents, rc, opt;
25+
rcPath = path.resolve(process.cwd(), '.buddyrc');
26+
opts = {encoding: 'utf8'};
27+
28+
if (fs.existsSync(rcPath) && fs.lstatSync(rcPath).isFile()) {
29+
try {
30+
rcContents = strip(fs.readFileSync(rcPath, opts));
31+
rc = JSON.parse(rcContents);
32+
} catch (e) {
33+
console.log('Invalid .buddyrc file:', e.message);
34+
process.exit(1);
35+
}
36+
37+
['enforceConst', 'ignore', 'reporter'].forEach(function(option) {
38+
if (program[option] === undefined) {
39+
program[option] = rc[option];
40+
}
41+
});
42+
}
43+
2044
// Assume all unconsumed arguments are paths
2145
var suppliedPaths = program.args || [];
2246
if (!suppliedPaths.length) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"acorn": "0.9.0",
2727
"commander": "*",
2828
"node-filepaths": "*",
29-
"chalk": "*"
29+
"chalk": "*",
30+
"strip-json-comments": "1.0.2"
3031
},
3132
"devDependencies": {
3233
"mocha": "*",

0 commit comments

Comments
 (0)