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

Fix lint errors #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
96 changes: 48 additions & 48 deletions bin/jsctags
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node

var format = require('util').format;
var forceArray = require('force-array');
var argv = require('optimist').argv;
var path = require('path');
var glob = require('glob');
var collect = require('collect-stream');
var flatten = require('lodash.flatten');
var async = require('async');
var fs = require('fs');

var jsctags = require('../');

var dir = (function() {
const format = require('util').format;
const forceArray = require('force-array');
const argv = require('optimist').argv;
const path = require('path');
const glob = require('glob');
const collect = require('collect-stream');
const flatten = require('lodash.flatten');
const async = require('async');
const fs = require('fs');

const jsctags = require('../');

const dir = (function () {
if (argv.dir) {
return path.resolve(argv.dir);
}
Expand All @@ -28,7 +28,7 @@ var dir = (function() {
return '///null';
})();

var file = (function() {
const file = (function () {
if (argv.file) {
return path.resolve(process.cwd(), argv.file);
}
Expand All @@ -37,40 +37,40 @@ var file = (function() {
return format('///null/%s', Math.floor(Math.random() * 100));
}

var find = forceArray(argv.find);
var files = !find.length
? argv._
: find.reduce(function(files, pattern) {
return files.concat(
glob.sync(pattern, {
nosort: true,
silent: true
})
);
}, []);

return files.map(function(file) {
const find = forceArray(argv.find);
const files = find.length ?
find.reduce((files, pattern) => {
return files.concat(
glob.sync(pattern, {
nosort: true,
silent: true
})
);
}, []) :
argv._;

return files.map(file => {
return path.resolve(process.cwd(), file);
});
})();

var outputTags = function(tags) {
var ctags = flatten(jsctags.ctags(tags));
const outputTags = function (tags) {
const ctags = flatten(jsctags.ctags(tags));
console.log(ctags.join(''));
};

var outputJSON = function(tags) {
const outputJSON = function (tags) {
console.log(JSON.stringify(flatten(forceArray(tags)), null, 2));
};

var onResults = function(err, results) {
const onResults = function (err, results) {
if (err) {
throw err;
}

var fn = argv.f ? outputTags : outputJSON;
const fn = argv.f ? outputTags : outputJSON;

var tags = results.filter(function(res) {
const tags = results.filter(res => {
if (res instanceof Error) {
console.error(err);
return false;
Expand All @@ -84,23 +84,23 @@ var onResults = function(err, results) {
fn(tags);
};

var parse = function(ctx, fn) {
jsctags(ctx, function(err, tags) {
const parse = function (ctx, fn) {
jsctags(ctx, (err, tags) => {
if (err) {
return fn(err);
}

tags.tagfile = ctx.file;
tags.forEach(function(tag) {
tags.forEach(tag => {
tag.tagfile = ctx.file;
});

fn(err, tags);
});
};

var fromStdin = function() {
collect(process.stdin, function(err, content) {
const fromStdin = function () {
collect(process.stdin, (err, content) => {
if (err) {
throw err;
}
Expand All @@ -111,30 +111,30 @@ var fromStdin = function() {

parse(
{
file: file,
dir: dir,
content: content
file,
dir,
content
},
onResults
);
});
};

var fromFiles = function() {
var files = Array.isArray(file) ? file : [file];
const fromFiles = function () {
const files = Array.isArray(file) ? file : [file];
async.map(
files,
function(file, fn) {
fs.readFile(file, 'utf8', function(err, content) {
(file, fn) => {
fs.readFile(file, 'utf8', (err, content) => {
if (err) {
return fn(null, err);
}

parse(
{
file: file,
dir: dir,
content: content
file,
dir,
content
},
fn
);
Expand Down
10 changes: 5 additions & 5 deletions bin/xjsctags
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/usr/bin/env node

var path = require('path');
var cp = require('child_process');
const path = require('path');
const cp = require('child_process');

var jsctags = path.join(__dirname, 'jsctags');
const jsctags = path.join(__dirname, 'jsctags');

var bin = cp.execFile(
const bin = cp.execFile(
jsctags,
process.argv.shift(),
{
cwd: process.cwd(),
env: process.env
},
function(err, stderr, stdout) {
(err, stderr, stdout) => {
if (err) {
throw err;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"scripts": {
"test": "NODE_ENV=test nyc node test",
"lint": "eslint . --fix",
"lint": "eslint . bin/* --fix",
"coverage": "nyc report --reporter=text-lcov | codeclimate-test-reporter"
},
"dependencies": {
Expand Down
17 changes: 9 additions & 8 deletions src/condenser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const once = require('once');
require('tern-jsx');
require('./local-scope');

const config = function(dir, file) {
const config = function (dir, file) {
const config = tryor(() => {
return fs.readFileSync(path.join(dir, '.tern-project'), 'utf8');
}, '{}');
Expand All @@ -24,7 +24,7 @@ const config = function(dir, file) {
};

const plugins = {
doc_comment: true,
doc_comment: true, // eslint-disable-line camelcase
'local-scope': true
};

Expand All @@ -35,7 +35,7 @@ const config = function(dir, file) {
});
};

const defs = function(libs) {
const defs = function (libs) {
const base = path.resolve(__dirname, '../node_modules/tern/defs');

return libs
Expand All @@ -47,23 +47,24 @@ const defs = function(libs) {
if (fs.existsSync(file)) {
return require(file);
}

return null;
})
.filter(lib => {
return Boolean(lib);
});
};

const server = function(config, dir) {
const server = function (config, dir) {
const base = path.resolve(__dirname, '../node_modules/tern/plugin');

Object.keys(config.plugins).forEach(plugin => {
const file = path.join(base, format('%s.js', plugin));

if (fs.existsSync(file)) {
return require(file);
} else {
return tryor(require.bind(require, 'tern-' + plugin));
}
return tryor(require.bind(require, 'tern-' + plugin));
});

return new tern.Server({
Expand All @@ -74,10 +75,10 @@ const server = function(config, dir) {
});
};

module.exports = function(options, fn) {
module.exports = function (options, fn) {
const __fn = once(fn);

const _fn = function(err, tags) {
const _fn = function (err, tags) {
if (err) {
return __fn(err);
}
Expand Down
8 changes: 5 additions & 3 deletions src/ctags.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const SPECIAL_FIELDS = {
parent: true
};

const convert = (module.exports = function(tags) {
const convert = function (tags) {
return tags.map(tag => {
if (isArray(tag)) {
return convert(tag);
}

const buf = [tag.name, '\t', tags.tagfile, '\t'];
buf.push(tag.addr !== undefined ? tag.addr : '//');
buf.push(tag.addr === undefined ? '//' : tag.addr);
const tagfields = [];

Object.keys(tag).forEach(key => {
Expand Down Expand Up @@ -68,4 +68,6 @@ const convert = (module.exports = function(tags) {
buf.push('\n');
return buf.join('');
});
});
};

module.exports = convert;
Loading