Skip to content

Commit

Permalink
Bring the options order in sync and add missing allowAny in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrichb committed Apr 14, 2020
1 parent 9ebb323 commit 8d74671
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Expand Up @@ -28,6 +28,8 @@ type Options = {
allowNumber?: boolean;
// if true, also allow boolean type in template expressions
allowBoolean?: boolean;
// if true, also allow any in template expressions
allowAny?: boolean;
// if true, also allow null and undefined in template expressions
allowNullable?: boolean;
};
Expand Down
20 changes: 10 additions & 10 deletions packages/eslint-plugin/src/rules/restrict-template-expressions.ts
Expand Up @@ -7,10 +7,10 @@ import * as util from '../util';

type Options = [
{
allowNullable?: boolean;
allowNumber?: boolean;
allowBoolean?: boolean;
allowAny?: boolean;
allowNullable?: boolean;
},
];

Expand All @@ -33,10 +33,10 @@ export default util.createRule<Options, MessageId>({
{
type: 'object',
properties: {
allowAny: { type: 'boolean' },
allowNumber: { type: 'boolean' },
allowBoolean: { type: 'boolean' },
allowAny: { type: 'boolean' },
allowNullable: { type: 'boolean' },
allowNumber: { type: 'boolean' },
},
},
],
Expand All @@ -51,13 +51,6 @@ export default util.createRule<Options, MessageId>({
return true;
}

if (
options.allowNullable &&
util.isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined)
) {
return true;
}

if (
options.allowNumber &&
util.isTypeFlagSet(
Expand All @@ -79,6 +72,13 @@ export default util.createRule<Options, MessageId>({
return true;
}

if (
options.allowNullable &&
util.isTypeFlagSet(type, ts.TypeFlags.Null | ts.TypeFlags.Undefined)
) {
return true;
}

return false;
}

Expand Down

0 comments on commit 8d74671

Please sign in to comment.