From 35df06e34ac6cac4d8925af009f2747b23794e89 Mon Sep 17 00:00:00 2001 From: Amaresh S M <30730124+amareshsm@users.noreply.github.com> Date: Thu, 12 Sep 2024 23:33:45 +0530 Subject: [PATCH 1/5] fix: remove `assert` package reference --- packages/eslint-scope/lib/index.js | 5 ++--- packages/eslint-scope/lib/referencer.js | 2 +- packages/eslint-scope/lib/scope-manager.js | 2 +- packages/eslint-scope/lib/scope.js | 2 +- packages/eslint-scope/lib/util/assert.js | 21 +++++++++++++++++++++ packages/eslint-scope/rollup.config.js | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 packages/eslint-scope/lib/util/assert.js diff --git a/packages/eslint-scope/lib/index.js b/packages/eslint-scope/lib/index.js index 5a27d062..62dc769d 100644 --- a/packages/eslint-scope/lib/index.js +++ b/packages/eslint-scope/lib/index.js @@ -46,14 +46,13 @@ * @module escope */ -import assert from "node:assert"; - import ScopeManager from "./scope-manager.js"; import Referencer from "./referencer.js"; import Reference from "./reference.js"; import Variable from "./variable.js"; - import eslintScopeVersion from "./version.js"; +import {assert} from './util/assert.js'; + /** * Set the default options diff --git a/packages/eslint-scope/lib/referencer.js b/packages/eslint-scope/lib/referencer.js index cf6ea999..f255b907 100644 --- a/packages/eslint-scope/lib/referencer.js +++ b/packages/eslint-scope/lib/referencer.js @@ -28,7 +28,7 @@ import Reference from "./reference.js"; import Variable from "./variable.js"; import PatternVisitor from "./pattern-visitor.js"; import { Definition, ParameterDefinition } from "./definition.js"; -import assert from "node:assert"; +import { assert } from './util/assert.js'; const { Syntax } = estraverse; diff --git a/packages/eslint-scope/lib/scope-manager.js b/packages/eslint-scope/lib/scope-manager.js index 077b0491..49f657ef 100644 --- a/packages/eslint-scope/lib/scope-manager.js +++ b/packages/eslint-scope/lib/scope-manager.js @@ -36,7 +36,7 @@ import { SwitchScope, WithScope } from "./scope.js"; -import assert from "node:assert"; +import { assert } from './util/assert.js'; /** * @constructor ScopeManager diff --git a/packages/eslint-scope/lib/scope.js b/packages/eslint-scope/lib/scope.js index 6c3f3cfe..eab816f4 100644 --- a/packages/eslint-scope/lib/scope.js +++ b/packages/eslint-scope/lib/scope.js @@ -27,7 +27,7 @@ import estraverse from "estraverse"; import Reference from "./reference.js"; import Variable from "./variable.js"; import { Definition } from "./definition.js"; -import assert from "node:assert"; +import { assert } from './util/assert.js'; const { Syntax } = estraverse; diff --git a/packages/eslint-scope/lib/util/assert.js b/packages/eslint-scope/lib/util/assert.js new file mode 100644 index 00000000..98223ef4 --- /dev/null +++ b/packages/eslint-scope/lib/util/assert.js @@ -0,0 +1,21 @@ +/** + * @fileoverview - This file provides a utility function `assert` that checks whether a given condition is true + * and throws an error with a specified message if the condition is false. + * @author Amaresh S M + */ + +/** + * Asserts that a condition is true. If the condition is false, an error is thrown with the provided message. + * + * @param {boolean} condition - The condition that is being asserted. If `false`, an error will be thrown. + * @param {string} [message="Assertion failed."] - The error message that will be thrown if the condition is false. + * @returns {void} + * + * @throws {Error} Throws an error if the condition is not met. + */ + +export function assert(condition, message = "Assertion failed.") { + if (!condition) { + throw new Error(message); + } +} diff --git a/packages/eslint-scope/rollup.config.js b/packages/eslint-scope/rollup.config.js index 135e147a..564ff2f7 100644 --- a/packages/eslint-scope/rollup.config.js +++ b/packages/eslint-scope/rollup.config.js @@ -1,6 +1,6 @@ export default { input: "./lib/index.js", - external: ["assert", "estraverse", "esrecurse"], + external: ["estraverse", "esrecurse"], treeshake: false, output: { format: "cjs", From 5b170749363943881197e32de6d40b257ad03cfc Mon Sep 17 00:00:00 2001 From: "amaresh.sm" Date: Fri, 27 Sep 2024 00:15:03 +0530 Subject: [PATCH 2/5] lint fix --- packages/eslint-scope/lib/index.js | 2 +- packages/eslint-scope/lib/referencer.js | 2 +- packages/eslint-scope/lib/scope-manager.js | 2 +- packages/eslint-scope/lib/scope.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/eslint-scope/lib/index.js b/packages/eslint-scope/lib/index.js index 62dc769d..74baa74c 100644 --- a/packages/eslint-scope/lib/index.js +++ b/packages/eslint-scope/lib/index.js @@ -51,7 +51,7 @@ import Referencer from "./referencer.js"; import Reference from "./reference.js"; import Variable from "./variable.js"; import eslintScopeVersion from "./version.js"; -import {assert} from './util/assert.js'; +import { assert } from "./util/assert.js"; /** diff --git a/packages/eslint-scope/lib/referencer.js b/packages/eslint-scope/lib/referencer.js index f255b907..4016a9c5 100644 --- a/packages/eslint-scope/lib/referencer.js +++ b/packages/eslint-scope/lib/referencer.js @@ -28,7 +28,7 @@ import Reference from "./reference.js"; import Variable from "./variable.js"; import PatternVisitor from "./pattern-visitor.js"; import { Definition, ParameterDefinition } from "./definition.js"; -import { assert } from './util/assert.js'; +import { assert } from "./util/assert.js"; const { Syntax } = estraverse; diff --git a/packages/eslint-scope/lib/scope-manager.js b/packages/eslint-scope/lib/scope-manager.js index 49f657ef..f06f1357 100644 --- a/packages/eslint-scope/lib/scope-manager.js +++ b/packages/eslint-scope/lib/scope-manager.js @@ -36,7 +36,7 @@ import { SwitchScope, WithScope } from "./scope.js"; -import { assert } from './util/assert.js'; +import { assert } from "./util/assert.js"; /** * @constructor ScopeManager diff --git a/packages/eslint-scope/lib/scope.js b/packages/eslint-scope/lib/scope.js index eab816f4..694b2f82 100644 --- a/packages/eslint-scope/lib/scope.js +++ b/packages/eslint-scope/lib/scope.js @@ -27,7 +27,7 @@ import estraverse from "estraverse"; import Reference from "./reference.js"; import Variable from "./variable.js"; import { Definition } from "./definition.js"; -import { assert } from './util/assert.js'; +import { assert } from "./util/assert.js"; const { Syntax } = estraverse; From 1da6f0c7b9d13dd80e2327e2c4bd25b8281076b5 Mon Sep 17 00:00:00 2001 From: "amaresh.sm" Date: Fri, 27 Sep 2024 00:26:16 +0530 Subject: [PATCH 3/5] lint fix --- packages/eslint-scope/lib/util/assert.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/eslint-scope/lib/util/assert.js b/packages/eslint-scope/lib/util/assert.js index 98223ef4..c2448290 100644 --- a/packages/eslint-scope/lib/util/assert.js +++ b/packages/eslint-scope/lib/util/assert.js @@ -1,5 +1,5 @@ /** - * @fileoverview - This file provides a utility function `assert` that checks whether a given condition is true + * @fileoverview This file provides a utility function `assert` that checks whether a given condition is true * and throws an error with a specified message if the condition is false. * @author Amaresh S M */ @@ -10,11 +10,9 @@ * @param {boolean} condition - The condition that is being asserted. If `false`, an error will be thrown. * @param {string} [message="Assertion failed."] - The error message that will be thrown if the condition is false. * @returns {void} - * * @throws {Error} Throws an error if the condition is not met. */ - -export function assert(condition, message = "Assertion failed.") { + export function assert(condition, message = "Assertion failed.") { if (!condition) { throw new Error(message); } From a4d6d889ec2d051b520d48be5bf6b584530b8a9c Mon Sep 17 00:00:00 2001 From: "amaresh.sm" Date: Fri, 27 Sep 2024 00:32:36 +0530 Subject: [PATCH 4/5] lint fix --- packages/eslint-scope/lib/util/assert.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/eslint-scope/lib/util/assert.js b/packages/eslint-scope/lib/util/assert.js index c2448290..a7d4c717 100644 --- a/packages/eslint-scope/lib/util/assert.js +++ b/packages/eslint-scope/lib/util/assert.js @@ -6,13 +6,12 @@ /** * Asserts that a condition is true. If the condition is false, an error is thrown with the provided message. - * - * @param {boolean} condition - The condition that is being asserted. If `false`, an error will be thrown. - * @param {string} [message="Assertion failed."] - The error message that will be thrown if the condition is false. + * @param {boolean} condition The condition that is being asserted. If `false`, an error will be thrown. + * @param {string} [message="Assertion failed."] The error message that will be thrown if the condition is false. * @returns {void} * @throws {Error} Throws an error if the condition is not met. */ - export function assert(condition, message = "Assertion failed.") { + export function assert(condition, message ="Assertion failed.") { if (!condition) { throw new Error(message); } From f6926760fdfc5fec046ad9ca3832950e1fb85329 Mon Sep 17 00:00:00 2001 From: "amaresh.sm" Date: Fri, 27 Sep 2024 00:37:57 +0530 Subject: [PATCH 5/5] fix indentation --- packages/eslint-scope/lib/util/assert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-scope/lib/util/assert.js b/packages/eslint-scope/lib/util/assert.js index a7d4c717..3680ecf5 100644 --- a/packages/eslint-scope/lib/util/assert.js +++ b/packages/eslint-scope/lib/util/assert.js @@ -11,7 +11,7 @@ * @returns {void} * @throws {Error} Throws an error if the condition is not met. */ - export function assert(condition, message ="Assertion failed.") { +export function assert(condition, message = "Assertion failed.") { if (!condition) { throw new Error(message); }