Skip to content

Commit f5f43dd

Browse files
refactor!: switch to meta.defaultOptions (#353)
Consolidate default options for each rule into one place. Resolves #51
1 parent 605331b commit f5f43dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+399
-368
lines changed

.eslint-doc-generatorrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@
22

33
/** @type {import('eslint-doc-generator').GenerateOptions} */
44
export default {
5+
ruleDocTitleFormat: 'desc-parens-prefix-name',
6+
ruleDocNotices: [
7+
'deprecated',
8+
'configs',
9+
'fixableAndHasSuggestions',
10+
'requiresTypeChecking',
11+
],
512
};

.yarn/patches/eslint-plugin-eslint-plugin-npm-7.3.0-d800475165.patch renamed to .yarn/patches/eslint-plugin-eslint-plugin-npm-7.3.1-6b766f9a07.patch

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,47 @@
11
diff --git a/dist/rules/require-test-case-name.js b/dist/rules/require-test-case-name.js
2-
index 74d279129e367ed2a4e6c601f2b596579a690f9e..9aec1f032bea7ae9324e9928b522fc6f386a9c83 100644
2+
index b60e75d4ac94a725e09ba1fdd86dbd71228762b4..8bf4fbc0009eaecc429a0f54f22e454f825c66d0 100644
33
--- a/dist/rules/require-test-case-name.js
44
+++ b/dist/rules/require-test-case-name.js
5-
@@ -54,6 +54,12 @@ const rule = {
5+
@@ -54,6 +54,13 @@ const rule = {
66
hasName: false,
77
hasConfig: false
88
};
9+
+ // We use tagged template literals to strip indentation in test cases.
910
+ if (testCase.type === "TaggedTemplateExpression" && testCase.quasi?.type === "TemplateLiteral") return {
10-
+ node: testCase.quasi,
11-
+ isObject: false,
12-
+ hasName: false,
13-
+ hasConfig: false
14-
+ };
11+
+ node: testCase,
12+
+ isObject: false,
13+
+ hasName: false,
14+
+ hasConfig: false
15+
+ };
1516
if (testCase.type === "ObjectExpression") {
1617
let hasName = false;
1718
let hasConfig = false;
1819
diff --git a/dist/rules/test-case-shorthand-strings.js b/dist/rules/test-case-shorthand-strings.js
19-
index 584c6a36a619ab1241b72ce4f8aa199e8023f8bc..b4134b70f1871b1fcb99f0f33c16fa7524cb81a3 100644
20+
index 8474a7400eddb2fba2e46b71b815f237e2ee1242..c7ddefb9b16007166086246962ac44451f231565 100644
2021
--- a/dist/rules/test-case-shorthand-strings.js
2122
+++ b/dist/rules/test-case-shorthand-strings.js
2223
@@ -37,6 +37,12 @@ const rule = {
2324
shorthand: true,
2425
needsLongform: false
2526
};
27+
+ // We use tagged template literals to strip indentation in test cases.
2628
+ if (testCase.type === "TaggedTemplateExpression" && testCase.quasi?.type === "TemplateLiteral") return {
27-
+ node: testCase.quasi,
28-
+ fixNode: testCase,
29-
+ shorthand: true,
30-
+ needsLongform: false
31-
+ };
29+
+ node: testCase,
30+
+ shorthand: true,
31+
+ needsLongform: false
32+
+ };
3233
if (testCase.type === "ObjectExpression") return {
3334
node: testCase,
3435
shorthand: false,
35-
@@ -71,7 +77,8 @@ const rule = {
36-
actual: badCaseInfo.shorthand ? "a string" : "an object"
37-
},
38-
fix(fixer) {
39-
- return fixer.replaceText(badCaseInfo.node, badCaseInfo.shorthand ? `{code: ${sourceCode.getText(badCaseInfo.node)}}` : sourceCode.getText(badCaseInfo.node.properties[0].value));
40-
+ const fixNode = badCaseInfo.fixNode || badCaseInfo.node;
41-
+ return fixer.replaceText(fixNode, badCaseInfo.shorthand ? `{code: ${sourceCode.getText(fixNode)}}` : sourceCode.getText(fixNode.properties[0].value));
42-
}
43-
});
44-
});
4536
diff --git a/dist/utils.js b/dist/utils.js
46-
index 8ab5f760911fb4441ed9c54272504bb848a1e705..140e1a3cd080905752a6865a775c4bd9ddd70ba7 100644
37+
index 8ab5f760911fb4441ed9c54272504bb848a1e705..04eba7ce82ef00e9b9d4188946065a6d4d8d1718 100644
4738
--- a/dist/utils.js
4839
+++ b/dist/utils.js
49-
@@ -22,6 +22,7 @@ function isNormalFunctionExpression(node) {
40+
@@ -22,6 +22,8 @@ function isNormalFunctionExpression(node) {
5041
* @returns `true` if the node is probably constructing a RuleTester instance
5142
*/
5243
function isRuleTesterConstruction(node) {
44+
+ // We import "ruleTester" from a custom util.
5345
+ if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "ruleTester") return true;
5446
return node.type === "NewExpression" && (node.callee.type === "Identifier" && node.callee.name === "RuleTester" || node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === "RuleTester");
5547
}

AGENTS.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ eslint-plugin-rxjs-x/
6161
├── package.json
6262
├── README.md
6363
├── tsdown.config.ts # Build configuration
64-
├── vitest.config.mts # Test configuration
64+
├── vitest.config.ts # Test configuration
6565
└── yarn.lock # Packages lockfile
6666
```
6767

@@ -164,32 +164,34 @@ import { TSESTree as es } from '@typescript-eslint/utils';
164164
import { getTypeServices } from '../etc';
165165
import { ruleCreator } from '../utils';
166166

167-
const defaultOptions: readonly {
167+
type Options = [{
168168
allowSomething?: boolean;
169-
}[] = [];
169+
}];
170170

171171
export const ruleName = ruleCreator({
172-
defaultOptions,
173172
meta: {
174173
docs: {
175174
description: 'Rule description',
176175
recommended: 'recommended', // or 'strict' or false or { recommended: true, strict: {...stricterOptions} }
177176
requiresTypeChecking: true, // if TypeScript info needed (e.g importing getTypeServices)
178177
},
178+
fixable: 'code' | 'whitespace', // if auto-fixable
179+
hasSuggestions: true, // if reported issues have suggestions
179180
messages: {
180181
messageId: 'Error message with {{interpolation}}',
181182
},
182183
schema: [ // JSON schema for options
183184
{
184185
properties: {
185-
allowSomething: { type: 'boolean', description: 'Allows something.', default: false },
186+
allowSomething: { type: 'boolean', description: 'Allows something.' },
186187
},
187188
type: 'object',
188189
},
189190
],
190191
type: 'problem' | 'suggestion' | 'layout', // "problem" identifies code that causes errors or unexpected behavior; "suggestion" identifies something that could be done better; "layout" is stylistic outside the AST
191-
fixable: 'code' | 'whitespace', // if auto-fixable
192-
hasSuggestions: true, // if reported issues have suggestions
192+
defaultOptions: [{
193+
allowSomething: false,
194+
}] as Options,
193195
},
194196
name: 'rule-name',
195197
create: (context) => {

docs/rules/finnish.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ const answer$ = 'green';
4040

4141
<!-- begin auto-generated rule options list -->
4242

43-
| Name | Description | Type |
44-
| :----------- | :------------------------------------------------------------------------- | :------ |
45-
| `functions` | Require for functions. | Boolean |
46-
| `methods` | Require for methods. | Boolean |
47-
| `names` | Enforce for specific names. Keys are a RegExp, values are a boolean. | Object |
48-
| `objects` | Require for object literal keys. | Boolean |
49-
| `parameters` | Require for parameters. | Boolean |
50-
| `properties` | Require for properties, except object literal keys (see "objects" option). | Boolean |
51-
| `strict` | Disallow Finnish notation for non-Observables. | Boolean |
52-
| `types` | Enforce for specific types. Keys are a RegExp, values are a boolean. | Object |
53-
| `variables` | Require for variables. | Boolean |
43+
| Name | Description | Type | Default |
44+
| :----------- | :------------------------------------------------------------------------- | :------ | :---------------- |
45+
| `functions` | Require for functions. | Boolean | `true` |
46+
| `methods` | Require for methods. | Boolean | `true` |
47+
| `names` | Enforce for specific names. Keys are a RegExp, values are a boolean. | Object | `[object Object]` |
48+
| `objects` | Require for object literal keys. | Boolean | `true` |
49+
| `parameters` | Require for parameters. | Boolean | `true` |
50+
| `properties` | Require for properties, except object literal keys (see "objects" option). | Boolean | `true` |
51+
| `strict` | Disallow Finnish notation for non-Observables. | Boolean | `false` |
52+
| `types` | Enforce for specific types. Keys are a RegExp, values are a boolean. | Object | `[object Object]` |
53+
| `variables` | Require for variables. | Boolean | `true` |
5454

5555
<!-- end auto-generated rule options list -->
5656

docs/rules/suffix-subjects.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ combineLatest({ answers: new Subject<number>() });
3232

3333
<!-- begin auto-generated rule options list -->
3434

35-
| Name | Description | Type |
36-
| :----------- | :------------------------------------------------------------------------- | :------ |
37-
| `objects` | Require for object literal keys. | Boolean |
38-
| `parameters` | Require for parameters. | Boolean |
39-
| `properties` | Require for properties, except object literal keys (see "objects" option). | Boolean |
40-
| `suffix` | The suffix to enforce. | String |
41-
| `types` | Enforce for specific types. Keys are a RegExp, values are a boolean. | Object |
42-
| `variables` | Require for variables. | Boolean |
35+
| Name | Description | Type | Default |
36+
| :----------- | :------------------------------------------------------------------------- | :------ | :---------------- |
37+
| `objects` | Require for object literal keys. | Boolean | `true` |
38+
| `parameters` | Require for parameters. | Boolean | `true` |
39+
| `properties` | Require for properties, except object literal keys (see "objects" option). | Boolean | `true` |
40+
| `suffix` | The suffix to enforce. | String | `Subject` |
41+
| `types` | Enforce for specific types. Keys are a RegExp, values are a boolean. | Object | `[object Object]` |
42+
| `variables` | Require for variables. | Boolean | `true` |
4343

4444
<!-- end auto-generated rule options list -->
4545

eslint.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ export default defineConfig(gitignore(), {
8080
],
8181
'eslint-plugin/unique-test-case-names': 'error',
8282
'eslint-plugin/no-matching-violation-suggest-message-ids': 'error',
83-
// TODO(https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/issues/51):
84-
// fixing these may require bumping the minimum ESLint version.
85-
'eslint-plugin/require-meta-default-options': 'off',
86-
'eslint-plugin/no-meta-schema-default': 'off',
87-
'eslint-plugin/no-meta-replaced-by': 'off',
8883

8984
'@typescript-eslint/no-unnecessary-condition': 'off',
9085
'@typescript-eslint/restrict-template-expressions': [

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
"bumpp": "^10.4.1",
8282
"eslint": "^10.0.0",
8383
"eslint-config-flat-gitignore": "^2.1.0",
84-
"eslint-doc-generator": "^2.4.0",
84+
"eslint-doc-generator": "^3.1.0",
8585
"eslint-import-resolver-typescript": "^4.4.4",
86-
"eslint-plugin-eslint-plugin": "patch:eslint-plugin-eslint-plugin@npm%3A7.3.0#~/.yarn/patches/eslint-plugin-eslint-plugin-npm-7.3.0-d800475165.patch",
86+
"eslint-plugin-eslint-plugin": "patch:eslint-plugin-eslint-plugin@npm%3A7.3.1#~/.yarn/patches/eslint-plugin-eslint-plugin-npm-7.3.1-6b766f9a07.patch",
8787
"eslint-plugin-import-x": "^4.16.1",
8888
"eslint-plugin-n": "^17.23.2",
8989
"markdownlint-cli2": "~0.19.0",

src/rules/ban-observables.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { AST_NODE_TYPES, TSESTree as es } from '@typescript-eslint/utils';
1+
import { TSESTree as es } from '@typescript-eslint/utils';
22
import { stripIndent } from 'common-tags';
3+
import { isIdentifier } from '../etc';
34
import { ruleCreator } from '../utils';
45

5-
const defaultOptions: readonly Record<string, boolean | string>[] = [];
6+
type Options = readonly [Record<string, boolean | string>];
67

78
export const banObservablesRule = ruleCreator({
8-
defaultOptions,
99
meta: {
1010
docs: {
1111
description: 'Disallow banned observable creators.',
@@ -19,16 +19,27 @@ export const banObservablesRule = ruleCreator({
1919
description: stripIndent`
2020
An object containing keys that are names of observable factory functions
2121
and values that are either booleans or strings containing the explanation for the ban.`,
22+
additionalProperties: {
23+
anyOf: [
24+
{
25+
type: 'boolean',
26+
},
27+
{
28+
type: 'string',
29+
},
30+
],
31+
},
2232
},
2333
],
2434
type: 'problem',
35+
defaultOptions: [{}] as Options,
2536
},
2637
name: 'ban-observables',
2738
create: (context) => {
2839
const bans: { explanation: string; regExp: RegExp }[] = [];
2940

3041
const [config] = context.options;
31-
if (!config) {
42+
if (!config || !Object.keys(config).length) {
3243
return {};
3344
}
3445

@@ -60,7 +71,7 @@ export const banObservablesRule = ruleCreator({
6071
node: es.ImportSpecifier,
6172
) => {
6273
const identifier = node.imported;
63-
const name = identifier.type === AST_NODE_TYPES.Identifier ? identifier.name : identifier.value;
74+
const name = isIdentifier(identifier) ? identifier.name : identifier.value;
6475
const failure = getFailure(name);
6576
if (failure) {
6677
context.report({

src/rules/ban-operators.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import { stripIndent } from 'common-tags';
33
import { getTypeServices } from '../etc';
44
import { ruleCreator } from '../utils';
55

6-
const defaultOptions: readonly Record<string, boolean | string>[] = [];
6+
type Options = readonly [Record<string, boolean | string>];
77

88
export const banOperatorsRule = ruleCreator({
9-
defaultOptions,
109
meta: {
1110
docs: {
1211
description: 'Disallow banned operators.',
@@ -21,17 +20,28 @@ export const banOperatorsRule = ruleCreator({
2120
description: stripIndent`
2221
An object containing keys that are names of operators
2322
and values that are either booleans or strings containing the explanation for the ban.`,
23+
additionalProperties: {
24+
anyOf: [
25+
{
26+
type: 'boolean',
27+
},
28+
{
29+
type: 'string',
30+
},
31+
],
32+
},
2433
},
2534
],
2635
type: 'problem',
36+
defaultOptions: [{}] as Options,
2737
},
2838
name: 'ban-operators',
2939
create: (context) => {
3040
const { couldBeType } = getTypeServices(context);
3141
const bans: { name: string; explanation: string }[] = [];
3242

3343
const [config] = context.options;
34-
if (!config) {
44+
if (!config || !Object.keys(config).length) {
3545
return {};
3646
}
3747

0 commit comments

Comments
 (0)