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

1
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');

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) {
@ -26,4 +26,4 @@ function writeContributors(configPath, contributors, 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;
} }
@ -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

@ -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) {
@ -22,4 +21,4 @@ module.exports = function getUserInfo(username, cb) {
}; };
return cb(null, user); return cb(null, user);
}); });
} };

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,7 +2,7 @@
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 %>)');

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;

View file

@ -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

@ -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

@ -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
} };