mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
fix lint/style issues
This commit is contained in:
parent
a963ee7bb1
commit
c51b0a27ff
15 changed files with 53 additions and 76 deletions
11
cli.js
11
cli.js
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
|
@ -23,7 +24,7 @@ var argv = require('yargs')
|
|||
.default('contributorsPerLine', 7)
|
||||
.default('contributors', [])
|
||||
.default('config', defaultRCFile)
|
||||
.config('config', function(configPath) {
|
||||
.config('config', function (configPath) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
} catch (error) {
|
||||
|
@ -37,11 +38,11 @@ var argv = require('yargs')
|
|||
|
||||
function startGeneration(argv, cb) {
|
||||
argv.files
|
||||
.map(function(file) {
|
||||
.map(function (file) {
|
||||
return path.join(cwd, file);
|
||||
})
|
||||
.forEach(function(file) {
|
||||
markdown.read(file, function(error, fileContent) {
|
||||
.forEach(function (file) {
|
||||
markdown.read(file, function (error, fileContent) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
|
@ -65,7 +66,7 @@ if (command === 'generate') {
|
|||
var username = argv._[1];
|
||||
var contributions = argv._[2];
|
||||
// Add or update contributor in the config file
|
||||
updateContributors(argv, username, contributions, function(error, contributors) {
|
||||
updateContributors(argv, username, contributions, function (error, contributors) {
|
||||
if (error) {
|
||||
return onError(error);
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@ function formatCommaFirst(o) {
|
|||
return JSON.stringify(o, null, 2)
|
||||
.split(/(,\n\s+)/)
|
||||
.map(function (e, i) {
|
||||
return i % 2 ? '\n' + e.substring(4) + ', ' : e
|
||||
return i % 2 ? '\n' + e.substring(4) + ', ' : e;
|
||||
})
|
||||
.join('')
|
||||
+ '\n';
|
||||
.join('') +
|
||||
'\n';
|
||||
}
|
||||
|
||||
function readConfig(configPath) {
|
||||
|
@ -19,11 +19,11 @@ function readConfig(configPath) {
|
|||
|
||||
function writeContributors(configPath, contributors, cb) {
|
||||
var config = readConfig(configPath);
|
||||
var content = _.assign(config, { contributors: contributors });
|
||||
var content = _.assign(config, {contributors: contributors});
|
||||
return fs.writeFile(configPath, formatCommaFirst(content), cb);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
readConfig: readConfig,
|
||||
writeContributors: writeContributors
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,12 +2,6 @@
|
|||
|
||||
var _ = require('lodash/fp');
|
||||
|
||||
function matchContribution(type) {
|
||||
return function(existing) {
|
||||
return type === existing || type === existing.type;
|
||||
};
|
||||
}
|
||||
|
||||
function uniqueTypes(contribution) {
|
||||
return contribution.type || contribution;
|
||||
}
|
||||
|
@ -15,11 +9,11 @@ function uniqueTypes(contribution) {
|
|||
function formatContributions(options, existing, newTypes) {
|
||||
var types = newTypes.split(',');
|
||||
if (options.url) {
|
||||
return (existing || []).concat(types.map(function(type) {
|
||||
return { type: type, url: options.url };
|
||||
return (existing || []).concat(types.map(function (type) {
|
||||
return {type: type, url: options.url};
|
||||
}));
|
||||
}
|
||||
return _.uniqBy(uniqueTypes, (existing || []).concat(types));
|
||||
return _.uniqBy(uniqueTypes, (existing || []).concat(types));
|
||||
}
|
||||
|
||||
function updateContributor(options, contributor, contributions) {
|
||||
|
@ -29,7 +23,7 @@ function updateContributor(options, contributor, contributions) {
|
|||
}
|
||||
|
||||
function updateExistingContributor(options, username, contributions) {
|
||||
return options.contributors.map(function(contributor, index) {
|
||||
return options.contributors.map(function (contributor) {
|
||||
if (username !== contributor.login) {
|
||||
return contributor;
|
||||
}
|
||||
|
@ -38,7 +32,7 @@ function updateExistingContributor(options, username, contributions) {
|
|||
}
|
||||
|
||||
function addNewContributor(options, username, contributions, infoFetcher, cb) {
|
||||
infoFetcher(username, function(error, userData) {
|
||||
infoFetcher(username, function (error, userData) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
|
@ -54,4 +48,4 @@ module.exports = function addContributor(options, username, contributions, infoF
|
|||
return cb(null, updateExistingContributor(options, username, contributions));
|
||||
}
|
||||
return addNewContributor(options, username, contributions, infoFetcher, cb);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ function fixtures() {
|
|||
avatar_url: 'www.avatar.url',
|
||||
profile: 'www.profile.url',
|
||||
contributions: [
|
||||
{ type: 'blog', url: 'www.blog.url/path' },
|
||||
{type: 'blog', url: 'www.blog.url/path'},
|
||||
'code'
|
||||
]
|
||||
}]
|
||||
|
@ -42,7 +42,7 @@ test.cb('should callback with error if infoFetcher fails', t => {
|
|||
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.end();
|
||||
});
|
||||
|
@ -53,7 +53,7 @@ test.cb('should add new contributor at the end of the list of contributors', t =
|
|||
const username = 'login3';
|
||||
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.is(contributors.length, 3);
|
||||
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';
|
||||
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.is(contributors.length, 3);
|
||||
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',
|
||||
profile: 'www.profile.url',
|
||||
contributions: [
|
||||
{ type: 'doc', url: 'www.foo.bar' }
|
||||
{type: 'doc', url: 'www.foo.bar'}
|
||||
]
|
||||
});
|
||||
t.end();
|
||||
|
@ -96,7 +96,7 @@ test.cb(`should not update an existing contributor's contributions where nothing
|
|||
const username = 'login2';
|
||||
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.same(contributors, options.contributors);
|
||||
t.end();
|
||||
|
@ -108,7 +108,7 @@ test.cb(`should update an existing contributor's contributions if a new type is
|
|||
const username = 'login1';
|
||||
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.is(contributors.length, 2);
|
||||
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';
|
||||
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.is(contributors.length, 2);
|
||||
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',
|
||||
contributions: [
|
||||
'code',
|
||||
{ type: 'bug', url: 'www.foo.bar' },
|
||||
{type: 'bug', url: 'www.foo.bar'}
|
||||
]
|
||||
});
|
||||
t.end();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash/fp');
|
||||
var request = require('request');
|
||||
|
||||
module.exports = function getUserInfo(username, cb) {
|
||||
|
@ -9,7 +8,7 @@ module.exports = function getUserInfo(username, cb) {
|
|||
headers: {
|
||||
'User-Agent': 'request'
|
||||
}
|
||||
}, function(error, res) {
|
||||
}, function (error, res) {
|
||||
if (error) {
|
||||
return cb(error);
|
||||
}
|
||||
|
@ -22,4 +21,4 @@ module.exports = function getUserInfo(username, cb) {
|
|||
};
|
||||
return cb(null, user);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,11 +5,11 @@ var github = require('./github');
|
|||
var configFile = require('../configFile');
|
||||
|
||||
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) {
|
||||
return cb(error);
|
||||
}
|
||||
configFile.writeContributors(options.config, contributors, function(error) {
|
||||
configFile.writeContributors(options.config, contributors, function (error) {
|
||||
return cb(error, contributors);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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)';
|
||||
|
||||
module.exports = function formatBadge(options, contributors) {
|
||||
return _.template(options.badgeTemplate || defaultTemplate)({
|
||||
return _.template(options.badgeTemplate || defaultTemplate)({
|
||||
contributors: contributors
|
||||
});
|
||||
};
|
||||
|
|
|
@ -2,15 +2,6 @@ import test from 'ava';
|
|||
import _ from 'lodash/fp';
|
||||
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 => {
|
||||
const options = {};
|
||||
const expected8 =
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
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 linkTemplate = _.template('[<%= symbol %>](<%= url %>)');
|
||||
|
||||
var defaultTypes = {
|
||||
blog: { symbol: '📝' },
|
||||
blog: {symbol: '📝'},
|
||||
bug: {
|
||||
symbol: '🐛',
|
||||
link: linkToIssues
|
||||
|
@ -16,24 +16,24 @@ var defaultTypes = {
|
|||
symbol: '💻',
|
||||
link: linkToCommits
|
||||
},
|
||||
design: { symbol: '🎨' },
|
||||
design: {symbol: '🎨'},
|
||||
doc: {
|
||||
symbol: '📖',
|
||||
link: linkToCommits
|
||||
},
|
||||
example: { symbol: '💡' },
|
||||
plugin: { symbol: '🔌' },
|
||||
question: { symbol: '❓' },
|
||||
review: { symbol: '👀' },
|
||||
talk: { symbol: '📢' },
|
||||
example: {symbol: '💡'},
|
||||
plugin: {symbol: '🔌'},
|
||||
question: {symbol: '❓'},
|
||||
review: {symbol: '👀'},
|
||||
talk: {symbol: '📢'},
|
||||
test: {
|
||||
symbol: '⚠️',
|
||||
link: linkToCommits
|
||||
},
|
||||
translation: { symbol: '🌍' },
|
||||
tool: { symbol: '🔧' },
|
||||
tutorial: { symbol: '✅' },
|
||||
video: { symbol: '📹' }
|
||||
translation: {symbol: '🌍'},
|
||||
tool: {symbol: '🔧'},
|
||||
tutorial: {symbol: '✅'},
|
||||
video: {symbol: '📹'}
|
||||
};
|
||||
|
||||
function getType(options, contribution) {
|
||||
|
|
|
@ -9,7 +9,7 @@ const fixtures = () => {
|
|||
imageSize: 100
|
||||
};
|
||||
return {options};
|
||||
}
|
||||
};
|
||||
|
||||
test('should return corresponding symbol', t => {
|
||||
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 {options} = fixtures();
|
||||
options.types = {
|
||||
cheerful: { symbol: ':smiley:' }
|
||||
cheerful: {symbol: ':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 {options} = fixtures();
|
||||
options.types = {
|
||||
code: { symbol: ':smiley:' }
|
||||
code: {symbol: ':smiley:'}
|
||||
};
|
||||
|
||||
t.is(formatContributionType(options, contributor, 'code'), ':smiley:');
|
||||
|
|
|
@ -10,8 +10,8 @@ var contributorTemplate = _.template('<%= avatarBlock %><br /><%= contributions
|
|||
|
||||
function defaultTemplate(templateData) {
|
||||
var avatar = avatarTemplate(templateData);
|
||||
var avatarBlock = avatarBlockTemplate(_.assign({ avatar: avatar }, templateData));
|
||||
return contributorTemplate(_.assign({ avatarBlock: avatarBlock }, templateData));
|
||||
var avatarBlock = avatarBlockTemplate(_.assign({avatar: avatar}, templateData));
|
||||
return contributorTemplate(_.assign({avatarBlock: avatarBlock}, templateData));
|
||||
}
|
||||
|
||||
function updateAvatarUrl(options, contributor) {
|
||||
|
@ -20,7 +20,6 @@ function updateAvatarUrl(options, contributor) {
|
|||
return _.assign(contributor, {
|
||||
avatar_url: avatarUrl + paramJoiner + 's=' + options.imageSize
|
||||
});
|
||||
'<%= contributor.avatar_url %>?s=<%= options.imageSize %>'
|
||||
}
|
||||
|
||||
module.exports = function formatContributor(options, contributor) {
|
||||
|
|
|
@ -13,7 +13,7 @@ function fixtures() {
|
|||
}
|
||||
|
||||
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 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 => {
|
||||
const contributor = contributors.kentcdodds;
|
||||
const {options} = fixtures();
|
||||
options.contributorTemplate = '<%= contributor.name %> is awesome!'
|
||||
options.contributorTemplate = '<%= contributor.name %> 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 => {
|
||||
const {options} = fixtures();
|
||||
const contributor = contributors.kentcdodds;
|
||||
options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>'
|
||||
options.contributorTemplate = '<%= contributor.name %> at <%= contributor.avatar_url %>';
|
||||
|
||||
var contributionWithoutQuestionMarkUrl = _.assign(contributor, {
|
||||
avatar_url: 'www.some-url-without-question-mark.com'
|
||||
|
|
|
@ -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 openingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':START '), lines);
|
||||
var closingTagIndex = _.findIndex(_.startsWith('<!-- ALL-CONTRIBUTORS-' + tag + ':END '), lines);
|
||||
|
|
|
@ -2,13 +2,6 @@ import test from 'ava';
|
|||
import generate from './';
|
||||
import contributors from './fixtures/contributors.json';
|
||||
|
||||
function getUserLine(content, {login}) {
|
||||
return content
|
||||
.split('\n')
|
||||
.filter(line => line.indexOf(login) !== -1)
|
||||
[0];
|
||||
}
|
||||
|
||||
function fixtures() {
|
||||
const options = {
|
||||
projectOwner: 'kentcdodds',
|
||||
|
|
|
@ -13,4 +13,4 @@ function write(filePath, content, cb) {
|
|||
module.exports = {
|
||||
read: read,
|
||||
write: write
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue