cartant / eslint-plugin-rxjs

ESLint rules for RxJS
MIT License
312 stars 37 forks source link

no-ignored-error error #94

Open osltest opened 2 years ago

osltest commented 2 years ago

According to the description the no-ignored-error rule should produce an error for both way to handle a subsciption. For this way it works as expected:

source.subscribe((value) => console.log(value));

But when using next like below no eslint error is given:

source.subscribe({
  next: (value) => console.log(value)
});

Simple code to reproduce:

const observable = interval(1000);
// shows eslint rxjs/no-ignored-error
const subscription1 = observable.subscribe(x => console.log(x));
// no rxjs/no-ignored-error message
const subscription2 = observable.subscribe({ next: x => console.log(x) });

My .eslintrc.js config:

{
    "env": {
        "es2021": true,
        "node": true
    },
    "extends": [
        "standard",
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking",
        "plugin:rxjs/recommended"
    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "project": [
            "tsconfig.json"
        ],
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "@typescript-eslint",
        "eslint-plugin-no-null",
        "eslint-plugin-unicorn",
        "simple-import-sort",
        "only-warn"
    ],
    "rules": {
        "@typescript-eslint/array-type": [
            "error",
            {
                "default": "generic"
            }
        ],
        "@typescript-eslint/await-thenable": "error",
        "@typescript-eslint/ban-ts-comment": "error",
        "@typescript-eslint/consistent-type-definitions": "error",
        "@typescript-eslint/dot-notation": "off",
        "@typescript-eslint/explicit-member-accessibility": [
            "off",
            {
                "accessibility": "explicit"
            }
        ],
        "@typescript-eslint/member-ordering": "off",
        "@typescript-eslint/no-extraneous-class": [
            "error",
            {
                "allowStaticOnly": true
            }
        ],
        "@typescript-eslint/no-floating-promises": "error",
        "@typescript-eslint/no-for-in-array": "error",
        "@typescript-eslint/no-require-imports": "error",
        "@typescript-eslint/no-this-alias": "error",
        "@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
        "@typescript-eslint/no-unnecessary-type-arguments": "error",
        "@typescript-eslint/no-unnecessary-type-assertion": "error",
        "@typescript-eslint/prefer-readonly": "error",
        "@typescript-eslint/promise-function-async": "error",
        "@typescript-eslint/quotes": [
            "error",
            "double"
        ],
        "@typescript-eslint/require-await": "error",
        "@typescript-eslint/restrict-plus-operands": "error",
        "@typescript-eslint/triple-slash-reference": "error",
        "@typescript-eslint/unbound-method": [
            "error",
            {
                "ignoreStatic": true
            }
        ],
        "arrow-parens": [
            "error",
            "as-needed"
        ],
        "brace-style": [
            "error",
            "1tbs"
        ],
        "class-methods-use-this": "off",
        "comma-dangle": "error",
        "complexity": [
            "error",
            {
                "max": 20
            }
        ],
        "default-case": "error",
        "id-blacklist": "off",
        "id-match": "off",
        "indent": "off",
        "import/no-default-export": "error",
        "import/no-extraneous-dependencies": "error",
        "import/no-unassigned-import": "error",
        "import/order": "off",
        "max-classes-per-file": [
            "error",
            1
        ],
        "max-len": [
            "off",
            {
                "ignorePattern": "//",
                "code": 140
            }
        ],
        "max-lines": "off",
        "newline-per-chained-call": "off",
        "no-duplicate-case": "error",
        "no-duplicate-imports": "error",
        "no-extra-bind": "error",
        "no-invalid-this": "error",
        "no-multiple-empty-lines": [
            "error",
            {
                "max": 1
            }
        ],
        "no-new-func": "error",
        "no-null/no-null": "error",
        "no-plusplus": "off",
        "no-redeclare": "error",
        "no-restricted-syntax": [
            "error",
            "ForInStatement"
        ],
        "no-return-await": "error",
        "no-sequences": "error",
        "no-sparse-arrays": "error",
        "no-template-curly-in-string": "error",
        "no-underscore-dangle": "off",
        "no-unused-vars": "off",
        "no-use-before-define": "off",
        "no-useless-constructor": "off",
        "no-void": "error",
        "quotes": [
            "error",
            "double"
        ],
        "padded-blocks": [
            "error",
            {
                "classes": "always"
            }
        ],
        "padding-line-between-statements": [
            "off",
            {
                "blankLine": "always",
                "prev": "*",
                "next": "return"
            }
        ],
        "prefer-object-spread": "error",
        "prefer-template": "error",
        "rxjs/no-ignored-error": "error",
        "rxjs/no-implicit-any-catch": "off",
        "semi": [
            "error",
            "always"
        ],
        "simple-import-sort/imports": "error",
        "space-before-function-paren": [
            "error",
            {
                "anonymous": "always",
                "named": "never",
                "asyncArrow": "always"
            }
        ],
        "space-in-parens": [
            "error",
            "never"
        ],
        "sort-imports": [
            "off",
            {
                "ignoreCase": true,
                "ignoreDeclarationSort": false,
                "ignoreMemberSort": false,
                "memberSyntaxSortOrder": [
                    "all",
                    "none",
                    "single",
                    "multiple"
                ],
                "allowSeparatedGroups": true
            }
        ],
        "unicorn/filename-case": "error",
        "yoda": "error"
    }
}
Znerole commented 2 years ago

Just ran into the same issue. The rule is excellent and has prevented us from obvious programming mistakes for a long while, but with the old subscribe signature deprecated, we basically lost this safeguard.

Unfortunately I lack the skills to provide a fix.

dilame commented 1 year ago

One more cornerstone about rxjs/no-ignored-error rule is that is doesn't work if we just call .subscribe() with no arguments.

// ESLint: Calling subscribe without an error handler is forbidden.(rxjs/no-ignored-error)
obs$.subscribe((x) => x);
// BUT
// This line is ok for the linter, which is not what i expect
obs$.subscribe();