Search code examples
typescripteslintprettier

How to use atom-typescript or alternative with eslint


Atom packages - installed

  • atom-typescript
  • language-typescript-grammars-only
  • linter
  • linter-eslint
  • linter-stylelint
  • linter-ui-default
  • prettier-atom

Prettier - settings:

  • ESLint Integration = checked
  • Stylelint Integration = checked
  • EditotConfig Integration = unchecked

.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

  • Correctly shows error - A form label must be associated with a control
import React, { FC } from 'react';
const SomeLabel: FC = () => {
  return (
    <label>hello world</label>
  );
};
export default SomeLabel;

SomeLabel.tsx

  • Does not show an error!
import React, { FC } from 'react';
const SomeLabel: FC = () => {
  return (
    <label>hello world</label>
  );
};
export default SomeLabel;

The jsx files correctly take on the eslint errors, where as the typescript file extensions do not. This works automatically with visual studio code, but not atom. How can I get atom to work the same?

thankyou


Solution

  • I had the same problem and the issue on linter-eslint GitHub's repo helped me.

    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:

    Screenshot of linter-eslint settings

    The screenshot above is from settings page of the package linter-eslint (Preferences > Packages > linter-eslint).

    I've added source.ts and source.tsx, reloaded the window (View > Developer > Reload window) and Atom started to display my lint errors.