Skip to content

Commit

Permalink
chore: enabled restrict-template-expressions internally (#3854)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg committed Sep 20, 2021
1 parent 5ec9c33 commit 955d7a6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.js
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
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
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
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
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

0 comments on commit 955d7a6

Please sign in to comment.