Skip to content

Commit

Permalink
Converted no-single-element-tuple-type from TSLint to ESLint (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Mar 24, 2023
1 parent f02f34c commit 214c7bd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 43 deletions.
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) {
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.

0 comments on commit 214c7bd

Please sign in to comment.