Skip to content

Commit

Permalink
Convert no-any-union from TSLint to ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMunoz committed Aug 23, 2022
1 parent 9854c97 commit d7e6ec7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 44 deletions.
1 change: 0 additions & 1 deletion packages/dtslint/dtslint.json
Expand Up @@ -11,7 +11,6 @@
"redundant-undefined": true,
"no-relative-import-in-test": true,
"strict-export-declare-modifiers": true,
"no-any-union": true,
"no-single-declare-module": true,
"no-unnecessary-generics": true,
"no-useless-files": 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 hasAny = node.types.some((t) => t.type === AST_NODE_TYPES.TSAnyKeyword);
if (hasAny) {
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.

0 comments on commit d7e6ec7

Please sign in to comment.