【问题标题】:eslinting issue and my typescript react app is bonking outeslinting 问题和我的打字稿反应应用程序正在崩溃
【发布时间】:2020-10-09 06:17:14
【问题描述】:

我认为这个应用程序正在发挥我的最大优势。我正在使用打字稿,sass(scss),打字稿是基于每个文件的。我的简单设置会产生错误,然而,它的常规 react/js.. 标准东西。谁有想法。下面是我的 eslint 文件和非常简单的组件和错误的屏幕截图....

我认为问题在于我的 linting 不适用于“.js”文件。我的应用程序需要同时具有 .tsx 和 .js,因为不需要打字稿。能不能用。

.eslint 文件

const path = require('path');

module.exports = {
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2019,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    },
    "project": "./tsconfig.json"
  },
  "plugins": ["@typescript-eslint/eslint-plugin", 'react', 'prettier', 'import'],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:react-hooks/recommended",
    "plugin:react/recommended",
    "eslint-config-prettier",
    "eslint-config-prettier/@typescript-eslint",
    "airbnb-base",
    "prettier",
    "prettier/react",
  ],
  "globals": {},
  "rules": {
    "strict": ["error", "never"],
    "import/prefer-default-export": 1,
    "global-require": 1,
    "react/jsx-key": 1,
    "prefer-destructuring": 1
  },
  "env": {
    "browser": true,
    "jest": true,
    "es2020": true
  },
  settings: {
    'import/resolver': {
      'babel-module': {
        "import/resolver": {
          src: path.join(__dirname, '/src'),
        },
      },
    },
    react: {
      version: 'detect',
    },
  },
  overrides: [
    {
      "files": ["**/*.tsx?"],
      "excludedFiles": "**/*.js",
      "rules": {
        "react/prop-types": "off"
      }
    },
    {
      files: ['**/__tests__/**'],
      settings: {
        'import/resolver': {
          jest: {
            jestConfigFile: path.join(__dirname, '/jest.config.js'),
          },
        },
      },
    },
  ],
}

另外,我一直在 webstorm 中进行开发,这是我的 javascript 设置:

【问题讨论】:

    标签: typescript webstorm eslint


    【解决方案1】:

    打开文件时应将文件标记为jsx/tsx。或者手动配置:

    Preferences | Languages & Frameworks | JavaScript.

    https://blog.jetbrains.com/webstorm/2015/10/working-with-reactjs-in-webstorm-coding-assistance/

    【讨论】:

    • 我相信它的设置是正确的。我在 webstorm 中添加了我的设置的屏幕截图。
    • 您可以尝试创建一个新文件test.js 并在其中插入相同的内容吗?
    猜你喜欢
    • 2017-09-26
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2020-08-01
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多