Skip to content

Commit

Permalink
Add new eslint rules (#11800)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Aug 16, 2018
1 parent 88cb478 commit db6aa02
Show file tree
Hide file tree
Showing 1,344 changed files with 11,125 additions and 11,391 deletions.
15 changes: 14 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
}],
"no-void": 2,
"no-var": 2,
"no-multiple-empty-lines": [2, { "max": 2 }],
"arrow-parens": [2, "always"],
"quote-props": [2, "as-needed"],
"no-array-constructor": 2,
"arrow-spacing": 2,
"arrow-body-style": [2, "as-needed"],
"no-confusing-arrow": [2, { "allowParens": true }],
"dot-notation": 2,
"no-unneeded-ternary": 2,
"spaced-comment": 2,
"space-infix-ops": 2,
"array-bracket-spacing": [2, "never"],
"object-curly-spacing": [2, "always"],
"one-var": [2, "never"],
"no-lonely-if": 2,
"no-trailing-spaces": 2,
Expand All @@ -63,7 +76,7 @@
"space-before-blocks": [2, "always"],
"indent": [2, "tab", {"SwitchCase": 1}],
"eol-last": [2, "always"],
"comma-dangle": [2, "never"],
"comma-dangle": [2, "always-multiline"],
"keyword-spacing": 2,
"block-spacing": 2,
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
Expand Down
60 changes: 28 additions & 32 deletions .scripts/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let historyData = (() => {

octokit.authenticate({
type: 'token',
token: process.env.GITHUB_TOKEN
token: process.env.GITHUB_TOKEN,
});
const owner = 'RocketChat';
const repo = 'Rocket.Chat';
Expand All @@ -31,8 +31,8 @@ function promiseRetryRateLimit(promiseFn, retryWait = 60000) {
return new Promise((resolve, reject) => {
function exec() {
promiseFn()
.then(data => resolve(data))
.catch(error => {
.then((data) => resolve(data))
.catch((error) => {
if (error.headers['x-ratelimit-remaining'] === '0') {
let reset = error.headers['x-ratelimit-reset'];
if (reset) {
Expand All @@ -56,24 +56,24 @@ function getPRInfo(number, commit) {
process.exit(1);
}

return promiseRetryRateLimit(() => octokit.pullRequests.get({owner, repo, number}))
return promiseRetryRateLimit(() => octokit.pullRequests.get({ owner, repo, number }))
.catch(onError)
.then(pr => {
.then((pr) => {
const info = {
pr: number,
title: pr.data.title,
userLogin: pr.data.user.login
userLogin: pr.data.user.login,
};
// data.author_association: 'CONTRIBUTOR',

if (pr.data.milestone) {
info.milestone = pr.data.milestone.title;
}

return promiseRetryRateLimit(() => octokit.pullRequests.getCommits({owner, repo, number}))
return promiseRetryRateLimit(() => octokit.pullRequests.getCommits({ owner, repo, number }))
.catch(onError)
.then(commits => {
info.contributors = _.unique(_.flatten(commits.data.map(i => {
.then((commits) => {
info.contributors = _.unique(_.flatten(commits.data.map((i) => {
if (!i.author || !i.committer) {
return;
}
Expand All @@ -94,7 +94,7 @@ function getPRNumeberFromMessage(message, item) {
const number = match[2] || match[4];

if (!/^\d+$/.test(number)) {
console.error('Invalid number', {number, message});
console.error('Invalid number', { number, message });
process.exit(1);
}

Expand All @@ -108,25 +108,25 @@ function getPullRequests(from, to) {
date: '%ai',
message: '%s',
author_name: '%aN',
author_email: '%ae'
author_email: '%ae',
};

return git.log(logParams).then((log) => {
const items = log.all
.filter(item => /^(\*\s)[0-9a-z]+$/.test(item.hash))
.map(item => {
.filter((item) => /^(\*\s)[0-9a-z]+$/.test(item.hash))
.map((item) => {
item.hash = item.hash.replace(/^(\*\s)/, '');
return item;
})
.filter(item => commitRegex.test(item.message));
.filter((item) => commitRegex.test(item.message));

const data = [];

return new Promise((resolve, reject) => {
const bar = new ProgressBar(' [:bar] :current/:total :percent :etas', {
total: items.length,
incomplete: ' ',
width: 20
width: 20,
});

function process() {
Expand All @@ -137,18 +137,16 @@ function getPullRequests(from, to) {
const partItems = items.splice(0, 10);
bar.tick(partItems.length);

const promises = partItems.map(item => {
return getPRInfo(getPRNumeberFromMessage(item.message, item), item);
});
const promises = partItems.map((item) => getPRInfo(getPRNumeberFromMessage(item.message, item), item));

return Promise.all(promises).then(result => {
return Promise.all(promises).then((result) => {
data.push(..._.compact(result));
if (items.length) {
setTimeout(process, 100);
} else {
resolve(data);
}
}).catch(error => reject(error));
}).catch((error) => reject(error));
}

process();
Expand All @@ -158,7 +156,7 @@ function getPullRequests(from, to) {

function getTags() {
return git.tags().then((tags) => {
tags = tags.all.filter(tag => /^\d+\.\d+\.\d+(-rc\.\d+)?$/.test(tag));
tags = tags.all.filter((tag) => /^\d+\.\d+\.\d+(-rc\.\d+)?$/.test(tag));

tags = tags.sort((a, b) => {
if (semver.gt(a, b)) {
Expand All @@ -173,13 +171,11 @@ function getTags() {
tags.push('HEAD');

return tags
.map((item, index) => {
return {
tag: item,
before: index ? tags[--index] : null
};
})
.filter(item => item.tag === 'HEAD' || semver.gte(item.tag, minTag))
.map((item, index) => ({
tag: item,
before: index ? tags[--index] : null,
}))
.filter((item) => item.tag === 'HEAD' || semver.gte(item.tag, minTag))
.reduce((value, item) => {
value[item.tag] = item;
return value;
Expand All @@ -188,14 +184,14 @@ function getTags() {
}

function getMissingTags() {
return getTags().then(tags => {
return getTags().then((tags) => {
const missingTags = _.difference(Object.keys(tags), Object.keys(historyData));
missingTags.push('HEAD');
return _.pick(tags, missingTags);
});
}

getMissingTags().then(missingTags => {
getMissingTags().then((missingTags) => {
console.log('Missing tags:');
console.log(JSON.stringify(Object.keys(missingTags), null, 2));
missingTags = Object.values(missingTags);
Expand All @@ -209,10 +205,10 @@ getMissingTags().then(missingTags => {
const from = item.before;
const to = item.tag;
console.log('Fetching data for tag:', to, `(from ${ from })`);
getPullRequests(from, to).then(prs => {
getPullRequests(from, to).then((prs) => {
// console.log(' ', prs.length, 'item(s) found');
historyData = Object.assign(historyData, {
[to]: prs
[to]: prs,
});
fs.writeFileSync(historyDataFile, JSON.stringify(historyData, null, 2));
loadMissingTag();
Expand Down
48 changes: 23 additions & 25 deletions .scripts/md.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ const nonContributors = [
'rodrigok',
'renatobecker',
'sampaiodiego',
'SeanPackham'
'SeanPackham',
];

const GroupNames = {
FIX: '### 🐛 Bug fixes',
NEW: '### 🎉 New features',
BREAK: '### ⚠️ BREAKING CHANGES',
MINOR: '🔍 Minor changes'
MINOR: '🔍 Minor changes',
};

const SummaryNameEmoticons = {
FIX: '🐛',
NEW: '🎉',
BREAK: '️️️⚠️',
NOGROUP: '🔍',
contributor: '👩‍💻👨‍💻'
contributor: '👩‍💻👨‍💻',
};

const historyData = (() => {
Expand All @@ -64,7 +64,7 @@ const historyManualData = (() => {
}
})();

Object.keys(historyManualData).forEach(tag => {
Object.keys(historyManualData).forEach((tag) => {
historyData[tag] = historyData[tag] || [];
historyData[tag].unshift(...historyManualData[tag]);
});
Expand All @@ -74,10 +74,10 @@ function groupPRs(prs) {
BREAK: [],
NEW: [],
FIX: [],
NOGROUP: []
NOGROUP: [],
};

prs.forEach(pr => {
prs.forEach((pr) => {
const match = pr.title.match(/\[(FIX|NEW|BREAK)\]\s*(.+)/);
if (match) {
pr.title = match[2];
Expand All @@ -98,26 +98,26 @@ function getLatestCommitDate() {
return execSync('git log --date=short --format=\'%ad\' -1').toString().replace(/\n/, '');
}

Object.keys(historyData).forEach(tag => {
Object.keys(historyData).forEach((tag) => {
historyData[tag] = {
prs: historyData[tag],
rcs: []
rcs: [],
};
});

Object.keys(historyData).forEach(tag => {
Object.keys(historyData).forEach((tag) => {
if (/-rc/.test(tag)) {
const mainTag = tag.replace(/-rc.*/, '');
historyData[mainTag] = historyData[mainTag] || {
noMainRelease: true,
prs: [],
rcs: []
rcs: [],
};

if (historyData[mainTag].noMainRelease) {
historyData[mainTag].rcs.push({
tag,
prs: historyData[tag].prs
prs: historyData[tag].prs,
});
} else {
historyData[mainTag].prs.push(...historyData[tag].prs);
Expand All @@ -132,7 +132,7 @@ const file = [];
function getSummary(contributors, groupedPRs) {
const summary = [];

Object.keys(groupedPRs).forEach(group => {
Object.keys(groupedPRs).forEach((group) => {
if (groupedPRs[group].length) {
summary.push(`${ groupedPRs[group].length } ${ SummaryNameEmoticons[group] }`);
}
Expand All @@ -153,7 +153,7 @@ function renderPRs(prs) {
const data = [];
const groupedPRs = groupPRs(prs);

Object.keys(groupedPRs).forEach(group => {
Object.keys(groupedPRs).forEach((group) => {
const prs = groupedPRs[group];
if (!prs.length) {
return;
Expand All @@ -166,10 +166,10 @@ function renderPRs(prs) {
} else {
data.push(`\n${ groupName }\n`);
}
prs.forEach(pr => {
prs.forEach((pr) => {
let contributors = _.compact(_.difference(pr.contributors, nonContributors))
.sort()
.map(contributor => `[@${ contributor }](https://github.com/${ contributor })`)
.map((contributor) => `[@${ contributor }](https://github.com/${ contributor })`)
.join(' & ');

if (contributors) {
Expand All @@ -184,21 +184,19 @@ function renderPRs(prs) {
}
});

const contributors = _.compact(_.difference(prs.reduce((value, pr) => {
return _.unique(value.concat(pr.contributors));
}, []), nonContributors));
const contributors = _.compact(_.difference(prs.reduce((value, pr) => _.unique(value.concat(pr.contributors)), []), nonContributors));

if (contributors.length) {
// TODO: Improve list like https://gist.github.com/paulmillr/2657075/
data.push('\n### 👩‍💻👨‍💻 Contributors 😍\n');
contributors.sort().forEach(contributor => {
contributors.sort().forEach((contributor) => {
data.push(`- [@${ contributor }](https://github.com/${ contributor })`);
});
}

return {
data,
summary: getSummary(contributors, groupedPRs)
summary: getSummary(contributors, groupedPRs),
};
}

Expand All @@ -219,16 +217,16 @@ function sort(a, b) {
return 0;
}

Object.keys(historyData).sort(sort).forEach(tag => {
const {prs, rcs} = historyData[tag];
Object.keys(historyData).sort(sort).forEach((tag) => {
const { prs, rcs } = historyData[tag];

if (!prs.length && !rcs.length) {
return;
}

const tagDate = tag === 'HEAD' ? getLatestCommitDate() : getTagDate(tag);

const {data, summary} = renderPRs(prs);
const { data, summary } = renderPRs(prs);

const tagText = tag === 'HEAD' ? 'Next' : tag;

Expand All @@ -242,8 +240,8 @@ Object.keys(historyData).sort(sort).forEach(tag => {
file.push(...data);

if (Array.isArray(rcs)) {
rcs.reverse().forEach(rc => {
const {data, summary} = renderPRs(rc.prs);
rcs.reverse().forEach((rc) => {
const { data, summary } = renderPRs(rc.prs);

if (historyData[tag].noMainRelease) {
const tagDate = getTagDate(rc.tag);
Expand Down
Loading

0 comments on commit db6aa02

Please sign in to comment.