Skip to content

Commit

Permalink
[deprecated] Drop regex rules, as too nitpicking, in times of GPT poi…
Browse files Browse the repository at this point in the history
…ntless (#151)

* [deprecated] Drop regex rules, as too nitpicking, in times of GPT pointless

* [docs] avoid using sets as too complicated and bloated, use particular rules instead
  • Loading branch information
TomasVotruba authored Dec 16, 2024
1 parent 2eacb49 commit 0ffb1c0
Show file tree
Hide file tree
Showing 29 changed files with 2 additions and 916 deletions.
162 changes: 2 additions & 160 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,84 +16,9 @@ composer require symplify/phpstan-rules --dev

<br>

## A. Add Prepared Sets
## Register Rules you Need

Sets are bunch of rules grouped by a common area, e.g. improve naming. You can pick from 5 sets:

```yaml
includes:
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
- vendor/symplify/phpstan-rules/config/naming-rules.neon
- vendor/symplify/phpstan-rules/config/regex-rules.neon
- vendor/symplify/phpstan-rules/config/static-rules.neon
```
<br>
## B. Cherry-pick Configurable Rules
There is one set with pre-configured configurable rules. Include it and see what is errors are found:
```yaml
# phpstan.neon
includes:
- vendor/symplify/phpstan-rules/config/configurable-rules.neon
```
<br>
Would you like to tailor it to fit your taste? Pick one PHPStan rule and configure it manually ↓
```yaml
services:
-
class: Symplify\PHPStanRules\Rules\ForbiddenNodeRule
tags: [phpstan.rules.rule]
arguments:
forbiddenNodes:
- PhpParser\Node\Expr\Empty_
- PhpParser\Node\Stmt\Switch_
```
<br>
## 3. Register Particular Rules
<br>
# 30 Rules Overview
## AnnotateRegexClassConstWithRegexLinkRule
Add regex101.com link to that shows the regex in practise, so it will be easier to maintain in case of bug/extension in the future
```yaml
rules:
- Symplify\PHPStanRules\Rules\AnnotateRegexClassConstWithRegexLinkRule
```
```php
class SomeClass
{
private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
}
```

:x:

<br>

```php
class SomeClass
{
/**
* @see https://regex101.com/r/SZr0X5/12
*/
private const COMPLICATED_REGEX = '#some_complicated_stu|ff#';
}
```

:+1:
Pick from 25+ rules:

<br>

Expand Down Expand Up @@ -562,48 +487,6 @@ class SomeClass

<br>

## NoInlineStringRegexRule

Use local named constant instead of inline string for regex to explain meaning by constant name

```yaml
rules:
- Symplify\PHPStanRules\Rules\NoInlineStringRegexRule
```
```php
class SomeClass
{
public function run($value)
{
return preg_match('#some_stu|ff#', $value);
}
}
```

:x:

<br>

```php
class SomeClass
{
/**
* @var string
*/
public const SOME_STUFF_REGEX = '#some_stu|ff#';

public function run($value)
{
return preg_match(self::SOME_STUFF_REGEX, $value);
}
}
```

:+1:

<br>

## NoReferenceRule

Use explicit return value over magic &reference
Expand Down Expand Up @@ -895,47 +778,6 @@ class SomeClass extends SomeParentClass

<br>

## RegexSuffixInRegexConstantRule

Name your constant with "_REGEX" suffix, instead of "%s"

```yaml
rules:
- Symplify\PHPStanRules\Rules\RegexSuffixInRegexConstantRule
```
```php
class SomeClass
{
public const SOME_NAME = '#some\s+name#';

public function run($value)
{
$somePath = preg_match(self::SOME_NAME, $value);
}
}
```

:x:

<br>

```php
class SomeClass
{
public const SOME_NAME_REGEX = '#some\s+name#';

public function run($value)
{
$somePath = preg_match(self::SOME_NAME_REGEX, $value);
}
}
```

:+1:

<br>

## RequireAttributeNameRule

Attribute must have all names explicitly defined
Expand Down
4 changes: 0 additions & 4 deletions config/regex-rules.neon

This file was deleted.

2 changes: 0 additions & 2 deletions config/services/services.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ services:
- Symplify\PHPStanRules\Naming\ClassToSuffixResolver
- Symplify\PHPStanRules\NodeAnalyzer\AttributeFinder
- Symplify\PHPStanRules\NodeAnalyzer\EnumAnalyzer
- Symplify\PHPStanRules\NodeAnalyzer\RegexFuncCallAnalyzer
- Symplify\PHPStanRules\NodeAnalyzer\RegexStaticCallAnalyzer
- Symplify\PHPStanRules\ParentClassMethodNodeResolver
- Symplify\PHPStanRules\PhpDoc\BarePhpDocParser
- Symplify\PHPStanRules\PhpDoc\PhpDocResolver
Expand Down
1 change: 0 additions & 1 deletion config/symplify-rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ includes:
- code-complexity-rules.neon
- configurable-rules.neon
- naming-rules.neon
- regex-rules.neon
- static-rules.neon
5 changes: 0 additions & 5 deletions src/Enum/ClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ final class ClassName
*/
public const ROUTE_ATTRIBUTE = 'Symfony\Component\Routing\Annotation\Route';

/**
* @var string
*/
public const NETTE_STRINGS = 'Nette\Utils\Strings';

/**
* @var string
*/
Expand Down
15 changes: 0 additions & 15 deletions src/Enum/RuleIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ final class RuleIdentifier
*/
public const SEE_ANNOTATION_TO_TEST = 'symplify.seeAnnotationToTest';

/**
* @var string
*/
public const REGEX_SUFFIX_IN_REGEX_CONSTANT = 'symplify.regexSuffixInRegexConstant';

/**
* @var string
*/
Expand Down Expand Up @@ -66,11 +61,6 @@ final class RuleIdentifier
*/
public const PARENT_METHOD_VISIBILITY_OVERRIDE = 'symplify.parentMethodVisibilityOverride';

/**
* @var string
*/
public const CLASS_CONSTANT_REGEX = 'symplify.classConstantRegex';

/**
* @var string
*/
Expand Down Expand Up @@ -126,11 +116,6 @@ final class RuleIdentifier
*/
public const FORBIDDEN_ARRAY_METHOD_CALL = 'symplify.forbiddenArrayMethodCall';

/**
* @var string
*/
public const REGEX_ANNOTATE_CLASS_CONST = 'symplify.regexAnnotateClassConst';

/**
* @var string
*/
Expand Down
32 changes: 0 additions & 32 deletions src/NodeAnalyzer/RegexFuncCallAnalyzer.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/NodeAnalyzer/RegexStaticCallAnalyzer.php

This file was deleted.

Loading

0 comments on commit 0ffb1c0

Please sign in to comment.