palantir / tslint

:vertical_traffic_light: An extensible linter for the TypeScript language
http://palantir.github.io/tslint/
Apache License 2.0
5.91k stars 889 forks source link

TypeError: Cannot read property 'uses' of undefined: preferForOfRule #3526

Closed ghost closed 6 years ago

ghost commented 6 years ago

Bug Report

Seems to fail at this line: https://github.com/palantir/tslint/blob/master/src/rules/preferForOfRule.ts#L66 though what I just linked to, and what appears when I click the file in my terminal are not the same.

// ./node_modules/tslint/lib/rules/preferForOfRule.js
for (var _i = 0, _a = variables.get(indexVariable).uses; _i < _a.length; _i++) {

TypeScript code being linted

// code snippet
?

with tslint.json configuration:

{
  "extends": [
    "tslint:recommended",
    "tslint-immutable",
    "tslint-consistent-codestyle",
    "tslint-microsoft-contrib",
    "codelyzer",
    "tslint-config-prettier"
  ],
  "rulesDirectory": "node_modules/codelyzer",
  "project": "./tsconfig.json",
  "exclude": [
    "**/src/**/*.ts",
    "**/e2e/**",
    "**/node_modules/**/*",
    "**/coverage/**/*"
  ],
  "format": "stylish",
  "rules": {
    "object-literal-sort-keys": false,
    "ordered-imports": false,
    "member-access": false,
    "member-ordering": false,
    "no-string-literal": false,
    "radix": false,
    "no-angle-bracket-type-assertion": false,
    "no-as-type-assertion": true,
    "no-empty": false,
    "array-type": false,
    "typedef": [
      true,
      "parameter",
      "property-declaration",
      "object-destructuring",
      "array-destructuring",
      "call-signature"
    ],
    "no-var-keyword": true,
    "no-parameter-reassignment": true,
    "readonly-array": true,
    "no-mixed-interface": true,
    "insecure-random": true,
    "no-banned-terms": true,
    "no-empty-interface": true,
    "no-useless-files": true,
    "possible-timing-attack": true,
    "valid-typeof": true,
    "use-named-parameter": true,
    "arrow-return-shorthand": [true, "multiline"],
    "triple-equals": true,
    "no-unnecessary-initializer": true,
    "no-var-before-return": true,
    "no-unnecessary-qualifier": true,
    "no-unnecessary-callback-wrapper": true,
    "prefer-const": true,
    "object-literal-shorthand": true,
    "prefer-template": true,
    "no-non-null-assertion": true,
    "await-promise": true,
    "no-conditional-assignment": true,
    "no-construct": true,
    "no-for-in-array": true,
    "no-misused-new": true,
    "promise-function-async": true,
    "no-unused-expression": true,
    "no-unused-variable": true,
    "no-object-literal-type-assertion": true,
    "deprecation": true,
    "no-accessor-recursion": true,
    "no-return-undefined": true,
    "no-static-this": true,
    "prefer-while": true,
    "prefer-const-enum": true,
    "no-function-expression": true,
    "parameter-properties": [true, "all-or-none"],
    "cyclomatic-complexity": true,
    "directive-selector": [
      true,
      "attribute",
      ["dir-prefix1", "dir-prefix2"],
      "camelCase"
    ],
    "component-selector": [true, "element", "cng", "kebab-case"],
    "angular-whitespace": [true, "check-interpolation", "check-semicolon"],
    "use-input-property-decorator": true,
    "use-output-property-decorator": true,
    "use-host-property-decorator": true,
    "no-attribute-parameter-decorator": true,
    "no-input-rename": true,
    "no-output-on-prefix": true,
    "no-output-rename": true,
    "no-forward-ref": true,
    "use-life-cycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": [true, "Component"],
    "directive-class-suffix": [true, "Directive"],

    "no-invalid-this": false,
    "underscore-consistent-invocation": false,
    "no-parameter-properties": false,
    "no-multiline-string": false,
    "no-void-expression": false,
    "variable-name": false,
    "function-name": false,
    "newline-before-return": false,
    "missing-jsdoc": false,
    "export-name": false,
    "completed-docs": false,
    "no-relative-imports": false,
    "no-stateless-class": false,
    "restrict-plus-operands": false,
    "no-increment-decrement": false,
    "mocha-no-side-effect-code": false,
    "no-floating-promises": false,
    "strict-boolean-expressions": false,
    "no-backbone-get-set-outside-model": false,
    "no-any": false,
    "no-import-side-effect": false,
    "no-unsafe-any": false,
    "no-http-string": [
      false,
      "http://www.example.com/?.*",
      "http://www.examples.com/?.*"
    ],
    "no-reserved-keywords": false,
    "early-exit": false,
    "no-unused": false,
    "readonly-keyword": false,
    "no-else-after-return": false,
    "no-collapsible-if": false,
    "no-unnecessary-else": false,
    "no-object-mutation": false,
    "no-magic-numbers": false,
    "no-let": false,
    "no-expression-statement": false,
    "no-this": false,
    "no-class": false
  }
}

Actual behavior

TypeError: Cannot read property 'uses' of undefined
    at visitForStatement ($MY_PROJECT/node_modules/tslint/lib/rules/preferForOfRule.js:66:59)
    at cb ($MY_PROJECT/node_modules/tslint/lib/rules/preferForOfRule.js:53:13)
    at visitNodes ($MY_PROJECT/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild ($MY_PROJECT/node_modules/typescript/lib/typescript.js:12875:24)
    at cb ($MY_PROJECT/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNode ($MY_PROJECT/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild ($MY_PROJECT/node_modules/typescript/lib/typescript.js:12889:21)
    at cb ($MY_PROJECT/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNodes ($MY_PROJECT/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild ($MY_PROJECT/node_modules/typescript/lib/typescript.js:12875:24)

Expected behavior

No errors.

ghost commented 6 years ago

I dropped TS back to 2.6.1 and this went away.

ajafff commented 6 years ago

Same as in the other issue: I'd like to fix this.

retorquere commented 6 years ago

What info do you need? I'm also seeing this.

ajafff commented 6 years ago

@retorquere First I'd like to know if this happens during editing when the code likely has syntax errors or if it also occurs when linting valid code. We'll try to fix it in both cases, but the latter could be a bug in TypeScript, too.

Then I need a code snippet to reproduce. To narrow it down to the file that causes the exception, you could edit lib/linter.js. Inside the catch clause of the try-catch in applyRule, you can simply console.log(sourceFile.fileName).

retorquere commented 6 years ago

I'm not using it inside an editor (vim user here), only during my build.

OK, I have the filenames, assuming the filename displays above the error (for my reference: content/BetterBibTeX.ts, content/keymanager.ts, content/cayw/formatter.ts, resource/Better BibTeX.ts, webpack/scripts/release.ts, setup/preferences.ts)

retorquere commented 6 years ago

Ah and yes, valid code, as it compiles cleanly after. I no see they don't all display the same error, but they do look similar to me:

/home/ubuntu/zotero-better-bibtex/content/BetterBibTeX.ts
TypeError: Cannot read property 'kind' of undefined
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:69:26)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12923:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:81:19)
    at visitNode (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12921:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:81:19)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:81:19)
/home/ubuntu/zotero-better-bibtex/content/Preferences.ts
/home/ubuntu/zotero-better-bibtex/content/auto-export.ts
/home/ubuntu/zotero-better-bibtex/content/dateparser.ts
/home/ubuntu/zotero-better-bibtex/content/keymanager.ts
/home/ubuntu/zotero-better-bibtex/content/keymanager.ts
TypeError: Cannot read property 'uses' of undefined
    at visitForStatement (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:66:59)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:53:13)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNode (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12889:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
/home/ubuntu/zotero-better-bibtex/content/qr-check.ts
/home/ubuntu/zotero-better-bibtex/content/serializer.ts
/home/ubuntu/zotero-better-bibtex/content/cayw/formatter.ts
TypeError: Cannot read property 'uses' of undefined
    at visitForStatement (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:66:59)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:53:13)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNode (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12782:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12950:21)
/home/ubuntu/zotero-better-bibtex/content/keymanager/formatter.ts
/home/ubuntu/zotero-better-bibtex/content/test/support.ts
/home/ubuntu/zotero-better-bibtex/resource/Better BibLaTeX.ts
/home/ubuntu/zotero-better-bibtex/resource/Better BibLaTeX.ts
/home/ubuntu/zotero-better-bibtex/resource/Better BibTeX.ts
/home/ubuntu/zotero-better-bibtex/resource/Better BibTeX.ts
TypeError: Cannot read property 'uses' of undefined
    at visitForStatement (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:66:59)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:53:13)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNode (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12910:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
/home/ubuntu/zotero-better-bibtex/resource/Better CSL YAML.ts
/home/ubuntu/zotero-better-bibtex/resource/bibtex/reference.ts
/home/ubuntu/zotero-better-bibtex/resource/bibtex/unicode_translator.ts
/home/ubuntu/zotero-better-bibtex/resource/csl/csl.ts
/home/ubuntu/zotero-better-bibtex/resource/lib/markupparser.ts
/home/ubuntu/zotero-better-bibtex/resource/lib/markupparser.ts
/home/ubuntu/zotero-better-bibtex/webpack/loaders/wrap.ts
/home/ubuntu/zotero-better-bibtex/webpack/scripts/release.ts
TypeError: Cannot read property 'uses' of undefined
    at visitForStatement (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:66:59)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:53:13)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNode (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12890:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/preferForOfRule.js:55:19)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12875:24)
