Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up code (drop unreachable code) and minor modernization #565

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Jan 25, 2024

No description provided.

Copy link
Contributor Author

@susnux susnux left a comment

Choose a reason for hiding this comment

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

For easier review, left some comments

if (file.substring(file.length - 3) === 'php' && !isCore) {
link += '/index.php/apps/' + app
if (isPHP && !isCore) {
link += `/index.php/apps/${app}`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

template strings are more performant on modern browsers than string concatenation (and I think better readable).

}
if (link.substring(link.length - 1) !== '/') {
if (link.at(-1) !== '/') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.at supports negative indices (like in most other languages) which are the index from the end, meaning -1 is the last char.
Reduces the complexity of this statement.

Comment on lines -177 to -192
if (!isCore) {
link += 'apps/'
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could never reached, because the above if-else were covering !isCore && isPHP and !isCore && !isPHP meaning when we end here isCore is always true.

Copy link

codecov bot commented Jan 25, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (3f8327e) 97.53% compared to head (e0becaf) 98.73%.

Files Patch % Lines
lib/index.ts 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
+ Coverage   97.53%   98.73%   +1.20%     
==========================================
  Files           1        1              
  Lines         243      238       -5     
  Branches       36       34       -2     
==========================================
- Hits          237      235       -2     
+ Misses          5        1       -4     
- Partials        1        2       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@susnux susnux requested a review from Pytal January 25, 2024 15:54
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Copy link
Contributor

@Antreesy Antreesy left a comment

Choose a reason for hiding this comment

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

Couldn't find nothing wrong or broken, seem to be a good patch)
Only tests are missing, right?

@@ -148,43 +148,38 @@ export const imagePath = (app: string, file: string) => {
* @return {string} URL with webroot for a file in an app
*/
export const generateFilePath = (app: string, type: string, file: string) => {
const isCore = window?.OC?.coreApps?.indexOf(app) !== -1
const isCore = window?.OC?.coreApps?.includes(app)
const isPHP = file.slice(-3) === 'php'
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also equivalent to file.substring(file.length - 3) === 'php', good catch to reuse it

link += '/index.php/'
} else {
link += '/'
link += '/index.php'
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving a / character a bit seems to be correct, and isolated in the else block

@susnux
Copy link
Contributor Author

susnux commented Jan 29, 2024

Only tests are missing, right?

Yes added the missing test for when the coreApps variable is undefined.

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux merged commit 47c71c1 into master Jan 29, 2024
14 of 15 checks passed
@susnux susnux deleted the fix/cleanup branch January 29, 2024 12:18
@Antreesy Antreesy mentioned this pull request Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants