Giter Site home page Giter Site logo

rxjs-tslint's Introduction

RxJS TSLint

TSLint rules for rxjs.

Rules

This repository provides the following rules:

Rule name Configuration Description
rxjs-collapse-imports none Collapses multiple imports from rxjs to a single one
rxjs-pipeable-operators-only none Migrates side-effect operators to pipeables
rxjs-no-static-observable-methods none Migrates static Observable method calls
rxjs-proper-imports none Updates RxJS 5.x.x imports to RxJS 6.0

Migration to RxJS 6

Using the current set of rules allows you to automatically migrate your project which uses RxJS 5 to RxJS 6. Here's how you can perform the automatic migration:

npm i -g rxjs-tslint
rxjs-5-to-6-migrate -p [PATH_TO_TSCONFIG]

For an Angular CLI project the invocation of rxjs-5-to-6-migrate will be:

rxjs-5-to-6-migrate -p src/tsconfig.app.json

Note: The rules use type checking to find all the instances of operators that need to be migrated to pipeables. This requires you to have rxjs@5 installed so that tslint could find the correct type definitions.

If you're following the migration instructions from https://update.angular.io, between versions 5 and 6 you'll have to run ng update @angular/core. This step will install rxjs-compat, which will let rxjs-5-to-6-migrate to perform the correct code transformations.

Use rules

To use the exported rules without rxjs-5-to-6-migrate, use the rulesDirectory configuration property of tslint.json:

{
  "rulesDirectory": [
    "node_modules/rxjs-tslint"
  ],
  "rules": {
    "rxjs-collapse-imports": true,
    "rxjs-pipeable-operators-only": true,
    "rxjs-no-static-observable-methods": true,
    "rxjs-proper-imports": true
  }
}

To lint your project use:

./node_modules/.bin/tslint -c tslint.json -p tsconfig.json

Notes

  • Once you run all the migrations check the diff and make sure that everything looks as expected. These fixers cover almost all cases we know of, but it's possible that some manual fixes can be required.
  • Although the migration will format your source code, it's likely that that the style is not consistent with the rest of your project. To make sure that everything is properly following your project's style guide, we recommend you apply a formatter such as prettier or clang-format after the edits are made.

License

MIT

rxjs-tslint's People

Contributors

alexeagle avatar benlesh avatar bowenni avatar cedricss avatar dependabot[bot] avatar jamesjansson avatar jdforsythe avatar lance-cfa avatar mgechev avatar nagrock avatar shairez avatar timdeschryver avatar wkoza avatar ziyaddin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxjs-tslint's Issues

PipeableOperatorsOnlyRule.js fails silently when RXJS 6 is installed

As recommended by the angular update guide, I updated to rxjs 6 before running rxjs-5-to-6-migrate.

rxjs-5-to-6-migrate ran without errors, and correctly fixed the imports, but left patched operator calls unchanged.

Looking at the implementation of the PipeableOperatorsOnlyRule.js, I noticed that is uses the typeChecker to identity instance operator calls. Suspecting that the type checker needs the source code to compile, and therefore the old rxjs in node_modules, I ran

npm install rxjs@^5.0.0
rxjs-5-to-6-migrate -p src/tsconfig.app.json

and the patched operator calls were rewritten correctly.

Please consider emitting an error message if the wrong rxjs version is installed - if I hadn't seen rxjs-5-to-6-migrate rewrite patched operator calls in another project, I would have assumed it incapable of doing so, and missed out on a great feature.

javascript migration guide

Hi,
I am trying to use this package to migrate rxjs 5 code written in javascript. I am thrown various errors, and in the end after fixing those dependency bugs i got:
Running the automatic migrations. Please, be patient and wait until the execution completes.
Cannot find any possible migrations

I want to know whether there is some guide to help migrate javascript rxjs code, or is this even possible with this package? As typescript is superset of js, I guess it might be possible to do so but lack of any clear guide makes the process quite unreliable. I have to migrate 2k-3k lines of nodejs based rxjs code, and would surely not love to mess anything working. Although, I can use rxjs-compat to keep legacy code, but moving forward it would be just another contextual penalty for programmer working on that codebase.

Error when running tslint directly

I am getting errors when running tslint.

This is the error on rxjsNoStaticObservableMethodsRule.js:

TypeError: Cannot read property 'kind' of undefined
    at Object.isPropertyAccessExpression (C:\p\rabiscos\ngtemp2\Template2\node_modules\tsutils\typeguard\node.js:542:17)
    at isRxjsStaticOperatorCallExpression (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsNoStaticObservableMethodsRule.js:88:18)
    at checkPatchableOperatorUsage (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsNoStaticObservableMethodsRule.js:34:18)
    at visitNodes (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14006:30)
    at Object.forEachChild (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14173:21)
    at checkPatchableOperatorUsage (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsNoStaticObservableMethodsRule.js:35:27)
    at visitNode (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:13997:24)
    at Object.forEachChild (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14229:24)
    at checkPatchableOperatorUsage (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsNoStaticObservableMethodsRule.js:35:27)
    at visitNodes (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14006:30)

This is from rxjsPipeableOperatorsOnlyRule.js:

TypeError: Cannot read property 'kind' of undefined
    at Object.isPropertyAccessExpression (C:\p\rabiscos\ngtemp2\Template2\node_modules\tsutils\typeguard\node.js:542:17)
    at isRxjsInstanceOperatorCallExpression (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsPipeableOperatorsOnlyRule.js:96:18)
    at checkPatchableOperatorUsage (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsPipeableOperatorsOnlyRule.js:33:18)
    at visitNodes (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14006:30)
    at Object.forEachChild (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14173:21)
    at checkPatchableOperatorUsage (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsPipeableOperatorsOnlyRule.js:34:27)
    at visitNode (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:13997:24)
    at Object.forEachChild (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14229:24)
    at checkPatchableOperatorUsage (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\rxjsPipeableOperatorsOnlyRule.js:34:27)
    at visitNodes (C:\p\rabiscos\ngtemp2\Template2\node_modules\rxjs-tslint\node_modules\typescript\lib\typescript.js:14006:30)

The errors actually happen several times.

It seems that the error is on this call:

if (!tsutils.isPropertyAccessExpression(node.expression)) {

Which is here:

if (!tsutils.isPropertyAccessExpression(node.expression)) {

I am on version 0.1.2.

If you need more information please let me know.

Cannot find tslint (when it's already installed?)

Error: Command failed: /my/project/path/node_modules/rxjs-tslint/node_modules/.bin/tslint -c /my/project/path/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.json -p tsconfig.json --fix
/bin/sh: /my/project/path/node_modules/rxjs-tslint/node_modules/.bin/tslint: No such file or directory

my copy of tslint currently at /my/project/path/node_modules/.bin/tslint

Existing let operator is not combined into the pipe operator

rxjs-tslint version 0.0.0

BEFORE

this.actions$
    .withLatestFrom(this.store$.select(getOrdersState))
    .let(effects.loadAllDataActionEffect);

AFTER

this.actions$
    .pipe(withLatestFrom(this.store$.select(getOrdersState)))
    .let(effects.loadAllDataActionEffect);

I would have expected that the let operator be merged with the pipe operator.

EXPECTED:

this.actions$
    .pipe(
      withLatestFrom(this.store$.select(getOrdersState)),
      effects.loadAllDataActionEffect);

How to use the rules in Webstorm

Hello, I'm using "tslint": "5.11.0" and "rxjs-tslint": "0.1.5",

And I'd like to show as errors in webstorm the rules.

{
  "rulesDirectory": [
    "node_modules/rxjs-tslint"
  ],
  "rules": {
    "rxjs-collapse-imports": true,
    "rxjs-pipeable-operators-only": true,
    "rxjs-no-static-observable-methods": true,
    "rxjs-proper-imports": true
  }
}

I added that rules to my tslint.json but nothing happens, am I doing something wrong?

Thanks

Errors when linting Angular 5 project.

When I added rxjs-tslint@^0.1.1 to my Angular 5 project I started getting strange errors. Both VSC and IDEA reported things such as name collisions on import statements. Manually running ng lint resulted in a series of type errors, such as the following, that ultimately lead to JS running out of heap memory.

TypeError: Cannot read property 'kind' of undefined
    at isLabelable (/app/node_modules/tslint/lib/rules/labelPositionRule.js:57:18)
    at cb (/app/node_modules/tslint/lib/rules/labelPositionRule.js:50:52)
    at visitNodes (/app/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/app/node_modules/typescript/lib/typescript.js:12884:24)
    at cb (/app/node_modules/tslint/lib/rules/labelPositionRule.js:53:19)
    at visitNode (/app/node_modules/typescript/lib/typescript.js:12690:24)
    at Object.forEachChild (/app/node_modules/typescript/lib/typescript.js:12882:21)
    at cb (/app/node_modules/tslint/lib/rules/labelPositionRule.js:53:19)
    at visitNodes (/app/node_modules/typescript/lib/typescript.js:12699:30)
    at Object.forEachChild (/app/node_modules/typescript/lib/typescript.js:12875:24)

I think it has to do with rxjs-tslint depending on "typescript": "~2.8.1" and Angular 5 depending on "typescript": "2.6.x". Folks who encountered this error in other situations ended up altering the version of Typescript they used.

The only solution I could come up with was to remove my dependency on rxjs-tslint. Am I missing an alternative?

Error "Could not find implementations of custom rules"

Hi team,

the idea for the package is great! I cannot get it to work though following the steps in the migration guide though.

After installing rxjs-tslint, adding the file migrate-rxjs.tslint.json and running the command ./node_modules/.bin/tslint -c migrate-rxjs.tslint.json --project src/tsconfig.app.json --fix I get the following error:

`Could not find implementations for the following rules specified in the configuration:
update-rxjs-imports
migrate-to-pipeable-operators
migrate-static-observable-methods
collapse-rxjs-imports
Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.
If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.

No valid rules have been specified`

Am I doing something wrong or is this a bug within the package? I tried uninstalling TSLint, delete the global rules file and re-install it. But to no avail. I even tried removing all rules from that TSLint file to test if any of them is corrupted.

There is a folder at node_modules/rxjs-tslint. It looks like this:
image

[email protected]
[email protected]

Code is not migrated correctly

There is a code

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';

Observable.of(1, 2, 3).map(i => i.toString());

Running of rxjs-tslint rules shows correct errors:

  • outdated import path
  • prefer operator imports with no side-effects
  • prefer pipeable operators

Then run with --fix and this produce invalid code:

import { Observable } from 'rxjs';



Observable.of(1, 2, 3).map(i => i.toString());

Is it expected behaviour or I have to adjust my original code somehow in order to achieve (after --fix) something like

import { of } from 'rxjs';
import { map } from 'rxjs/operators';

of(1, 2, 3).pipe(map(i => i.toString()));

rxjs-5-to-6-migrate - cannot find any possible migration

rxjs-5-to-6-migrate -p src/tsconfig.json throws me below exception

Running the automatic migrations. Please, be patient and wait until the execution completes.
module.js:549
throw err;
^

Error: Cannot find module 'typescript'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (C:\Users\josephjs.NCS\AppData\Roaming\npm\node_modules\rxjs-tslint\node_modules\tslint\lib\linter.js:22:10)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
child_process.js:644

rxjs-tslint breaks tslint

When I install rxjs-tslint with yarn every thing works fine. But when I remove node_modules and use again yarn to install all dependencies I get many errors like this one:

TypeError: Cannot read property 'length' of undefined
    at cb (C:\workspaces\angular-components\node_modules\tslint\lib\rules\noDuplicateVariableRule.js:79:66)
    at visitNodes (C:\workspaces\angular-components\node_modules\typescript\lib\typescript.js:13272:30)
    at Object.forEachChild (C:\workspaces\angular-components\node_modules\typescript\lib\typescript.js:13479:24)
    at NoDuplicateVariableWalker.walk (C:\workspaces\angular-components\node_modules\tslint\lib\rules\noDuplicateVariableRule.js:86:19)
    at Rule.AbstractRule.applyWithWalker (C:\workspaces\angular-components\node_modules\tslint\lib\language\rule\abstractRule.js:31:16)
    at Rule.apply (C:\workspaces\angular-components\node_modules\tslint\lib\rules\noDuplicateVariableRule.js:34:21)
    at Linter.applyRule (C:\workspaces\angular-components\node_modules\tslint\lib\linter.js:197:29)
    at C:\workspaces\angular-components\node_modules\tslint\lib\linter.js:139:85
    at Object.flatMap (C:\workspaces\angular-components\node_modules\tslint\lib\utils.js:151:29)
    at Linter.getAllFailures (C:\workspaces\angular-components\node_modules\tslint\lib\linter.js:139:32)

I don't need to add any rule to tslint.json, just add rxjs-tslint as dependency and install all dependencies depending on yarn.lock file.

Don't know if this is related to: palantir/tslint#3711 (comment)

rxjs-5-to-6-migrate doesn't seem to handle operator chaining.

I'm having issues with migrating and still have some type errors that the migrate tool didn't fix. It seems to be related to operator chaining.

BEFORE:

return this.api.request(config).map(res => {
  this.translations = JSON.parse(res.translations);
  return res;
}).share();

AFTER:

return this.api.request(config).pipe(
  map(res => {
    this.translations = JSON.parse(res.translations);
    return res;
  }))
  .share();

EXPECTED:

return this.api.request(config).pipe(
  map(res => {
    this.translations = JSON.parse(res.translations);
    return res;
  }), share());

If I understand correctly the share() in this case should be within the pipe call after map separated by a comma (as shown above). Let me know if I'm mistaken!

Here are the some of the remaining rxjs related type errors I'm getting after the migrate:

error TS2339: Property 'takeUntil' does not exist on type 'Observable<any>'.
error TS2339: Property 'debounceTime' does not exist on type 'EventEmitter<any>'.
error TS2339: Property 'first' does not exist on type 'EventEmitter<any>'.
error TS2339: Property 'share' does not exist on type 'Observable<any>'.
error TS2339: Property 'forkJoin' does not exist on type 'typeof Observable'.
error TS2339: Property 'from' does not exist on type 'typeof Observable'.
error TS2339: Property 'flatMap' does not exist on type 'Observable<any>'.
error TS2339: Property 'forkJoin' does not exist on type 'typeof Observable'.
error TS2339: Property 'from' does not exist on type 'typeof Observable'.

Utility functions and error types not imported straight from "rxjs"

These imports are not migrated to pure 6.0 (without rxjs-compat):

import { pipe } from "rxjs/util/pipe";
import { identity } from "rxjs/util/identity";
import { ArgumentOutOfRangeError } from "rxjs/util/ArgumentOutOfRangeError";
import { EmptyError } from "rxjs/util/EmptyError";

This what I expected after a migration:

import { pipe, identity, ArgumentOutOfRangeError, EmptyError } from "rxjs";

The PR #9 fix this issue.

PS. that's probably the same for other types (subjects, schedulers...).

Creation imports need cleaned up

Example

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rxjs/add/observable/interval';
import { fromEvent } from 'rxjs/observable/fromEvent';

const a$ = Observable.from([1, 2, 3]);
const b$ = Observable.interval(1000);
const c$ = fromEvent(button, 'click');

Should be:

import { from, interval, fromEvent } from 'rxjs';

const a$ = from([1, 2, 3]);
const b$ = interval(1000);
const c$ = fromEvent(button, 'click');

Error after running npm install -g rxjs-tslint

After updating from angular 5.2 to angular 6 I'm trying to run npm install -g rxjs-tslint but I keep getting following warning:
npm WARN [email protected] requires a peer of tslint@^5.0.0 but none is installed. You must install peer dependencies yourself.

Even though I have "tslint": "^5.0.0" installed.

I can't run rxjs-5-to-6-migrate -p src/tsconfig.app.json

Anyone can help with this?

"dependencies": {
agm/core: "^1.0.0-beta.3",
angular/animations: "^6.0.3",
angular/common: "^6.0.3",
angular/compiler: "^6.0.3",
angular/core: "^6.0.3",
angular/forms: "^6.0.3",
angular/platform-browser: "^6.0.3",
angular/platform-browser-dynamic: "^6.0.3",
angular/platform-server: "^6.0.3",
angular/router: "^6.0.3"
}
angular/cli: "^6.0.7",
Node : v8.11.2
Win 7

Cannot read property 'getText' of undefined

Hi team! I had got some errors in rxjs-tslint when I added "rxjs-pipeable-operators-only" and "rxjs-no-static-observable-methods" rules in my project

image

tslint.json

{
  "extends": "tslint:recommended",
  "rulesDirectory": [
    "node_modules/rxjs-tslint"
  ],
  "rules": {
    "no-consecutive-blank-lines": [
      true,
      2
    ],
    "ordered-imports": false,
    "typedef-whitespace": {
      "options": [
        {
          "call-signature": "nospace",
          "index-signature": "nospace",
          "parameter": "nospace",
          "property-declaration": "nospace",
          "variable-declaration": "nospace"
        },
        {
          "call-signature": "nospace",
          "index-signature": "nospace",
          "parameter": "nospace",
          "property-declaration": "nospace",
          "variable-declaration": "nospace"
        }
      ]
    },
    "whitespace": {
      "options": [
        "check-branch",
        "check-decl",
        "check-operator",
        "check-separator",
        "check-typecast"
      ]
    },
    "max-classes-per-file": false,
    "trailing-comma": {
      "options": {
        "singleline": "never"
      }
    },
    "variable-name": {
      "options": [
        "ban-keywords",
        "allow-snake-case"
      ]
    },
    "member-ordering": false,
    "max-line-length": false,
    "object-literal-sort-keys": false,
    "only-arrow-functions": false,
    "space-before-function-paren": {
      "options": {
        "anonymous": "always",
        "asyncArrow": "always",
        "constructor": "never",
        "method": "never",
        "named": "never"
      }
    },
    "rxjs-collapse-imports": true,
    "rxjs-pipeable-operators-only": true,
    "rxjs-no-static-observable-methods": true,
    "rxjs-proper-imports": false
  }
}

Because of what might be the problem?

How do I use this project?

I am on a just created Angular 6 RC project. I added rxjs-lint, but tsline complains.

Here is my src/tslint.json:

{
  "extends": [
    "../tslint.json",
    "rxjs-tslint"
  ],
  "rules": {
    "rxjs-collapse-imports": true,
    "rxjs-pipeable-operators-only": true,
    "rxjs-no-static-observable-methods": true,
    "rxjs-proper-imports": true,
    "directive-selector": [true, "attribute", "app", "camelCase"],
    "component-selector": [true, "element", "app", "kebab-case"]
  }
}

I get this error when I run tslint --project .\tsconfig.app.json from the src directory:

Could not find implementations for the following rules specified in the configuration:
    rxjs-collapse-imports
    rxjs-pipeable-operators-only
    rxjs-no-static-observable-methods
    rxjs-proper-imports
Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.
If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.

I tried adding, as per your tests to a .ts file:

import { foo } from 'rxjs';
import { bar } from 'rxjs';

But got no warnings.

I am using tslint 5.9.1.

Unable to install other modules after installing this

Cannot install modules after install this package,
Have to uninstall first

error An unexpected error occurred: "could not find a copy of typescript to link in ...\\node_modules\\rxjs-tslint\\node_modules".

Typescript: 3.1.6
Rxjs-Tslint: 0.1.6

Error when running rxjs-5-to-6-migrate

Installed rxjs-tslint globally, attempting to upgrade my Angular application from version 5 to 6.

I'm using the command

rxjs-5-to-6-migrate -p src/tsconfig.app.json

But it results in this error

Running the automatic migrations. Please, be patient and wait until the execution completes.
child_process.js:644
    throw err;
    ^

Error: Command failed: /usr/lib/node_modules/rxjs-tslint/node_modules/.bin/tslint -c /usr/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.json -p src/tsconfig.app.json --fix
    at checkExecSyncError (child_process.js:601:13)
    at Object.execSync (child_process.js:641:13)
    at migrate (/usr/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.js:18:34)
    at Object.<anonymous> (/usr/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.js:25:14)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)

There are no spaces in the path to any of the files.
I have tried specifying the full path to tsconfig.app.json, same result.

Linux Kubuntu 18.04
Node 8.11.1
NPM 6.0.0
Installed packages:

/usr/lib
├── @angular/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Whats the correct?

I'm trying to use the rxjs-5-to-6-migrate command, but it looks strange!

This two imports:

import {ReplaySubject} from 'rxjs/ReplaySubject';
import {Observable} from 'rxjs/Observable';

are linted to

import {ReplaySubject, Observable} from 'rxjs';

then it shows:

WARNING: /path/to/file.ts[6, 1]: duplicate RxJS import

to the same line that it linted.

If I run ng tslint it say's that this import path is black-listed (the linted one)

Error installing rxjs-tslint

Error while installing into a newly updated Angular app:

-> % npm i -g rxjs-tslint
events.js:167░░░░░░⸩ ⠏ extract:sprintf-js: sill extract [email protected]
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:243:12)
    at PassThrough.Writable.write (_stream_writable.js:292:5)
    at PassThrough.Writable.end (_stream_writable.js:592:10)
    at ReadEntry.entry.on (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/extract-stream.js:19:41)
    at ReadEntry.emit (events.js:187:15)
    at ReadEntry.emit (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:296:25)
    at ReadEntry.[maybeEmitEnd] (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:249:12)
    at ReadEntry.end (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:162:27)
    at Unpack.[consumeBody] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:210:13)
    at Unpack.[consumeChunkSub] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:391:40)
    at Unpack.[consumeChunk] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:362:30)
    at Unzip.(anonymous function).on.chunk (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:291:59)
    at Unzip.emit (events.js:182:13)
    at Unzip.emit (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:296:25)
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:99:17)
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib/index.js:284:29)
Emitted 'error' event at:
    at writeAfterEnd (_stream_writable.js:245:10)
    at PassThrough.Writable.write (_stream_writable.js:292:5)
    [... lines matching original stack trace ...]
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib/index.js:284:29)
events.js:167░░░░░░⸩ ⠏ extract:typescript: sill extract [email protected]
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at writeAfterEnd (_stream_writable.js:243:12)
    at PassThrough.Writable.write (_stream_writable.js:292:5)
    at PassThrough.Writable.end (_stream_writable.js:592:10)
    at ReadEntry.entry.on (/usr/local/lib/node_modules/npm/node_modules/pacote/lib/extract-stream.js:19:41)
    at ReadEntry.emit (events.js:187:15)
    at ReadEntry.emit (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:296:25)
    at ReadEntry.[maybeEmitEnd] (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:249:12)
    at ReadEntry.end (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:162:27)
    at Unpack.[consumeBody] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:210:13)
    at Unpack.[consumeChunkSub] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:391:40)
    at Unpack.[consumeChunk] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:362:30)
    at Unzip.(anonymous function).on.chunk (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:291:59)
    at Unzip.emit (events.js:182:13)
    at Unzip.emit (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:296:25)
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minipass/index.js:99:17)
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib/index.js:284:29)
Emitted 'error' event at:
    at writeAfterEnd (_stream_writable.js:245:10)
    at PassThrough.Writable.write (_stream_writable.js:292:5)
    [... lines matching original stack trace ...]
    at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/tar/node_modules/minizlib/index.js:284:29)
npm WARN [email protected] requires a peer of tslint@^5.0.0 but none is installed. You must install peer dependencies yourself.

npm ERR! cancel after 1 retries!

RxJS version:
6.1.0

Node/NPM
Node v10.0.0
NPM v6.0.0

Code to reproduce:
Type: npm i -g rxjs-tslint

Expected behavior:
Package is installed

Actual behavior:
Error above.

Additional information:

Error: Cannot find module 'typescript'

Following angular 5 - 6 upgrade guide, I cannot run:

rxjs-5-to-6-migrate -p src/tsconfig.app.json as it throws error:

Running the automatic migrations. Please, be patient and wait until the execution completes.
module.js:538
    throw err;
    ^

Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/i304804/.nvm/versions/node/v8.9.1/lib/node_modules/rxjs-tslint/node_modules/tslint/lib/linter.js:22:10)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
child_process.js:644

Error: Command failed: "/Users/i304804/.nvm/versions/node/v8.9.1/lib/node_modules/rxjs-tslint/node_modules/.bin/tslint" -c "/Users/i304804/.nvm/versions/node/v8.9.1/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.json" -p "src/tsconfig.app.json" --fix
module.js:538
    throw err;
    ^

My env:

Angular CLI: 6.0.8
Node: 8.9.1
OS: darwin x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

The ng build runs fine.

rxjs-tslint doesn't work in vscode

After I added the rxjs-tslint to tslint.json:

Using tslint 5.9.1, vsCode 1.23.1 x64 Windows
"rulesDirectory": [
"node_modules/codelyzer",
"node_modules/rxjs-tslint"
],

I saw the following issue:
[Info - 9:55:32 AM] Linter is running.
[Info - 9:55:35 AM] TSLint library loaded from: c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\index.js
TypeError: Cannot read property 'length' of undefined
at cb (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\callableTypesRule.js:52:28)
at visitNode (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13263:24)
at Object.forEachChild (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13335:21)
at cb (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\callableTypesRule.js:64:19)
at visitNodes (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13272:30)
at Object.forEachChild (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13559:21)
at cb (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\callableTypesRule.js:64:19)
at visitNodes (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13272:30)
at Object.forEachChild (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13479:24)
at walk (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\callableTypesRule.js:50:15)
Warning: The 'deprecation' rule requires type information.
TypeError: Cannot read property 'kind' of undefined
at Object.isBlock (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tsutils\typeguard\node.js:52:16)
at cb (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\forinRule.js:49:59)
at visitNodes (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13272:30)
at Object.forEachChild (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13477:24)
at cb (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\forinRule.js:52:19)
at visitNode (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13263:24)
at Object.forEachChild (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13384:21)
at cb (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\tslint\lib\rules\forinRule.js:52:19)
at visitNodes (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13272:30)
at Object.forEachChild (c:\Work\Git\convert-phonecat\angular-phonecat-hybrid\node_modules\typescript\lib\typescript.js:13552:21)
FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
[Info - 9:55:47 AM] Connection to server got closed. Server will restart.
[Info - 9:55:47 AM] Linter has stopped.

