Browse Source

refactor: updates types

e22m4u 3 days ago
parent
commit
6e3860f599

+ 0 - 4
.mocharc.cjs

@@ -1,4 +0,0 @@
-module.exports = {
-  extension: ['js'],
-  spec: 'src/**/*.spec.js',
-}

+ 4 - 0
.mocharc.json

@@ -0,0 +1,4 @@
+{
+  "extension": ["js"],
+  "spec": "src/**/*.spec.js"
+}

+ 58 - 58
dist/cjs/index.cjs

@@ -1,3 +1,4 @@
+"use strict";
 var __defProp = Object.defineProperty;
 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
 var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -60,65 +61,8 @@ function generateRandomHex(length = 4) {
 }
 __name(generateRandomHex, "generateRandomHex");
 
-// src/debuggable.js
-var _Debuggable = class _Debuggable {
-  /**
-   * Debug.
-   *
-   * @type {*}
-   */
-  debug;
-  /**
-   * Ctor Debug.
-   *
-   * @type {Function}
-   */
-  ctorDebug;
-  /**
-   * Возвращает функцию-отладчик с сегментом пространства имен
-   * указанного в параметре метода.
-   *
-   * @param {Function} method
-   * @returns {Function}
-   */
-  getDebuggerFor(method) {
-    const name = method.name || "anonymous";
-    return this.debug.withHash().withNs(name);
-  }
-  /**
-   * Constructor.
-   *
-   * @param {DebuggableOptions|undefined} options
-   */
-  constructor(options = void 0) {
-    const className = toCamelCase(this.constructor.name);
-    options = typeof options === "object" && options || {};
-    const namespace = options.namespace && String(options.namespace) || void 0;
-    if (namespace) {
-      this.debug = createDebugger(namespace, className);
-    } else {
-      this.debug = createDebugger(className);
-    }
-    const noEnvironmentNamespace = Boolean(options.noEnvironmentNamespace);
-    if (noEnvironmentNamespace) this.debug = this.debug.withoutEnvNs();
-    this.ctorDebug = this.debug.withNs("constructor").withHash();
-    const noInstantiationMessage = Boolean(options.noInstantiationMessage);
-    if (!noInstantiationMessage)
-      this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
-  }
-};
-__name(_Debuggable, "Debuggable");
-/**
- * Instantiation message.
- *
- * @type {string}
- */
-__publicField(_Debuggable, "INSTANTIATION_MESSAGE", "Instantiated.");
-var Debuggable = _Debuggable;
-
 // src/create-debugger.js
 var import_js_format = require("@e22m4u/js-format");
-var import_js_format2 = require("@e22m4u/js-format");
 
 // src/create-colorized-dump.js
 var import_util = require("util");
