【问题标题】:How to use atom-typescript or alternative with eslint如何在 eslint 中使用 atom-typescript 或替代方法
【发布时间】:2020-11-16 12:22:15
【问题描述】:

Atom 包 - 已安装

  • 原子打字稿
  • 仅语言打字稿语法
  • 短绒
  • linter-eslint
  • linter-stylelint
  • linter-ui-default
  • 更漂亮的原子

更漂亮 - 设置:

  • ESLint 集成 = 已检查
  • Stylelint 集成 = 选中
  • EditotConfig 集成 = 未选中

.eslintrc

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true,
      "modules": true,
      "impliedStrict": true,
      "experimentalObjectRestSpread": true
    }
  },
  "settings": {
    "react": {
      "pragma": "React",
      "version": "detect"
    },
    "import/resolver": {
      "node": {
        "extensions": [".js", ".jsx", ".ts", ".tsx"],
        "paths": ["./"]
      },
      "babel-module": {}
    }
  },
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "plugin:prettier/recommended",
    "plugin:@typescript-eslint/recommended",
    "prettier/react",
    "prettier/@typescript-eslint",
    "plugin:import/typescript"
  ],
  "plugins": ["react", "@typescript-eslint", "prettier", "mocha"],
  "env": {
    "es6": true,
    "browser": true,
    "jest": true,
    "mocha": true,
    "node": true
  }
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "react",
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noImplicitAny": true,
    "outDir": "./dist/out-tsc",
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext",
    "downlevelIteration": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "skipLibCheck": true,
    "esModuleInterop": true
  },
  "include": [
    "src",
    "src/__tests__"
  ],
  "exclude": [
    "node_modules",
    "public"
  ]
}

SomeLabel.jsx

  • 正确显示错误 - 表单标签必须与控件相关联
import React, { FC } from 'react';
const SomeLabel: FC = () => {
  return (
    <label>hello world</label>
  );
};
export default SomeLabel;

SomeLabel.tsx

  • 不显示错误!
import React, { FC } from 'react';
const SomeLabel: FC = () => {
  return (
    <label>hello world</label>
  );
};
export default SomeLabel;

jsx 文件正确处理 eslint 错误,而 typescript 文件扩展名则没有。这适用于 Visual Studio 代码,但不适用于 atom。我怎样才能让 atom 以同样的方式工作?

谢谢

【问题讨论】:

    标签: typescript eslint prettier


    【解决方案1】:

    我遇到了同样的问题,issue on linter-eslint GitHub's repo 帮助了我。

    你需要告诉 linter-eslint 它实际上知道如何处理 打字稿文件。

    您可以通过添加 TypeScript 文件 (source.ts) 的范围来做到这一点 这里:

    以上截图来自包linter-eslint的设置页面(Preferences > Packages > linter-eslint)。

    我添加了source.tssource.tsx,重新加载了窗口(查看 > 开发人员 > 重新加载窗口),Atom 开始显示我的 lint 错误。

    【讨论】:

    • 这有点复杂,但谢谢你,这是答案的一部分:1.第一个错误:从'react'导入反应;因为找不到 eslint-plugin-react。我必须在我的 npm 项目中包含 eslint 插件。 2.第二个错误是缺少插件-语言打字稿。 3. 出现恼人的更漂亮的错误 - 用 eslintrc 规则解决 - "prettier/prettier": ["error", {"singleQuote": true, "parser": "flow", "endOfLine": "auto"}], 现在像魅力一样工作:)
    猜你喜欢
    • 2018-06-20
    • 2023-02-18
    • 1970-01-01
    • 2017-01-11
    • 2021-03-10
    • 1970-01-01
    • 2023-03-14
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多