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

Convert no-any-union from TSLint to ESLint #526

Merged
merged 2 commits into from Dec 29, 2022
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
1 change: 0 additions & 1 deletion packages/dtslint/dtslint.json
Expand Up @@ -9,7 +9,6 @@
"redundant-undefined": true,
"no-relative-import-in-test": true,
"strict-export-declare-modifiers": true,
"no-any-union": true,
"no-single-declare-module": true,
"prefer-declare-function": true,
"unified-signatures": true,
Expand Down
34 changes: 34 additions & 0 deletions packages/dtslint/src/rules/no-any-union.ts
@@ -0,0 +1,34 @@
import { createRule } from "../util";
import { AST_NODE_TYPES } from "@typescript-eslint/utils";

const rule = createRule({
name: "no-any-union",
defaultOptions: [],
meta: {
type: "problem",
docs: {
description: "Forbid a union to contain `any`",
recommended: "error",
},
messages: {
anyUnion: "Including `any` in a union will override all other members of the union.",
},
schema: [],
},
create(context) {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
TSUnionType(node) {
const hasAnyType = node.types.some((t) => t.type === AST_NODE_TYPES.TSAnyKeyword);
if (hasAnyType) {
context.report({
messageId: "anyUnion",
node,
});
}
},
};
},
});

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

This file was deleted.

23 changes: 23 additions & 0 deletions packages/dtslint/test/no-any-union.test.ts
@@ -0,0 +1,23 @@
import { ESLintUtils } from "@typescript-eslint/utils";

import * as noAnyUnion from "../src/rules/no-any-union";

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

ruleTester.run("no-any-union", noAnyUnion, {
invalid: [
{
code: `export const y: string | any;`,
errors: [
{
line: 1,
messageId: "anyUnion",
},
],
},
],
valid: [`export const x: any;`],
});

4 changes: 0 additions & 4 deletions packages/dtslint/test/no-any-union/test.d.ts.lint

This file was deleted.

6 changes: 0 additions & 6 deletions packages/dtslint/test/no-any-union/tslint.json

This file was deleted.