Skip to content

Commit a8d1ce5

Browse files
authored
chore: update xo to 0.39.1 (#375)
This is the last version that supports CommonJS.
1 parent 45ad46d commit a8d1ce5

20 files changed

+2292
-5380
lines changed

lib/definitions/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const {inspect} = require('util');
22
const pkg = require('../../package.json');
33

44
const [homepage] = pkg.homepage.split('#');
5-
const linkify = file => `${homepage}/blob/master/${file}`;
6-
const stringify = object => inspect(object, {breakLength: Infinity, depth: 2, maxArrayLength: 5});
5+
const linkify = (file) => `${homepage}/blob/master/${file}`;
6+
const stringify = (object) => inspect(object, {breakLength: Number.POSITIVE_INFINITY, depth: 2, maxArrayLength: 5});
77

88
module.exports = {
99
EINVALIDASSETS: ({assets}) => ({

lib/fail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = async (pluginConfig, context) => {
3131
const openFailTitleIssueEndpoint = urlJoin(issuesEndpoint, `?state=opened&search=${encodedFailTitle}`);
3232

3333
const openFailTitleIssues = await got(openFailTitleIssueEndpoint, {...apiOptions}).json();
34-
const existingIssue = openFailTitleIssues.find(openFailTitleIssue => openFailTitleIssue.title === failTitle);
34+
const existingIssue = openFailTitleIssues.find((openFailTitleIssue) => openFailTitleIssue.title === failTitle);
3535

3636
if (existingIssue) {
3737
debug('comment on issue: %O', existingIssue);

lib/get-fail-comment.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ const GET_HELP_URL = `${HOME_URL}#get-help`;
55
const USAGE_DOC_URL = `${HOME_URL}/blob/master/docs/usage/README.md`;
66
const NEW_ISSUE_URL = `${HOME_URL}/issues/new`;
77

8-
const formatError = error => `### ${error.message}
8+
const formatError = (error) => `### ${error.message}
99
10-
${error.details ||
10+
${
11+
error.details ||
1112
`Unfortunately this error doesn't have any additional information.${
1213
error.pluginName
1314
? ` Feel free to kindly ask the author of the \`${error.pluginName}\` plugin to add more helpful information.`
1415
: ''
15-
}`}`;
16+
}`
17+
}`;
1618

1719
module.exports = (branch, errors) => `## :rotating_light: The automated release from the \`${
1820
branch.name
@@ -37,7 +39,7 @@ If those don't help, or if this issue is reporting something you think isn't rig
3739
3840
---
3941
40-
${errors.map(error => formatError(error)).join('\n\n---\n\n')}
42+
${errors.map((error) => formatError(error)).join('\n\n---\n\n')}
4143
4244
---
4345

lib/get-success-comment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {HOME_URL} = require('./definitions/constants');
22

3-
const linkify = releaseInfo =>
3+
const linkify = (releaseInfo) =>
44
`${releaseInfo.url ? `[${releaseInfo.name}](${releaseInfo.url})` : `\`${releaseInfo.name}\``}`;
55

66
module.exports = (issueOrMergeRequest, releaseInfos, nextRelease) =>
@@ -11,7 +11,7 @@ module.exports = (issueOrMergeRequest, releaseInfos, nextRelease) =>
1111
? `\n\nThe release is available on${
1212
releaseInfos.length === 1
1313
? ` ${linkify(releaseInfos[0])}.`
14-
: `:\n${releaseInfos.map(releaseInfo => `- ${linkify(releaseInfo)}`).join('\n')}`
14+
: `:\n${releaseInfos.map((releaseInfo) => `- ${linkify(releaseInfo)}`).join('\n')}`
1515
}`
1616
: ''
1717
}

lib/glob-assets.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require('path');
2-
const {basename} = require('path');
32
const {isPlainObject, castArray, uniqWith, uniq} = require('lodash');
43
const dirGlob = require('dir-glob');
54
const globby = require('globby');
@@ -8,9 +7,10 @@ const debug = require('debug')('semantic-release:gitlab');
87
module.exports = async ({cwd}, assets) =>
98
uniqWith(
109
[]
10+
// eslint-disable-next-line unicorn/prefer-spread
1111
.concat(
1212
...(await Promise.all(
13-
assets.map(async asset => {
13+
assets.map(async (asset) => {
1414
// Wrap single glob definition in Array
1515
let glob = castArray(isPlainObject(asset) ? asset.path : asset);
1616
// TODO Temporary workaround for https://github.com/mrmlnc/fast-glob/issues/47
@@ -42,7 +42,7 @@ module.exports = async ({cwd}, assets) =>
4242
// - `filepath` ignored (also to avoid duplicates)
4343
// - other properties of the original asset definition
4444
const {filepath, ...others} = asset;
45-
return globbed.map(file => ({...others, path: file, label: basename(file)}));
45+
return globbed.map((file) => ({...others, path: file, label: path.basename(file)}));
4646
}
4747

4848
// If asset is an Object, output an Object definition with:
@@ -62,7 +62,7 @@ module.exports = async ({cwd}, assets) =>
6262
// Sort with Object first, to prioritize Object definition over Strings in dedup
6363
))
6464
)
65-
.sort(asset => (isPlainObject(asset) ? -1 : 1)),
65+
.sort((asset) => (isPlainObject(asset) ? -1 : 1)),
6666
// Compare `path` property if Object definition, value itself if String
6767
(a, b) => path.resolve(cwd, isPlainObject(a) ? a.path : a) === path.resolve(cwd, isPlainObject(b) ? b.path : b)
6868
);

lib/publish.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const {createReadStream} = require('fs');
2-
const {resolve} = require('path');
2+
const pathlib = require('path');
33
const {stat} = require('fs-extra');
44
const {isPlainObject, template} = require('lodash');
55
const FormData = require('form-data');
@@ -35,15 +35,15 @@ module.exports = async (pluginConfig, context) => {
3535
debug('globbed assets: %o', globbedAssets);
3636

3737
await Promise.all(
38-
globbedAssets.map(async asset => {
38+
globbedAssets.map(async (asset) => {
3939
const {path, type, filepath} = isPlainObject(asset) ? asset : {path: asset};
40-
const file = resolve(cwd, path);
40+
const file = pathlib.resolve(cwd, path);
4141
const label = asset.label ? template(asset.label)(context) : undefined;
4242
let fileStat;
4343

4444
try {
4545
fileStat = await stat(file);
46-
} catch (_) {
46+
} catch {
4747
logger.error('The asset %s cannot be read, and will be ignored.', path);
4848
return;
4949
}

lib/resolve-config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function shouldProxy(gitlabUrl, NO_PROXY) {
7878
// Stripping ports in this way instead of using parsedUrl.hostname to make
7979
// sure that the brackets around IPv6 addresses are kept.
8080
hostname = hostname.replace(/:\d*$/, '');
81-
port = parseInt(port, 10) || DEFAULT_PORTS[proto] || 0;
81+
port = Number.parseInt(port, 10) || DEFAULT_PORTS[proto] || 0;
8282

8383
if (!NO_PROXY) {
8484
return true; // Always proxy if NO_PROXY is not set.
@@ -88,14 +88,14 @@ function shouldProxy(gitlabUrl, NO_PROXY) {
8888
return false; // Never proxy if wildcard is set.
8989
}
9090

91-
return NO_PROXY.split(/[,\s]/).every(function(proxy) {
91+
return NO_PROXY.split(/[,\s]/).every((proxy) => {
9292
if (!proxy) {
9393
return true; // Skip zero-length hosts.
9494
}
9595

9696
const parsedProxy = proxy.match(/^(.+):(\d+)$/);
9797
let parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy;
98-
const parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2], 10) : 0;
98+
const parsedProxyPort = parsedProxy ? Number.parseInt(parsedProxy[2], 10) : 0;
9999
if (parsedProxyPort && parsedProxyPort !== port) {
100100
return true; // Skip if ports don't match.
101101
}

lib/success.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ module.exports = async (pluginConfig, context) => {
2222
if (successComment === false) {
2323
logger.log('Skip commenting on issues and pull requests.');
2424
} else {
25-
const releaseInfos = releases.filter(release => Boolean(release.name));
25+
const releaseInfos = releases.filter((release) => Boolean(release.name));
2626
try {
27-
const postCommentToIssue = issue => {
27+
const postCommentToIssue = (issue) => {
2828
const issueNotesEndpoint = urlJoin(gitlabApiUrl, `/projects/${issue.project_id}/issues/${issue.iid}/notes`);
2929
debug('Posting issue note to %s', issueNotesEndpoint);
3030
const body = successComment
@@ -37,7 +37,7 @@ module.exports = async (pluginConfig, context) => {
3737
});
3838
};
3939

40-
const postCommentToMergeRequest = mergeRequest => {
40+
const postCommentToMergeRequest = (mergeRequest) => {
4141
const mergeRequestNotesEndpoint = urlJoin(
4242
gitlabApiUrl,
4343
`/projects/${mergeRequest.project_id}/merge_requests/${mergeRequest.iid}/notes`
@@ -53,7 +53,7 @@ module.exports = async (pluginConfig, context) => {
5353
});
5454
};
5555

56-
const getRelatedMergeRequests = async commitHash => {
56+
const getRelatedMergeRequests = async (commitHash) => {
5757
const relatedMergeRequestsEndpoint = urlJoin(
5858
gitlabApiUrl,
5959
`/projects/${encodedRepoId}/repository/commits/${commitHash}/merge_requests`
@@ -66,10 +66,10 @@ module.exports = async (pluginConfig, context) => {
6666
})
6767
.json();
6868

69-
return relatedMergeRequests.filter(x => x.state === 'merged');
69+
return relatedMergeRequests.filter((x) => x.state === 'merged');
7070
};
7171

72-
const getRelatedIssues = async mergeRequest => {
72+
const getRelatedIssues = async (mergeRequest) => {
7373
const relatedIssuesEndpoint = urlJoin(
7474
gitlabApiUrl,
7575
`/projects/${mergeRequest.project_id}/merge_requests/${mergeRequest.iid}/closes_issues`
@@ -82,16 +82,19 @@ module.exports = async (pluginConfig, context) => {
8282
})
8383
.json();
8484

85-
return relatedIssues.filter(x => x.state === 'closed');
85+
return relatedIssues.filter((x) => x.state === 'closed');
8686
};
8787

8888
const relatedMergeRequests = uniqWith(
89-
(await Promise.all(commits.map(x => x.hash).map(getRelatedMergeRequests))).flat(),
89+
(await Promise.all(commits.map((commit) => getRelatedMergeRequests(commit.hash)))).flat(),
9090
isEqual
9191
);
92-
const relatedIssues = uniqWith((await Promise.all(relatedMergeRequests.map(getRelatedIssues))).flat(), isEqual);
93-
await Promise.all(relatedIssues.map(postCommentToIssue));
94-
await Promise.all(relatedMergeRequests.map(postCommentToMergeRequest));
92+
const relatedIssues = uniqWith(
93+
(await Promise.all(relatedMergeRequests.map((mergeRequest) => getRelatedIssues(mergeRequest)))).flat(),
94+
isEqual
95+
);
96+
await Promise.all(relatedIssues.map((issues) => postCommentToIssue(issues)));
97+
await Promise.all(relatedMergeRequests.map((mergeRequest) => postCommentToMergeRequest(mergeRequest)));
9598
} catch (error) {
9699
logger.error('An error occurred while posting comments to related issues and merge requests:\n%O', error);
97100
throw error;

lib/verify.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ const resolveConfig = require('./resolve-config');
77
const getRepoId = require('./get-repo-id');
88
const getError = require('./get-error');
99

10-
const isNonEmptyString = value => isString(value) && value.trim();
11-
const isStringOrStringArray = value => isNonEmptyString(value) || (isArray(value) && value.every(isNonEmptyString));
12-
const isArrayOf = validator => array => isArray(array) && array.every(value => validator(value));
13-
const canBeDisabled = validator => value => value === false || validator(value);
10+
const isNonEmptyString = (value) => isString(value) && value.trim();
11+
const isStringOrStringArray = (value) =>
12+
isNonEmptyString(value) || (isArray(value) && value.every((item) => isNonEmptyString(item)));
13+
const isArrayOf = (validator) => (array) => isArray(array) && array.every((value) => validator(value));
14+
const canBeDisabled = (validator) => (value) => value === false || validator(value);
1415

1516
const VALIDATORS = {
1617
assets: isArrayOf(
17-
asset => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
18+
(asset) => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
1819
),
1920
failTitle: canBeDisabled(isNonEmptyString),
2021
failComment: canBeDisabled(isNonEmptyString),
@@ -37,11 +38,9 @@ module.exports = async (pluginConfig, context) => {
3738
return isNil(value) || isNil(validator) || VALIDATORS[option](value);
3839
};
3940

40-
const errors = Object.entries({...options}).reduce(
41-
(errors, [option, value]) =>
42-
isValid(option, value) ? errors : [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})],
43-
[]
44-
);
41+
const errors = Object.entries({...options})
42+
.filter(([option, value]) => !isValid(option, value))
43+
.map(([option, value]) => getError(`EINVALID${option.toUpperCase()}`, {[option]: value}));
4544

4645
if (!repoId) {
4746
errors.push(getError('EINVALIDGITLABURL'));

0 commit comments

Comments
 (0)