Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[enhancement] max-classes-per-file / config to exclude class expressions #3281

Merged
merged 5 commits into from
Oct 19, 2017

Conversation

aervin
Copy link
Contributor

@aervin aervin commented Oct 5, 2017

PR checklist

  • Addresses an existing issue: #3270
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update

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.

@@ -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
Copy link
Contributor

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",
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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

],
additionalItems: false,
minLength: 1,
maxLength: 2,
minLength: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minLength is still 1

minLength: 1,
maxLength: 2,
minLength: 2,
maxLength: 3,
Copy link
Contributor

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

options: {
type: "array",
items: [
{
type: "number",
minimum: 1,
},
{
type: "string",
enum: OPTION_INCLUDE_CLASS_EXPRESSIONS,
Copy link
Contributor

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

isClassLikeDeclaration(node) &&
(excludeClassExpressions
? !isClassExpression(node)
: true)
Copy link
Contributor

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.

maxClasses: number;
}

const OPTION_INCLUDE_CLASS_EXPRESSIONS = "exclude-class-expressions";
Copy link
Contributor

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

],
additionalItems: false,
minLength: 1,
maxLength: 2,
},
optionExamples: [[true, 1], [true, 5]],
optionExamples: [[true, 1], [true, 5, "exclude-class-expressions"]],
Copy link
Contributor

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

@aervin aervin changed the title [enhancement] max-classes-per-file / config to include class expressions [enhancement] max-classes-per-file / config to exclude class expressions Oct 5, 2017
@ajafff ajafff merged commit 7f77a65 into palantir:master Oct 19, 2017
@ajafff
Copy link
Contributor

ajafff commented Oct 19, 2017

Thanks @aervin

@aervin aervin deleted the bug/mcpf branch October 22, 2017 14:22
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this pull request Apr 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants