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

fix(eslint-plugin): [ban-types] update message to suggest object instead of Record<string, unknown> #6079

Merged
merged 19 commits into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 14 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
17 changes: 6 additions & 11 deletions packages/eslint-plugin/src/rules/ban-types.ts
Expand Up @@ -3,16 +3,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils';

import * as util from '../util';

type Types = Record<
string,
| null
| false
| string
| {
message: string;
fixWith?: string;
}
>;
kmin-jeong marked this conversation as resolved.
Show resolved Hide resolved
type Types = string | number | boolean | undefined | null | object;

export type Options = [
{
Expand Down Expand Up @@ -173,7 +164,11 @@ export default util.createRule<Options, MessageIds>({
typeNode: TSESTree.Node,
name = stringifyNode(typeNode, context.getSourceCode()),
): void {
const bannedType = bannedTypes.get(name);
type checkrequiredTypes =
| string
| false
| { fixWith?: string; message: string };
const bannedType = bannedTypes.get(name) as checkrequiredTypes;

if (bannedType === undefined || bannedType === false) {
return;
Expand Down
33 changes: 33 additions & 0 deletions packages/eslint-plugin/tests/rules/ban-types.test.ts
Expand Up @@ -388,6 +388,39 @@ let b: Foo<NS.Good>;
},
],
},

{
code: noFormat`
declare let j: unknown;
let m3 = { ...(j as Record<string, never>) };
`,
output: `
declare let j: unknown;
let m3 = { ...(j as object) };
`,
options: [
{
types: {
'Record<string, never>': {
message: 'Use object instead.',
fixWith: 'object',
},
},
},
],
errors: [
{
messageId: 'bannedTypeMessage',
data: {
name: 'Record<string,never>',
customMessage: ' Use object instead.',
},
line: 3,
column: 21,
},
],
},

JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
{
code: noFormat`
let foo: {} = {};
Expand Down