error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary

16,259

Try the good way =). No need to use statements in this case.

$scope.IsVisible = !$scope.IsVisible;
Share:
16,259
manvi77
Author by

manvi77

“I think if you do something and it turns out pretty good, then you should go do something else wonderful, not dwell on it for too long. Just figure out what’s next.” - Steve Jobs

Updated on June 05, 2022

Comments

  • manvi77
    manvi77 almost 2 years

    I am trying this code in atom with ESLint

    Code snippet:

    $scope.IsVisible = false;
    $scope.ShowHide = function () {
      $scope.IsVisible = $scope.IsVisible ? false : true; // error
    };
    

    Got this ESLint error: error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary

    Tried with these solutions solution 1 and solution 2, but error is not fixed. Furthermore, code works fine in editor without ESLint.

  • kylesimmonds
    kylesimmonds about 7 years
    If, like me, you need to check for a true value, use the double bang: !!$scope.IsVisible