Skip to content

Commit

Permalink
Merge pull request #63 from worksome/JIRA-13724_single-quote
Browse files Browse the repository at this point in the history
feat(ecs): JIRA-13724 Add `single_quote`
  • Loading branch information
owenvoke authored Oct 11, 2024
2 parents 3fd2ce8 + d5fca8e commit 2b5cff3
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 34 deletions.
14 changes: 7 additions & 7 deletions src/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GenerateCommand extends BaseCommand
{
protected function configure()
{
$this->setName("generate-coding-style-stubs");
$this->setName('generate-coding-style-stubs');
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -24,7 +24,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
];

foreach ($files as $newFile => $oldFile) {
$path = sprintf("%s/%s", getcwd(), $newFile);
$path = sprintf('%s/%s', getcwd(), $newFile);
if (file_exists($path)) {
$output->writeln("$newFile already exist. Skipping...");
continue;
Expand All @@ -36,11 +36,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->tryComposer()->getConfig()->merge([
'scripts' => [
"ecs" => "vendor/bin/ecs",
"ecs:fix" => "vendor/bin/ecs --fix",
"phpstan" => "vendor/bin/phpstan analyse",
"rector" => "vendor/bin/rector process --dry-run --ansi",
"rector:fix" => "vendor/bin/rector process --ansi",
'ecs' => 'vendor/bin/ecs',
'ecs:fix' => 'vendor/bin/ecs --fix',
'phpstan' => 'vendor/bin/phpstan analyse',
'rector' => 'vendor/bin/rector process --dry-run --ansi',
'rector:fix' => 'vendor/bin/rector process --ansi',
]
]);

Expand Down
2 changes: 1 addition & 1 deletion src/Rector/Generic/DisallowedAttributesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getRuleDefinition(): RuleDefinition
#[NotAllowed]
class MyClass {}
PHP,
"class MyClass {}",
'class MyClass {}',
)
]
);
Expand Down
4 changes: 2 additions & 2 deletions src/Sniffs/Classes/ExceptionSuffixSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ExceptionSuffixSniff implements Sniff
{
public string $suffix = "Exception";
public string $suffix = 'Exception';

public function register(): array
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addError(
"Exceptions should have `Exception` suffix.",
'Exceptions should have `Exception` suffix.',
$classNamePointer,
self::class,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Sniffs/Comments/DisallowTodoCommentsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addError(
"Comments with TODO are disallowed",
'Comments with TODO are disallowed',
$stackPtr,
self::class
);
Expand Down
2 changes: 1 addition & 1 deletion src/Sniffs/Enums/PascalCasingEnumCasesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addError(
"Enum cases MUST be PascalCase",
'Enum cases MUST be PascalCase',
$nameRef,
self::class
);
Expand Down
6 changes: 3 additions & 3 deletions src/Sniffs/Functions/DisallowCompactUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addFixableError(
"Usage of compact function is disallowed.",
'Usage of compact function is disallowed.',
$stackPtr,
self::class
);
Expand All @@ -37,7 +37,7 @@ public function process(File $phpcsFile, $stackPtr)
foreach (range(1, $lastTokenPointer - 1) as $currentPointer) {
$phpcsFile->fixer->replaceToken(
$stackPtr + $currentPointer,
""
''
);
}

Expand All @@ -58,7 +58,7 @@ private function generatePhpArray(array $variables): string
// Remove the trailing `, ` from the array.
$phpCode = substr($phpCode, 0, -2);
// Close the array
$phpCode .= "]";
$phpCode .= ']';

return $phpCode;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sniffs/Laravel/ConfigFilenameKebabCaseSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addError(
"Config files should be named with kebab-case.",
'Config files should be named with kebab-case.',
0,
self::class,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function process(File $phpcsFile, $stackPtr): void
}

$phpcsFile->addError(
"Blade files must be placed in the resources directory.",
'Blade files must be placed in the resources directory.',
$stackPtr,
self::class
);
Expand Down
2 changes: 1 addition & 1 deletion src/Sniffs/Laravel/DisallowEnvUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addError(
"Usage of env in non-config file is disallowed.",
'Usage of env in non-config file is disallowed.',
$stackPtr,
self::class
);
Expand Down
8 changes: 4 additions & 4 deletions src/Sniffs/Laravel/DisallowHasFactorySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class DisallowHasFactorySniff implements Sniff
{
private const HAS_FACTORY_FQCN = "Illuminate\\Database\\Eloquent\\Factories\\HasFactory";
private const HAS_FACTORY_FQCN = 'Illuminate\\Database\\Eloquent\\Factories\\HasFactory';

private string|null $partial = null;

Expand All @@ -34,7 +34,7 @@ public function process(File $phpcsFile, $stackPtr)
private function isHasFactoryNamespace(string $givenNamespace): bool
{
if ($this->partial !== null && strlen($this->partial) > 0) {
$givenNamespace = $this->partial . Str::after($givenNamespace, Str::afterLast($this->partial, "\\"));
$givenNamespace = $this->partial . Str::after($givenNamespace, Str::afterLast($this->partial, '\\'));
}

if ($givenNamespace !== self::HAS_FACTORY_FQCN) {
Expand All @@ -47,7 +47,7 @@ private function isHasFactoryNamespace(string $givenNamespace): bool
private function trackRelevantPartialNamespace(string $givenNamespace): void
{
Str::of(self::HAS_FACTORY_FQCN)
->explode("\\")
->explode('\\')
->skip(1)
->reduce(function (string $carry, string $item) use ($givenNamespace) {
$updatedNamespacePartial = "{$carry}\\{$item}";
Expand All @@ -63,7 +63,7 @@ private function trackRelevantPartialNamespace(string $givenNamespace): void
private function addError(File $phpcsFile, int $line): void
{
$phpcsFile->addError(
"Models should not use the `HasFactory` trait.",
'Models should not use the `HasFactory` trait.',
$line,
self::class,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Sniffs/Laravel/EventListenerSuffixSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class EventListenerSuffixSniff implements Sniff
{
public string $suffix = "Listener";
public string $suffix = 'Listener';

public function register(): array
{
Expand All @@ -35,7 +35,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addError(
"Listeners should have `Listener` suffix.",
'Listeners should have `Listener` suffix.',
$classNamePointer,
self::class,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Sniffs/PhpDoc/DisallowParamNoTypeOrCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addFixableError(
"@param tags with no type or comment are disallowed",
'@param tags with no type or comment are disallowed',
$stackPtr,
self::class
);

foreach (range(-4, 2) as $pointer) {
$phpcsFile->fixer->replaceToken(
$stackPtr + $pointer,
""
''
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sniffs/PhpDoc/PropertyDollarSignSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$phpcsFile->addFixableError(
"All @property variables should start with a dollar symbol.",
'All @property variables should start with a dollar symbol.',
$stackPtr,
self::class
);
Expand Down
2 changes: 2 additions & 0 deletions src/WorksomeEcsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer;
use PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer;
use PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\LineEndingFixer;
use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer;
use SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff;
Expand Down Expand Up @@ -200,6 +201,7 @@ public static function setup(ECSConfig $ecsConfig): void
PropertyDollarSignSniff::class,
TypesSpacesFixer::class,
PascalCasingEnumCasesSniff::class,
SingleQuoteFixer::class,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$lineNumber,
], [4, 5, 6]);

expect(__DIR__ . "/Fixture/app_helper_environment_checks.php.inc")->toHaveRuleErrors($errors);
expect(__DIR__ . '/Fixture/app_helper_environment_checks.php.inc')->toHaveRuleErrors($errors);
});

it('checks for environment checks made using the app facade', function () {
Expand All @@ -23,7 +23,7 @@
$lineNumber,
], [4, 5, 6, 9, 10, 11]);

expect(__DIR__ . "/Fixture/app_facade_environment_checks.php.inc")->toHaveRuleErrors($errors);
expect(__DIR__ . '/Fixture/app_facade_environment_checks.php.inc')->toHaveRuleErrors($errors);
});

it('checks for environment checks made using an imported app facade', function () {
Expand All @@ -34,7 +34,7 @@
$lineNumber,
], [6, 7, 8]);

expect(__DIR__ . "/Fixture/imported_app_facade_environment_checks.php.inc")->toHaveRuleErrors($errors);
expect(__DIR__ . '/Fixture/imported_app_facade_environment_checks.php.inc')->toHaveRuleErrors($errors);
});

it('checks for environment checks made using the application contract', function () {
Expand All @@ -45,5 +45,5 @@
$lineNumber,
], [6, 10]);

expect(__DIR__ . "/Fixture/application_class_environment_checks.php.inc")->toHaveRuleErrors($errors);
expect(__DIR__ . '/Fixture/application_class_environment_checks.php.inc')->toHaveRuleErrors($errors);
});
4 changes: 2 additions & 2 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

Assert::assertEmpty(
$value->getErrors(),
"The following errors were found: " . PHP_EOL . json_encode($value->getErrors())
'The following errors were found: ' . PHP_EOL . json_encode($value->getErrors())
);

return $this;
Expand Down Expand Up @@ -144,7 +144,7 @@ function getSniffName(string $sniffClassName): string
{
$dotted = preg_replace(
[
"~\\\\~",
'~\\\\~',
'~\.Sniffs~',
'~Sniff$~',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Rector/BaseRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ abstract class BaseRectorTestCase extends AbstractRectorTestCase
{
public function provideConfigFilePath(): string
{
return Str::beforeLast(invade($this)->__filename, "/") . '/config/configured_rule.php';
return Str::beforeLast(invade($this)->__filename, '/') . '/config/configured_rule.php';
}
}

0 comments on commit 2b5cff3

Please sign in to comment.