Btw, I installed this rxjs-tslint locally into my project package.json

Bug report - optimist, minimist dependency security vulnerability high

┌───────────────┬──────────────────────────────────────────────────────────────┐ │ High │ minimist before 1.2.2 could be tricked into adding or │ │ │ modifying properties of Object.prototype using a │ │ │ "constructor" or "__proto__" payload. │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Package │ minimist │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Patched in │ 0.2.1||1.2.2 │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Dependency of │ rxjs-tslint [dev] │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ Path │ rxjs-tslint > optimist > minimist │ ├───────────────┼──────────────────────────────────────────────────────────────┤ │ More info │ http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2020-75… │ └───────────────┴──────────────────────────────────────────────────────────────┘

optimist depends on minimist, which has this security issue. optimist is no longer maintained and owner wont patch.
Suggest replacing optimist with yargs.
Solution provided here.

material.angular.io fails to upgrade

When I run this on material.angular.io site (https://github.com/angular/material.angular.io), it gives the following error:

./node_modules/.bin/tslint -c migrate-rxjs.tslint.json --project src/tsconfig.json --fix
Warning: The 'migrate-to-pipeable-operators' rule requires type checking
/Users/austin/dev/material.angular.io/node_modules/tslint/lib/runner.js:118
            throw error;
            ^

TypeError: Cannot read property 'apply' of undefined
    at /Users/austin/dev/material.angular.io/node_modules/tslint/lib/language/rule/rule.js:28:66
    at Array.reduce (<anonymous>)
    at Function.Replacement.applyAll (/Users/austin/dev/material.angular.io/node_modules/tslint/lib/language/rule/rule.js:28:29)
    at Function.Fix.applyAll (/Users/austin/dev/material.angular.io/node_modules/tslint/lib/language/rule/rule.js:88:28)
    at Linter.lint (/Users/austin/dev/material.angular.io/node_modules/tslint/lib/linter.js:92:41)
    at Runner.processFiles (/Users/austin/dev/material.angular.io/node_modules/tslint/lib/runner.js:161:20)
    at Runner.run (/Users/austin/dev/material.angular.io/node_modules/tslint/lib/runner.js:110:18)
    at Object.<anonymous> (/Users/austin/dev/material.angular.io/node_modules/tslint/lib/tslint-cli.js:139:6)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)

