Skip to content

Commit

Permalink
Feat: Require comparisons to be strict (fixes #90)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 23, 2024
1 parent 0551ba6 commit 1be476c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer;
use PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
Expand Down Expand Up @@ -358,6 +359,8 @@
DeclareStrictTypesFixer::class,
// Functions should be used with `$strict` param set to `true`
StrictParamFixer::class,
// Comparisons should be strict, `===` or `!==` must be used for comparisons
StrictComparisonFixer::class,
// Convert double quotes to single quotes for simple strings
SingleQuoteFixer::class,
// Remove extra spaces in a nullable typehint
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Basic
$lambdaWithUnusedImport = function () { return 'foo'; };
// NoUselessSprintfFixer
$uselessSprintf = 'bar';
// SingleSpaceAfterConstructFixer
if ($a == $b) {
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a === $b || $bazLength !== 3) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Basic
$lambdaWithUnusedImport = function () use ($fooBar) { return 'foo'; };
// NoUselessSprintfFixer
$uselessSprintf = sprintf('bar');
// SingleSpaceAfterConstructFixer
if ($a == $b) { return true; }
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a == $b || $bazLength != 3) { return true; }
return false; // BlankLineBeforeStatementFixer
}

Expand Down

0 comments on commit 1be476c

Please sign in to comment.