Skip to content

Commit

Permalink
Merge df07255 into e5f8401
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwillette committed Dec 6, 2018
2 parents e5f8401 + df07255 commit a911b57
Show file tree
Hide file tree
Showing 3 changed files with 2,926 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
26 changes: 21 additions & 5 deletions bin/gqlint.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#!/usr/bin/env node
'use strict';

var program = require('commander');

var fs = require('fs');
var gqlint = require('../lib/gqlint');
var os = require('os');
var path = require('path');

var gqlint = require('../lib/gqlint');
var pkg = require('../package.json');
var program = require('commander');

var reportResult;

initProgram();
Expand All @@ -23,7 +27,7 @@ function initProgram() {
)
.option(
'-c, --config <config>',
'the config file to use: .gqlint (default)',
'the config filename to use: .gqlint (default)',
'.gqlint'
)
.parse(process.argv);
Expand All @@ -33,8 +37,20 @@ function initProgram() {
function getGQLintConfig() {
let data;

// paths to search for a config file in order of precedence
let paths = ['.', path.dirname(program.args[0]), os.homedir()];

for (let p of paths) {
let configPath = path.join(p, program.config);
if (fs.existsSync(configPath)) {
program.fullConfigPath = configPath;
console.error('Using config file: ' + program.fullConfigPath);
break;
}
}

try {
data = fs.readFileSync(program.config, { encoding: 'utf8' });
data = fs.readFileSync(program.fullConfigPath, { encoding: 'utf8' });
} catch (e) {
console.error('Found no config file, running with default config.');
return;
Expand All @@ -43,7 +59,7 @@ function getGQLintConfig() {
try {
return JSON.parse(data);
} catch (e) {
console.error('Could not parse .gqlint file.');
console.error(`Could not parse ${program.config} config file.`);
throw e;
}
}
Expand Down

0 comments on commit a911b57

Please sign in to comment.