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

Add use-default-type-parameter rule #2253

Merged
merged 6 commits into from
May 25, 2017

Conversation

andy-hanson
Copy link
Contributor

@andy-hanson andy-hanson commented Feb 27, 2017

PR checklist

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

Overview of change:

Added the use-default-type-parameter rule, which encourages the use of defaults for type parameters.
Note: Tests will of course only work with typescript@next (to be [email protected] when it releases). How should we handle this so that CircleCI doesn't fail? Maybe the TSLint testing tool could manage installations of TypeScript, and allow settings for rules that only work in newer versions?

CHANGELOG.md entry:

[new-rule] use-default-type-parameter

@adidahiya
Copy link
Contributor

Here's how I think we should proceed with this:

  1. wrap up all the commits we want for the v4.5 release
  2. merge master branch into next
  3. submit this PR against next, which uses typescript@next

@andy-hanson
Copy link
Contributor Author

Actually, now that we support specifying a typescript version for a test (#2323), does this still need to be targeted to next?

@adidahiya
Copy link
Contributor

adidahiya commented Mar 21, 2017

@andy-hanson you're right; this can stay on master now. can you merge the latest master?

@andy-hanson
Copy link
Contributor Author

andy-hanson commented Mar 22, 2017

Note: Needed to change typescript devDependency to "next".
And it's still broken in CircleCI... may be best to wait until TS2.3 is actually released.

@adidahiya
Copy link
Contributor

bump @andy-hanson, I think we're unblocked here now

@andy-hanson
Copy link
Contributor Author

Still need to finish the 2.3 upgrade first (#2544)

};
/* tslint:enable:object-literal-sort-keys */

public static FAILURE_STRING = "This is the default value for this type parameter.";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be more descriptive by telling the user what to do, i.e. "This is the default value for this type parameter, it can be omitted."

}
}

interface ArgsAndParams {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's move this higher up in the file since it's used above this line

ctx.addFailureAtNode(arg, Rule.FAILURE_STRING, fix());
}

function fix(): Lint.Fix {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: name this createFix()

case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.ClassExpression:
case ts.SyntaxKind.TypeAliasDeclaration:
return (decl as ts.ClassLikeDeclaration | ts.TypeAliasDeclaration).typeParameters;
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm... how about this

import { isClassLikeDeclaration, isTypeAliasDeclaration } from "tsutils";

for (const decl of sym.declarations) {
    if (isClassLikeDeclaration(decl) || isTypeAliasDeclaration(decl)) {
        return decl.typeParameters;
    }
}

@@ -1,7 +1,4 @@
{
"linterOptions": {
"typeCheck": true
},
Copy link
Contributor

Choose a reason for hiding this comment

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

this change is unrelated, please revert...

class D extends C<number> {}
~~~~~~ [0]

[0]: This is the default value for this type parameter.
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some tests for interfaces too?

@adidahiya adidahiya modified the milestones: TSLint v5.5, TSLint v5.4 May 24, 2017
@adidahiya adidahiya merged commit 3088a2d into palantir:master May 25, 2017
@adidahiya adidahiya modified the milestones: TSLint v5.4, TSLint v5.5 May 25, 2017
@andy-hanson andy-hanson deleted the use-default-type-parameter branch May 25, 2017 23:45
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