From c2dd3782b835ed79185b50db8ba832e6d508b581 Mon Sep 17 00:00:00 2001 From: Pascal Reitermann Date: Thu, 19 Nov 2026 19:52:44 +0000 Subject: [PATCH] refactor(adapter): define isEmptyMapping before its use DeepSource reported "'isEmptyMapping' was used before it was defined": the helper was declared after the JsYamlAdapter class that calls it. This works at runtime, because the method only runs after the module is loaded, but it reads backwards and is a temporal dead zone trap. Move the helper above the class and enable @typescript-eslint/no-use-before-define, so the local lint step and CI catch this before DeepSource does. The rule reports no other findings. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Jdb5is9YsMnteaxHryN26M --- .eslintrc.js | 3 +++ src/adapter/js-yaml-adapter.ts | 15 +++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5533fc7..b197a9b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,6 +16,9 @@ module.exports = { "plugin:import/typescript", ], rules: { + // the base rule does not understand typescript, so use the typescript-eslint variant + "no-use-before-define": "off", + "@typescript-eslint/no-use-before-define": "error", "semi": ["error", "never"], "sort-imports": [ "error", diff --git a/src/adapter/js-yaml-adapter.ts b/src/adapter/js-yaml-adapter.ts index 25be6f0..d21ed5d 100644 --- a/src/adapter/js-yaml-adapter.ts +++ b/src/adapter/js-yaml-adapter.ts @@ -4,6 +4,13 @@ import { Settings } from "../settings" import { SortUtil } from "../util/sort-util" import { removeTrailingCharacters, splitYaml } from "../util/yaml-text" +/** + * @param value Any loaded yaml value. + * @returns True for a mapping without keys, e.g. an empty document. + */ +const isEmptyMapping = (value: unknown): boolean => + typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0 + export class JsYamlAdapter { settings: Settings @@ -88,12 +95,4 @@ export class JsYamlAdapter { } return sortKeys } - } - -/** - * @param value Any loaded yaml value. - * @returns True for a mapping without keys, e.g. an empty document. - */ -const isEmptyMapping = (value: unknown): boolean => - typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0