### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flip-operator/test/other operators/should flip add operator.js.test.md
This snippet shows a basic JavaScript input expression. It demonstrates the starting point for processing.
```javascript
a + b;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/pull-up-negation/test/should pull up negation from >=.js.test.md
An example of JavaScript code representing input data. This snippet demonstrates a simple boolean comparison.
```javascript
const a = a >= b;
```
--------------------------------
### Configure js-assistant with JSON
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/node types/property access expression/should skip invalid inner expression part.js.test.md
Shows a sample JSON configuration object for the js-assistant. It specifies the file extension to process ('js') and the line range ('2-5') for selection. This configuration is essential for guiding the assistant's operations.
```json
{
"extension": "js",
"selection": "2-5"
}
```
--------------------------------
### JavaScript Input Declaration
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/should retain declare modifier.ts.test.md
This snippet shows the initial JavaScript input with a 'var' declaration. It serves as the starting point for the transformation process.
```javascript
declare var a = "123";
```
--------------------------------
### JavaScript Input Array Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-array-element/test/move down/should move down array element with comment.js.test.md
Demonstrates a simple JavaScript array with numeric values and a comment. This serves as an example input for processing.
```javascript
[
1,
// comment
2,
3,
];
```
--------------------------------
### JavaScript Input: Variable Declaration and Increment
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/declaration splitting/should keep groups together when splitting.js.test.md
This snippet shows the initial input state with several variables declared using `var` and then incremented. It serves as the starting point for the transformation.
```javascript
var a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6;
a++;
b++;
e++;
f++;
```
--------------------------------
### JavaScript JSX Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/collapse-jsx-element/test/should collapse jsx element with newline whitespace content.js.test.md
This snippet shows a basic example of JavaScript JSX syntax for input. It defines a component with nested tags.
```javascript
const jsx =
;
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/pull-up-negation/test/should pull up negation from >=.js.test.md
An example of JavaScript code representing the expected output. This snippet shows an alternative boolean comparison logic.
```javascript
const a = !(a < b);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-to-increment/test/a -= 1/should skip a -= 2.js.test.md
Example of JavaScript input syntax. This snippet demonstrates a simple assignment operation.
```javascript
a -= 2;
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/collapse-property-into-shorthand/test/regression/should work in array literal.js.test.md
This JavaScript code snippet demonstrates the expected output after processing or transforming the input. It shows a more concise syntax for object property initialization (shorthand property names and shorthand method names) compared to the input example.
```javascript
let a = [{ v1 }];
let b = {
v2,
};
```
--------------------------------
### JSON: Configuration Settings
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/add-braces/test/do/should add block to single statement.js.test.md
This JSON snippet defines configuration settings, specifically the file extension for a JavaScript project. It's a simple key-value pair used to guide processing or tooling.
```json
{
"extension": "js"
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-template-literal-to-string/test/should convert template literal to string.js.test.md
Demonstrates how to call a function 'x' with a template literal as input. This is a basic example of how input might be formatted.
```javascript
x(`template`);
```
--------------------------------
### JSON Configuration for Processing
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/node types/identifier/should not change unrelated identifiers with the same name in the same block.js.test.md
Specifies configuration parameters for processing, including the file extension and a selection range. This JSON object guides the processing of the associated code snippets.
```json
{
"extension": "js",
"selection": "72-82"
}
```
--------------------------------
### JavaScript Input Code Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-first-statement-out-of-if-else/test/whitespace/should insert moved statement immediately before if-statement.js.test.md
This snippet represents the initial JavaScript code provided as input. It includes variable declarations, comments, and conditional logic.
```javascript
const myVar = 123;
// a comment
if (x) {
f1();
f2a();
} else {
f1();
f2b();
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flip-operator/test/comparison operators/should flip < to >.js.test.md
Demonstrates a simple JavaScript comparison for input. This code snippet shows a basic less-than comparison.
```javascript
a < b;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/should keep variable declaration if there are other variables in it.js.test.md
This snippet shows a basic JavaScript input with two string variables 'a' and 'b', and a console log for variable 'a'. It serves as a starting point for code processing.
```javascript
const a = "3",
b = "4";
console.log(a);
```
--------------------------------
### Javascript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/comments/should preserve comment in the same line at the end.js.test.md
Demonstrates a basic Javascript input snippet. It initializes an empty object and logs it to the console. This serves as a foundational example for processing Javascript code.
```javascript
var a = {}; // comment
console.log(a);
```
--------------------------------
### JavaScript Output Example: Simplified Array
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flatten-array-rest-property/test/should flatten nested array construction with rest operator.js.test.md
Shows the expected output of the input JavaScript code, demonstrating a simplified array structure. This represents the result after processing.
```javascript
const something = [a, b];
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flip-operator/test/comparison operators/should flip <= to >=.js.test.md
This snippet shows an example of input code in JavaScript. It represents a less than or equal to comparison.
```javascript
a <= b;
```
--------------------------------
### Configuration for js-assistant
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/safety/should show unknown when property access is function call parameter.js.test.md
This JSON configuration specifies parameters for the js-assistant tool. It includes the file extension to process and the specific selection range within the file. This configuration guides the transformation process.
```json
{
"extension": "js",
"selection": "2-7"
}
```
--------------------------------
### JavaScript Input Handling
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-expression-with-existing-variable/test/should replace string from outer scope.js.test.md
This snippet demonstrates how to define and use variables within a JavaScript scope. It includes an example of a function call with a string literal.
```javascript
const aValue = "some value";
{
const anotherValue = 123;
doSomething("some value");
}
```
--------------------------------
### JavaScript Function Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-function-to-arrow-function/test/formatting/should keep extra space in documentation comments.js.test.md
This snippet shows the initial input format for a JavaScript function, including an empty constant declaration and a JSDoc comment. It serves as the starting point for transformations within the assistant.
```javascript
const f1 = function () {
/**
* documentation
*/
const x;
};
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/should skip when used inside its own initialization.js.test.md
Demonstrates an input example in JavaScript. This code defines an object 'a' with a function 'f' that logs the object itself to the console, followed by logging the object 'a'.
```javascript
let a = {
f() {
console.log(a);
}
};
console.log(a);
```
--------------------------------
### JavaScript JSX Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/collapse-jsx-element/test/should collapse jsx element with newline whitespace content.js.test.md
This snippet presents the expected output format for JavaScript JSX. It shows a simplified version of the input JSX.
```javascript
const jsx = ;
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-array-index-of-to-array-includes/test/should convert indexOf call on any array with bigint literal.ts.test.md
Shows the expected output in JavaScript, refining the input example by using the `includes` method for checking BigInt presence, which is generally more readable and direct than `indexOf` for this purpose.
```javascript
const a: Array = [1, "2", 3];
a.includes(12n);
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/split-variable-declaration/test/whitespace/should not insert blank line when there is trailing whitespace.js.test.md
Illustrates the expected formatted output in JavaScript, with variables declared on separate lines. This serves as a target output example.
```javascript
var value1 = 1;
var value2 = 2;
console.log(value1);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/should inline two occurences of const.js.test.md
Demonstrates a simple JavaScript input variable and console logging. This code snippet is intended to show basic JavaScript execution.
```javascript
const a = "3";
console.log(a);
console.log(a);
```
--------------------------------
### JavaScript Expected Output Array Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-array-element/test/move down/should move down array element with comment.js.test.md
Shows the expected output array after a transformation, reordering elements from the input array and retaining the comment. This example illustrates the result of the assistant's processing.
```javascript
[
1,
3,
// comment
2,
];
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/expand-self-closing-jsx-element/test/should expand empty self-closing jsx element.js.test.md
Demonstrates a simple JavaScript input, showcasing JSX syntax. No specific dependencies are required for this basic example.
```javascript
const jsx = ;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/split-variable-declaration/test/whitespace/should not insert blank line when there is trailing whitespace.js.test.md
Demonstrates basic JavaScript variable declaration and console output. This snippet is intended as an input example for the js-assistant.
```javascript
var value1 = 1,
value2 = 2;
console.log(value1);
```
--------------------------------
### JavaScript Input Example: Math.pow with Optional Chaining
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-math-pow-to-exponentiation/test/should add parentheses when converting Math.pow in optional property access expression.js.test.md
This JavaScript snippet showcases the use of Math.pow with optional chaining and toString() method. It represents an input transformation scenario.
```javascript
Math.pow(2, 3)?.toString();
```
--------------------------------
### Setup Language Server Initialization and Capabilities Management (JavaScript)
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/regression/new expression with type arguments.ts.test.md
This snippet demonstrates how to set up a language server using `vscode-languageserver`. It includes initializing the server, handling document changes, and managing custom capabilities via a request handler. Dependencies include `vscode-languageserver` and `vscode-languageserver-textdocument`.
```javascript
/*
* Copyright P42 Software UG (haftungsbeschränkt). All Rights Reserved.
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
*/
import {
Connection,
InitializeParams,
InitializeResult,
RequestType,
ServerCapabilities,
TextDocuments,
} from "vscode-languageserver";
import { TextDocument } from "vscode-languageserver-textdocument";
import { BasicCapabilityManager } from "../shared/license/BasicCapabilityManager";
import { CapabilityConfiguration } from "../shared/license/Capability";
export const setCapabilitiesRequestType = new RequestType<
CapabilityConfiguration,
void,
void
>("p42/set-capabilities");
export const setupServer = (connection: Connection) => {
connection.onInitialize((params: InitializeParams): InitializeResult => {
const capabilities: ServerCapabilities = {};
return { capabilities };
});
const documents = new TextDocuments(TextDocument);
documents.listen(connection);
const capabilityManager = new BasicCapabilityManager();
capabilityManager.onCapabilitiesChanged(async () => {
console.log(
"capabilities changed",
await capabilityManager.getCapabilities()
);
});
connection.onRequest(
setCapabilitiesRequestType,
async (capabilities) => void capabilityManager.setCapabilities(capabilities)
);
connection.listen();
};
```
--------------------------------
### JavaScript: Check if string does not start with '/'
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-string-starts-with/test/should convert first character for strict not equal comparison on string.ts.test.md
Demonstrates how to check if a given string does not start with a '/' character in JavaScript. This is useful for parsing commands or file paths. It shows an alternative implementation using the startsWith() method for improved readability.
```javascript
let s: string = '123';
const match = !(s[0] === '/');
```
```javascript
let s: string = '123';
const match = !s.startsWith('/');
```
--------------------------------
### JavaScript Input Example for JS Assistant
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/formatting/should inline one occurence of const into multiline function param.js.test.md
This snippet shows a basic JavaScript input example. It declares a string variable and logs it to the console along with another string. No external dependencies are required.
```javascript
const a = "3";
console.log(
"abc",
a
);
```
--------------------------------
### JSON Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable-occurrence/test/should skip variable that is modified.test.md
Shows a sample JSON configuration object for the project. This configuration specifies file extensions and selection ranges, likely used for parsing or processing code. It's a standard JSON object with string values.
```json
{
"extension": "js",
"selection": "68-68"
}
```
--------------------------------
### JavaScript Output Format Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-loop-to-for-each/test/for-of-loop/should preserve element type annotation.ts.test.md
Illustrates an expected output format in JavaScript using the forEach method for iteration. This example shows an alternative to the for...of loop for processing elements.
```javascript
elements.forEach((element: ElementType) => {
console.log(element);
});
```
--------------------------------
### JavaScript Input Handling Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-loop-to-for-with-index/test/for-of-loop/should provide index variable without local collisions 1.js.test.md
This JavaScript snippet demonstrates iterating over elements and logging them to the console. It assumes a variable 'elements' is defined elsewhere.
```javascript
const i = "123";
for (const element of elements) {
console.log(element);
}
```
--------------------------------
### JavaScript Input Handling and Function Execution
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/variable hiding/should consider scope and variable hiding with decrement expression.js.test.md
This snippet demonstrates how to declare variables, define functions, and use console logging in JavaScript. It highlights variable scope differences between 'var' and 'let' by showing the expected output after a function call.
```javascript
var x = "";
function f(b) {
var x = 3;
x--;
console.log(x);
}
console.log(x);
```
```javascript
const x = "";
function f(b) {
let x = 3;
x--;
console.log(x);
}
console.log(x);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-expression-with-existing-variable/test/should replace string.js.test.md
Demonstrates a basic JavaScript input snippet. It declares a variable and calls a function with a string literal. This is a common pattern for initial script setup.
```javascript
const aValue = "some value";
doSomething("some value");
```
--------------------------------
### JSON Expected Matches Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/pull-up-negation/test/safety/should provide information if nullish or NaN values are affected.js.test.md
Shows an example of expected matches in JSON format, including safety level and a descriptive message for binary expressions.
```json
{
"9-16-BinaryExpression": {
"safety": {
"level": "WARNING",
"message": "can affect result for nullish and NaN values"
}
}
}
```
--------------------------------
### JavaScript AST Input: Double Negation
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-double-negation/test/parentheses/should retain parentheses around binary expression inside type assertion.ts.test.md
This JavaScript AST snippet represents the input code with a double negation applied to a logical OR expression. It serves as the starting point for the transformation.
```javascript
!!(a || b) as AType;
```
--------------------------------
### Input Code Example in JavaScript
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/pull-up-negation/test/should pull up negation from ===.js.test.md
This snippet shows a basic JavaScript input example. It declares a constant 'a' and assigns it the result of a comparison between 'a' and 'b'. The primary dependency is the JavaScript runtime environment.
```javascript
const a = a === b;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/pull-up-negation/test/should pull up negation from ==.js.test.md
This snippet shows an example of JavaScript code that serves as input for the assistant. It declares a variable 'a' and assigns the result of a comparison between 'a' and 'b'.
```javascript
const a = a == b;
```
--------------------------------
### JavaScript Tagged Template Input
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-substring-to-variable/test/full template/safety/should show warning when extracting from tagged template middle.js.test.md
Defines the input for a tagged template literal in JavaScript. It uses custom boundary markers to segment the string. This is the starting point for template processing.
```javascript
const a = tag`1${boundary}2345678${boundary2}9`;
```
--------------------------------
### JSON Configuration for Code Analysis
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-substring-to-variable/test/full template/safety/should show warning when extracting from tagged template middle.js.test.md
Provides configuration settings for a code analysis tool, specifying the file extension and the selection range for analysis. This is used to guide the scanning process.
```json
{
"extension": "js",
"selection": "28-31"
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/safety/should show safe when inlining negative bigint literals.js.test.md
Demonstrates a simple JavaScript input snippet declaring and logging a BigInt value. This showcases basic variable declaration and console output.
```javascript
const a = -33n;
console.log(a);
```
--------------------------------
### JavaScript Conditional Logic: Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/split-if/test/on ||/should split if on 2nd || in 2-|| chain.js.test.md
Presents an alternative JavaScript conditional structure that processes the same input conditions as the first example but with a different logic flow. It first checks 'a || b' and then 'c' in an 'else if' block. This demonstrates how to achieve similar outcomes with varied conditional statements.
```javascript
if (a || b) {
console.log("1");
} else if (c) {
console.log("1");
}
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/safety/should show safe when inlining negative bigint literals.js.test.md
Shows the expected JavaScript output based on the provided input and matches. This snippet simplifies the input to directly log the BigInt value.
```javascript
console.log(-33n);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-braces-from-jsx-attribute/test/should skip non-string expression.js.test.md
Illustrates a JavaScript input snippet, likely for parsing or processing. This example shows a JSX-like tag with an attribute.
```javascript
const a =
```
--------------------------------
### JavaScript Input Code Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-double-negation/test/safety and suggestion/should show safe on parenthesized && expression with boolean components.js.test.md
This snippet demonstrates a basic JavaScript input with boolean variables and a logical operation. It serves as an example input for the JavaScript assistant.
```javascript
const a = true;
const b = false;
const x = !!(a && b);
```
--------------------------------
### Vue Input Component Script (TypeScript)
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/language/vue/inline let variable in typescript script section.vue.test.md
Represents the input script section of a Vue.js component written in TypeScript. It demonstrates variable declaration and function invocation, serving as the starting point for transformations.
```typescript
const a = new A("test");
f(a);
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-array-index-of-to-array-includes/test/should convert indexOf call on any array with numeric literal.ts.test.md
Shows the expected output in JavaScript, illustrating a transformation from the input example using the includes method for a more robust check.
```javascript
const a: Array = [1, "2", 3];
a.includes(123);
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/surround-with-try-catch/test/should surround 3 selected statements with try-catch in 2-level-deep block.js.test.md
Illustrates the expected JavaScript output after processing. This example shows the original structure augmented with a try-catch block around a section of the code.
```javascript
{
{
console.log("1");
try {
console.log("2");
console.log("3");
console.log("4");
} catch (error) {
}
console.log("5");
}
}
```
--------------------------------
### Process Input with Lodash in JavaScript
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-lodash-every-with-javascript-array-every/test/should skip every with string argument.js.test.md
Demonstrates processing an input array using the Lodash library in JavaScript. It utilizes the `_.every` function to check if all elements in the input array satisfy a condition. The example requires the 'lodash' package to be installed.
```javascript
const _ = require('lodash');
const input = [1, 2];
const result = _.every(input, 'value');
```
--------------------------------
### JavaScript Input Handling Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-template-literal/test/escape/should escape double backticks when creating template literal.js.test.md
This snippet demonstrates how to declare a variable and then concatenate it within a string. It highlights a common pattern for processing user input or data.
```javascript
var x;
let s = "``" + x;
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/should inline two occurences of const.js.test.md
Illustrates the expected output from the provided JavaScript input. This shows the result of executing the input code, specifically logging the value '3' twice.
```javascript
console.log("3");
console.log("3");
```
--------------------------------
### Expected Matches Object Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/simplify-switch/test/replace with default statements/suggestion/should show simplify switch suggestion.test.md
An example of an object detailing expected matches, including a 'suggestion' with a 'description'. This format appears to be used for providing feedback or guidance on code analysis.
```json
{
"0-58-SwitchStatement": {
"suggestion": {
"description": "You can simplify the switch statement."
}
}
}
```
--------------------------------
### JavaScript Input Example: Array indexOf Method
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-array-index-of-to-array-includes/test/should convert 2nd argument.js.test.md
Demonstrates the usage of the Array.prototype.indexOf() method in JavaScript to find the index of an element within an array, starting from a specified index. It checks if the element is found by comparing the result to -1.
```javascript
[1, 2, 3].indexOf(c, 2) !== -1;
```
--------------------------------
### JSON Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/node types/should skip variable declaration name.js.test.md
This snippet shows a sample JSON configuration. It specifies an 'extension' as 'js' and a 'selection' range from line 6 to 7. This configuration is typically used to define settings for processing or analysis.
```json
{
"extension": "js",
"selection": "6-7"
}
```
--------------------------------
### JavaScript Output Example: Double Negated OR Expression
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-down-negation/test/should push down negation into && condition with negated arguments.js.test.md
This snippet shows the expected JavaScript output for a given input, transforming a negated AND into a double-negated OR expression. This demonstrates logical equivalence.
```javascript
!!a || !!b;
```
--------------------------------
### Configuration for JavaScript Code Transformation
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/split-if/test/on &&/should split if-else on && and warn.js.test.md
This JSON object outlines the configuration parameters for a code transformation. It specifies the file extension ('js'), the exact line range for the transformation ('6-6'), and the identifier for the transformation itself ('split-and-into-nested-if'). This configuration guides the transformation process.
```json
{
"extension": "js",
"selection": "6-6",
"transformationId": "split-and-into-nested-if"
}
```
--------------------------------
### JSON Configuration for JavaScript Extension
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-jsx-element/test/arrow function target/jsx element/should extract jsx element with a several parameters.test.md
A JSON configuration object specifying file extension as 'js', a selection range '67-95', and interactive input settings for selecting an option to 'Extract as arrow function'. This is used to guide code transformations.
```json
{
"extension": "js",
"selection": "67-95",
"interactiveInput": {
"selectOption": {
"return": "Extract as arrow function"
}
}
}
```
--------------------------------
### Vue Input Code
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/language/vue/inline let variable in basic script section with crlf.vue.test.md
This snippet represents the initial Vue component code provided as input. It includes template, script, and style sections. The script section declares a variable 'a' and logs it to the console.
```vue
```
--------------------------------
### JavaScript Input Handling with Caching
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-return/test/inner function/should skip if assignment is in a inner function that returns variable.js.test.md
Demonstrates a JavaScript function 'q' that caches the result of another function 'source'. This is useful for optimizing repeated calls with the same context, avoiding redundant computations.
```javascript
const q = (x) => {
let cachedValues;
return (context) => {
if (cachedValues == null) {
cachedValues = source(context);
}
return cachedValues;
};
};
```
--------------------------------
### JavaScript Function for Input String Check
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-string-starts-with/test/should convert first character when called in function.ts.test.md
This JavaScript function checks if a given string starts with a forward slash. It takes a string as input and returns a boolean indicating the match. This is a common pattern for command parsing or URL handling.
```javascript
function f(s: string) {
const match = s[0] === '/';
}
```
```javascript
function f(s: string) {
const match = s.startsWith('/');
}
```
--------------------------------
### Activate VS Code Extension Entry Point with TypeScript
Source: https://context7.com/lgrammel/js-assistant/llms.txt
The entry point for the VS Code extension, responsible for activating and initializing the language server client. It imports necessary VS Code modules and custom setup classes.
```typescript
import * as vscode from "vscode";
import { ExtensionSetup } from "./ExtensionSetup";
import { NodeLanguageServerClient } from "./NodeLanguageServerClient";
export const activate = async (context: vscode.ExtensionContext) => {
await ExtensionSetup.activate({
context,
type: "node",
languageServerClient: new NodeLanguageServerClient(context),
});
};
export const deactivate = async () => {
await ExtensionSetup.deactivate();
};
```
--------------------------------
### Transform JavaScript Function with Conditional Logic
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-return/test/should inline single return and keep original variable declaration when return is inside if.js.test.md
This snippet shows an initial JavaScript function and its transformed version. The transformation, guided by an external condition `x`, changes the function's behavior to either return the result of `f()` or a default value. The configuration specifies the file extension as 'js'.
```javascript
function g() {
let a = 123;
if (x) {
a = f();
}
return a;
};
```
```javascript
function g() {
if (x) {
return f();
}
return 123;
};
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/add-braces-to-arrow-function/test/should add braces to arrow function with object literal body and remove parentheses.js.test.md
Demonstrates a simple JavaScript arrow function that returns an object. This snippet serves as an input example for processing.
```javascript
let a = () => ({ x: "abc" });
```
--------------------------------
### Iterate JavaScript Object Entries with for...of
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/loops/should convert var to const in for of loop over object without modification.js.test.md
This snippet shows how to iterate over the key-value pairs of a JavaScript object. It uses the `Object.entries()` method to get an array of a given object's own enumerable string-keyed property [key, value] pairs, and then iterates over this array using a `for...of` loop. This is a standard way to access both keys and values simultaneously in modern JavaScript.
```javascript
var object = {
'a': 1,
'b': 2,
'c': 3,
'd': 4,
};
for (var [key, value] of object.entries()) {
console.log(key, value);
}
```
```javascript
const object = {
'a': 1,
'b': 2,
'c': 3,
'd': 4,
};
for (const [key, value] of object.entries()) {
console.log(key, value);
}
```
--------------------------------
### Configuration Settings (JSON)
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/container types/for loops/should convert for loop content to block when needed.js.test.md
This snippet shows a sample JSON configuration object. It includes properties like 'extension' and 'selection', commonly used for defining operational parameters.
```json
{
"extension": "js",
"selection": "59-69"
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/should skip when identifier is hoisted through object value.js.test.md
This snippet demonstrates a JavaScript input example with a variable declaration and assignment. It highlights a potential issue with hoisting or variable scope if 'b' is not defined before its usage.
```javascript
const data = { x: b };
var b = 3;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/safety/should show safe when inlining numeric literals.js.test.md
Demonstrates a basic JavaScript input snippet. This code declares a variable and logs its value to the console. It serves as a simple example of code processing within the assistant.
```javascript
const a = 123;
console.log(a);
```
--------------------------------
### JavaScript Input Function Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-named-function-to-function-expression/test/should convert named function without parameters.js.test.md
This snippet demonstrates a basic JavaScript function named 'f' that logs 'test' to the console. It serves as an example of input code.
```javascript
function f() {
console.log("test");
}
```
--------------------------------
### JSON Expected Matches Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-array-index-of-to-array-includes/test/should convert indexOf call on any array with bigint literal.ts.test.md
An example of JSON structure for expected matches, including safety level and suggestions. This format is likely used for testing or validation purposes.
```json
{
"34-56-BinaryExpression": {
"safety": {
"level": "SAFE"
},
"suggestion": {}
}
}
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flip-operator/test/safety/should show safe when flipping plus with 2 numbers.ts.test.md
An example of expected JavaScript output, showing a function where the order of addition might be changed. This illustrates a potential transformation or refactoring outcome.
```javascript
function f(a: number, b: number) {
b + a;
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-let-to-const/test/should skip var declaration.js.test.md
Demonstrates a basic JavaScript input snippet. This code initializes a string variable 'a' and then calls a function 'f' with 'a' as an argument. It assumes the existence of a function 'f'.
```javascript
var a = "123";
f(a);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-if-else-to-conditional-expression/test/variable assignment/should skip if-else-assignment with non-assignment binary expression.test.md
An example of JavaScript code input, demonstrating conditional logic and short-circuit evaluation. This snippet assumes variables 'x', 'f', and 'g' are defined elsewhere.
```javascript
let a = 23;
if (x) {
a && f();
} else {
a && g();
}
```
--------------------------------
### JavaScript Input Handling Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-console-log/test/should skip console.log in expression.js.test.md
Demonstrates a basic JavaScript input pattern, showing a function call with a console log. This snippet illustrates how input might be processed or represented.
```javascript
f(console.log("hello"));
```
--------------------------------
### JavaScript Input: Function Binding Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-function-to-arrow-function/test/this and arguments/should remove this binding.js.test.md
Demonstrates a JavaScript input snippet showcasing function binding. This example uses a common pattern for binding the 'this' context to a function.
```javascript
const f = function () {}.bind(this);
```
--------------------------------
### Expected Matches Structure Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-operator-into-assignment/test/should push + operator into self-assignent for strings.js.test.md
An example structure representing expected matches, including safety levels and suggestions, often used in code analysis or validation tools.
```json
{
"12-22-BinaryExpression": {
"safety": {
"level": "SAFE"
},
"suggestion": {}
}
}
```
--------------------------------
### JSON Configuration for JavaScript Processing
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/node types/call expression/should extract call expression with three occurences from 3rd occurence.js.test.md
Specifies configuration parameters for processing JavaScript code. It includes the expected file extension and the line selection for the operation.
```json
{
"extension": "js",
"selection": "50-54"
}
```
--------------------------------
### Configuration for React Component Refactoring
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-jsx-element/test/function declaration target/jsx element/should extract jsx element from arrow function.js.test.md
JSON configuration specifying parameters for code transformation. This example details the file extension, selection range, and the desired interactive action (extracting as a function declaration).
```json
{
"extension": "js",
"selection": "16-34",
"interactiveInput": {
"selectOption": {
"return": "Extract as function declaration"
}
}
}
```
--------------------------------
### Check if String Ends with Slash (JavaScript)
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-string-ends-with/test/should convert last character for strict equal comparison on string.ts.test.md
Demonstrates checking if the last character of a JavaScript string is a '/'. The first example uses direct index access, while the second, more idiomatic example, uses the `endsWith()` method.
```javascript
let s: string = '123';
const match = s[s.length - 1] === '/';
```
```javascript
let s: string = '123';
const match = s.endsWith('/');
```
--------------------------------
### JavaScript Input Handling Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-expression-with-existing-variable/test/should skip when there is no replace and uninitialized variable.js.test.md
Demonstrates basic input handling in JavaScript. It shows variable declaration and function invocation with a string argument. No specific dependencies are mentioned.
```javascript
const aValue;
doSomething("some value");
```
--------------------------------
### Initialize and Log JavaScript Objects
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/formatting/should preserve multiline formatting when converting variable type.js.test.md
Demonstrates the initialization of two empty JavaScript objects, 'a' and 'b', and logs them to the console. This showcases basic variable declaration and output in JavaScript.
```javascript
var a = {},
b = {};
console.log(a);
console.log(b);
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-function-to-arrow-function/test/should convert function that returns complex expression.js.test.md
This snippet shows the expected output format for the JavaScript input, utilizing an arrow function syntax for the IIFE. It achieves the same result as the input example but with more concise syntax.
```javascript
(() => ({ a: "b" })["a"]);
```
--------------------------------
### JavaScript Input Loop Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/loops/should skip var when used outside of loop initializer.js.test.md
Demonstrates a basic JavaScript for loop and accessing a variable after the loop. No external dependencies are required.
```javascript
for (var i = 0; i < 10; i++) {}
i;
```
--------------------------------
### JavaScript Conditional Logic: Transformed Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/invert-condition/test/else-if/should move if from else-if into block.js.test.md
Presents the transformed JavaScript code corresponding to the input example. This snippet rewrites the 'if-else if' logic into a nested 'if' structure with negation, showcasing an alternative way to achieve the same outcome.
```javascript
if (!a) {
if (b) {
console.log("2");
}
} else {
console.log("1");
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/safety/should show safe when inlining null.js.test.md
Demonstrates a simple JavaScript input, declaring a null variable and logging it to the console. This serves as a basic test case for the assistant.
```javascript
const a = null;
console.log(a);
```
--------------------------------
### JavaScript Input Example: Array Destructuring
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flatten-array-rest-property/test/should flatten nested array construction with rest operator.js.test.md
Illustrates how to use the spread syntax to create a new array from an existing array in JavaScript. This is a common pattern for array manipulation.
```javascript
const something = [...[a, b]];
```
--------------------------------
### JavaScript Input Element Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-jsx-attribute/test/move down/should move down first attribute in self closing jsx element with 2 attributes.js.test.md
Shows an example of a JavaScript element with attributes. This serves as the input for processing.
```javascript
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/escaping/should inline simple template with newline.js.test.md
Demonstrates how to define and log a multi-line string in JavaScript. This snippet shows the basic usage of template literals for string interpolation and multi-line strings.
```javascript
const a = `1
2`;
console.log(a);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flip-operator/test/binary operators/should flip binary xor.js.test.md
This snippet represents the input code to be processed by the JS Assistant. It is a simple JavaScript expression.
```javascript
a ^ b;
```
--------------------------------
### JavaScript Expected Output Code Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/formatting/should not change indentation of unaffected lines.js.test.md
Illustrates the expected output after processing the input JavaScript code. It shows potential transformations, such as changing 'var' to 'let'.
```javascript
const a = 1,
b = 2;
let c;
c = 3;
console
.log(a);
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-loop-to-for-with-index/test/for-of-loop/should provide index variable without local collisions 1.js.test.md
This JavaScript snippet shows an alternative way to iterate over elements using a traditional for loop and log them to the console. It assumes a variable 'elements' is defined.
```javascript
const i = "123";
for (let j = 0; j < elements.length; j++) {
const element = elements[j];
console.log(element);
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-down-negation/test/should push down negation into <.js.test.md
This JavaScript code snippet represents an input expression. It is a simple negation of a less-than comparison.
```javascript
!(a < b);
```
--------------------------------
### JavaScript Input Function
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/introduce-early-return/test/inside function-like/if/should invert already negated condition.js.test.md
This snippet shows the initial JavaScript code. It defines a function 'f' that checks a condition 'a' and executes 'doSomething()' if the condition is false.
```javascript
function f() {
if (!a) {
doSomething();
}
}
```
--------------------------------
### JavaScript JSX Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/collapse-jsx-element/test/should skip jsx element with children.js.test.md
Demonstrates a basic JavaScript input using JSX syntax. This snippet shows how a JSX element is defined, which is common in libraries like React.
```javascript
const jsx = ;
```
--------------------------------
### JavaScript Input Example: Undefined Variable Assignment
Source: https://github.com/lgrammel/js-assistant/blob/main/augmentation/undefined-alias/test/void constant/should not augment void aVariable.test.md
This snippet shows a JavaScript code example where a variable named 'undefined' is assigned an object. It then references this variable. This might be used to test how linters or static analysis tools handle reassignments of global properties.
```javascript
let undefined = {};
undefined;
```
--------------------------------
### Initialize JavaScript Array
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-new-array-to-array-literal/test/should convert new Array call without parameters to array literal.js.test.md
Shows how to create a new, empty JavaScript array using the Array constructor. This is a fundamental operation in JavaScript for creating collections of data.
```javascript
new Array();
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/flip-operator/test/comparison operators/should flip < to >.js.test.md
Illustrates the expected output of a JavaScript operation, showing a greater-than comparison. This is the result of processing the input.
```javascript
b > a;
```
--------------------------------
### JavaScript Input Example for js-assistant
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-es-private-to-typescript-private/test/should do something.js.test.md
This snippet represents the expected input format for the js-assistant project. It is written in JavaScript and serves as a placeholder for actual input data.
```javascript
/*
* Placeholder for JavaScript input data.
*/
```
--------------------------------
### JavaScript String Concatenation Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-template-literal/test/regression/should work in object literal expression.js.test.md
This snippet shows a basic JavaScript example of string concatenation using the '+' operator. It initializes a variable 'x' and then constructs strings by concatenating literal parts with the value of 'x'. Note that 'x' is undefined, so it will be represented as 'undefined' in the resulting strings.
```javascript
let x;
let a = { value: "a" + x + "a" };
let b = { value: "b" + x + "b" };
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/comments/should preserve comment in the same line before the change.js.test.md
This snippet demonstrates a basic JavaScript input structure. It initializes an empty object and logs it to the console. It uses a variable declaration and a comment.
```javascript
/* comment */ var a = {};
console.log(a);
```
--------------------------------
### JavaScript Expected Output Example: Modern Variable Declaration
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/should work in case block with var.ts.test.md
This snippet presents the expected JavaScript output, refactoring the input example to use the `const` keyword for variable declarations within the `case` block. This reflects modern JavaScript practices emphasizing block-scoping.
```javascript
const a = "1";
switch (a) {
case "1":
const x = "2", y = "3";
}
```
--------------------------------
### Iterate and Log Elements in JavaScript
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-loop-to-for-each/test/for-of-loop/should convert for-of loop with non-block statement.js.test.md
This snippet demonstrates iterating over a collection of elements using a `for...of` loop and logging each element to the console. It's a basic input processing technique.
```javascript
for (const element of elements) console.log(element);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-unnecessary-template/test/safety/should show safe when removing template with string variable.js.test.md
Demonstrates a JavaScript code snippet for input handling, specifically using template literals. It shows the initial declaration of a constant and a variable assigned using a template expression.
```javascript
const x = "123";
let a = `${x}`;
```
--------------------------------
### Initialize New Array (JavaScript)
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-new-array-to-array-literal/test/safety/should show warning when type information is dropped.ts.test.md
Demonstrates the initialization of a new array in JavaScript, specifically showing how generic types are removed in the expected output. This transformation is flagged with a warning.
```javascript
new Array();
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-parameter-into-iife/test/should push middle parameter with argument into IIFE.js.test.md
A simple JavaScript immediately-invoked function expression (IIFE) that logs the first argument. It takes three arguments and logs 'a'.
```javascript
(function(a, b, c) {
console.log(a);
})(12, 23, 34);
```
--------------------------------
### JavaScript Input Negation Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-down-negation/test/should push down negation into !=.js.test.md
Demonstrates a JavaScript input snippet where a non-equality check is negated. This is a basic example of how input is processed.
```javascript
!(a != b);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/comments/should preserve comments after variable declarators.js.test.md
Demonstrates a basic JavaScript input structure with variable declarations and console logging. This snippet shows how multiple object variables can be declared on a single line.
```javascript
var a = {}, // comment a
b = {}, // comment b
c = {}; // comment c
console.log(a);
console.log(b);
console.log(c);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/safety/should show unknown when inlining from object destructuring.js.test.md
Demonstrates destructuring an object property and passing it to a function. This is a common pattern for accessing and utilizing object data in JavaScript.
```javascript
const { aProperty } = anObject;
doSomething(aProperty);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-template-literal/test/escape/should keep backslash escaping when creating template literal.js.test.md
Demonstrates a JavaScript code snippet for input handling. It initializes a variable 'x' and then creates a string 's' by concatenating a backslash with 'x'.
```javascript
var x;
let s = "\" + x;
```
--------------------------------
### Configure Code Assist Metadata (JSON)
Source: https://context7.com/lgrammel/js-assistant/llms.txt
This JSON configuration file defines metadata for the 'convert-let-to-const' code assist. It specifies platform requirements, suggestion availability, documentation details including descriptions and related assists, and VS Code integration settings like code action kinds.
```json
{
"id": "convert-let-to-const",
"canBeSafe": true,
"platform": {
"ecmaScript": "ES2015",
"languages": ["JAVASCRIPT", "TYPESCRIPT"]
},
"suggestions": {
"available": true
},
"documentation": {
"shortDescription": "Replace `let` declarations that have no re-assignment with `const` declarations.",
"relatedCodeAssists": [
"replace-var-with-let-and-const",
"merge-variable-declaration-and-initialization"
],
"references": [
{
"label": "Let (MDN)",
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let"
},
{
"label": "Const (MDN)",
"href": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const"
}
],
"categories": ["variable"],
"title": "Convert let to const"
},
"visualStudioCode": {
"codeActionKinds": ["refactor.rewrite.let-to-const"]
}
}
```
--------------------------------
### JavaScript Input Code Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-let-to-const/test/should convert let without re-assignment.js.test.md
An example of JavaScript code input to the assistant, demonstrating a variable declaration and a function call.
```javascript
let a = "123";
f(a);
```
--------------------------------
### Input Example in JavaScript
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-bracket-notation-property-access-to-dot-notation/test/should skip property access with function call.js.test.md
Demonstrates how to access an element from an array using a function call in JavaScript. Assumes 'x' is an array and 'f()' returns a valid index.
```javascript
const c = x[f()];
```
--------------------------------
### JavaScript Input: Rendering a Component and Div
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-jsx-element/test/function declaration target/jsx fragment/should extract jsx fragment with one parameter.js.test.md
This JavaScript code snippet defines a function 'f' that returns JSX. It renders a custom component 'MyComponent' with two parameters and a simple div element. This represents the initial input to the assistant.
```javascript
function f(x) {
return <>
test
>;
}
```
--------------------------------
### JavaScript Object Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-object-property/test/move down/should move down first object property with trailing last comma.js.test.md
Illustrates the expected output of a JavaScript object after a potential reordering of its properties. This is the anticipated result after processing the input object.
```javascript
const anObject = {
property2: "value2",
property1: "value1",
};
```
--------------------------------
### JavaScript Expected Output
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-statement/test/move up/should keep whitespace but move comment when moving up.js.test.md
This snippet shows the expected result after processing the input JavaScript code, demonstrating a rearrangement of function calls and comments.
```javascript
{
// comment
second();
first();
}
```
--------------------------------
### Exporting from Example Module in JavaScript
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-string-to-template-literal/test/invalid parents/should skip export declaration module spcifiers.js.test.md
This snippet demonstrates how to export all members from a local module named 'Example' in JavaScript. It utilizes the 'export * from' syntax for re-exporting.
```javascript
export * from "./Example";
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/merge-into-preceding-destructuring-assignment/test/safety and suggestion/should show warning when changing previous declaration to let.js.test.md
Shows the transformed JavaScript code after analysis and potential modifications, consolidating destructuring assignments.
```javascript
const obj = { a: "1", b: "2" };
let { a, b } = obj;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/surround-with-try-catch/test/should surround 3 selected statements with try-catch in 2-level-deep block.js.test.md
Demonstrates a basic JavaScript input structure. This snippet shows a nested block that might be processed by the assistant. No specific dependencies are noted.
```javascript
{
{
console.log("1");
console.log("2");
console.log("3");
console.log("4");
console.log("5");
}
}
```
--------------------------------
### Define Input Function in JavaScript
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/add-braces-to-arrow-function/test/should add braces to arrow function with expression body.js.test.md
This snippet defines a simple arrow function in JavaScript that returns a string. It serves as an example of input data structure.
```javascript
let a = () => "abc";
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/regression/5.js.test.md
Demonstrates the initial JavaScript code snippet used as input. This code defines two variables, 'a' and 'b', using logical OR and AND operators.
```javascript
const a = x || y;
const b = a && a;
```
--------------------------------
### Install Prerequisites with Homebrew
Source: https://github.com/lgrammel/js-assistant/blob/main/DEVGUIDE.md
Installs pnpm and zx, essential command-line tools for JavaScript development and scripting, using the Homebrew package manager.
```sh
brew install pnpm
brew install zx
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-parameter-into-iife/test/should push middle parameter with argument into IIFE.js.test.md
The expected output JavaScript code after processing. This IIFE has been modified to only take two arguments and assigns a value to 'b' internally.
```javascript
(function(a, c) {
const b = 23;
console.log(a);
})(12, 34);
```
--------------------------------
### JavaScript Input Execution
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/push-parameter-into-iife/test/safety/should mark single argument as safe.js.test.md
Demonstrates an immediately invoked function expression (IIFE) in JavaScript, logging an input value. This serves as an example of executable input code.
```javascript
(function(a) {
console.log(a);
})(12);
```
--------------------------------
### JavaScript Input Handling Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-if-else-to-conditional-expression/test/variable declaration/should skip variable declaration followed by if-assignment with different operator.test.md
Demonstrates a basic conditional input handling in JavaScript. It initializes a variable 'a' and increments it if a 'condition' is met. No specific external dependencies are shown.
```javascript
let a = 0;
if (condition) {
a += 1;
}
```
--------------------------------
### Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-apply-to-spread-syntax/test/should convert apply call on inline objects.ts.test.md
A basic configuration object specifying an extension type, likely for a build process or linter. This configuration does not directly involve code execution but sets parameters for tooling.
```json
{
"extension": "ts"
}
```
--------------------------------
### JavaScript Analysis Result
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/merge-into-preceding-destructuring-assignment/test/safety and suggestion/should show warning when changing previous declaration to var.js.test.md
An example of an analysis result for JavaScript code, indicating a 'WARNING' about changing a declaration to 'var'. This JSON object details the safety assessment and suggestions.
```json
{
"50-67-VariableStatement": {
"safety": {
"level": "WARNING",
"message": "changes declaration to var"
},
"suggestion": null
}
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/insert-console-log/test/should skip when identifier is not a variable.js.test.md
A simple JavaScript example demonstrating object declaration and function invocation. It defines an object 'a' with a function property 'f123' and then calls this function.
```javascript
const a = {
f123: () => {}
};
a.f123();
```
--------------------------------
### JavaScript Input Conditional Logic
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-if-else-to-switch/test/should retain block when let is defined.js.test.md
This JavaScript snippet demonstrates conditional execution based on the value of 'x'. It covers a simple if-else if structure.
```javascript
if (x === 1) {
let a = 3;
fa(a);
} else if (x === 2) {
fb();
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-function-to-arrow-function/test/constructor/should skip constructor function.js.test.md
An example of an immediately invoked function expression (IIFE) in JavaScript, returning an object. This demonstrates a common pattern for self-executing code blocks.
```javascript
new function () { return {a: 'b'}; };
```
--------------------------------
### JSON Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/variable name/should use name from new call.js.test.md
Shows a basic JSON configuration object with properties for 'extension' and 'selection'. This configuration might be used to specify file types or line ranges for processing.
```json
{
"extension": "js",
"selection": "2-15"
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/node types/string literal/should extract string literal.js.test.md
This snippet demonstrates a basic JavaScript input operation, printing the string 'abc' to the console. It requires a JavaScript runtime environment.
```javascript
console.log("abc");
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/variable name/should use name from getX function call.js.test.md
Demonstrates a simple JavaScript input function call.
```javascript
f(getRandom());
```
--------------------------------
### JSON Configuration Object
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/insert-console-log/test/should skip when identifier is not availabe on statement parent level.js.test.md
A sample JSON object representing configuration settings. It includes an 'extension' property set to 'js' and a 'selection' property indicating a range '21-21'. This is likely used for file or text selection within the assistant.
```json
{
"extension": "js",
"selection": "21-21"
}
```
--------------------------------
### JSON Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-substring-to-variable/test/should choose non-conflicting variable name.js.test.md
This JSON snippet represents the configuration for processing. It specifies the file extension as 'js' and the selection range as lines '41-44'.
```json
{
"extension": "js",
"selection": "41-44"
}
```
--------------------------------
### JavaScript Function Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-unused-variable/test/var/should remove unused var variable with initializer in function.js.test.md
This snippet demonstrates a JavaScript function named 'f' which contains a variable declaration and a recursive call. It serves as an example input for analysis.
```javascript
function f() {
var b = "hello";
f("hello");
}
```
--------------------------------
### JSON Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-function-to-object-method/test/should keep return type.ts.test.md
A simple JSON configuration object specifying an 'extension' property, set to 'ts' (TypeScript).
```json
{
"extension": "ts"
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-iife/test/in statement/should remove IIFE with void, multi-line body and no return.js.test.md
Demonstrates an immediately invoked function expression (IIFE) in JavaScript. It declares a constant 'a' and logs it to the console. This serves as an example of input code.
```javascript
void function() {
const a = 3;
console.log(a);
}();
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/move-first-statement-out-of-if-else/test/whitespace/should insert moved statement immediately before if-statement.js.test.md
This snippet represents the transformed JavaScript code after processing. The conditional logic has been optimized, removing redundant function calls.
```javascript
const myVar = 123;
// a comment
f1();
if (x) {
f2a();
} else {
f2b();
}
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-var-with-let-and-const/test/should skip when declared twice in different blocks.js.test.md
Demonstrates a basic JavaScript input structure with variable declarations. This snippet shows how variables can be declared and assigned values within blocks.
```javascript
{
var c = "3";
}
{
var c = "5";
}
```
--------------------------------
### JavaScript Input Code
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-to-increment/test/a = a + 1/should convert a = a + 1 to a++ with numeric a.js.test.md
This snippet demonstrates basic JavaScript variable declaration and arithmetic operation. It serves as an example of input code that might be processed by the assistant.
```javascript
let a = 3;
a = a + 1;
```
--------------------------------
### JavaScript Input Handling Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/replace-expression-with-existing-variable/test/should skip occurrences before the variable definition.js.test.md
Demonstrates a basic JavaScript function call and variable assignment for input processing. This snippet showcases typical input patterns for a JavaScript environment.
```javascript
doSomething("some value");
const aValue = "some value";
```
--------------------------------
### JavaScript Variable Declaration Input
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-to-destructuring-assignment/test/should show correct action zones.js.test.md
This snippet shows a basic JavaScript variable declaration. It serves as an input example for potential code transformations, such as converting to destructuring.
```javascript
let something = anObject.something;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-unnecessary-expression-statement/test/should skip use strict directive.js.test.md
This snippet demonstrates a basic JavaScript input. It uses strict mode and calls a function 'f2'. No external dependencies are explicitly mentioned.
```javascript
"use strict";
f2();
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/inline-variable/test/safety/should show safe when inlining boolean expression true && false.js.test.md
Demonstrates a basic JavaScript input snippet involving a logical AND operation and console logging. It showcases a simple variable declaration and its subsequent output.
```javascript
const a = true && false;
console.log(a);
```
--------------------------------
### JSON Expected Matches Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/convert-if-else-to-conditional-expression/test/suggestions/should not suggest if-return.test.md
An example of a JSON structure representing expected matches. It includes a key '19-64-Block' with a nested 'suggestion' property, which is currently null.
```json
{
"19-64-Block": {
"suggestion": null
}
}
```
--------------------------------
### JavaScript Code Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-empty-if-block/test/safety/should show safe when there is an else block.js.test.md
Demonstrates a basic JavaScript code snippet with an if-else statement and function calls. This serves as the input for the assistant.
```javascript
if (x) {
} else {
g();
}
f();
```
--------------------------------
### JavaScript Expected Output Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/use-template-literal/test/escape/should escape backticks when creating simple template literal.js.test.md
Illustrates the expected output for a JavaScript snippet. This example shows the result of processing the input code, particularly concerning string interpolation with backticks.
```javascript
var x;
let s = ``x`;
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/node types/should skip variable declaration name.js.test.md
This snippet demonstrates a basic JavaScript input. It declares a string variable 'a' and then logs its value to the console. No external dependencies are required for this basic operation.
```javascript
const a = "123";
console.log(a);
```
--------------------------------
### JavaScript Input Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/collapse-property-into-shorthand/test/regression/should work in array literal.js.test.md
This JavaScript code snippet shows how to declare and initialize variables 'a' and 'b'. Variable 'a' is an array of objects, and variable 'b' is an object. This illustrates basic data structure initialization in JavaScript.
```javascript
let a = [{ v1: v1 }];
let b = {
v2: v2,
};
```
--------------------------------
### JSON Expected Matches Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/select-expression-occurrences/test/skip when only 1 occurrence is available.js.test.md
A JSON object defining expected matches, likely for testing or validation purposes. This example specifies a null value for a particular match key.
```json
{
"12-16-CallExpression": null
}
```
--------------------------------
### JSON Configuration Example
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/extract-variable/test/should skip matches containing this when they are in a different this context.js.test.md
This JSON snippet represents a configuration object. It specifies an 'extension' as 'js' and a 'selection' range from '49-63', likely used for text processing or code manipulation tasks.
```json
{
"extension": "js",
"selection": "49-63"
}
```
--------------------------------
### JavaScript Input Code Transformation
Source: https://github.com/lgrammel/js-assistant/blob/main/code-assist/remove-unused-variable/test/var/should remove unused var variable with side-effect initializer in function.js.test.md
This snippet shows an example of JavaScript input code that is subject to transformation. The transformation aims to remove variable declarations that might have side effects.
```javascript
function f() {
var b = g();
f("hello");
}
```