Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions extensions/git-id-switcher/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export default [
"unicorn/prevent-abbreviations": "off",
// userName/userEmail/userSigningKey mirror git config keys (user.name/user.email/user.signingkey);
// "username" connotes a login handle, which these display-name values are not
"unicorn/consistent-compound-words": ["error", { replacements: { userName: false } }],
"unicorn/consistent-compound-words": [
"error",
{ replacements: { userName: false } },
],
"unicorn/filename-case": "off",
"unicorn/no-process-exit": "off",
"unicorn/prefer-module": "off",
Expand All @@ -120,6 +123,34 @@ export default [
"unicorn/import-style": "off",
"unicorn/no-useless-undefined": "off", // TypeScript requires explicit undefined arguments (resolve(undefined), update(key, undefined))
"unicorn/no-useless-error-capture-stack-trace": "off", // V8-specific Error.captureStackTrace is guarded by if-check for non-V8 engines

// ADR-00240 Phase 1: disable v67 rules that conflict with VS Code extension patterns.
"unicorn/no-top-level-assignment-in-function": "off",
"unicorn/no-top-level-side-effects": "off",
"unicorn/no-non-function-verb-prefix": "off",
"unicorn/no-error-property-assignment": "off",

// ADR-00240 Phase 1: keep remaining v67 findings visible while unblocking CI.
"unicorn/prefer-await": "warn",
"unicorn/max-nested-calls": "warn",
"unicorn/consistent-boolean-name": "warn",
"unicorn/no-computed-property-existence-check": "warn",
"unicorn/consistent-class-member-order": "warn",
"unicorn/no-break-in-nested-loop": "warn",
"unicorn/no-unsafe-string-replacement": "warn",
"unicorn/prefer-unicode-code-point-escapes": "warn",
"unicorn/prefer-early-return": "warn",
"unicorn/prefer-number-coercion": "warn",
"unicorn/no-declarations-before-early-exit": "warn",
"unicorn/no-incorrect-template-string-interpolation": "warn",
"unicorn/no-unreadable-array-destructuring": "warn",
"unicorn/number-literal-case": "warn",
"unicorn/require-array-sort-compare": "warn",
"unicorn/no-optional-chaining-on-undeclared-variable": "warn",
"unicorn/prefer-iterator-to-array": "warn",
"unicorn/prefer-minimal-ternary": "warn",
"unicorn/prefer-uint8array-base64": "warn",
"unicorn/prefer-private-class-fields": "warn",
},
linterOptions: {
reportUnusedDisableDirectives: "warn",
Expand Down Expand Up @@ -165,7 +196,12 @@ export default [
},
},
{
files: ["**/validators/common.ts", "**/core/constants.ts", "**/ui/htmlTemplates/csp.ts", "**/ui/htmlTemplates/shell.ts"],
files: [
"**/validators/common.ts",
"**/core/constants.ts",
"**/ui/htmlTemplates/csp.ts",
"**/ui/htmlTemplates/shell.ts",
],
rules: {
"no-restricted-syntax": "off",
"no-magic-numbers": "off",
Expand Down Expand Up @@ -204,6 +240,14 @@ export default [
},
},
{
ignores: ["out/**", "node_modules/**", "coverage/**", "scripts/**", ".vscode-test/**", "*.js", "*.mjs"],
ignores: [
"out/**",
"node_modules/**",
"coverage/**",
"scripts/**",
".vscode-test/**",
"*.js",
"*.mjs",
],
},
];
2 changes: 1 addition & 1 deletion extensions/git-id-switcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
"@vscode/vsce": "^3.9.2",
"eslint": "^10.5.0",
"eslint-plugin-sonarjs": "^4.0.3",
"eslint-plugin-unicorn": "^65.0.1",
"eslint-plugin-unicorn": "^67.0.0",
"fast-check": "^4.8.0",
"glob": "^13.0.6",
"mocha": "^11.7.6",
Expand Down
12 changes: 6 additions & 6 deletions extensions/git-id-switcher/src/commands/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
* @returns New lastIndex after add operation
*/
async function handleManageAdd(lastIndex: number): Promise<number> {
const success = await handleAddIdentity();
if (success) {
const isSuccess = await handleAddIdentity();
if (isSuccess) {
const newIdentities = getIdentitiesWithValidation();
return newIdentities.length - 1;
}
Expand Down Expand Up @@ -140,8 +140,8 @@
context: vscode.ExtensionContext,
statusBar: IdentityStatusBar
): Promise<number> {
const success = await handleDeleteIdentity(context, statusBar, identity);
if (success) {
const isSuccess = await handleDeleteIdentity(context, statusBar, identity);
if (isSuccess) {
const newIdentities = getIdentitiesWithValidation();
return Math.min(index, Math.max(0, newIdentities.length - 1));
}
Expand All @@ -163,8 +163,8 @@
direction: 'up' | 'down'
): Promise<number> {
try {
const moved = await moveIdentityInConfig(identity.id, direction);
if (moved) {
const isMoved = await moveIdentityInConfig(identity.id, direction);
if (isMoved) {
return direction === 'up' ? index - 1 : index + 1;
}
return index;
Expand Down Expand Up @@ -211,24 +211,24 @@
switch (result.action) {
case 'add': {
lastIndex = await handleManageAdd(lastIndex);
break;

Check warning on line 214 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / Security Linting

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 214 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 214 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 214 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Move this nested loop or switch into a function instead of using `break` here
}
case 'edit': {
await handleManageEdit(result.identity, context, statusBar);
lastIndex = result.index;
break;

Check warning on line 219 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / Security Linting

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 219 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 219 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 219 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Move this nested loop or switch into a function instead of using `break` here
}
case 'delete': {
lastIndex = await handleManageDelete(result.identity, result.index, context, statusBar);
break;

Check warning on line 223 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / Security Linting

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 223 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 223 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 223 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Move this nested loop or switch into a function instead of using `break` here
}
case 'moveUp': {
lastIndex = await handleManageMove(result.identity, result.index, 'up');
break;

Check warning on line 227 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / Security Linting

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 227 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 227 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 227 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Move this nested loop or switch into a function instead of using `break` here
}
case 'moveDown': {
lastIndex = await handleManageMove(result.identity, result.index, 'down');
break;

Check warning on line 231 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / Security Linting

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 231 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 231 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Move this nested loop or switch into a function instead of using `break` here

Check warning on line 231 in extensions/git-id-switcher/src/commands/handlers.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Move this nested loop or switch into a function instead of using `break` here
}
}
}
Expand Down
54 changes: 28 additions & 26 deletions extensions/git-id-switcher/src/core/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,38 @@ async function performTrustedInitialization(context: vscode.ExtensionContext): P
});
}),
vscode.workspace.onDidChangeConfiguration((e: vscode.ConfigurationChangeEvent) => {
if (e.affectsConfiguration('gitIdSwitcher')) {
if (!e.affectsConfiguration('gitIdSwitcher')) {
return;
}

try {
const newSnapshot = securityLogger.createConfigSnapshot();
const changes = securityLogger.detectConfigChanges(newSnapshot);
if (changes.length > 0) {
securityLogger.logConfigChanges(changes);
}
securityLogger.storeConfigSnapshot();
} catch (error) {
extensionLogger.error(`Error handling config change: ${getUserSafeMessage(error)}`);
try {
const newSnapshot = securityLogger.createConfigSnapshot();
const changes = securityLogger.detectConfigChanges(newSnapshot);
if (changes.length > 0) {
securityLogger.logConfigChanges(changes);
}
securityLogger.storeConfigSnapshot();
} catch (error) {
extensionLogger.error(`Error handling config change: ${getUserSafeMessage(error)}`);
try {
securityLogger.storeConfigSnapshot();
} catch (snapshotError) {
extensionLogger.error(`Error storing config snapshot: ${getUserSafeMessage(snapshotError)}`);
}
} catch (snapshotError) {
extensionLogger.error(`Error storing config snapshot: ${getUserSafeMessage(snapshotError)}`);
}

invalidateIdentityCache();
initializeState(context)
.then(() => performSyncCheck())
.catch(error => {
const safeMessage = getUserSafeMessage(error);
extensionLogger.error(`Failed to initialize after config change: ${safeMessage}`);
if (isFatalError(error)) {
vscode.window.showErrorMessage(
vscode.l10n.t('Failed to initialize Git ID Switcher: {0}', safeMessage)
);
}
});
}

invalidateIdentityCache();
initializeState(context)
.then(() => performSyncCheck())
.catch(error => {
const safeMessage = getUserSafeMessage(error);
extensionLogger.error(`Failed to initialize after config change: ${safeMessage}`);
if (isFatalError(error)) {
vscode.window.showErrorMessage(
vscode.l10n.t('Failed to initialize Git ID Switcher: {0}', safeMessage)
);
}
});
}),
// Sync check on window focus return
vscode.window.onDidChangeWindowState((state: vscode.WindowState) => {
Expand Down
Loading
Loading