如何在 eslint 中使用 atom-typescript 或替代方案

How to use atom-typescript or alternative with eslint

Atom 包 - 已安装

更漂亮 - 设置:

.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 以同样的方式工作?

谢谢

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

You need to tell linter-eslint that it actually knows how to handle TypeScript files.

You can do that by adding the scope for TypeScript files (source.ts) here:

上面的屏幕截图来自软件包 linter-eslint 的设置页面(首选项 > 软件包 > linter-eslint)。

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