microsoft / tslint-microsoft-contrib

A set of TSLint rules used on some Microsoft projects.
MIT License
702 stars 198 forks source link

Could not require "tslint-microsoft-contrib/recommended" #886

Closed AndrewCraswell closed 4 years ago

AndrewCraswell commented 5 years ago

Bug Report

with tslint.json configuration:

{
  "extends": [
    "tslint:recommended",
    "tslint-react",
    "tslint-microsoft-contrib/recommended",
    "tslint-config-prettier"
  ],
  "linterOptions": {
    "exclude": [
      "**/*.js",
      "node_modules/**/*.*",
      "**/*/node_modules/**/*.*",
      "**/*.d.ts"
    ]
  },
  "defaultSeverity": "warning",
  "rulesDirectory": [
    "node_modules/tslint-microsoft-contrib"
  ],
  "rules": {
    "completed-docs": {
      "severity": "warning"
    },
    "no-unused-variable": false,
    "no-suspicious-comment": false,
    "prefer-type-cast": false,
    "no-single-line-block-comment": false,
    "no-backbone-get-set-outside-model": false,
    "prefer-array-literal": [
      true,
      {
        "allow-type-parameters": true
      }
    ],
    "max-classes-per-file": false,
    "object-literal-sort-keys": false,
    "no-relative-imports": false,
    "import-name": false,
    "export-name": false,
    "variable-name": [
      true,
      "check-format",
      "allow-leading-underscore",
      "allow-pascal-case",
      "ban-keywords"
    ],
    "member-ordering": [
      true,
      {
        "order": [
          "public-static-field",
          "protected-static-field",
          "private-static-field",
          "public-instance-field",
          "protected-instance-field",
          "private-instance-field",
          "public-static-method",
          "protected-static-method",
          "private-static-method",
          "public-constructor",
          "public-instance-method",
          "protected-constructor",
          "protected-instance-method",
          "private-constructor",
          "private-instance-method"
        ]
      }
    ]
  }
}

Actual behavior

Not sure how long ago this started because I just realized that my linting was failing silently for some time... but if I run tslint from the command line I get the following error:

Error output

However, if I change tslint-microsoft-contrib/recommended to tslint-microsoft-contrib/recommended.json it works properly. If anyone has encountered this, some suggestions would be very helpful.

I guess this just feels more like a module resolution issue to me, and I'm less familiar with how tslint resolves packages but I had assumed it should match the node resolution pattern, meaning the .json should be optional... If it seems this bug needs to be filed somewhere else I can do that.

Expected behavior

Linting should execute and provide results.

IllusionMH commented 5 years ago

Hmmm... It looks strange but I can't reproduce this error on my PC when I install mentioned package versions and copy tslint.json. image

As I can see - you are using global TSLint installation this might have some impact. Does error appear if you use npx tslint ... or ./node_modules/.bin/tslint? Are there any specifics in folder layout (where you run command and where node_modules are located)?

Are there any warnings with the same message in your IDE if you configured TSLint there?

AndrewCraswell commented 5 years ago

Interesting, uninstalling the global package then running locally in the project worked fine. Anyways it's not a problem for me because I should be running TSLint from the project's node_modules anyway. You can close this.