microsoft / tslint-microsoft-contrib

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

False positive for prefer-array-literal when using `Array` from other namespace #856

Closed NateScarlet closed 5 years ago

NateScarlet commented 5 years ago

Bug Report

TypeScript code being linted

import { Types } from 'mongoose';

export const foo: Types.Array<number> = new Types.Array();

with tslint.json configuration:

  "extends": ["tslint-microsoft-contrib"],
  "rulesDirectory": ["node_modules/tslint-microsoft-contrib"],
  "rules": {
    "trailing-comma": false,
    "no-relative-imports": false,
    "no-implicit-dependencies": [true, ["dev", "graphql-tools"]],
    "newline-per-chained-call": false,
    "no-console": false,
    "quotemark": false,
    "export-name": [true, { "allow": ["resolvers"] }],
    "no-backbone-get-set-outside-model": false,
    "no-unsafe-any": false,
    "strict-boolean-expressions": false,
    "typedef": [
      true,
      "call-signature",
      "arrow-call-signature",
      "parameter",
      // "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ],
    "match-default-export-name": false
  }

Actual behavior

Got Replace Array constructor with an array literal: new Types.Array() (prefer-array-literal)tslint(prefer-array-literal)

Expected behavior

Got nothing

JoshuaKGoldberg commented 5 years ago

Good find @NateScarlet! Looks like the node should not be complained on if its .parent is a ts.PropertyAccessExpression.