Skip to content

Conversation

@jaymcp
Copy link
Contributor

@jaymcp jaymcp commented Mar 10, 2025

This PR adds several new rules that will help us with common code smells:

  • Use statements A-Z
    • must be in alphabetical order
      • SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
  • No unused use statements
    • for if a namespace is being imported, but is not referenced
      • SlevomatCodingStandard.Namespaces.UnusedUses
  • No use statement grouping
    • no use Namespace\{Sub_NS_One,Sub_NS_Two}\Foo
      • SlevomatCodingStandard.Namespaces.DisallowGroupUse
  • Strict equality
    • will shout at you for == or !=
      • SlevomatCodingStandard.Operators.DisallowEqualOperators
  • No increment/decrement
    • will shout at you for $i++ or $i-- (instead of $i += 1 or $i -= 1)
      • Squiz.Operators.IncrementDecrementUsage
      • SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators
  • Generics for array type hints
    • use array<int,string> instead of string[]
      • SlevomatCodingStandard.TypeHints.DisallowArrayTypeHintSyntax
  • Shorthand scalars
    • int and bool instead of integer and boolean in type hint comments (we already have this for the actual type hints)
      • SlevomatCodingStandard.TypeHints.LongTypeHints
  • Nullable in type hints
    • will flag when a param has int $foo = null but comment type hint is not nullable
      • SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue
  • No variable variables
    • disallows $$foo
      • SlevomatCodingStandard.Variables.DisallowVariableVariable
  • No unused variables
    • self explanatory
      • SlevomatCodingStandard.Variables.UnusedVariable
  • No useless variables
    • this will throw when a variable is assigned and then returned
      • SlevomatCodingStandard.Variables.UselessVariable

- Use statements A-Z
- No unused use statements
- No use statement grouping
- Strict equality
- No increment/decrement
- Generics for array type hints
- Shorthand scalars
- Nullable in type hints
- No variable variables
- No unused variables
- No useless variables
@jaymcp jaymcp marked this pull request as ready for review March 10, 2025 15:36
@jaymcp jaymcp requested a review from a team March 10, 2025 15:36
@jaymcp jaymcp merged commit 02a44a6 into main Mar 17, 2025
5 checks passed
@jaymcp jaymcp deleted the feat/new-rules branch March 17, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants