-
Notifications
You must be signed in to change notification settings - Fork 889
[enhancement] max-classes-per-file / config to exclude class expressions #3281
Conversation
@@ -1,6 +1,23 @@ | |||
export abstract class UnsupportedVisitor extends NodeVisitor { | |||
public static withDescriptor(descriptor: string): typeof UnsupportedVisitor { | |||
return class extends UnsupportedVisitor { // ignores this class b/c it's an expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment here is wrong and should be removed
options: { | ||
type: "array", | ||
items: [ | ||
{ | ||
type: "number", | ||
minimum: 1, | ||
}, | ||
{ | ||
type: "string", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use "enum"
to specify the valid options
src/rules/maxClassesPerFileRule.ts
Outdated
@@ -29,20 +36,25 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
rationale: Lint.Utils.dedent` | |||
Ensures that files have a single responsibility so that that classes each exist in their own files`, | |||
optionsDescription: Lint.Utils.dedent` | |||
The one required argument is an integer indicating the maximum number of classes that can appear in a file.`, | |||
The one required argument is an integer indicating the maximum number of classes that can appear in a | |||
file. An optional argument \`"include-class-expressions"\` can be provided to include class expressions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use "exclude-class-expressions"
since that will not change the default behavior
src/rules/maxClassesPerFileRule.ts
Outdated
], | ||
additionalItems: false, | ||
minLength: 1, | ||
maxLength: 2, | ||
minLength: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minLength is still 1
src/rules/maxClassesPerFileRule.ts
Outdated
minLength: 1, | ||
maxLength: 2, | ||
minLength: 2, | ||
maxLength: 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxLength should be 2, seems like it was wrong before
src/rules/maxClassesPerFileRule.ts
Outdated
options: { | ||
type: "array", | ||
items: [ | ||
{ | ||
type: "number", | ||
minimum: 1, | ||
}, | ||
{ | ||
type: "string", | ||
enum: OPTION_INCLUDE_CLASS_EXPRESSIONS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be an array
src/rules/maxClassesPerFileRule.ts
Outdated
isClassLikeDeclaration(node) && | ||
(excludeClassExpressions | ||
? !isClassExpression(node) | ||
: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also be isClassDeclaration(node) || (!excludeClassExpression && isClassExpression(node))
It's up to you which one you prefer.
src/rules/maxClassesPerFileRule.ts
Outdated
maxClasses: number; | ||
} | ||
|
||
const OPTION_INCLUDE_CLASS_EXPRESSIONS = "exclude-class-expressions"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable name is off now
src/rules/maxClassesPerFileRule.ts
Outdated
], | ||
additionalItems: false, | ||
minLength: 1, | ||
maxLength: 2, | ||
}, | ||
optionExamples: [[true, 1], [true, 5]], | ||
optionExamples: [[true, 1], [true, 5, "exclude-class-expressions"]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the constant declared above
…o be more readable
Thanks @aervin |
PR checklist
Overview of change:
Rule accepts an optional
"include-class-expressions"
argument. If arg is provided, class expressions count toward the file's overall class count, otherwise they are ignored.