Skip to content

Commit ae31c22

Browse files
Copilotalexr00
andcommitted
Extract magic number to class constant for better maintainability
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 4a315a4 commit ae31c22

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/test/view/compareChangesTreeDataProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { default as assert } from 'assert';
77

88
// Test the text truncation logic that should be applied to tree view button text
99
describe('CompareChangesTreeDataProvider text truncation', () => {
10-
const MAX_BUTTON_TEXT_LENGTH = 40; // Same constant used in implementation
10+
const MAX_BUTTON_TEXT_LENGTH = 40; // Same constant used in CompareChangesFilesTreeProvider
1111

1212
function truncateButtonText(buttonText: string): string {
1313
return buttonText.length > MAX_BUTTON_TEXT_LENGTH

src/view/compareChangesTreeDataProvider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ abstract class CompareChangesTreeProvider extends Disposable implements vscode.T
208208
}
209209

210210
class CompareChangesFilesTreeProvider extends CompareChangesTreeProvider {
211+
private static readonly MAX_BUTTON_TEXT_LENGTH = 40; // Reasonable length for tree view messages
212+
211213
constructor(
212214
model: CreatePullRequestDataModel,
213215
private folderRepoManager: FolderRepositoryManager,
@@ -267,9 +269,8 @@ class CompareChangesFilesTreeProvider extends CompareChangesTreeProvider {
267269

268270
// Create the button text with potential truncation for better UI in smaller panels
269271
const buttonText = vscode.l10n.t('$(sparkle) {0} Code Review', preReviewer.title);
270-
const MAX_BUTTON_TEXT_LENGTH = 40; // Reasonable length for tree view messages
271-
const truncatedButtonText = buttonText.length > MAX_BUTTON_TEXT_LENGTH
272-
? buttonText.substring(0, MAX_BUTTON_TEXT_LENGTH - 3) + '...'
272+
const truncatedButtonText = buttonText.length > CompareChangesFilesTreeProvider.MAX_BUTTON_TEXT_LENGTH
273+
? buttonText.substring(0, CompareChangesFilesTreeProvider.MAX_BUTTON_TEXT_LENGTH - 3) + '...'
273274
: buttonText;
274275

275276
markdown.appendMarkdown(`[${truncatedButtonText}](command:pr.preReview)`);

0 commit comments

Comments
 (0)