N
N
Nikita Sokolov2020-08-23 09:18:58
typescript
Nikita Sokolov, 2020-08-23 09:18:58

ESLint constantly throws errors for valid code, how to fix it?

Periodically, the Typescript parser for ESLint generates type errors. Parsing error: ',' expected.
After closing the file, the error disappears for a while, while the code, of course, works and compiles. Here is an example where the linter throws an error (this code is in the class):

set values(newValues: Values) {
    if (Array.isArray(newValues)) {
      if (this.checkValue(newValues)) {
        this._values = newValues;
        this.trigger('valueUpdated');
        this.trigger('valueEnd');
      } else throw new RangeError('Value is out of range!');
    } else throw new TypeError('New value must be an Array!');
  } //вот на этой скобке ошибка

And so it appears periodically in all files, it really infuriates!

Here is my .eslintrc.js:
module.exports = {
  env: {
    browser: true,
    es6: true,
  },
  extends: ['airbnb-base', 'prettier', 'plugin:fsd/all'],
  globals: {
    Atomics: 'readonly',
    SharedArrayBuffer: 'readonly',
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    projects: './tsconfig.json',
    sourceType: 'module',
  },
  plugins: ['@typescript-eslint', 'fsd'],
  rules: {
    indent: ['error', 2],
    'no-underscore-dangle': ['error', { allowAfterThis: true }],
    'no-tabs': ['error', { allowIndentationTabs: true }],
    'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
    'no-console': 'off',
    'no-undef': 'off',
    'no-unused-vars': 'off',
    'import/no-extraneous-dependencies': 'off',
    'func-names': ['error', 'never'],
  },
  settings: {
    'import/extensions': {
      extensions: ['.js', '.jsx', '.ts', '.tsx'],
    },
  },
};

tsconfig.json:
{
  "compilerOptions": {
    "noImplicitAny": true,
    "removeComments": true,
    "target": "es5",
    "noEmit": true,
    "esModuleInterop": true
  },
  "include": [
    "src/plugin/types/slider.d.ts",
    "src/plugin/types/jquery.d.ts",
    "src/plugin/slider/slider.ts"
  ],
  "exclude": ["build/*", "dist/*", "node_modules/*", "src/plugin/tests/*"],
  "awesomeTypescriptLoaderOptions": {
    "useBabel": true,
    "babelOptions": {
      "babelrc": true
    },
    "babelCore": "@babel/core"
  }
}

Maybe you know what is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question