rxjs-5-to-6-migrate

I have typescript installed as a module using npm but why it cannot still find the module.

Running the automatic migrations. Please, be patient and wait until the execution completes.
internal/modules/cjs/loader.js:596
throw err;
^

Error: Cannot find module 'typescript'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (C:\Users\GuptaV\AppData\Roaming\npm\node_modules\rxjs-tslint\node_modules\tslint\lib\linter.js:22:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
child_process.js:643
throw err;
^

Error: Command failed: "C:\Users\GuptaV\AppData\Roaming\npm\node_modules\rxjs-tslint\node_modules.bin\tslint" -c "C:\Users\GuptaV\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.json" -p "src/tsconfig.app.json" --fix
internal/modules/cjs/loader.js:596
throw err;
^

Error: Cannot find module 'typescript'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (C:\Users\GuptaV\AppData\Roaming\npm\node_modules\rxjs-tslint\node_modules\tslint\lib\linter.js:22:10)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)

at checkExecSyncError (child_process.js:603:11)
at Object.execSync (child_process.js:640:13)
at migrate (C:\Users\GuptaV\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.js:18:34)
at Object.<anonymous> (C:\Users\GuptaV\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.js:25:14)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
at Module.require (internal/modules/cjs/loader.js:650:17)

Please release a fix for this issue

Imports don't get imported in one statement

First of all, props for making this! 👌

I ran the rules and I think found an error.

Before:

import { Component, Injectable, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';
import { debounceTime, distinctUntilChanged, map, catchError, switchMap } from 'rxjs/operators';
import { empty } from 'rxjs/observable/empty';

After:

import { Component, Injectable, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Subject } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, catchError, switchMap } from 'rxjs/operators';
import { EMPTY as empty } from 'rxjs';

Expected:

import { Component, Injectable, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, Subject, EMPTY as empty  } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, catchError, switchMap } from 'rxjs/operators';

Running rxjs-5-to-6-migrate -p src/tsconfig.app.json fails

Hi,
i've been trying to update to angular 6, but i'm failing while trying to run the rxjs migration. Actually on my Windows computer, the folder name of my user is "Blair Jersyer" with a space. When i'm running the code i get an error like so :

"C:\Users\Blair" is not a valid command

I assume it's because there is a space on that folder. After having console.logged the command on C:\Users\Blair Jersyer\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.js:18 here is the resulting command :

C:\Users\Blair Jersyer\AppData\Roaming\npm\node_modules\rxjs-tslint\node_modules\.bin\tslint -c C:\Users\Blair Jersyer\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.json -p src/tsconfig.app.json --fix

Still wondering if the space within my username (Blair Jersyer) is the cause of this issue.

Regards.

Out of memory

I have a large app I am trying to migrate from Angular 5 to 6 and then to 7. When I try to run rxjs-5-to-6-migrate -p src/tsconfig.app.json I get FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory. I tried running it with node --max-old-space-size=8192 C:\Users\myName\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.js -p src/tsconfig.app.json and I still get the same error. It seems to "run out of memory" in a matter of seconds, so I suspect there is something else going on. Any help would be appreciated. Thanks!

Package.json

  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "@clr/angular": "^0.11.8",
    "@clr/icons": "^0.11.8",
    "@clr/ui": "^0.11.8",
    "@ng-bootstrap/ng-bootstrap": "1.0.1",
    "@ngrx/store": "^5.2.0",
    "@progress/kendo-angular-buttons": "3.0.4",
    "@progress/kendo-angular-charts": "2.0.3",
    "@progress/kendo-angular-dateinputs": "2.2.0",
    "@progress/kendo-angular-dialog": "3.2.0",
    "@progress/kendo-angular-dropdowns": "2.1.0",
    "@progress/kendo-angular-excel-export": "1.0.7",
    "@progress/kendo-angular-grid": "2.1.2",
    "@progress/kendo-angular-inputs": "2.2.0",
    "@progress/kendo-angular-intl": "1.3.2",
    "@progress/kendo-angular-l10n": "1.0.7",
    "@progress/kendo-angular-layout": "2.1.1",
    "@progress/kendo-angular-popup": "2.0.2",
    "@progress/kendo-angular-resize-sensor": "3.0.2",
    "@progress/kendo-angular-sortable": "1.0.8",
    "@progress/kendo-angular-treeview": "2.1.3",
    "@progress/kendo-angular-upload": "3.0.3",
    "@progress/kendo-data-query": "1.2.0",
    "@progress/kendo-drawing": "1.5.1",
    "@progress/kendo-theme-default": "2.48.1",
    "@telerik/kendo-intl": "1.4.0",
    "@webcomponents/custom-elements": "^1.0.8",
    "angular2-hotkeys": "^2.1.2",
    "bootstrap": "3.3.7",
    "classlist.js": "1.1.20150312",
    "core-js": "^2.5.4",
    "font-awesome": "4.7.0",
    "hammerjs": "2.0.8",
    "jquery": "3.3.1",
    "linq": "3.0.9",
    "moment": "^2.22.2",
    "primeng": "^7.0.0-beta.1",
    "rxjs": "~6.3.3",
    "ts-helpers": "1.1.2",
    "tslib": "^1.9.0",
    "tui-editor": "^1.3.0",
    "web-animations-js": "^2.3.1",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.4",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@compodoc/compodoc": "^1.1.9",
    "@types/bootstrap": "^3.3.38",
    "@types/jest": "^23.3.1",
    "@types/jquery": "^3.3.0",
    "@types/kendo-ui": "^2018.1.1",
    "@types/node": "~8.9.4",
    "babel-core": "^6.26.3",
    "codelyzer": "~4.5.0",
    "htmlhint": "^0.11.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "jest": "^23.5.0",
    "jest-coverage-badges": "^1.1.2",
    "jest-preset-angular": "^6.0.2",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "rxjs-tslint": "~0.1.7",
    "ts-helpers": "1.1.2",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typemoq": "^2.1.0",
    "typescript": "~3.2.2"
  }
}

fix mix

For unknown reasons one file in my code contains this code (certainly months ago when update to pipeable manually I omit this ... it compile = i forget)

import "rxjs/add/operator/distinctUntilChanged";
...
this.form.get('iban').valueChanges.pipe(takeUntil(<Observable<any>> this.ngUnsubscribe))
      .distinctUntilChanged()
      .subscribe(this.onChange_iban.bind(this));

When running tslint my migrate-rxjs.tslint.json nothing change ^^
Is it relevant to fix this kind of code too?

subscribe is deprecated: Use an observer instead of a complete callback (deprecation)

Hi, I just upgraded my vscode to the latest (1.54.1) and suddenly all our subcscribe() methods to observables are marked as warnings by tslint with this message:

subscribe is deprecated: Use an observer instead of a complete callback (deprecation)

Searching online I found that the new syntax for subscribe() has been around for almost 2 years now 😮 and this is the first time I see it 🤦🏼

This is an Angular 11 project, we migrated over the years "by the book" from Angular 6, so why was this not taken care earlier by the migration scripts? And can rxjs-tslint do this migration automatically?

rename fromPromise to from

I had "fromPromise" in my code which is correctly fixed by rxjs-tslint
from : import {fromPromise} from 'rxjs/observable/fromPromise'
to : import {fromPromise} from 'rxjs';

Problem is this is not available and renamed to from

Can we here be more smarter and rename it by the way ? :)

Messy imports with rxjs-5-to-6-migrate

Issues

  • It appends a new line at the start of most imports/files
  • It adds a new line in between
  • It moves rxjs imports to the top
  • It does not add spaces between the brackets

Examples:


import {of as observableOf} from 'rxjs';

import {take} from 'rxjs/operators/take';
import { Injectable } from '@angular/core';
...

import {fromEvent as observableFromEvent} from 'rxjs';

import {map} from 'rxjs/operators/map';

import {takeUntil} from 'rxjs/operators/takeUntil';
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { Observable } from 'rxjs';

import { UploadFile } from '@core/models';
...

The one about the spaces might be a bit opinionated, but it would be nice to be able to configure, because this is a lot of manual labour to fix, unless someone has a clever script or plugin for webstorm to fix that :)

But the new line thing should definitely not happen.

Change rule names

The current rule names hint at them only being useful as migration tools. They're actually useful for normal linting as well. I think we should rename them to reflect their lint purpose, rather than their migration use.

  1. Prefix them with rxjs-
  2. Change the names slightly to reflect their usage as linting rules.
name configuration description
rxjs-collapse-imports none Collapses multiple imports from rxjs to a single one.
rxjs-pipeable-operators-only none Migrates side-effect operators to pipeables.
rxjs-no-static-observable-methods none Migrates static Observable method calls
rxjs-proper-imports none Updates RxJS 5.x.x imports to RxJS 6.0

Error: Cannot find module 'typescript'

While running this command: rxjs-5-to-6-migrate -p src/tsconfig.app.json I get the following error:

Running the automatic migrations. Please, be patient and wait until the execution completes.
module.js:549
    throw err;
    ^

Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/rxjs-tslint/node_modules/tslint/lib/linter.js:22:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
child_process.js:644
    throw err;
    ^

Error: Command failed: "/usr/local/lib/node_modules/rxjs-tslint/node_modules/.bin/tslint" -c "/usr/local/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.json" -p "src/tsconfig.app.json" --fix
module.js:549
    throw err;
    ^

Error: Cannot find module 'typescript'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/rxjs-tslint/node_modules/tslint/lib/linter.js:22:10)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

    at checkExecSyncError (child_process.js:601:13)
    at Object.execSync (child_process.js:641:13)
    at migrate (/usr/local/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.js:18:34)
    at Object.<anonymous> (/usr/local/lib/node_modules/rxjs-tslint/rxjs-5-to-6-migrate.js:25:14)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)

I checked my package.json and I see I have typescript among my devDependencies, and I vlaidated it like this:

$ yarn list | grep typescript
│  ├─ typescript@~2.9.1
│  ├─ typescript@>=2.6.2 <2.8
│  └─ [email protected]
├─ [email protected]

I also tried installing typescript globally with yarn add global typescript.

What can be the reason for this error?

Migrating TsLint to EsLint

Will the migration affect the way this plugin works?

For the moment we create the rules in a tslint.json file. While migrating to ESlint this will disappear. Is it possible to add the rule to an eslint.json file and keep the plugin alive or will it require more work?

rxjs-pipeable-operators-only rule not producing any output

In particular, trying to enforce using pipeable operators.

Sample code

Sample code in the codebase:

this.accountService.loadAccount().subscribe(account => {
  this.account = account;
});

Expect output

I expect a warning/error about this not using pipeable operators

Actual output

> ng lint
All files pass linting.
✨  Done in 13.05s.

tslint.json

{
  "rulesDirectory": [
    "node_modules/codelyzer",
    "node_modules/rxjs-tslint"
  ],
  "rules": {
    "rxjs-pipeable-operators-only": true
  }
}

Versions

ng: 6.2.8
rxjs: 6.3.3
rxjs-tslint: 0.1.5

Specify path for rxjs-5-to-6-migrate

It would be really helpful if I could pass a path to rxjs-5-to-6-migrate in order to migrate in chunks, because our code base is too big to do at once.

So something like:

rxjs-5-to-6-migrate -P [path/to/some/route-module] -p [path/to/tsconfig.json]

I've tried modifying baseUrl in tsconfig.json, but it's ignored.

Extra comma being added after migration

Hi after running: rxjs-5-to-6-migrate -p ./tsconfig.json there seems to be a problem with some of my observable definitions as a comma (,) is being added at the end of the chain.

Please see some examples below:

BEFORE

 return this.httpService
      .patch(url, body)
      .do((response: any) => {
        // do stuff
      })
      .catch(e => this.isError409(e));

AFTER

    return this.httpService
      .patch(url, body).pipe(
      tap((response: any) => {
       // do stuff
      }),
      catchError(e => this.isError409(e)),);

As you can see at the catchError line a , was added.

Another example is here:

BEFORE

  click$ = Observable.defer(() => Observable.fromEvent(this.ele.nativeElement, 'click'))
    .takeUntil(this.destroy$)
    .publish();

AFTER

  click$ = observableDefer(() => observableFromEvent(this.ele.nativeElement, 'click')).pipe(
    takeUntil(this.destroy$),
    publish(),);

Is this expected?
Is there a CLI flag that i might have missed?

Thank you.

imports not added/changed

Since importing operators (and observables) in rjxs before 6 was prototype based, it was not needed to import them in each file, thus in our project we did all the

import "rxjs/add/operator/filter";

in our app.module.ts file and no imports in the rest of the application.
So now when we run the upgrade tooling, we don't get any of the new imports where they need to be since the upgrade only search and replaces old imports with new not taking into consideration that the imports may need to be in other files.

I would love it if there "change old import to new ones" added a new import for each operator and observable used in a specific file, even if it was not imported before in that file. That would save me (and I assume several more people have done this since there was no point in adding the same operator to the Observable prototype again and again) a lot of work. (In my case I have around 500 files to manually fix where I have used this pattern)

Add support for tslint 6.x

Currently the peer dependency of tslint: ^5.0.0 means you get this warning when using tslint 6.x

npm WARN [email protected] requires a peer of tslint@^5.0.0 but none is installed. You must install peer dependencies yourself.

Can support for 6.x be added?

observeOn operator not being migrated

I'm using observeOn and the async scheduler in a few places. But it gets migrated to something that still requires rxjs-compat. And for the life of me I can't find how this is supposed to be done in RxJS 6. The migration documentation is frankly horrific!

So basically the migration tool leaves me with

import { async } from 'rxjs/scheduler/async';

this.leftNavVisibleSubject.pipe(
            distinctUntilChanged(),
            observeOn(async));

This fails to compile as soon as I drop rxjs-compat and as said I've been pulling my hair trying to find how this is supposed to be migrated.

Error if path has spaces

If your project has a space in its path the call to execSync will fail because the unescaped space(s) causes the remainder of the command to be interpreted as command-line argument(s).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.