Skip to content

Commit

Permalink
Use TypeFlags from TypeScript API instead of hardcoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
rayane-djouah committed Oct 3, 2024
1 parent 4ba4cbc commit 46040c1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions eslint-plugin-expensify/boolean-conditional-rendering.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable no-bitwise */
const _ = require('underscore');
const {ESLintUtils} = require('@typescript-eslint/utils');
const ts = require('typescript');

module.exports = {
name: 'boolean-conditional-rendering',
Expand All @@ -22,11 +24,20 @@ module.exports = {
}
function isBoolean(type) {
return (
// eslint-disable-next-line no-bitwise
(type.getFlags() & (16 | 528 | 512)) !== 0 // TypeFlags.Boolean | TypeFlags.BooleanLike | TypeFlags.BooleanLiteral
(type.getFlags()
& (ts.TypeFlags.Boolean
| ts.TypeFlags.BooleanLike
| ts.TypeFlags.BooleanLiteral))
!== 0
|| (type.isUnion()
// eslint-disable-next-line no-bitwise
&& _.every(type.types, t => (t.getFlags() & (16 | 528 | 512)) !== 0))
&& _.every(
type.types,
t => (t.getFlags()
& (ts.TypeFlags.Boolean
| ts.TypeFlags.BooleanLike
| ts.TypeFlags.BooleanLiteral))
!== 0,
))
);
}
const parserServices = ESLintUtils.getParserServices(context);
Expand Down

0 comments on commit 46040c1

Please sign in to comment.