cmd eslint can not find ts error which found by IDE

Viewed 236

I want to use eslint in cmd to check ts file, but it can not get error info which I got in IDE.

I have set @typescript-eslint/parser in eslintrc.js. And eslint which running in cmd gave me some ts error when I did some wrong. But some wrong else did not be found.

I have a ts file with code:

interface Item {
  name: string;
  age: number;
}
const config: Array<Item> = [{
  name: 'foo',
}]

so, I got some error in IDE:

Property 'age' is missing in type '{ name: string; age: number }' but required in type 'Item'.ts(2741)

That right. I need this error info.

But when I run eslint in cmd

eslint fileName.ts  or  eslint --ext .ts fileName.ts

cmd eslint return nothing or some other warning/error in this file.

eslintrc here


module.exports = {
  "extends": ["xxx"],
  "globals": {
    "__SERVER_ENV__": true,
  },
  "rules": {
    "react/jsx-filename-extension": 0,
    "no-console": ["warn", { allow: ["error", "warn"] }],
    "@typescript-eslint/no-unused-vars": ["error", {
      "vars": "all",
      "args": "after-used",
      "ignoreRestSiblings": true
    }],
  },

  "settings": {
    "react": {
      "createClass": "createReactClass", // Regex for Component Factory to use,
      // default to "createReactClass"
      "pragma": "React",  // Pragma to use, default to "React"
      "version": "detect", // React version. "detect" automatically picks the version you have installed.
      // You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
      // default to latest and warns if missing
      // It will default to "detect" in the future
    },
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      // use <root>/tsconfig.json
      "typescript": {
        // always try to resolve types under `<roo/>@types` directory even it doesn't contain any source code, like`@types/unist`
        "alwaysTryTypes": true,
        "directory": "./",
      },
    },
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json",
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "modules": true,
    },
  },
  "plugins": ["@typescript-eslint", "import"],
};

and tsconfig.json

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "module": "commonjs",
    "lib": ["es6","dom","es2017"],
    "target": "es5",
    "jsx": "react",
    "types":["react"],
    "outDir": "/output",
    "baseUrl": ".",
    "paths": {
        "src/*": ["./src/*"]
    },
    "allowSyntheticDefaultImports": true,
    "sourceMap": true
  },
  "awesomeTypescriptLoaderOptions": {
    "useWebpackText": true,
    "useTranspileModule": true,
    "doTypeCheck": true,
    "forkChecker": true
  },
  "include": [
    ".d.ts",
    "./src/**/*"
  ]
}


I hope to get whole error info by cmd. what should I do?

1 Answers

It appears that eslint by design will not perform your Typescript type checking. I am just running my build command locally using tsc to be notified of this "property missing in type" error message, and fixing when the build fails.

It's very inconvenient because I only get alerted to one error per build attempt. If anyone has a better solution I'd appreciate any help.

Related