/home/ubuntu/zotero-better-bibtex/setup/preferences.ts
TypeError: Cannot read property 'kind' of undefined
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:69:26)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12923:24)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:81:19)
    at visitNode (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12921:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:81:19)
    at visitNodes (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/home/ubuntu/zotero-better-bibtex/node_modules/typescript/lib/typescript.js:12926:21)
    at cb (/home/ubuntu/zotero-better-bibtex/node_modules/tslint/lib/rules/objectLiteralShorthandRule.js:81:19)
/home/ubuntu/zotero-better-bibtex/setup/translator-typing.ts
/home/ubuntu/zotero-better-bibtex/setup/loaders/bcf.ts
/home/ubuntu/zotero-better-bibtex/content/keymanager/formatter.ts
ajafff commented 6 years ago

Can you share one of the failing files? Otherwise you could try to remove a big chunk of code and see if the error still occurs. Ideally I only need the offending for-loop or object literal if you can narrow it down so far.

retorquere commented 6 years ago

All live at https://github.com/retorquere/zotero-better-bibtex

If I comment out https://github.com/retorquere/zotero-better-bibtex/blob/master/webpack/scripts/release.ts#L137 - https://github.com/retorquere/zotero-better-bibtex/blob/master/webpack/scripts/release.ts#L141, the error in /webpack/scripts/release.ts ("TypeError: Cannot read property 'uses' of undefined") goes away.

