Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

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

Closed
NateScarlet opened this issue Apr 9, 2019 · 1 comment · Fixed by #862
Closed
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Bug
Milestone

Comments

@NateScarlet
Copy link

Bug Report

  • tslint-microsoft-contrib version: 6.1.0-beta2
  • TSLint version: 5.12.1
  • TypeScript version: 3.3.3333
  • Running TSLint via: VSCode

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

@NateScarlet NateScarlet changed the title False positive for prefer-array-literal when using Array function from other namespace False positive for prefer-array-literal when using Array from other namespace Apr 9, 2019
@JoshuaKGoldberg JoshuaKGoldberg added Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Bug labels Apr 19, 2019
@JoshuaKGoldberg
Copy link

JoshuaKGoldberg commented Apr 19, 2019

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

IllusionMH added a commit to IllusionMH/tslint-microsoft-contrib that referenced this issue May 12, 2019
IllusionMH added a commit to IllusionMH/tslint-microsoft-contrib that referenced this issue May 17, 2019
IllusionMH added a commit that referenced this issue May 17, 2019
* Use only tslint --test for prefer-array-literal rule

* Restrict only global objects with Array (fixes #856)

* Add allow-single-argument option and check argument types (fixes #822)

* Update docs and metadata for prefer-array-literal rule

* Apply suggestions related to wording in README.md

Co-Authored-By: Josh Goldberg <joshuakgoldberg@outlook.com>

* Change new option name to allow-size-argument

* Use Set for restricted namespaces. Add `self` to restrictions

* Fix error message for incorrect size argument

* Handle array spread in argument position

* Drop node text from all error messages

* Handle potential exceptions from TS

* Add comment about additional check for SpreadElement
@IllusionMH IllusionMH added this to the 6.2.0-beta milestone May 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants