fix lint/style issues

This commit is contained in:
Jeroen Engels 2016-03-07 00:20:24 +01:00
parent a963ee7bb1
commit c51b0a27ff
15 changed files with 53 additions and 76 deletions

11
cli.js
View file

@ -1,4 +1,5 @@
#!/usr/bin/env node #!/usr/bin/env node
/* eslint-disable no-console */
'use strict'; 'use strict';
var fs = require('fs'); var fs = require('fs');
@ -23,7 +24,7 @@ var argv = require('yargs')
.default('contributorsPerLine', 7) .default('contributorsPerLine', 7)
.default('contributors', []) .default('contributors', [])
.default('config', defaultRCFile) .default('config', defaultRCFile)
.config('config', function(configPath) { .config('config', function (configPath) {
try { try {
return JSON.parse(fs.readFileSync(configPath, 'utf-8')); return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
} catch (error) { } catch (error) {
@ -37,11 +38,11 @@ var argv = require('yargs')
function startGeneration(argv, cb) { function startGeneration(argv, cb) {
argv.files argv.files
.map(function(file) { .map(function (file) {
return path.join(cwd, file); return path.join(cwd, file);
}) })
.forEach(function(file) { .forEach(function (file) {
markdown.read(file, function(error, fileContent) { markdown.read(file, function (error, fileContent) {
if (error) { if (error) {
return cb(error); return cb(error);
} }
@ -65,7 +66,7 @@ if (command === 'generate') {
var username = argv._[1]; var username = argv._[1];
var contributions = argv._[2]; var contributions = argv._[2];
// Add or update contributor in the config file // Add or update contributor in the config file
updateContributors(argv, username, contributions, function(error, contributors) { updateContributors(argv, username, contributions, function (error, contributors) {
if (error) { if (error) {
return onError(error); return onError(error);
} }

View file

@ -7,10 +7,10 @@ function formatCommaFirst(o) {
return JSON.stringify(o, null, 2) return JSON.stringify(o, null, 2)
.split(/(,\n\s+)/) .split(/(,\n\s+)/)
.map(function (e, i) { .map(function (e, i) {
return i % 2 ? '\n' + e.substring(4) + ', ' : e return i % 2 ? '\n' + e.substring(4) + ', ' : e;
}) })
.join('') .join('') +
+ '\n'; '\n';
} }
function readConfig(configPath) { function readConfig(configPath) {
@ -19,11 +19,11 @@ function readConfig(configPath) {
function writeContributors(configPath, contributors, cb) { function writeContributors(configPath, contributors, cb) {
var config = readConfig(configPath); var config = readConfig(configPath);
var content = _.assign(config, { contributors: contributors }); var content = _.assign(config, {contributors: contributors});
return fs.writeFile(configPath, formatCommaFirst(content), cb); return fs.writeFile(configPath, formatCommaFirst(content), cb);
} }
module.exports = { module.exports = {
readConfig: readConfig, readConfig: readConfig,
writeContributors: writeContributors writeContributors: writeContributors
} };

View file

@ -2,12 +2,6 @@
var _ = require('lodash/fp'); var _ = require('lodash/fp');
function matchContribution(type) {
return function(existing) {
return type === existing || type === existing.type;
};
}
function uniqueTypes(contribution) { function uniqueTypes(contribution) {
return contribution.type || contribution; return contribution.type || contribution;
} }
@ -15,11 +9,11 @@ function uniqueTypes(contribution) {
function formatContributions(options, existing, newTypes) { function formatContributions(options, existing, newTypes) {
var types = newTypes.split(','); var types = newTypes.split(',');
if (options.url) { if (options.url) {
return (existing || []).concat(types.map(function(type) { return (existing || []).concat(types.map(function (type) {
return { type: type, url: options.url }; return {type: type, url: options.url};
})); }));
} }
return _.uniqBy(uniqueTypes, (existing || []).concat(types)); return _.uniqBy(uniqueTypes, (existing || []).concat(types));
} }
function updateContributor(options, contributor, contributions) { function updateContributor(options, contributor, contributions) {
@ -29,7 +23,7 @@ function updateContributor(options, contributor, contributions) {
} }
function updateExistingContributor(options, username, contributions) { function updateExistingContributor(options, username, contributions) {
return options.contributors.map(function(contributor, index) { return options.contributors.map(function (contributor) {
if (username !== contributor.login) { if (username !== contributor.login) {
return contributor; return contributor;
} }
@ -38,7 +32,7 @@ function updateExistingContributor(options, username, contributions) {
} }
function addNewContributor(options, username, contributions, infoFetcher, cb) { function addNewContributor(options, username, contributions, infoFetcher, cb) {
infoFetcher(username, function(error, userData) { infoFetcher(username, function (error, userData) {
if (error) { if (error) {
return cb(error); return cb(error);
} }
@ -54,4 +48,4 @@ module.exports = function addContributor(options, username, contributions, infoF
return cb(null, updateExistingContributor(options, username, contributions)); return cb(null, updateExistingContributor(options, username, contributions));
} }
return addNewContributor(options, username, contributions, infoFetcher, cb); return addNewContributor(options, username, contributions, infoFetcher, cb);
} };

View file

@ -26,7 +26,7 @@ function fixtures() {
avatar_url: 'www.avatar.url', avatar_url: 'www.avatar.url',
profile: 'www.profile.url', profile: 'www.profile.url',
contributions: [ contributions: [
{ type: 'blog', url: 'www.blog.url/path' }, {type: 'blog', url: 'www.blog.url/path'},
'code' 'code'
] ]
}] }]
@ -42,7 +42,7 @@ test.cb('should callback with error if infoFetcher fails', t => {
return cb(new Error('infoFetcher error')); return cb(new Error('infoFetcher error'));
} }
return addContributor(options, username, contributions, infoFetcher, function(error) { return addContributor(options, username, contributions, infoFetcher, function (error) {
t.is(error.message, 'infoFetcher error'); t.is(error.message, 'infoFetcher error');
t.end(); t.end();
}); });
@ -53,7 +53,7 @@ test.cb('should add new contributor at the end of the list of contributors', t =
const username = 'login3'; const username = 'login3';
const contributions = 'doc'; const contributions = 'doc';
return addContributor(options, username, contributions, mockInfoFetcher, function(error, contributors) { return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
t.notOk(error); t.notOk(error);
t.is(contributors.length, 3); t.is(contributors.length, 3);
t.same(contributors[2], { t.same(contributors[2], {
@ -75,7 +75,7 @@ test.cb('should add new contributor at the end of the list of contributors with
const contributions = 'doc'; const contributions = 'doc';
options.url = 'www.foo.bar'; options.url = 'www.foo.bar';
return addContributor(options, username, contributions, mockInfoFetcher, function(error, contributors) { return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
t.notOk(error); t.notOk(error);
t.is(contributors.length, 3); t.is(contributors.length, 3);
t.same(contributors[2], { t.same(contributors[2], {
@ -84,7 +84,7 @@ test.cb('should add new contributor at the end of the list of contributors with
avatar_url: 'www.avatar.url', avatar_url: 'www.avatar.url',
profile: 'www.profile.url', profile: 'www.profile.url',
contributions: [ contributions: [
{ type: 'doc', url: 'www.foo.bar' } {type: 'doc', url: 'www.foo.bar'}
] ]
}); });
t.end(); t.end();
@ -96,7 +96,7 @@ test.cb(`should not update an existing contributor's contributions where nothing
const username = 'login2'; const username = 'login2';
const contributions = 'blog,code'; const contributions = 'blog,code';
return addContributor(options, username, contributions, mockInfoFetcher, function(error, contributors) { return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
t.notOk(error); t.notOk(error);
t.same(contributors, options.contributors); t.same(contributors, options.contributors);
t.end(); t.end();
@ -108,7 +108,7 @@ test.cb(`should update an existing contributor's contributions if a new type is
const username = 'login1'; const username = 'login1';
const contributions = 'bug'; const contributions = 'bug';
return addContributor(options, username, contributions, mockInfoFetcher, function(error, contributors) { return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
t.notOk(error); t.notOk(error);
t.is(contributors.length, 2); t.is(contributors.length, 2);
t.same(contributors[0], { t.same(contributors[0], {
@ -131,7 +131,7 @@ test.cb(`should update an existing contributor's contributions if a new type is
const contributions = 'bug'; const contributions = 'bug';
options.url = 'www.foo.bar'; options.url = 'www.foo.bar';
return addContributor(options, username, contributions, mockInfoFetcher, function(error, contributors) { return addContributor(options, username, contributions, mockInfoFetcher, function (error, contributors) {
t.notOk(error); t.notOk(error);
t.is(contributors.length, 2); t.is(contributors.length, 2);
t.same(contributors[0], { t.same(contributors[0], {
@ -141,7 +141,7 @@ test.cb(`should update an existing contributor's contributions if a new type is
profile: 'www.profile.url', profile: 'www.profile.url',
contributions: [ contributions: [
'code', 'code',
{ type: 'bug', url: 'www.foo.bar' }, {type: 'bug', url: 'www.foo.bar'}
] ]
}); });
t.end(); t.end();

View file

@ -1,6 +1,5 @@
'use strict'; 'use strict';
var _ = require('lodash/fp');
var request = require('request'); var request = require('request');
module.exports = function getUserInfo(username, cb) { module.exports = function getUserInfo(username, cb) {
@ -9,7 +8,7 @@ module.exports = function getUserInfo(username, cb) {
headers: { headers: {
'User-Agent': 'request' 'User-Agent': 'request'
} }
}, function(error, res) { }, function (error, res) {
if (error) { if (error) {
return cb(error); return cb(error);
} }
@ -22,4 +21,4 @@ module.exports = function getUserInfo(username, cb) {
}; };
return cb(null, user); return cb(null, user);
}); });
} };

View file

@ -5,11 +5,11 @@ var github = require('./github');
var configFile = require('../configFile'); var configFile = require('../configFile');
module.exports = function addContributor(options, username, contributions, cb) { module.exports = function addContributor(options, username, contributions, cb) {
add(options, username, contributions, github, function(error, contributors) { add(options, username, contributions, github, function (error, contributors) {
if (error) { if (error) {
return cb(error); return cb(error);
} }
configFile.writeContributors(options.config, contributors, function(error) { configFile.writeContributors(options.config, contributors, function (error) {
return cb(error, contributors); return cb(error, contributors);
}); });
}); });

View file

@ -5,7 +5,7 @@ var _ = require('lodash/fp');
var defaultTemplate = '[![All Contributors](https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square)](#contributors)'; var defaultTemplate = '[![All Contributors](https://img.shields.io/badge/all_contributors-<%= contributors.length %>-orange.svg?style=flat-square)](#contributors)';
module.exports = function formatBadge(options, contributors) { module.exports = function formatBadge(options, contributors) {
return _.template(options.badgeTemplate || defaultTemplate)({ return _.template(options.badgeTemplate || defaultTemplate)({
contributors: contributors contributors: contributors
}); });
}; };

View file

@ -2,15 +2,6 @@ import test from 'ava';
import _ from 'lodash/fp'; import _ from 'lodash/fp';
import formatBadge from './formatBadge'; import formatBadge from './formatBadge';
const fixtures = () => {
const options = {
projectOwner: 'jfmengels',
projectName: 'all-contributors-cli',
imageSize: 100
};
return {options};
}
test('should return badge with the number of contributors', t => { test('should return badge with the number of contributors', t => {
const options = {}; const options = {};
const expected8 = const expected8 =

View file

@ -2,12 +2,12 @@
var _ = require('lodash/fp'); var _ = require('lodash/fp');
var linkToCommits = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/commits?author=<%= contributor.login %>' var linkToCommits = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/commits?author=<%= contributor.login %>';
var linkToIssues = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/issues?q=author%3A<%= contributor.login %>'; var linkToIssues = 'https://github.com/<%= options.projectOwner %>/<%= options.projectName %>/issues?q=author%3A<%= contributor.login %>';
var linkTemplate = _.template('[<%= symbol %>](<%= url %>)'); var linkTemplate = _.template('[<%= symbol %>](<%= url %>)');
var defaultTypes = { var defaultTypes = {
blog: { symbol: '📝' }, blog: {symbol: '📝'},
bug: { bug: {
symbol: '🐛', symbol: '🐛',
link: linkToIssues link: linkToIssues
@ -16,24 +16,24 @@ var defaultTypes = {
symbol: '💻', symbol: '💻',
link: linkToCommits link: linkToCommits
}, },
design: { symbol: '🎨' }, design: {symbol: '🎨'},
doc: { doc: {
symbol: '📖', symbol: '📖',
link: linkToCommits link: linkToCommits
}, },
example: { symbol: '💡' }, example: {symbol: '💡'},
plugin: { symbol: '🔌' }, plugin: {symbol: '🔌'},
question: { symbol: '❓' }, question: {symbol: '❓'},
review: { symbol: '👀' }, review: {symbol: '👀'},
talk: { symbol: '📢' }, talk: {symbol: '📢'},
test: { test: {
symbol: '⚠️', symbol: '⚠️',
link: linkToCommits link: linkToCommits
}, },
translation: { symbol: '🌍' }, translation: {symbol: '🌍'},
tool: { symbol: '🔧' }, tool: {symbol: '🔧'},
tutorial: { symbol: '✅' }, tutorial: {symbol: '✅'},
video: { symbol: '📹' } video: {symbol: '📹'}
}; };
function getType(options, contribution) { function getType(options, contribution) {

View file

@ -9,7 +9,7 @@ const fixtures = () => {
imageSize: 100 imageSize: 100
}; };
return {options}; return {options};
} };
test('should return corresponding symbol', t => { test('should return corresponding symbol', t => {
const contributor = contributors.kentcdodds; const contributor = contributors.kentcdodds;
@ -63,7 +63,7 @@ test('should be able to add types to the symbol list', t => {
const contributor = contributors.kentcdodds; const contributor = contributors.kentcdodds;
const {options} = fixtures(); const {options} = fixtures();
options.types = { options.types = {
cheerful: { symbol: ':smiley:' } cheerful: {symbol: ':smiley:'}
}; };
t.is(formatContributionType(options, contributor, 'cheerful'), ':smiley:'); t.is(formatContributionType(options, contributor, 'cheerful'), ':smiley:');
@ -90,7 +90,7 @@ test('should be able to override existing types', t => {
const contributor = contributors.kentcdodds; const contributor = contributors.kentcdodds;
const {options} = fixtures(); const {options} = fixtures();
options.types = { options.types = {
code: { symbol: ':smiley:' } code: {symbol: ':smiley:'}
}; };
t.is(formatContributionType(options, contributor, 'code'), ':smiley:'); t.is(formatContributionType(options, contributor, 'code'), ':smiley:');

View file

@ -10,8 +10,8 @@ var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions
function defaultTemplate(templateData) { function defaultTemplate(templateData) {
var avatar = avatarTemplate(templateData); var avatar = avatarTemplate(templateData);
var avatarBlock = avatarBlockTemplate(_.assign({ avatar: avatar }, templateData)); var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData));
return contributorTemplate(_.assign({ avatarBlock: avatarBlock }, templateData)); return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData));
} }
function updateAvatarUrl(options, contributor) { function updateAvatarUrl(options, contributor) {
@ -20,7 +20,6 @@ function updateAvatarUrl(options, contributor) {
return _.assign(contributor, { return _.assign(contributor, {
avatar_url: avatarUrl + paramJoiner + 's=' + options.imageSize avatar_url: avatarUrl + paramJoiner + 's=' + options.imageSize
}); });
'<%= contributor.avatar_url %>?s=<%= options.imageSize %>'
} }
module.exports = function formatContributor(options, contributor) { module.exports = function formatContributor(options, contributor) {

View file

@ -13,7 +13,7 @@ function fixtures() {
} }
test('should format a simple contributor', t => { test('should format a simple contributor', t => {
const contributor = _.assign(contributors.kentcdodds, { contributions: ['review'] }); const contributor = _.assign(contributors.kentcdodds, {contributions: ['review']});
const {options} = fixtures(); const {options} = fixtures();
const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀'; const expected = '[![Kent C. Dodds](https://avatars1.githubusercontent.com/u/1500684?s=100)<br /><sub>Kent C. Dodds</sub>](http://kentcdodds.com)<br />👀';
@ -33,7 +33,7 @@ test('should format contributor with complex contribution types', t => {
test('should format contributor using custom template', t => { test('should format contributor using custom template', t => {
const contributor = contributors.kentcdodds; const contributor = contributors.kentcdodds;
const {options} = fixtures(); const {options} = fixtures();
options.contributorTemplate = '<%= contributor.name %> is awesome!' options.contributorTemplate = '<%= contributor.name %> is awesome!';
const expected = 'Kent C. Dodds is awesome!'; const expected = 'Kent C. Dodds is awesome!';
@ -43,7 +43,7 @@ test('should format contributor using custom template', t => {
test('should add image size to url', t => { test('should add image size to url', t => {
const {options} = fixtures(); const {options} = fixtures();
const contributor = contributors.kentcdodds; const contributor = contributors.kentcdodds;
options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>' options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>';
var contributionWithoutQuestionMarkUrl = _.assign(contributor, { var contributionWithoutQuestionMarkUrl = _.assign(contributor, {
avatar_url: 'www.some-url-without-question-mark.com' avatar_url: 'www.some-url-without-question-mark.com'

View file

@ -12,7 +12,7 @@ function injectContentBetween(lines, content, startIndex, endIndex) {
); );
} }
var injectBetweenTags = _.curry(function(tag, newContent, previousContent) { var injectBetweenTags = _.curry(function (tag, newContent, previousContent) {
var lines = previousContent.split('\n'); var lines = previousContent.split('\n');
var openingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':START '), lines); var openingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':START '), lines);
var closingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':END '), lines); var closingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':END '), lines);

View file

@ -2,13 +2,6 @@ import test from 'ava';
import generate from './'; import generate from './';
import contributors from './fixtures/contributors.json'; import contributors from './fixtures/contributors.json';
function getUserLine(content, {login}) {
return content
.split('\n')
.filter(line => line.indexOf(login) !== -1)
[0];
}
function fixtures() { function fixtures() {
const options = { const options = {
projectOwner: 'kentcdodds', projectOwner: 'kentcdodds',

View file

@ -13,4 +13,4 @@ function write(filePath, content, cb) {
module.exports = { module.exports = {
read: read, read: read,
write: write write: write
} };