Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

fix(link-replacer): add common helper to replace link references #259

Merged
merged 3 commits into from
Jul 19, 2022

Conversation

Arinono
Copy link
Contributor

@Arinono Arinono commented Jul 15, 2022

Authors

@Arinono

Issues

refs withthegrid/platform-client#1368

Implementation details

Mostly taking what was on both the client and the platform, refactoring it a bit and adding unit tests.

Screenshot 2022-07-15 at 19 46 06

src/commons/link-replacer.ts Outdated Show resolved Hide resolved
@@ -5,6 +5,7 @@ import Routes, * as IndividualRoutes from './routes';

import * as models from './models';
import * as routes from './routes/routes';
import * as commons from './commons';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with commons, but hesitated with shared. Please, I'm open to suggestions. (At least shared would match one pattern we have in the client)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have picked shared but without any particular reason. Both are completely fine as far as I'm concerned so I would leave it like this.

Comment on lines +6 to +19
const matchers = [
[
'issues',
new RegExp(`(?<key>${issue.join('|')}) #(?<hashid>[\\w\\d]{6,})`, 'gi'),
],
[
'reports',
new RegExp(`(?<key>${report.join('|')}) #(?<hashid>[\\w\\d]{6,})`, 'gi'),
],
[
'commands',
new RegExp(`(?<key>${command.join('|')}) #(?<hashid>[\\w\\d]{6,})`, 'gi'),
],
];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only match on strict strings (not space before or after), because it should be up to the consumer of this module to decide how to format.
And there were issues with the previous regexp I think ((^|\s) would match on the start string token before space in all cases I think)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: Here is an example of the "failing" regexp we used before this change

Spacing in the replacement is borked
Screenshot 2022-07-18 at 11 01 16

@Arinono Arinono marked this pull request as ready for review July 18, 2022 09:02
@Arinono Arinono requested a review from srieding July 18, 2022 09:02
Copy link
Collaborator

@srieding srieding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean and polished

@@ -5,6 +5,7 @@ import Routes, * as IndividualRoutes from './routes';

import * as models from './models';
import * as routes from './routes/routes';
import * as commons from './commons';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have picked shared but without any particular reason. Both are completely fine as far as I'm concerned so I would leave it like this.

@@ -27,7 +27,7 @@
"build:open-api-file": "ts-node -P tsconfig.cjs.json --files ./documentation/",
"build:redoc-index-html": "redoc-cli bundle ./documentation/redoc.json --output ./docs/index.html -t ./documentation/html-template.hbs",
"prepare": "npm run build",
"lint": "npm run build:cjs && eslint --ext .ts src",
"lint": "npm run build:cjs && eslint --ext .ts src test",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wanted the test files to also be formatted/linted

@Arinono Arinono merged commit 5f2ae4a into main Jul 19, 2022
@Arinono Arinono deleted the fix-platform-client-1368-link-replacement branch July 19, 2022 14:30
github-actions bot pushed a commit that referenced this pull request Jul 19, 2022
## [17.46.5](v17.46.4...v17.46.5) (2022-07-19)

### Bug Fixes

* **link-replacer:** add common helper to replace link references ([#259](#259)) ([5f2ae4a](5f2ae4a)), closes [withthegrid/platform-client#1368](https://github.com/withthegrid/platform-client/issues/1368)
@github-actions
Copy link

🎉 This PR is included in version 17.46.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants