Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted no-single-element-tuple-type from TSLint to ESLint #653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/dtslint/src/rules/no-single-element-tuple-type.ts
@@ -0,0 +1,31 @@
import { createRule } from "../util";
import { TSESTree } from "@typescript-eslint/utils";

const rule = createRule({
name: "no-single-element-tuple-type",
defaultOptions: [],
meta: {
type: "problem",
docs: {
description: "Forbids `[T]`, which should be `T[]`.",
recommended: "error",
},
messages: {
singleElementTupleType: `Type [T] is a single-element tuple type. You probably meant T[].`,
},
schema: [],
},
create(context) {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
"TSTupleType[elementTypes.length=1]"(node: TSESTree.TSTupleType) {
Copy link
Member

Choose a reason for hiding this comment

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

fancy!

context.report({
messageId: "singleElementTupleType",
node,
});
},
};
},
});

export = rule;
32 changes: 0 additions & 32 deletions packages/dtslint/src/rules/noSingleElementTupleTypeRule.ts

This file was deleted.

28 changes: 28 additions & 0 deletions packages/dtslint/test/no-single-element-tuple-type.test.ts
@@ -0,0 +1,28 @@
import { ESLintUtils } from "@typescript-eslint/utils";

import * as noDeclareCurrentPackage from "../src/rules/no-single-element-tuple-type";

const ruleTester = new ESLintUtils.RuleTester({
parser: "@typescript-eslint/parser",
});

ruleTester.run("no-single-element-tuple-type", noDeclareCurrentPackage, {
invalid: [
{
code: `type Test<T> = [T];`,
errors: [
{
line: 1,
messageId: "singleElementTupleType",
},
],
},
],
valid: [
`type Test = number[];`,
`type Test<T> = T;`,
`type Test<T> = T[];`,
`type Test<T> = [T, number];`,
`type Test<T> = [T, T];`,
],
});

This file was deleted.

This file was deleted.