Skip to content

Commit cbe5c6f

Browse files
Lint and docs fixes
1 parent 0bec767 commit cbe5c6f

File tree

6 files changed

+43
-41
lines changed

6 files changed

+43
-41
lines changed

docs/rules/prefer-composition.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ export class SomeComponent implements OnInit, OnDestroy {
5454

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

57-
| Name | Description | Type |
58-
| :---------------- | :--------------------------------------------- | :------- |
59-
| `checkDecorators` | An optional array of decorator names to check. | String[] |
57+
| Name | Description | Type |
58+
| :---------------- | :------------------------------------------------------------------------------------------- | :------- |
59+
| `checkDecorators` | An optional array of decorator names to check. | String[] |
60+
| `superClass` | An optional array of superclass names that already implement a `Subject`-based `ngOnDestroy` | String[] |
6061

6162
<!-- end auto-generated rule options list -->
6263

6364
This rule accepts a single option which is an object with a `checkDecorators` and `superClass` properties.
6465

6566
The `checkDecorators` property is an array containing the names of the decorators that determine whether or not a class is checked. By default, `checkDecorators` is `["Component"]`.
6667

67-
The `superClass` property is an array containing the names of classes to extend from that already implements a `Subject`-based `ngOnDestroy`.
68+
The `superClass` property is an array containing the names of classes to extend from that already implement a `Subject`-based `ngOnDestroy`.
6869

6970
```json
7071
{

docs/rules/prefer-takeuntil.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ class SomeComponent implements OnDestroy, OnInit {
5656

5757
<!-- begin auto-generated rule options list -->
5858

59-
| Name | Description | Type |
60-
| :---------------- | :-------------------------------------------------------------- | :------- |
61-
| `alias` | An optional array of operator names that alias for `takeUntil`. | String[] |
62-
| `checkComplete` | Check for `complete` calls. | Boolean |
63-
| `checkDecorators` | An optional array of decorator names to check. | String[] |
64-
| `checkDestroy` | Check for `Subject`-based `ngOnDestroy`. | Boolean |
59+
| Name | Description | Type |
60+
| :---------------- | :------------------------------------------------------------------------------------------- | :------- |
61+
| `alias` | An optional array of operator names that alias for `takeUntil`. | String[] |
62+
| `checkComplete` | Check for `complete` calls. | Boolean |
63+
| `checkDecorators` | An optional array of decorator names to check. | String[] |
64+
| `checkDestroy` | Check for `Subject`-based `ngOnDestroy`. | Boolean |
65+
| `superClass` | An optional array of superclass names that already implement a `Subject`-based `ngOnDestroy` | String[] |
6566

6667
<!-- end auto-generated rule options list -->
6768

@@ -73,7 +74,7 @@ The `checkDecorators` property is an array containing the names of the decorator
7374

7475
The `checkDestroy` property is a boolean that determines whether or not a `Subject`-based `ngOnDestroy` must be implemented.
7576

76-
The `superClass` property is an array containing the names of classes to extend from that already implements a `Subject`-based `ngOnDestroy`.
77+
The `superClass` property is an array containing the names of classes to extend from that already implement a `Subject`-based `ngOnDestroy`.
7778

7879
The `alias` property is an array of names of operators that should be treated similarly to `takeUntil`.
7980

src/rules/prefer-composition.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ export const preferCompositionRule = ruleCreator({
3535
{
3636
properties: {
3737
checkDecorators: { type: 'array', items: { type: 'string' }, description: 'An optional array of decorator names to check.' },
38-
superClass: { type: "array", items: { type: "string" } },
38+
superClass: { type: 'array', items: { type: 'string' }, description: 'An optional array of superclass names that already implement a `Subject`-based `ngOnDestroy`' },
3939
},
4040
type: 'object',
4141
description: stripIndent`
4242
An optional object with an optional \`checkDecorators\` property.
4343
The \`checkDecorators\` property is an array containing the names of the decorators that determine whether or not a class is checked.
44-
The \`superClass\` property is an array containing the names of classes to extend from that already implements a \`Subject\`-based \`ngOnDestroy\`.
44+
The \`superClass\` property is an array containing the names of classes to extend from that already implement a \`Subject\`-based \`ngOnDestroy\`.
4545
`,
4646
},
4747
],
@@ -50,7 +50,7 @@ export const preferCompositionRule = ruleCreator({
5050
name: 'prefer-composition',
5151
create: (context) => {
5252
const { couldBeObservable, couldBeSubscription } = getTypeServices(context);
53-
const [{ checkDecorators = ["Component"], superClass = [] } = {}] = context.options;
53+
const [{ checkDecorators = ['Component'], superClass = [] } = {}] = context.options;
5454

5555
interface Entry {
5656
addCallExpressions: es.CallExpression[];
@@ -244,15 +244,15 @@ export const preferCompositionRule = ruleCreator({
244244
return true;
245245
}
246246

247-
const extendsSuperClassDeclaration =
248-
superClass.length === 0
247+
const extendsSuperClassDeclaration
248+
= superClass.length === 0
249249
? {}
250250
: {
251251
[`ClassDeclaration:matches(${superClass
252252
.map((className) => `[superClass.name="${className}"]`)
253253
.join()})`]: (node: es.ClassDeclaration) => {
254254
const entry = getEntry();
255-
if (entry && entry.hasDecorator) {
255+
if (entry.hasDecorator) {
256256
entry.extendsSuperClassDeclaration = node;
257257
}
258258
},

src/rules/prefer-takeuntil.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const messages = {
2121
} as const;
2222
type MessageIds = keyof typeof messages;
2323

24-
const ngOnDestroyMethodSelector =
25-
"MethodDefinition[key.name='ngOnDestroy'][kind='method']";
24+
const ngOnDestroyMethodSelector
25+
= 'MethodDefinition[key.name=\'ngOnDestroy\'][kind=\'method\']';
2626

2727
const defaultOptions: readonly {
2828
alias?: string[];
@@ -50,7 +50,7 @@ export const preferTakeuntilRule = ruleCreator({
5050
checkComplete: { type: 'boolean', description: 'Check for `complete` calls.' },
5151
checkDecorators: { type: 'array', items: { type: 'string' }, description: 'An optional array of decorator names to check.' },
5252
checkDestroy: { type: 'boolean', description: 'Check for `Subject`-based `ngOnDestroy`.' },
53-
superClass: { type: "array", items: { type: "string" } },
53+
superClass: { type: 'array', items: { type: 'string' }, description: 'An optional array of superclass names that already implement a `Subject`-based `ngOnDestroy`' },
5454
},
5555
type: 'object',
5656
description: stripIndent`
@@ -59,7 +59,7 @@ export const preferTakeuntilRule = ruleCreator({
5959
The \`checkComplete\` property is a boolean that determines whether or not \`complete\` must be called after \`next\`.
6060
The \`checkDecorators\` property is an array containing the names of the decorators that determine whether or not a class is checked.
6161
The \`checkDestroy\` property is a boolean that determines whether or not a \`Subject\`-based \`ngOnDestroy\` must be implemented.
62-
The \`superClass\` property is an array containing the names of classes to extend from that already implements a \`Subject\`-based \`ngOnDestroy\`.
62+
The \`superClass\` property is an array containing the names of classes to extend from that already implement a \`Subject\`-based \`ngOnDestroy\`.
6363
`,
6464
},
6565
],
@@ -166,33 +166,33 @@ export const preferTakeuntilRule = ruleCreator({
166166
if (extendsSuperClassDeclaration) {
167167
if (!superNgOnDestroyCallExpression) {
168168
check.descriptors.push({
169-
data: { method: "ngOnDestroy", name: "super" },
170-
messageId: "notCalled",
169+
data: { method: 'ngOnDestroy', name: 'super' },
170+
messageId: 'notCalled',
171171
node: ngOnDestroyDefinition.key,
172172
});
173173
}
174174
} else {
175175
if (!checkSubjectProperty(name, entry)) {
176176
check.descriptors.push({
177177
data: { name },
178-
messageId: "notDeclared",
178+
messageId: 'notDeclared',
179179
node: classDeclaration.id ?? classDeclaration,
180180
});
181181
}
182182
if (!checkSubjectCall(name, nextCallExpressions)) {
183183
check.descriptors.push({
184-
data: { method: "next", name },
185-
messageId: "notCalled",
184+
data: { method: 'next', name },
185+
messageId: 'notCalled',
186186
node: ngOnDestroyDefinition.key,
187187
});
188188
}
189189
if (
190-
checkComplete &&
191-
!checkSubjectCall(name, completeCallExpressions)
190+
checkComplete
191+
&& !checkSubjectCall(name, completeCallExpressions)
192192
) {
193193
check.descriptors.push({
194-
data: { method: "complete", name },
195-
messageId: "notCalled",
194+
data: { method: 'complete', name },
195+
messageId: 'notCalled',
196196
node: ngOnDestroyDefinition.key,
197197
});
198198
}
@@ -331,15 +331,15 @@ export const preferTakeuntilRule = ruleCreator({
331331
);
332332
}
333333

334-
const extendsSuperClassDeclaration =
335-
superClass.length === 0
334+
const extendsSuperClassDeclaration
335+
= superClass.length === 0
336336
? {}
337337
: {
338338
[`ClassDeclaration:matches(${superClass
339339
.map((className) => `[superClass.name="${className}"]`)
340340
.join()})`]: (node: es.ClassDeclaration) => {
341341
const entry = getEntry();
342-
if (entry && entry.hasDecorator) {
342+
if (entry.hasDecorator) {
343343
entry.extendsSuperClassDeclaration = node;
344344
}
345345
},
@@ -391,7 +391,7 @@ export const preferTakeuntilRule = ruleCreator({
391391
[`${ngOnDestroyMethodSelector} CallExpression[callee.object.type='Super'][callee.property.name='ngOnDestroy']`]:
392392
(node: es.CallExpression) => {
393393
const entry = getEntry();
394-
if (entry && entry.hasDecorator) {
394+
if (entry.hasDecorator) {
395395
entry.superNgOnDestroyCallExpression = node;
396396
}
397397
},

tests/rules/prefer-composition.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ruleTester({ types: true }).run('prefer-composition', preferCompositionRule, {
127127
`,
128128
options: [
129129
{
130-
superClass: ["BaseComponent"],
130+
superClass: ['BaseComponent'],
131131
},
132132
],
133133
},

tests/rules/prefer-takeuntil.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ ruleTester({ types: true }).run('prefer-takeuntil', preferTakeuntilRule, {
399399
`,
400400
options: [
401401
{
402-
superClass: ["BaseComponent"],
402+
superClass: ['BaseComponent'],
403403
checkComplete: true,
404404
},
405405
],
@@ -443,7 +443,7 @@ ruleTester({ types: true }).run('prefer-takeuntil', preferTakeuntilRule, {
443443
`,
444444
options: [
445445
{
446-
superClass: ["BaseComponent"],
446+
superClass: ['BaseComponent'],
447447
checkComplete: true,
448448
},
449449
],
@@ -776,11 +776,11 @@ ruleTester({ types: true }).run('prefer-takeuntil', preferTakeuntilRule, {
776776
{
777777
options: [
778778
{
779-
superClass: ["BaseComponent"],
779+
superClass: ['BaseComponent'],
780780
checkComplete: true,
781781
},
782782
],
783-
}
783+
},
784784
),
785785
fromFixture(
786786
stripIndent`
@@ -814,11 +814,11 @@ ruleTester({ types: true }).run('prefer-takeuntil', preferTakeuntilRule, {
814814
{
815815
options: [
816816
{
817-
superClass: ["BaseComponent"],
817+
superClass: ['BaseComponent'],
818818
checkComplete: true,
819819
},
820820
],
821-
}
821+
},
822822
),
823823
],
824824
});

0 commit comments

Comments
 (0)