Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ The package includes the following rules.
| [no-subject-value](docs/rules/no-subject-value.md) | Disallow accessing the `value` property of a `BehaviorSubject` instance. | | | | 💭 | |
| [no-subscribe-handlers](docs/rules/no-subscribe-handlers.md) | Disallow passing handlers to `subscribe`. | | | | 💭 | |
| [no-tap](docs/rules/no-tap.md) | Disallow the `tap` operator. | | | | | ❌ |
| [no-topromise](docs/rules/no-topromise.md) | Disallow use of the `toPromise` method. | 🔒 | | 💡 | 💭 | |
| [no-topromise](docs/rules/no-topromise.md) | Disallow use of the `toPromise` method. | ✅ 🔒 | | 💡 | 💭 | |
| [no-unbound-methods](docs/rules/no-unbound-methods.md) | Disallow passing unbound methods. | ✅ 🔒 | | | 💭 | |
| [no-unsafe-catch](docs/rules/no-unsafe-catch.md) | Disallow unsafe `catchError` usage in effects and epics. | | | | 💭 | |
| [no-unsafe-first](docs/rules/no-unsafe-first.md) | Disallow unsafe `first`/`take` usage in effects and epics. | | | | 💭 | |
| [no-unsafe-subject-next](docs/rules/no-unsafe-subject-next.md) | Disallow unsafe optional `next` calls. | ✅ 🔒 | | | 💭 | |
| [no-unsafe-switchmap](docs/rules/no-unsafe-switchmap.md) | Disallow unsafe `switchMap` usage in effects and epics. | | | | 💭 | |
| [no-unsafe-takeuntil](docs/rules/no-unsafe-takeuntil.md) | Disallow applying operators after `takeUntil`. | ✅ 🔒 | | | 💭 | |
| [prefer-observer](docs/rules/prefer-observer.md) | Disallow passing separate handlers to `subscribe` and `tap`. | 🔒 | 🔧 | 💡 | 💭 | |
| [prefer-root-operators](docs/rules/prefer-root-operators.md) | Disallow importing operators from `rxjs/operators`. | 🔒 | 🔧 | 💡 | | |
| [prefer-observer](docs/rules/prefer-observer.md) | Disallow passing separate handlers to `subscribe` and `tap`. | ✅ 🔒 | 🔧 | 💡 | 💭 | |
| [prefer-root-operators](docs/rules/prefer-root-operators.md) | Disallow importing operators from `rxjs/operators`. | ✅ 🔒 | 🔧 | 💡 | | |
| [suffix-subjects](docs/rules/suffix-subjects.md) | Enforce the use of a suffix in subject identifiers. | | | | 💭 | |
| [throw-error](docs/rules/throw-error.md) | Enforce passing only `Error` values to `throwError`. | 🔒 | | | 💭 | |
| [throw-error](docs/rules/throw-error.md) | Enforce passing only `Error` values to `throwError`. | ✅ 🔒 | | | 💭 | |

<!-- end auto-generated rules list -->
2 changes: 1 addition & 1 deletion docs/rules/no-topromise.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Disallow use of the `toPromise` method (`rxjs-x/no-topromise`)

💼 This rule is enabled in the 🔒 `strict` config.
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.

💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-observer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Disallow passing separate handlers to `subscribe` and `tap` (`rxjs-x/prefer-observer`)

💼 This rule is enabled in the 🔒 `strict` config.
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.

🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/prefer-root-operators.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Disallow importing operators from `rxjs/operators` (`rxjs-x/prefer-root-operators`)

💼 This rule is enabled in the 🔒 `strict` config.
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.

🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/throw-error.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Enforce passing only `Error` values to `throwError` (`rxjs-x/throw-error`)

💼 This rule is enabled in the 🔒 `strict` config.
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.

💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"peerDependencies": {
"eslint": "^8.57.0 || ^9.0.0",
"rxjs": ">=7.0.0",
"rxjs": ">=7.2.0",
"typescript": ">=4.7.4"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 4 additions & 0 deletions src/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export const createRecommendedConfig = (
'rxjs-x/no-redundant-notify': 'error',
'rxjs-x/no-sharereplay': 'error',
'rxjs-x/no-subject-unsubscribe': 'error',
'rxjs-x/no-topromise': 'error',
'rxjs-x/no-unbound-methods': 'error',
'rxjs-x/no-unsafe-subject-next': 'error',
'rxjs-x/no-unsafe-takeuntil': 'error',
'rxjs-x/prefer-observer': 'error',
'rxjs-x/prefer-root-operators': 'error',
'rxjs-x/throw-error': 'error',
},
} satisfies TSESLint.FlatConfig.Config);
2 changes: 1 addition & 1 deletion src/rules/no-topromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const noTopromiseRule = ruleCreator({
meta: {
docs: {
description: 'Disallow use of the `toPromise` method.',
recommended: 'strict',
recommended: 'recommended',
requiresTypeChecking: true,
},
hasSuggestions: true,
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const preferObserverRule = ruleCreator({
docs: {
description:
'Disallow passing separate handlers to `subscribe` and `tap`.',
recommended: 'strict',
recommended: 'recommended',
requiresTypeChecking: true,
},
fixable: 'code',
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-root-operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const preferRootOperatorsRule = ruleCreator({
meta: {
docs: {
description: 'Disallow importing operators from `rxjs/operators`.',
recommended: 'strict',
recommended: 'recommended',
},
fixable: 'code',
hasSuggestions: true,
Expand Down
1 change: 1 addition & 0 deletions src/rules/throw-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const throwErrorRule = ruleCreator({
description:
'Enforce passing only `Error` values to `throwError`.',
recommended: {
recommended: true,
strict: [{ allowThrowingAny: false, allowThrowingUnknown: false }],
},
requiresTypeChecking: true,
Expand Down
55 changes: 24 additions & 31 deletions tests/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,35 @@ describe('package', () => {
}
});

it('has rules flagged according to their configs', () => {
if (!plugin.configs) {
expect.fail('No configs found.');
}

it.for(Object.keys(plugin.rules))('includes rule %s in configurations based on meta.docs.recommended', (ruleName, { expect }) => {
const rule = plugin.rules[ruleName as keyof typeof plugin.rules];
const namespace = 'rxjs-x';
const recommendedRules = plugin.configs.recommended.rules;
const strictRules = plugin.configs.strict.rules;
const fullRuleName = `${namespace}/${ruleName}`;

for (const [ruleName, rule] of Object.entries(plugin.rules)) {
const fullRuleName = `${namespace}/${ruleName}`;
const ruleRec = rule.meta.docs?.recommended;
if (!rule.meta.docs?.recommended) {
// Rule is not included in any configuration.
expect(plugin.configs.recommended.rules).not.toHaveProperty(fullRuleName);
expect(plugin.configs.strict.rules).not.toHaveProperty(fullRuleName);
} else if (typeof rule.meta.docs.recommended === 'string') {
// Rule specifies only a configuration name.
expect(rule.meta.docs.recommended).toMatch(/^(recommended|strict)$/);
if (rule.meta.docs.recommended === 'recommended') {
expect(plugin.configs.recommended.rules).toHaveProperty(fullRuleName);
} else {
expect(plugin.configs.recommended.rules).not.toHaveProperty(fullRuleName);
}

if (!ruleRec) {
// Rule is not part of any config.
expect(recommendedRules).not.toHaveProperty(fullRuleName);
expect(strictRules).not.toHaveProperty(fullRuleName);
} else if (typeof ruleRec === 'string') {
// Rule is part of a single config.
if (ruleRec === 'recommended') {
expect(recommendedRules).toHaveProperty(fullRuleName);
} else if (ruleRec === 'strict') {
expect(strictRules).toHaveProperty(fullRuleName);
expect(strictRules[fullRuleName as keyof typeof strictRules]).toBe('error');
} else {
expect.fail(`Invalid recommended value for rule ${fullRuleName}: ${ruleRec}`);
}
// Strict configuration always includes all recommended rules.
// Not allowed to specify non-default options since rule only specifies a configuration name.
expect(plugin.configs.strict.rules).toHaveProperty(fullRuleName, expect.any(String));
} else {
// Rule specifies non-default options for strict.
if (rule.meta.docs.recommended.recommended) {
expect(plugin.configs.recommended.rules).toHaveProperty(fullRuleName);
} else {
// Rule is part of several configs.
if (ruleRec.recommended) {
expect(recommendedRules).toHaveProperty(fullRuleName);
}
expect(strictRules).toHaveProperty(fullRuleName);
expect(strictRules[fullRuleName as keyof typeof strictRules]).toBeInstanceOf(Array);
expect(strictRules[fullRuleName as keyof typeof strictRules][1]).toEqual(ruleRec.strict[0]);
expect(plugin.configs.recommended.rules).not.toHaveProperty(fullRuleName);
}
expect(plugin.configs.strict.rules).toHaveProperty(fullRuleName, [expect.any(String), rule.meta.docs.recommended.strict[0]]);
}
});
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ __metadata:
vitest: "npm:^2.1.5"
peerDependencies:
eslint: ^8.57.0 || ^9.0.0
rxjs: ">=7.0.0"
rxjs: ">=7.2.0"
typescript: ">=4.7.4"
peerDependenciesMeta:
rxjs:
Expand Down