cartant / rxjs-tslint-rules

TSLint rules for RxJS
https://cartant.github.io/rxjs-tslint-rules/
MIT License
371 stars 22 forks source link

rxjs-suffix-subjects throws error in console #88

Closed emzet closed 5 years ago

emzet commented 5 years ago

When run ng lint, this outputs in console for some files, all subjects have required suffix so at the end it succeed, but outputs this ugly errors in console.

Error:

The 'rxjs-suffix-subjects' rule threw an error in '[PROJECT_PATH]/src/app/modules/deals/deals-filters/deals-filter-full/deals-filter-full.component.ts':
TypeError: Cannot read property 'flags' of undefined
    at Object.getCheckFlags ([PROJECT_PATH]node_modules\typescript\lib\typescript.js:12135:23)
    at getTypeOfSymbol ([PROJECT_PATH]node_modules\typescript\lib\typescript.js:35850:20)
    at getTypeOfNode ([PROJECT_PATH]node_modules\typescript\lib\typescript.js:56817:24)
    at Object.getTypeAtLocation ([PROJECT_PATH]node_modules\typescript\lib\typescript.js:30859:31)
    at [PROJECT_PATH]node_modules\rxjs-tslint-rules\dist\rules\rxjsSuffixSubjectsRule.js:57:36
    at Array.forEach (<anonymous>)
    at Rule.applyWithProgram ([PROJECT_PATH]node_modules\rxjs-tslint-rules\dist\rules\rxjsSuffixSubjectsRule.js:56:21)
    at Linter.applyRule ([PROJECT_PATH]node_modules\tslint\lib\linter.js:211:29)
    at [PROJECT_PATH]node_modules\tslint\lib\linter.js:155:85
    at Object.flatMap ([PROJECT_PATH]node_modules\tslint\lib\utils.js:160:29)
    at Linter.getAllFailures ([PROJECT_PATH]node_modules\tslint\lib\linter.js:155:32)
    at Linter.lint ([PROJECT_PATH]node_modules\tslint\lib\linter.js:110:33)
    at lint ([PROJECT_PATH]node_modules\@angular-devkit\build-angular\src\tslint\index.js:145:20)
    at Observable.rxjs_1.Observable.obs [as _subscribe] ([PROJECT_PATH]node_modules\@angular-devkit\build-angular\src\tslint\index.js:61:37)
    at Observable._trySubscribe ([PROJECT_PATH]node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe ([PROJECT_PATH]node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\Observable.js:30:22)

All files pass linting.

Rule config:

"rxjs-suffix-subjects": {
  "options": {
    "parameters": true,
    "properties": true,
    "suffix": "Sub",
    "variables": true
  }
}

Environment:

Angular CLI: 7.3.6
Node: 11.12.0
OS: win32 x64
Angular: 7.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.6
@angular-devkit/build-angular     0.13.6
@angular-devkit/build-optimizer   0.13.6
@angular-devkit/build-webpack     0.13.6
@angular-devkit/core              7.3.6
@angular-devkit/schematics        7.3.6
@angular/cli                      7.3.6
@ngtools/webpack                  7.3.6
@schematics/angular               7.3.6
@schematics/update                0.13.6
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0
cartant commented 5 years ago

Can you include one of the files that effects the error?

emzet commented 5 years ago

So this affects only 6 big files in project, each has >500 lines of code, but this one is small, hope it helps.

File:

import { RouterStateSerializer } from '@ngrx/router-store';
import { Params, RouterStateSnapshot } from '@angular/router';

/**
 * The RouterStateSerializer takes the current RouterStateSnapshot
 * and returns any pertinent information needed. The snapshot contains
 * all information about the state of the router at the given point in time.
 * The entire snapshot is complex and not always needed. In this case, you only
 * need the URL and query parameters from the snapshot in the store. Other items could be
 * returned such as route parameters and static route data.
 */
export interface RouterStateUrl {
  url: string;
  queryParams: Params;
}

export class CustomRouterStateSerializer implements RouterStateSerializer<RouterStateUrl> {
  serialize(routerState: RouterStateSnapshot): RouterStateUrl {
    const { url } = routerState;
    const queryParams = routerState.root.queryParams;

    return { url, queryParams };
  }
}

Error:

> ng lint

Linting "[PROJECT_NAME]"...
The 'rxjs-suffix-subjects' rule threw an error in '[PROJECT_PATH]/src/app/custom/custom-router-state-serializer.ts':
TypeError: Cannot read property 'flags' of undefined
    at Object.getCheckFlags ([PROJECT_PATH]\node_modules\typescript\lib\typescript.js:12135:23)
    at getTypeOfSymbol ([PROJECT_PATH]\node_modules\typescript\lib\typescript.js:35850:20)
    at getTypeOfNode ([PROJECT_PATH]\node_modules\typescript\lib\typescript.js:56817:24)
    at Object.getTypeAtLocation ([PROJECT_PATH]\node_modules\typescript\lib\typescript.js:30859:31)
    at [PROJECT_PATH]\node_modules\rxjs-tslint-rules\dist\rules\rxjsSuffixSubjectsRule.js:57:36
    at Array.forEach (<anonymous>)
    at Rule.applyWithProgram ([PROJECT_PATH]\node_modules\rxjs-tslint-rules\dist\rules\rxjsSuffixSubjectsRule.js:56:21)
    at Linter.applyRule ([PROJECT_PATH]\node_modules\tslint\lib\linter.js:211:29)
    at [PROJECT_PATH]\node_modules\tslint\lib\linter.js:155:85
    at Object.flatMap ([PROJECT_PATH]\node_modules\tslint\lib\utils.js:160:29)
    at Linter.getAllFailures ([PROJECT_PATH]\node_modules\tslint\lib\linter.js:155:32)
    at Linter.lint ([PROJECT_PATH]\node_modules\tslint\lib\linter.js:110:33)
    at lint ([PROJECT_PATH]\node_modules\@angular-devkit\build-angular\src\tslint\index.js:145:20)
    at Observable.rxjs_1.Observable.obs [as _subscribe] ([PROJECT_PATH]\node_modules\@angular-devkit\build-angular\src\tslint\index.js:61:37)
    at Observable._trySubscribe ([PROJECT_PATH]\node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe ([PROJECT_PATH]\node_modules\@angular-devkit\build-angular\node_modules\rxjs\internal\Observable.js:30:22)

All files pass linting.
cartant commented 5 years ago

This should be fixed in 4.19.1. Thanks for the detailed bug report.