@@ -324,7 +268,7 @@ function createDebugger(namespaceOrOptions = void 0, ...namespaceSegments) {
   function debugFn(messageOrData, ...args) {
     if (!isDebuggerEnabled()) return;
     const prefix = getPrefix();
-    const multiString = (0, import_js_format2.format)(messageOrData, ...args);
+    const multiString = (0, import_js_format.format)(messageOrData, ...args);
     const rows = multiString.split("\n");
     rows.forEach((message) => {
       prefix ? console.log(`${prefix} ${message}`) : console.log(message);
@@ -392,6 +336,62 @@ function createDebugger(namespaceOrOptions = void 0, ...namespaceSegments) {
   return debugFn;
 }
 __name(createDebugger, "createDebugger");
+
+// src/debuggable.js
+var _Debuggable = class _Debuggable {
+  /**
+   * Debug.
+   *
+   * @type {*}
+   */
+  debug;
+  /**
+   * Ctor Debug.
+   *
+   * @type {Function}
+   */
+  ctorDebug;
+  /**
+   * Возвращает функцию-отладчик с сегментом пространства имен
+   * указанного в параметре метода.
+   *
+   * @param {Function} method
+   * @returns {Function}
+   */
+  getDebuggerFor(method) {
+    const name = method.name || "anonymous";
+    return this.debug.withHash().withNs(name);
+  }
+  /**
+   * Constructor.
+   *
+   * @param {DebuggableOptions} [options]
+   */
+  constructor(options = void 0) {
+    const className = toCamelCase(this.constructor.name);
+    options = typeof options === "object" && options || {};
+    const namespace = options.namespace && String(options.namespace) || void 0;
+    if (namespace) {
+      this.debug = createDebugger(namespace, className);
+    } else {
+      this.debug = createDebugger(className);
+    }
+    const noEnvironmentNamespace = Boolean(options.noEnvironmentNamespace);
+    if (noEnvironmentNamespace) this.debug = this.debug.withoutEnvNs();
+    this.ctorDebug = this.debug.withNs("constructor").withHash();
+    const noInstantiationMessage = Boolean(options.noInstantiationMessage);
+    if (!noInstantiationMessage)
+      this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
+  }
+};
+__name(_Debuggable, "Debuggable");
+/**
+ * Instantiation message.
+ *
+ * @type {string}
+ */
+__publicField(_Debuggable, "INSTANTIATION_MESSAGE", "Instantiated.");
+var Debuggable = _Debuggable;
 // Annotate the CommonJS export names for ESM import in node:
 0 && (module.exports = {
   DEFAULT_OFFSET_STEP_SPACES,

+ 14 - 1
eslint.config.js

@@ -1,6 +1,8 @@
 import globals from 'globals';
 import eslintJs from '@eslint/js';
+import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
+import eslintImportPlugin from 'eslint-plugin-import';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 
@@ -14,15 +16,26 @@ export default [{
     },
   },
   plugins: {
+    'jsdoc': eslintJsdocPlugin,
     'mocha': eslintMochaPlugin,
+    'import': eslintImportPlugin,
     'chai-expect': eslintChaiExpectPlugin,
   },
   rules: {
     ...eslintJs.configs.recommended.rules,
     ...eslintPrettierConfig.rules,
+    ...eslintImportPlugin.flatConfigs.recommended.rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
-    "no-unused-vars": ["error", {caughtErrors: "none"}],
+    ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
+    'no-duplicate-imports': 'error',
+    'import/export': 0,
+    'jsdoc/reject-any-type': 0,
+    'jsdoc/reject-function-type': 0,
+    'jsdoc/require-param-description': 0,
+    'jsdoc/require-returns-description': 0,
+    'jsdoc/require-property-description': 0,
+    'jsdoc/tag-lines': ['error', 'any', {startLines: 1}],
   },
   files: ['src/**/*.js'],
 }];

+ 8 - 5
package.json

@@ -11,10 +11,10 @@
     "debugger",
     "interpolation"
   ],
-  "homepage": "https://github.com/e22m4u/js-debug",
+  "homepage": "https://gitrepos.ru/e22m4u/js-debug",
   "repository": {
     "type": "git",
-    "url": "git+https://github.com/e22m4u/js-debug.git"
+    "url": "git+https://gitrepos.ru/e22m4u/js-debug.git"
   },
   "type": "module",
   "types": "./src/index.d.ts",
@@ -38,14 +38,15 @@
     "prepare": "husky"
   },
   "dependencies": {
-    "@e22m4u/js-format": "~0.2.1",
+    "@e22m4u/js-format": "~0.3.1",
     "util": "~0.12.5"
   },
   "devDependencies": {
     "@commitlint/cli": "~20.1.0",
     "@commitlint/config-conventional": "~20.0.0",
-    "@e22m4u/js-spy": "~0.2.0",
+    "@e22m4u/js-spy": "~0.3.0",
     "@eslint/js": "~9.39.1",
+    "@types/chai": "~5.2.3",
     "@types/mocha": "~10.0.10",
     "c8": "~10.1.3",
     "chai": "~6.2.1",
@@ -53,11 +54,13 @@
     "eslint": "~9.39.1",
     "eslint-config-prettier": "~10.1.8",
     "eslint-plugin-chai-expect": "~3.1.0",
+    "eslint-plugin-import": "~2.32.0",
+    "eslint-plugin-jsdoc": "~61.4.1",
     "eslint-plugin-mocha": "~11.2.0",
     "globals": "~16.5.0",
     "husky": "~9.1.7",
     "mocha": "~11.7.5",
-    "prettier": "~3.7.2",
+    "prettier": "~3.7.4",
     "rimraf": "~6.1.2",
     "typescript": "~5.9.3"
   }

+ 3 - 4
src/create-debugger.js

@@ -1,8 +1,6 @@
-import {Errorf} from '@e22m4u/js-format';
-import {format} from '@e22m4u/js-format';
-import {isNonArrayObject} from './utils/index.js';
-import {generateRandomHex} from './utils/index.js';
+import {Errorf, format} from '@e22m4u/js-format';
 import {createColorizedDump} from './create-colorized-dump.js';
+import {isNonArrayObject, generateRandomHex} from './utils/index.js';
 
 /**
  * Доступные цвета.
@@ -226,6 +224,7 @@ export function createDebugger(
   };
   // формирование функции вывода
   // сообщений отладки
+  // eslint-disable-next-line jsdoc/require-jsdoc
   function debugFn(messageOrData, ...args) {
     if (!isDebuggerEnabled()) return;
     const prefix = getPrefix();

+ 1 - 2
src/create-debugger.spec.js

@@ -1,8 +1,7 @@
 import {expect} from 'chai';
 import {createSpy} from '@e22m4u/js-spy';
 import {stripAnsi} from './utils/strip-ansi.js';
-import {createDebugger} from './create-debugger.js';
-import {DEFAULT_OFFSET_STEP_SPACES} from './create-debugger.js';
+import {createDebugger, DEFAULT_OFFSET_STEP_SPACES} from './create-debugger.js';
 
 describe('createDebugger', function () {
   let consoleLogSpy;

+ 2 - 2
src/debuggable.js

@@ -1,5 +1,5 @@
 import {toCamelCase} from './utils/index.js';
-import {createDebugger} from '@e22m4u/js-debug';
+import {createDebugger} from './create-debugger.js';
 
 /**
  * @typedef {{
@@ -49,7 +49,7 @@ export class Debuggable {
   /**
    * Constructor.
    *
-   * @param {DebuggableOptions|undefined} options
+   * @param {DebuggableOptions} [options]
    */
   constructor(options = undefined) {
     const className = toCamelCase(this.constructor.name);

+ 1 - 2
src/debuggable.spec.js

@@ -1,8 +1,7 @@
 import {expect} from 'chai';
 import {createSpy} from '@e22m4u/js-spy';
 import {Debuggable} from './debuggable.js';
-import {stripAnsi} from './utils/index.js';
-import {escapeRegexp} from './utils/index.js';
+import {stripAnsi, escapeRegexp} from './utils/index.js';
 
 describe('Debuggable', function () {
   let consoleLogSpy;

+ 2 - 1
src/utils/is-non-array-object.js

@@ -1,7 +1,8 @@
 /**
  * Is non-array object.
  *
- * @param input
+ * @param {*} input
+ * @returns {boolean}
  */
 export function isNonArrayObject(input) {
   return Boolean(input && typeof input === 'object' && !Array.isArray(input));

+ 2 - 1
src/utils/to-camel-case.js

@@ -1,7 +1,8 @@
 /**
  * To camel case.
  *
- * @param input
+ * @param {string} input
+ * @returns {string}
  */
 export function toCamelCase(input) {
   return input

+ 3 - 3
tsconfig.json

@@ -1,11 +1,11 @@
 {
   "compilerOptions": {
-    "noEmit": true,
+    "strict": true,
     "target": "es2022",
     "module": "NodeNext",
     "moduleResolution": "NodeNext",
-    "allowJs": true,
-    "checkJs": true
+    "noEmit": true,
+    "allowJs": true
   },
   "include": [
     "./src/**/*.ts",