Эслинт дает ложный положительный результат - PullRequest
0 голосов
/ 23 марта 2020

Я новичок в Webpack и столкнулся с проблемой eslint и Typescript. eslint говорит мне, что мне не хватает возвращаемого типа для функций, но, как вы можете видеть, у меня есть один.

Я включил @typescript-eslint/parser в мой файл .eslintr c

// test-function.ts
7  function numberOne(): number {
8    return 1;
9  }
10    
11 const numberTwo = (): number => 2;
12    
13 console.log( numberTwo() - numberOne() );
// webpack.config.js
const path = require('path');

const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

module.exports = {
  context: __dirname,
  mode: 'development',
  watch: false,
  entry: path.join( __dirname, 'src', 'index.ts'),
  devtool: 'inline-source-map',
  devServer: {
    contentBase: './dist'
  },
  module: {
    rules: [
      {
        enforce: 'pre',
        test: /\.tsx?$/,
        exclude: [
          /node_modules/,
          /declarations/
        ],
        use: [
          {
            loader: 'eslint-loader',
            options: {
              configFile: '.eslintrc.json',
              cache: false,
              emitError: true,
              failOnError: true,
              fix: true
            }
          }
          ,
          {
            loader: 'ts-loader',
            options: {
              transpileOnly: true
            }
          }
        ]
      },
    ]
  },
  plugins: [
    new ForkTsCheckerWebpackPlugin(),
  ],
  output: {
    filename: 'main.js',
    path: path.resolve(__dirname, './dist')
  },
  resolve: {
    extensions: ['.wasm', '.ts', '.tsx', '.mjs', '.cjs', '.js', '.json']
  }
};
// .eslintrc
{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": 6,
    "project": "./tsconfig.json"
  },
  "env": {
    "es6": true,
    "browser": true,
    "worker": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "ignorePatterns": [],
  "rules": {
    "@typescript-eslint/no-explicit-any": ["error"]
  }
}

Вот как выглядит ошибка

   7:1   warning  Missing return type on function           @typescript-eslint/explicit-function-return-type
  10:19  warning  Missing return type on function           @typescript-eslint/explicit-function-return-type

Буду признателен за любую помощь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...