Skip to content

Commit

Permalink
Merge pull request #29 from worksome/feature/upper-snake-case-enum-cases
Browse files Browse the repository at this point in the history
fix: resolve correct name conversion for enum cases
  • Loading branch information
owenvoke authored Feb 13, 2023
2 parents a6cee1b + 84acebd commit ec1cbc1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"symfony/config": "^6.0",
"symplify/autowire-array-parameter": "^11.0",
"symplify/package-builder": "^11.0",
"thecodingmachine/safe": "^2.2"
"thecodingmachine/safe": "^2.2",
"jawira/case-converter": "^3.5"
},
"require-dev": {
"pestphp/pest": "^1.21",
Expand Down
10 changes: 2 additions & 8 deletions src/Fixes/UpperSnakeCaseNameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Worksome\Graphlint\Fixes;

use GraphQL\Language\AST\NameNode;
use Illuminate\Support\Str;
use Jawira\CaseConverter\Convert;
use Worksome\Graphlint\ProblemDescriptor;
use Worksome\Graphlint\Utils\NodeNameResolver;

Expand All @@ -30,12 +30,6 @@ public function fix(ProblemDescriptor $problemDescriptor): void
return;
}

$upperCase = Str::of($name)
->replace('_', ' ')
->title()
->snake()
->upper();

$node->value = $upperCase->__toString();
$node->value = (new Convert($name))->toMacro();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Worksome\Graphlint\Inspections;

use GraphQL\Language\AST\EnumValueDefinitionNode;
use Illuminate\Support\Str;
use Jawira\CaseConverter\Convert;
use Worksome\Graphlint\Fixes\UpperSnakeCaseNameFixer;
use Worksome\Graphlint\InspectionDescription;
use Worksome\Graphlint\ProblemsHolder;
Expand Down Expand Up @@ -35,7 +35,7 @@ public function visitEnumValueDefinition(
return;
}

$upperCase = Str::of($name)->replace('_', ' ')->title()->snake()->upper()->__toString();
$upperCase = (new Convert($name))->toMacro();

if ($name === $upperCase) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Status {
inProgress
}
-----
enum Status {
IN_PROGRESS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Status {
InProgress
}
-----
enum Status {
IN_PROGRESS
}

0 comments on commit ec1cbc1

Please sign in to comment.