Skip to content

Commit

Permalink
Refactor to fix ESLint issues in .changeset/ (#6498)
Browse files Browse the repository at this point in the history
- Because ESLint ignores dot-folders by default, adding an entry to the `.eslintignore` file is needed.
- Because an optional chaining operator (ES2020 syntax) is used, updating `parserOptions.ecmaVersion` is needed.
  • Loading branch information
ybiquitous committed Nov 30, 2022
1 parent 2290f55 commit f069c72
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
29 changes: 21 additions & 8 deletions .changeset/changelog-stylelint.js
Expand Up @@ -28,16 +28,19 @@ const changelogFunctions = {
return Object.entries(resolved)
.reduce((acc, [_type, lines]) => {
const type = /** @type {ReleaseType} */ (_type);

lines.forEach((line) => {
if (line) {
acc.push(`${line}${type === 'major' ? ' (BREAKING)' : ''}`);
}
});

return acc;
}, /** @type {string[]} */ ([]))
.sort((a, b) => {
const aSection = changesetSectionReg.exec(a)?.[1];
const bSection = changesetSectionReg.exec(b)?.[1];

return aSection === bSection
? a.localeCompare(b)
: CHANGESET_SECTIONS.indexOf(aSection) - CHANGESET_SECTIONS.indexOf(bSection);
Expand Down Expand Up @@ -66,15 +69,19 @@ const changelogFunctions = {
const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);

if (!isNaN(num)) prFromSummary = num;

return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
.replace(/^\s*commit:\s*(\S+)/im, (_, commit) => {
commitFromSummary = commit;

return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
.replace(/^\s*(?:author|user):\s*@?(\S+)/gim, (_, user) => {
usersFromSummary.push(user);

return '';
})
.trim();
Expand All @@ -83,26 +90,32 @@ const changelogFunctions = {

const links = await (async () => {
if (prFromSummary !== undefined) {
let { links } = await getInfoFromPullRequest({
let { links: resultLinks } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
});

if (commitFromSummary) {
links = {
...links,
resultLinks = {
...resultLinks,
commit: `[\`${commitFromSummary}\`](https://github.com/${options.repo}/commit/${commitFromSummary})`,
};
}
return links;

return resultLinks;
}

const commitToFetchFrom = commitFromSummary || changeset.commit;

if (commitToFetchFrom) {
let { links } = await getInfo({
let { links: resultLinks } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
return links;

return resultLinks;
}

return {
commit: null,
pull: null,
Expand Down
3 changes: 3 additions & 0 deletions .eslintignore
Expand Up @@ -3,3 +3,6 @@ lib/vendor

# Unignore config files like .prettierrc.js, because they're ignored by default
!.*rc.js

# Unignore dot-folders
!/.changeset
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -58,6 +58,9 @@
},
"prettier": "@stylelint/prettier-config",
"eslintConfig": {
"parserOptions": {
"ecmaVersion": 2020
},
"extends": [
"stylelint"
],
Expand Down

0 comments on commit f069c72

Please sign in to comment.