Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript (v3): Replace ESLint & Prettier with BiomeJS #6978

Merged
merged 6 commits into from
Oct 16, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 0 additions & 4 deletions javascriptv3/.eslintignore

This file was deleted.

32 changes: 0 additions & 32 deletions javascriptv3/.eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion javascriptv3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules/
package-lock.json
test_results/
test-results.xml
state.json
state.json
.mypy_cache
5 changes: 2 additions & 3 deletions javascriptv3/hook_scripts/pre-commit.sh → javascriptv3/.husky/pre-commit
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

set -e

# Lint
npm run lint
npm run --prefix ./javascriptv3 lint

# Test
npm test
npm test --prefix ./javascriptv3
14 changes: 5 additions & 9 deletions javascriptv3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ You can run tests for a specific service, or for every service in this repositor
If you run tests using the preceding commands, output will be stored in `unit_test.log` or `integration_test.log`. Errors are still logged to the console.

## Linting
You can run ESLint to statically check for errors.
You can run Biome to statically check for errors.

To run ESLint, use the following command:
`npm run ci-lint .`
To run Biome, use the following command:
`npm run ci-lint`

## Docker image (Beta)

Expand Down Expand Up @@ -87,13 +87,9 @@ run the example and verify that it ran correctly.

## Configure Visual Studio Code (VS Code)

### ESLint
### Biome

To configure ESLint in VS Code, add the following to `settings.json`:

```
"eslint.workingDirectories": ["javascriptv3/example_code/reactnative/ReactNativeApp", "javascriptv3"],
```
To configure Biome in VS Code, follow the instructions here: https://biomejs.dev/guides/getting-started/

## Additional resources

Expand Down
48 changes: 48 additions & 0 deletions javascriptv3/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false,
"ignore": [
"./example_code/reactnative/",
"./example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification",
"./example_code/kinesis/kinesis-cdk",
"./example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification/openjphjs/openjphjs.js",
"**/dist"
]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"indentStyle": "space",
"trailingCommas": "all"
}
},
"json": {
"formatter": {
"indentStyle": "space"
}
},
"css": {
"formatter": {
"indentStyle": "space"
}
}
}
3 changes: 0 additions & 3 deletions javascriptv3/example_code/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ jspm_packages/
# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const invokeBedrockAgent = async (prompt, sessionId) => {
throw new Error("Completion is undefined");
}

for await (let chunkEvent of response.completion) {
for await (const chunkEvent of response.completion) {
const chunk = chunkEvent.chunk;
console.log(chunk);
const decodedResponse = new TextDecoder("utf-8").decode(chunk.bytes);
Expand All @@ -60,7 +60,7 @@ export const invokeBedrockAgent = async (prompt, sessionId) => {
};

// Call function if run directly
import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
if (process.argv[1] === fileURLToPath(import.meta.url)) {
const result = await invokeBedrockAgent("I need help.", "123");
console.log(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
testTimeout: 50000,
threads: false,
},
test: {
testTimeout: 50000,
threads: false,
},
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import { checkForPlaceholders } from "../lib/utils.js";

import {
Expand Down Expand Up @@ -61,7 +61,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
// Check for unresolved placeholders in agentName and roleArn.
checkForPlaceholders([agentName, roleArn]);

console.log(`Creating a new agent...`);
console.log("Creating a new agent...");

const agent = await createAgent(agentName, foundationModel, roleArn);
console.log(agent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import { checkForPlaceholders } from "../lib/utils.js";

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import { checkForPlaceholders } from "../lib/utils.js";

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import { checkForPlaceholders } from "../lib/utils.js";

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import {
BedrockAgentClient,
Expand Down
4 changes: 2 additions & 2 deletions javascriptv3/example_code/bedrock-agent/hello.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import {
BedrockAgentClient,
Expand Down Expand Up @@ -35,7 +35,7 @@ export const main = async () => {
console.log(`Initializing Amazon Bedrock Agents client for ${region}...`);
const client = new BedrockAgentClient({ region });

console.log(`Retrieving the list of existing agents...`);
console.log("Retrieving the list of existing agents...");
const paginatorConfig = { client };
const pages = paginateListAgents(paginatorConfig, {});

Expand Down
4 changes: 3 additions & 1 deletion javascriptv3/example_code/bedrock-agent/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/
export const checkForPlaceholders = (variables) => {
if (
variables.some((variable) => isNaN(+variable) && variable.includes("["))
variables.some(
(variable) => Number.isNaN(+variable) && variable.includes("["),
)
) {
throw new Error(
"Error: One or more variables contain unresolved placeholders. Please ensure all placeholders are replaced with valid data and the brackets have been removed before proceeding.",
Expand Down
2 changes: 1 addition & 1 deletion javascriptv3/example_code/bedrock-runtime/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @property {Usage} usage
*/

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import {
BedrockRuntimeClient,
InvokeModelCommand,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down Expand Up @@ -137,7 +137,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
try {
console.log("-".repeat(53));
const response = await invokeModel(prompt, modelId);
console.log("\n" + "-".repeat(53));
console.log(`\n${"-".repeat(53)}`);
console.log("Final structured response:");
console.log(response);
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import { FoundationModels } from "../../config/foundation_models.js";
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";
import {
Scenario,
ScenarioAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, test, vi } from "vitest";
import path from "path";
import path from "node:path";

describe("Converse with text generation models", () => {
const baseDirectory = path.join(__dirname, "..", "models");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, test, vi } from "vitest";
import path from "path";
import { Writable } from "stream";
import path from "node:path";
import { Writable } from "node:stream";

describe("ConverseStream with text generation models", () => {
const fileName = "converseStream.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import {
BedrockClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { fileURLToPath } from "url";
import { fileURLToPath } from "node:url";

import {
BedrockClient,
Expand Down
Loading
Loading