retorquere commented 6 years ago

The other error ("Cannot read property 'kind' of undefined") comes from https://github.com/retorquere/zotero-better-bibtex/blob/master/setup/preferences.ts#L252, and there I only have to comment out the last line to make the error go away.

retorquere commented 6 years ago

The other scripts are bigger so harder to bisect -- I hope these two are sufficient to figure out what's going on.

retorquere commented 6 years ago

(tsconfig and tslint also in that repo, should that matter)

ajafff commented 6 years ago

@retorquere I cloned your repo, installed all dependencies with yarn and ran yarn lint. I don't see any of the errors. TSLint 5.8.0, TypeScript 2.6.2, macOS I even tried to lint with the latest changes from the master branch of TSLint.

retorquere commented 6 years ago

I can only reproduce the error on CircleCI (but there I can reproduce it reliably). On CircleCI, I have typescript 2.6.2, typescript 2.4.1 pulled in by typedoc 0.9.0, and tslint 5.8.0. The build runs in Ubuntu 14.04.4 LTS.

ajafff commented 6 years ago

@retorquere CircleCI still uses yarn@1.1.0 which caused a lot of trouble due to strangely installed dependencies: see #3251 (and a lot of duplicates) Since we both cannot reproduce the issue locally, this is likely to be the cause.

@KSuttle-cng can you still reproduce the issue when using yarn@^1.2.1 to install your dependencies?

retorquere commented 6 years ago

How do I upgrade yarn? Doing npm upgrade -g yarn and mpm install -g yarn didn't raise the version above 1.1.0.

What influence does yarn have here BTW? I thought yarn was just a package installer? Should I revert to npm?

ajafff commented 6 years ago

What influence does yarn have here BTW? I thought yarn was just a package installer? Should I revert to npm?

If the installer screws up, the installee (is that a word?) is not guaranteed to function correctly. If you run yarn list in your CI environment, you probably see that tsutils has a different version of typescript installed than tslint. That shouldn't have happened according to the dependencies of the packages. This bug was introduced somewhere in yarn 1.0.x and fixed in 1.2.x

ghost commented 6 years ago

Here you go @ajafff:

Found the file in question ```typescript import { IAgreementsInfoModel } from './../../application/models/agreements-info.model'; import { AgreementsInfoAction } from './../../redux/actions/agreements-info.actions'; import { IBankInfoModel } from 'app/application/models/bank-model'; import { IncomeInfoModel } from 'app/application/models/income-info.model'; import { IncomeInfoActions } from './../../redux/actions/income-info.actions'; import { BankInfoActions } from './../../redux/actions/bank-info.actions'; import { IAccountInfoModel } from 'app/application/models/account-info.model'; import { AccountInfoActions } from 'app/redux/actions/account-info.actions'; import { IPersonalInfoModel } from './../../application/models/personal-info.model'; import { UAT_SCENARIO_LIST, ZIP_PER_STATE } from './uat-scenarios.service'; import { Router } from '@angular/router'; import { LookupService } from './../../service/lookup/lookup.service'; import { Observable } from 'rxjs/Rx'; import { Injectable } from '@angular/core'; import { ILookupItem } from 'app/application/models/lookup-item'; import * as faker from 'faker'; import * as moment from 'moment'; import { PersonalInfoActions } from 'app/redux/actions/personal-info.actions'; import { UIValues, UICollections, US_STATES } from 'constants'; @Injectable() export class UatHelperService { uatData = { account: {}, personalInfo: {}, incomeInfo: {}, bankInfo: {}, agreementsInfo: {}, }; scenarioList = UAT_SCENARIO_LIST; states: ReadonlyArray; accounts: ReadonlyArray; constructor( private lookupService: LookupService, private router: Router, private personalInfoActions: PersonalInfoActions, private accountInfoActions: AccountInfoActions, private bankInfoAction: BankInfoActions, private incomeInfoAction: IncomeInfoActions, private agreementsInfoAction: AgreementsInfoAction ) {} getScenarios(): Observable> { return Observable.of(this.scenarioList); } getStates(scenarioId?: string): Observable { this.lookupService.getStates().subscribe(data => (this.states = data)); if (scenarioId) { let filterStates: ReadonlyArray = []; this.scenarioList.forEach(element => { if (element.id === scenarioId) { filterStates = element.states; } }); if (filterStates.length) { for (let index = this.states.length - 1; index >= 0; index--) { let exists = false; filterStates.forEach(element => { if (this.states[index].value === element) { exists = true; } }); if (!exists) { return Observable.of([ ...this.states.slice(0, index), ...this.states.slice(index + 1), ]); } } } } return Observable.of(this.states); } getAccounts(scenarioId: string): Observable> { this.accounts = []; this.scenarioList.forEach(data => { if (data.id === scenarioId) { const scenario = data; if (scenario) { const accountsArr = scenario.accounts; if (accountsArr.length > 0) { for (let ind = 0; ind < accountsArr.length; ind++) { if (accountsArr[ind].account) { this.accounts.concat({ id: ind, name: `${accountsArr[ind].account.lastName}, ${ accountsArr[ind].account.firstName }`, }); } } } } } }); return Observable.of(this.accounts); } goToApp(): void { this.router.navigate(['/application']); } generateData(data: any): void { this.generateDataPopulating(data); this.router.navigate([`/application/account`]); } generateDataPopulating(data: any): void { this.createRandomData(data.state); this.evaluateScenario(data); this.accountInfoActions.accountInfoCompleted(this.uatData .account); this.personalInfoActions.personalInfoCompleted(this .uatData.personalInfo); this.incomeInfoAction.incomeInfoCompleted(this.uatData .incomeInfo); this.bankInfoAction.bankInfoCompleted(this.uatData .bankInfo); this.agreementsInfoAction.agreementsInfoCompleted(this .uatData.agreementsInfo); } private evaluateScenario(dataForm: any): void { const obj = this.getScenarioData(dataForm.scenario, dataForm.account); const modelKeys = Object.getOwnPropertyNames(obj); modelKeys.forEach(key => { const objData = obj[key]; const objDataKeys = Object.getOwnPropertyNames(objData); objDataKeys.forEach(dataKey => { this.uatData[key][dataKey] = obj[key][dataKey]; }); }); const randomStateZip = this.getRandomZipCode(dataForm.scenario); this.uatData['personalInfo']['zipCode'] = dataForm.zip || (ZIP_PER_STATE[dataForm.state] && ZIP_PER_STATE[dataForm.state].zip) || (obj['personalInfo'] && obj['personalInfo']['zipCode']) || randomStateZip.zip; this.uatData['personalInfo']['stateOfResidence'] = (ZIP_PER_STATE[dataForm.state] && ZIP_PER_STATE[dataForm.state].name) || randomStateZip.name; } getRandomZipCode(scenario: string): any { let stateValue: string; stateValue = US_STATES[faker.random.number({ min: 1, max: US_STATES.length })][ 'value' ]; UAT_SCENARIO_LIST.forEach(element => { if (element.id === scenario && element.states.length) { stateValue = faker.random.arrayElement(element.states); } }); return { zip: ZIP_PER_STATE[stateValue].zip, name: ZIP_PER_STATE[stateValue].name, }; } private createRandomData(stateId: string): void { const basicInfo = { password: 'password1', fName: faker.name.firstName(), lName: faker.name.lastName(), state: stateId === '' ? faker.address.stateAbbr() : stateId, }; this.uatData.account = this.createRandomAccount(basicInfo); this.uatData.personalInfo = this.createRandomPersonal(); this.uatData.incomeInfo = this.createRandomIncome(); this.uatData.bankInfo = this.createRandomBank(); this.uatData.agreementsInfo = this.createRandomAgreementsInfo(); } private createRandomAccount(basicInfo: any): any { let secQuestion: string; this.lookupService.getSecurityQuestions().subscribe(data => { secQuestion = data[faker.random.number({ min: 0, max: 4 })].value; }); return { firstName: basicInfo.fName, lastName: basicInfo.lName, email: faker.internet.email( basicInfo.fName, basicInfo.lName, 'nocngholdings.com' ), password: basicInfo.password, confirmPassword: basicInfo.password, confirmedPassword: true, securityQuestion: secQuestion, securityAnswer: 'A', }; } createRandomPersonal(): any { const fakeSSN = faker.phone.phoneNumber('9##-##-####'); const fakeDob = moment( faker.date.between(new Date(1960, 0), new Date(1999, 4)) ); return { address: faker.address.streetAddress(false), aptSuite: faker.random.boolean() ? faker.address.secondaryAddress() : '', city: faker.address.city(), // zipCode: faker.address.zipCode('#####'), // stateOfResidence: faker.address.state(), ownRent: faker.random.arrayElement(['OWN', 'RENT']), yearsCurrentAddress: faker.random.number(3), monthsCurrentAddress: faker.random.number(11), primaryPhone: faker.phone.phoneNumber('(5##) ###-####'), secondaryPhone: '', identificationType: faker.random.arrayElement(['DL', 'SI']), identificationState: 'OH', identificationNumber: 'A1234567', ssn: fakeSSN, confirmSsn: fakeSSN, dateOfBirth: fakeDob.format('MM/DD/YYYY'), receiveSmsAlerts: true, }; } createRandomIncome(): any { // const fakeIncomeSource = faker.random.arrayElement(['E', 'S', 'D', 'PN', 'UB', 'O']); const fakeIncomeSource = 'E'; const fakeShift = faker.random.arrayElement(['F', 'S', 'T', 'W', 'O']); const fakeNextPayDate = new Date( moment() .add(4, 'days') .toDate() ); return { incomeSource: fakeIncomeSource, employmentBenefitStartDateMonth: faker.random.number({ min: 1, max: 12 }), employmentBenefitStartDateYear: faker.random.number({ min: 2012, max: 2016, }), employerName: fakeIncomeSource === 'E' ? faker.company.companyName() : '', jobTitleOrDepartment: faker.random.word(), shiftId: fakeIncomeSource === 'E' ? fakeShift : '', workPhoneNumber: fakeIncomeSource === 'E' ? faker.phone.phoneNumber('(5##) ###-####') : '', extension: fakeIncomeSource === 'E' && faker.random.boolean() ? faker.phone.phoneNumber('####') : '', paycheckFrequency: (UICollections.PAYCHECK_FREQUENCY[ faker.random.number({ min: 0, max: 3 }) ]).value, grossPayPerCheck: `${faker.random.number({ min: 12, max: 25 })}00`, paycheckReceivedAs: (UICollections.PAYCHECK_FORMATS[ faker.random.number({ min: 0, max: 2 }) ]).value, nextPayDate: fakeNextPayDate, }; } createRandomBank(): any { const fakeAccount = faker.phone.phoneNumber('##########'); return { bankAccountType: (UICollections.BANK_ACCOUNT_TYPE[ faker.random.number({ min: 0, max: 1 }) ]).value, routingNumber: '111111121', confirmRoutingNumber: '111111121', accountNumber: fakeAccount, confirmAccountNumber: fakeAccount, }; } createRandomAgreementsInfo(): IAgreementsInfoModel { return { arbitrationAgreement: true, electronicRecordsConsent: true, shareInformation: false, paymentMethod: UIValues.EFT, }; } getScenarioData(scenarioId: string, accountId?: number | string): any { let uatScenario = {}; this.scenarioList.forEach(data => { if (data.id === scenarioId) { const scenario = data; if (scenario) { let indexItem: number | string; indexItem = accountId === '0' || accountId > 0 ? accountId : faker.random.number(scenario.accounts.length - 1); if (scenario.accounts.length) { uatScenario = scenario.accounts[indexItem]; } } } }); return uatScenario; } } ```
retorquere commented 6 years ago

@ajafff upgrading yarn on circleci made the problem go away.

adidahiya commented 6 years ago

I'm going to close this as the problem seems to be rooted in the package installer and Yarn released a patch. Feel free to re-open if you think it's important.