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

chore: enabled restrict-template-expressions internally #3854

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
12 changes: 10 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ module.exports = {
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
allowAny: true,
allowNullish: true,
allowRegExp: true,
},
],
'@typescript-eslint/no-unused-vars': [
'warn',
{ varsIgnorePattern: '^_', argsIgnorePattern: '^_' },
],

// TODO - enable these new recommended rules
'@typescript-eslint/restrict-template-expressions': 'off',
// TODO - enable this
'@typescript-eslint/naming-convention': 'off',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default createRule({
missingBranches: missingBranchTypes
.map(missingType =>
isTypeFlagSet(missingType, ts.TypeFlags.ESSymbolLike)
? `typeof ${missingType.getSymbol()?.escapedName}`
? `typeof ${missingType.getSymbol()?.escapedName as string}`
: checker.typeToString(missingType),
)
.join(' | '),
Expand Down
2 changes: 1 addition & 1 deletion packages/scope-manager/tests/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function nestDescribe(
throw new Error(
`Expected value for ${key} to be one of (${Array.from(type[1]).join(
' | ',
)}), but got ${value}`,
)}), but got ${value as string}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const EXCLUDED_KEYS = new Set([

const generator = createIdGenerator();
type Node = Record<string, unknown> & { type: AST_NODE_TYPES };
type Identifier = Node & { name: string; type: AST_NODE_TYPES.Identifier };
const SEEN_NODES = new Map<Node, number>();

const serializer: NewPlugin = {
Expand All @@ -29,7 +30,7 @@ const serializer: NewPlugin = {
},
serialize(node: Node): string {
if (node.type === AST_NODE_TYPES.Identifier) {
return `Identifier<"${node.name}">`;
return `Identifier<"${(node as Identifier).name}">`;
}

const keys = Object.keys(node).filter(k => !EXCLUDED_KEYS.has(k));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function createSerializer<TConstructor extends ConstructorSignature>(
}

outputLines.push(
`${childIndentation}${key}: ${printer(
`${childIndentation}${key as string}: ${printer(
value,
config,
childIndentation,
Expand Down