import { TSESLint } from '@typescript-eslint/experimental-utils' ; import { ruleTester } from '../rule-tester' ; import rule = require ( '../../src/rules/no-inverted-boolean-check' ) ; ruleTester . run ( 'no-inverted-boolean-check' , rule , { valid : [ { code : `if (!x) {}` , } , { code : `if (x == 1) {}` , } , { code : `if (!(x + 1)) {}` , } , { code : `if (+(x == 1)) {}` , } , { code : `!x ? 2 : 3` , } , ] , invalid : [ { code : `if (!(x == 1)) {}` , errors : [ { ... message ( '!=' ) , line : 1 , endLine : 1 , column : 5 , endColumn : 14 , } , ] , output : `if (x != 1) {}` , } , { code : `if (!(x != 1)) {}` , errors : [ message ( '==' ) ] , output : `if (x == 1) {}` , } , { code : `if (!(x === 1)) {}` , errors : [ message ( '!==' ) ] , output : `if (x !== 1) {}` , } , { code : `if (!(x !== 1)) {}` , errors : [ message ( '===' ) ] , output : `if (x === 1) {}` , } , { code : `if (!(x > 1)) {}` , errors : [ message ( '<=' ) ] , output : `if (x <= 1) {}` , } , { code : `if (!(x < 1)) {}` , errors : [ message ( '>=' ) ] , output : `if (x >= 1) {}` , } , { code : `if (!(x >= 1)) {}` , errors : [ message ( '<' ) ] , output : `if (x < 1) {}` , } , { code : `if (!(x <= 1)) {}` , errors : [ message ( '>' ) ] , output : `if (x > 1) {}` , } , { code : `!(x != 1) ? 1 : 2` , errors : [ message ( '==' ) ] , output : `x == 1 ? 1 : 2` , } , { code : `foo(!(x === 1))` , errors : [ message ( '!==' ) ] , output : `foo(x !== 1)` , } , { code : `let foo = !(x <= 4)` , errors : [ message ( '>' ) ] , output : `let foo = x > 4` , } , { code : `let foo = !!(a < b)` , errors : [ message ( '>=' ) ] , output : 'let foo = !(a >= b)' , } , ] , } ) ; function message ( invertedOperator ) { return { messageId : 'useOppositeOperator' , data : { invertedOperator } } ; }