Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSC does not run when adding plugin and rule to .eslintrc.js #3

Open
laij84 opened this issue Dec 27, 2019 · 3 comments
Open

TSC does not run when adding plugin and rule to .eslintrc.js #3

laij84 opened this issue Dec 27, 2019 · 3 comments
Assignees

Comments

@laij84
Copy link

laij84 commented Dec 27, 2019

When following the README to add the package:

Add to plugins section:

tsc

Add rule to rules section, e.g.

"tsc/config": [1, {
    configFile: "tsconfig.json"
}]

When running eslint the tsc does not catch any errors.

However, if I remove this configuration and pass it inline with the command it works:

eslint --fix --plugin tsc --rule 'tsc/config: [2, {configFile: \"tsconfig.json\"}]'

Here is my eslint config:

module.exports = {
  "extends": ["prettier", "react-app", "plugin:import/typescript"],
  "plugins": ["tsc", "prettier", "react", "react-hooks", "@typescript-eslint"],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "env": {
    "es6": true,
    "browser": true,
    "node": true,
    "jest": true
  },
  "rules": {
    "tsc/config": [1, {
      configFile: "tsconfig.json"
    }],
    "array-callback-return": "off",
    "arrow-parens": "off",
    "comma-dangle": "off",
    "consistent-return": "off",
    "eqeqeq": "off",
    "function-paren-newline": "off",
    "import/extensions": "error",
    "import/first": "error",
    "import/order": "error",
    "import/no-deprecated": "error",
    "import/no-duplicates": "error",
    "import/no-extraneous-dependencies": "off",
    "import/no-named-as-default": "off",
    "import/no-unresolved": "error",
    "import/prefer-default-export": "off",
    "indent": "off", // in conflict with prettier
    "jsx-a11y/anchor-is-valid": "off",
    "jsx-a11y/no-redundant-roles": "off",
    "max-len": 0, // in conflict with prettier
    "no-confusing-arrow": "off",
    "no-else-return": "error",
    "no-nested-ternary": "off",
    "no-return-assign": "off",
    "no-param-reassign": "off",
    "no-undef": "error",
    "no-unused-vars": "error",
    "no-use-before-define": "error",
    "object-curly-newline": "off",
    "prefer-const": "error",
    "prefer-destructuring": "error",
    "prefer-rest-params": "off",
    "prettier/prettier": "error",
    "react/default-props-match-prop-types": "off",
    "react/forbid-prop-types": "off",
    "react/jsx-boolean-value": 2,
    "react/jsx-filename-extension": "off",
    "react/jsx-uses-react": 2,
    "react/jsx-uses-vars": 2,
    "react/no-array-index-key": 2,
    "react/no-unescaped-entities": "off",
    "react/no-unused-state": "off",
    "react/prefer-stateless-function": "error",
    "react/prop-types": "error",
    "react/require-default-props": 2,
    "react/sort-comp": 2,
    "semi": "off",
    "react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
    "react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
  },
  overrides: [
    {
      files: ['**/*.ts', '**/*.tsx'],
      rules: {
        "react/prop-types": "off",
        '@typescript-eslint/no-unused-vars': [
          'error',
          {
            args: 'none',
            ignoreRestSiblings: true,
          },
        ],
      },
      parser: '@typescript-eslint/parser',
      parserOptions: {
        ecmaVersion: 2018,
        sourceType: 'module',
        ecmaFeatures: { jsx: true },
        warnOnUnsupportedTypeScriptVersion: true,
      },
    },
  ],
  settings: {
    'import/resolver': {
      node: {
          extensions: ['.js', '.jsx', '.ts', '.tsx'],
      },
    },
  },
}
@unlight
Copy link
Owner

unlight commented Feb 10, 2020

Interesting.
Cannot tell what is reason of such behavior.
Can you show your tsconfig?

@unlight unlight self-assigned this Sep 15, 2020
@rumanHuq
Copy link
Contributor

for typescript files you need to explicitly pass the extensions
eslint . --ext .js,.jsx,.ts,.tsx

@christynwegner
Copy link

I know this is an old thread but in 2021 I had this issue, too; eslint should have errored for us but instead passed eslint and allowed commit. This also meant CI/CD also passed. We used the same configuration in the README.

"tsc/config": [1, {
    configFile: "tsconfig.json"
}]

Manually running yarn eslint ... on the problem file output (instead of through lint-staged on pre-commit) output warnings which allowed linting to pass.

After changing the config rule to error (or, as I recently discovered 2 = error, 1 = warn) , eslint now fails as expected and now fails both pre-commit and CI/CD linting:

"tsc/config": ["error", {
    configFile: "tsconfig.json"
}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants