0

I've got a quite strange error from eslint with this piece code:

 import axios from 'axios';
    import config from '../config.json';
    import AgentResult from './agentResult';

    /**
    * Class Agent used for making calls to api
    */
    class Agent {
    /**
     * 
     * @param {string} apiRoot 
     * @param {string} wsRoot
     * @constructor
     */
    constructor(apiRoot = config.apiRoot, wsRoot = config.wsRoot) {
        this._apiRoot = apiRoot;
        this._wsRoot = wsRoot;

        this._transport = axios.create({
            baseURL: this._apiRoot,
            timeout: 10000,
            withCredentials: true
        });
    }

    /**
     * Make request to apiRoot/users/me
     * @returns {Promise<AgentResult>} AgentResult
     */
    async getMe() {
        try {
            let res = await this._transport.get('/users/me');
            return AgentResult.ok(res.data);
        } catch (ex) {
            if (ex.request) {
                return AgentResult.fail(ex.request);
            }
            return AgentResult.fail(ex.response.error.message);
        }
    }

    /**
     * Make request to apiRoot/users/:id
     * @param {string} id
     * @returns {Promise<AgentResult>} AgentResult
     */
    async getUserById(id) {
        try {
            let res = await this._transport.get(`/users/${id}`);
            return AgentResult.ok(res.data);
        } catch (ex) {
            if (ex.request) {
                return AgentResult.fail(ex.request);
            }
            return AgentResult.fail(ex.response.error.message);
        }
    }

    /**
     * Make request to apiRoot/users/sign-in
     * @param {object} body
     * @returns {AgentResult} AgentResult
     */
    async postSignIn(body) {
        try {
            let res = await this._transport.post('/users/sign-in', body);
            return AgentResult.ok(res.data);
        } catch (ex) {
            if (ex.request) {
                return AgentResult.fail(ex.request);
            }
            return AgentResult.fail(ex.response.error.message);
        }
    }

    /**
     * Make request to apiRoot/users/sign-up
     * @param {object} body
     * @returns {Promise<AgentResult>} AgentResult
     */
    async postSignUp(body) {
        try {
            let res = await this._transport.post('/users/sign-up', body);
            return AgentResult.ok(res.data);
        } catch (ex) {
            if (ex.request) {
                return AgentResult.fail(ex.request);
            }
            return AgentResult.fail(ex.response.error.message);
        }
    }

    /**
     * Make request to apiRoot/users/update
     * @param {object} body
     * @returns {Promise<AgentResult>} AgentResult
     */
    async putUpdate(body) {
        try {
            let res = await this._transport.put('/users/update', body);
            return AgentResult.ok(res.data);
        } catch (ex) {
            if (ex.request) {
                return AgentResult.fail(ex.request);
            }
            return AgentResult.fail(ex.response.error.message);
        }
    }

    /**
     * Opens ws connection at wsRoot/find
     * @returns {WebSocket} websocket connection
     */
    wsFind() {
        let ws = new WebSocket('${this._wsRoot}/find')
        return ws;
    }

    /**
     * Opens ws connection at wsRoot/open?context=context
     * @param {string} context
     * @returns {WebSocket} websocket connection
     */
    wsOpen(context) {
        let ws = new WebSocket(`${this._wsRoot}/open?context=${context}`);
        return ws;
    }
 }

 export default Agent;

The error reads:

135:28 error '_x' is defined but never used no-unused-vars

186:27 error '_x2' is defined but never used no-unused-vars

237:27 error '_x3' is defined but never used no-unused-vars

288:26 error '_x4' is defined but never used no-unused-vars

The problem is: these lines don't even exist in the code, furthermore such variables. I can suspect that the problem is here because of async code. Am i right?

Community
  • 1
  • 1

0 Answers0