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

Implement new rules for further conformity checking #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaymcp
Copy link
Member

@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
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.

1 participant