Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds hexadecimal support for sequential number generation when the user’s input starts with a 0x prefix.
- Detects hex input via an
isHexflag - Parses the starting value with base 16 and formats subsequent results back to hex
- Falls back to decimal parsing and output when no hex prefix is found
Comments suppressed due to low confidence (1)
extension.js:43
- There are no tests covering the new hexadecimal input/output logic; consider adding unit tests to verify hex parsing and formatting behavior.
let isHex = start.startsWith('0x');
| } | ||
|
|
||
| let result = start; | ||
| let isHex = start.startsWith('0x'); |
There was a problem hiding this comment.
This only checks for a lowercase '0x' prefix; consider normalizing the input (e.g., start.toLowerCase().startsWith('0x')) to also support uppercase '0X'.
| let isHex = start.startsWith('0x'); | |
| let isHex = start.toLowerCase().startsWith('0x'); |
|
|
||
| let result = start; | ||
| let isHex = start.startsWith('0x'); | ||
| let result = isHex ? parseInt(start, 16) : parseInt(start); |
There was a problem hiding this comment.
Avoid using parseInt without an explicit radix on the decimal branch; specify parseInt(start, 10) to ensure consistent parsing.
| let result = isHex ? parseInt(start, 16) : parseInt(start); | |
| let result = isHex ? parseInt(start, 16) : parseInt(start, 10); |
| vscode.window.activeTextEditor.selections.forEach((element, index) => { | ||
| if (index != 0) { | ||
| result = eval(parseInt(result) + operator + parseInt(step)); | ||
| result = eval(result + operator + parseInt(step)); |
There was a problem hiding this comment.
Using eval for arithmetic operations can introduce security risks and performance overhead. Consider replacing it with direct arithmetic based on operator (e.g., a switch statement).
| result = eval(result + operator + parseInt(step)); | |
| switch (operator) { | |
| case '+': | |
| result += parseInt(step); | |
| break; | |
| case '-': | |
| result -= parseInt(step); | |
| break; | |
| case '*': | |
| result *= parseInt(step); | |
| break; | |
| case '/': | |
| result /= parseInt(step); | |
| break; | |
| default: | |
| throw new Error('Unsupported operator: ' + operator); | |
| } |
| vscode.window.activeTextEditor.selections.forEach((element, index) => { | ||
| if (index != 0) { | ||
| result = eval(parseInt(result) + operator + parseInt(step)); | ||
| result = eval(result + operator + parseInt(step)); |
There was a problem hiding this comment.
Also specify a radix when calling parseInt(step) (e.g., parseInt(step, 10)) to prevent unintended parsing behavior.
| result = eval(result + operator + parseInt(step)); | |
| result = eval(result + operator + parseInt(step, 10)); |
No description provided.