Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Require comparisons to be strict #93

Merged
merged 2 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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
6 changes: 4 additions & 2 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
@@ -14,8 +14,10 @@ class Basic
$lambdaWithUnusedImport = function () { return 'foo'; };
// NoUselessSprintfFixer
$uselessSprintf = 'bar';
// SingleSpaceAfterConstructFixer
if ($a == $b) {
// StrictParamFixer
$useStrictParam = in_array(1337, $fooBar, true);
// SingleSpaceAfterConstructFixer, StrictComparisonFixer
if ($a === $b || $bazLength !== 3) {
return true;
}

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