Browse Source

chore: imporve linting

e22m4u 3 days ago
parent
commit
c5d693786f
8 changed files with 42 additions and 21 deletions
  1. 0 4
      .mocharc.cjs
  2. 4 0
      .mocharc.json
  3. 10 7
      dist/cjs/index.cjs
  4. 13 1
      eslint.config.js
  5. 5 3
      package.json
  6. 6 3
      src/create-spies-group.js
  7. 1 0
      src/create-spy.spec.js
  8. 3 3
      tsconfig.json

+ 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"
+}

+ 10 - 7
dist/cjs/index.cjs

@@ -1,3 +1,4 @@
+"use strict";
 var __defProp = Object.defineProperty;
 var __defProp = Object.defineProperty;
 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
 var __getOwnPropNames = Object.getOwnPropertyNames;
 var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -171,10 +172,7 @@ function createSpy(target = void 0, methodNameOrImpl = void 0, customImplForMeth
 __name(createSpy, "createSpy");
 __name(createSpy, "createSpy");
 
 
 // src/create-spies-group.js
 // src/create-spies-group.js
-var SpiesGroup = class {
-  static {
-    __name(this, "SpiesGroup");
-  }
+var _SpiesGroup = class _SpiesGroup {
   /**
   /**
    * Constructor.
    * Constructor.
    */
    */
@@ -185,9 +183,10 @@ var SpiesGroup = class {
    * Создает шпиона для отдельной функции
    * Создает шпиона для отдельной функции
    * или метода объекта и добавляет его в группу.
    * или метода объекта и добавляет его в группу.
    *
    *
-   * @param target
-   * @param methodNameOrImpl
-   * @param customImplForMethod
+   * @param {Function|object} [target]
+   * @param {Function|string} [methodNameOrImpl]
+   * @param {Function} [customImplForMethod]
+   * @returns {Function}
    */
    */
   on(target, methodNameOrImpl, customImplForMethod) {
   on(target, methodNameOrImpl, customImplForMethod) {
     const spy = createSpy(target, methodNameOrImpl, customImplForMethod);
     const spy = createSpy(target, methodNameOrImpl, customImplForMethod);
@@ -199,6 +198,8 @@ var SpiesGroup = class {
    * для которых были созданы шпионы в этой группе,
    * для которых были созданы шпионы в этой группе,
    * и сброс истории вызовов для всех шпионов в группе.
    * и сброс истории вызовов для всех шпионов в группе.
    * Очищает внутренний список шпионов.
    * Очищает внутренний список шпионов.
+   *
+   * @returns {this}
    */
    */
   restore() {
   restore() {
     this.spies.forEach((spy) => spy.restore());
     this.spies.forEach((spy) => spy.restore());
@@ -206,6 +207,8 @@ var SpiesGroup = class {
     return this;
     return this;
   }
   }
 };
 };
+__name(_SpiesGroup, "SpiesGroup");
+var SpiesGroup = _SpiesGroup;
 function createSpiesGroup() {
 function createSpiesGroup() {
   return new SpiesGroup();
   return new SpiesGroup();
 }
 }

+ 13 - 1
eslint.config.js

@@ -1,6 +1,8 @@
 import globals from 'globals';
 import globals from 'globals';
 import eslintJs from '@eslint/js';
 import eslintJs from '@eslint/js';
+import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
+import eslintImportPlugin from 'eslint-plugin-import';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 
 
@@ -14,16 +16,26 @@ export default [{
     },
     },
   },
   },
   plugins: {
   plugins: {
+    'jsdoc': eslintJsdocPlugin,
     'mocha': eslintMochaPlugin,
     'mocha': eslintMochaPlugin,
+    'import': eslintImportPlugin,
     'chai-expect': eslintChaiExpectPlugin,
     'chai-expect': eslintChaiExpectPlugin,
   },
   },
   rules: {
   rules: {
     ...eslintJs.configs.recommended.rules,
     ...eslintJs.configs.recommended.rules,
     ...eslintPrettierConfig.rules,
     ...eslintPrettierConfig.rules,
+    ...eslintImportPlugin.flatConfigs.recommended.rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
-    "no-unused-vars": ["error", {caughtErrors: "none"}],
+    ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
     'no-duplicate-imports': 'error',
     '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'],
   files: ['src/**/*.js'],
 }];
 }];

+ 5 - 3
package.json

@@ -10,10 +10,10 @@
     "test",
     "test",
     "unit"
     "unit"
   ],
   ],
-  "homepage": "https://github.com/e22m4u/js-spy",
+  "homepage": "https://gitrepos.ru/e22m4u/js-spy",
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",
-    "url": "git+https://github.com/e22m4u/js-spy.git"
+    "url": "git+https://gitrepos.ru/e22m4u/js-spy.git"
   },
   },
   "type": "module",
   "type": "module",
   "types": "./src/index.d.ts",
   "types": "./src/index.d.ts",
@@ -48,11 +48,13 @@
     "eslint": "~9.39.1",
     "eslint": "~9.39.1",
     "eslint-config-prettier": "~10.1.8",
     "eslint-config-prettier": "~10.1.8",
     "eslint-plugin-chai-expect": "~3.1.0",
     "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",
     "eslint-plugin-mocha": "~11.2.0",
     "globals": "~16.5.0",
     "globals": "~16.5.0",
     "husky": "~9.1.7",
     "husky": "~9.1.7",
     "mocha": "~11.7.5",
     "mocha": "~11.7.5",
-    "prettier": "~3.6.2",
+    "prettier": "~3.7.4",
     "rimraf": "~6.1.2",
     "rimraf": "~6.1.2",
     "typescript": "~5.9.3"
     "typescript": "~5.9.3"
   }
   }

+ 6 - 3
src/create-spies-group.js

@@ -16,9 +16,10 @@ export class SpiesGroup {
    * Создает шпиона для отдельной функции
    * Создает шпиона для отдельной функции
    * или метода объекта и добавляет его в группу.
    * или метода объекта и добавляет его в группу.
    *
    *
-   * @param target
-   * @param methodNameOrImpl
-   * @param customImplForMethod
+   * @param {Function|object} [target]
+   * @param {Function|string} [methodNameOrImpl]
+   * @param {Function} [customImplForMethod]
+   * @returns {Function}
    */
    */
   on(target, methodNameOrImpl, customImplForMethod) {
   on(target, methodNameOrImpl, customImplForMethod) {
     const spy = createSpy(target, methodNameOrImpl, customImplForMethod);
     const spy = createSpy(target, methodNameOrImpl, customImplForMethod);
@@ -31,6 +32,8 @@ export class SpiesGroup {
    * для которых были созданы шпионы в этой группе,
    * для которых были созданы шпионы в этой группе,
    * и сброс истории вызовов для всех шпионов в группе.
    * и сброс истории вызовов для всех шпионов в группе.
    * Очищает внутренний список шпионов.
    * Очищает внутренний список шпионов.
+   *
+   * @returns {this}
    */
    */
   restore() {
   restore() {
     this.spies.forEach(spy => spy.restore());
     this.spies.forEach(spy => spy.restore());

+ 1 - 0
src/create-spy.spec.js

@@ -1,3 +1,4 @@
+/* eslint-disable jsdoc/require-jsdoc */
 import {expect} from 'chai';
 import {expect} from 'chai';
 import {createSpy} from './create-spy.js';
 import {createSpy} from './create-spy.js';
 
 

+ 3 - 3
tsconfig.json

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