-
Notifications
You must be signed in to change notification settings - Fork 371
refactor: replace substr with slice & use startsWith and endsWith #2032
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
26ddd99
8f94348
5e7690f
309a7c4
70d8891
5cabc4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,7 +136,7 @@ function inferFilePath(documentOrUri: string | TextDocument | URI | undefined): | |
| const extension = LanguageDefaults.getExtension(textDocument.languageId); | ||
| if (extension !== undefined) { | ||
| const extname = path.extname(filePath); | ||
| if (extname.length === 0 && filePath[0] === '.') { | ||
| if (extname.length === 0 && filePath.startsWith('.')) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this better than the array access?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep the array access.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dbaeumer |
||
| return `${filePath}.${extension}`; | ||
| } else if (extname.length > 0 && extname !== extension) { | ||
| return `${filePath.substring(0, filePath.length - extname.length)}.${extension}`; | ||
|
|
@@ -802,7 +802,7 @@ async function computeAllFixes(identifier: VersionedTextDocumentIdentifier, mode | |
| start: textDocument.positionAt(diff.originalStart), | ||
| end: textDocument.positionAt(diff.originalStart + diff.originalLength) | ||
| }, | ||
| newText: fixedContent.substr(diff.modifiedStart, diff.modifiedLength) | ||
| newText: fixedContent.slice(diff.modifiedStart, diff.modifiedStart + diff.modifiedLength) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| }); | ||
| } | ||
| } | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more. Why do you use slice instead of
substring. I makes it easier to see that you are manipulating a string.