Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular CLI gotcha when an RxJS function is used only in a unit test #14

Open
balassy opened this issue Oct 18, 2017 · 5 comments
Open
Labels

Comments

@balassy
Copy link

balassy commented Oct 18, 2017

I have the following rxjs.imports.ts file in an Angular 4 project:

import 'rxjs/add/observable/of';

I have the following rule in the tslint.json file:

"rxjs-add": {
  "options": [{
    "file": "./src/rxjs.imports.ts"
  }],
  "severity": "error"
}

The following error is thrown when I run tslint:

ERROR: (rxjs-add) C:/Git/MyProject/src/rxjs.imports.ts[3, 1]: 
Unused patched observable in ./src/rxjs.imports.ts: of

I am using Observable.of(...) in my code, however only in one single .spec.ts file. It seems that the error is thrown during linting the application files, because if I remove the following block from the lint section of the .angular-cli.json file, the error disappears:

{
  "project": "src/tsconfig.app.json",
  "exclude": "**/node_modules/**"
},

Do you have any recommendation on how can I fix this, or this is just another gotcha that would be useful to add to the README?

Thank you!

@cartant
Copy link
Owner

cartant commented Oct 18, 2017

I've (only quickly) read your issue and would like to confirm whether or not you've read and followed the Angular CLI recommendations in the README.md.

@balassy
Copy link
Author

balassy commented Oct 18, 2017

Yes, I did, thank you. If I understand correctly, it is about the case when only an application file is using an operator, but not any test file, and your recommendation helps fixing the problem when linting the test files.
This issue is about the opposite direction: only a test file is using an operator, but any application file, and the linting of the application files is failing.

@cartant
Copy link
Owner

cartant commented Oct 18, 2017

Off the top of my head, I cannot think of an ideal solution to this. The linting of the application and test files uses the same tslint.json configuration and, therefore, the same central file of imports.

A hacky solution would be to create an unused.ts file that will be matched in the linting of the application, but not the tests and include in that file a function that 'uses' whichever operators are not used in the application. Of course, that means that said operators will be linked into the application even though they are not really needed. Not ideal.

Alternatively, you could look into what's involved in getting Angular's CLI to use a different tslint.json file for the test linting, but that's probably something that cannot be changed without ejecting. If tests could be linted using their own tslint.json - like the e2e tests - this would be easy to solve, but they cannot be, as they are in the same directory as the application files (so creating a local, relative tslint.json won't work).

On the plus side, the good news is that this sort of annoyance will be a thing of the past with the lettable/pipeable operators in RxJS 5.5.

@balassy
Copy link
Author

balassy commented Oct 21, 2017

Thanks for your reply, Nicholas.

@kamok
Copy link

kamok commented Dec 19, 2017

@balassy Any stuff in tsconfig? I had a few unused variable rules in there which threw that error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants