Skip to content

Commit

Permalink
add dump-editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 8, 2024
1 parent 1ee7c9a commit 174f9a0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 22 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Downloads total](https://img.shields.io/packagist/dt/symplify/easy-ci.svg?style=flat-square)](https://packagist.org/packages/symplify/easy-ci/stats)

Tools that make easy to setup CI.
Swiss knife in pocket of every upgrade architect!

- Check git conflicts in CI
<br>

## Install

Expand All @@ -16,23 +16,19 @@ composer require symplify/easy-ci --dev

### 1. Check your Code for Git Merge Conflicts

Do you use Git? Then merge conflicts is not what you want in your code ever to see:
Do you use Git? Then merge conflicts is not what you want in your code ever to see in pushed code:

```bash
<<<<<<< HEAD
this is some content to mess with
content to append
=======
totally different content to merge later
````

How to avoid it? Add check to your CI:
Add this command to CI to spot these:

```bash
vendor/bin/easy-ci check-conflicts .
```

The `/vendor` directory is excluded by default.
*Note: The `/vendor` directory is excluded by default.*

<br>

Expand All @@ -46,7 +42,7 @@ Have you ever forgot commented code in your code?
// }
```
Clutter no more! Add `check-commented-code` command to your CI and don't worry about it:
No more! Add this command to CI to spot these:
```bash
vendor/bin/easy-ci check-commented-code <directory>
Expand All @@ -55,7 +51,9 @@ vendor/bin/easy-ci check-commented-code packages --line-limit 5
<br>
### 3. Find multiple classes in single file
### 3. Reach full PSR-4
#### Find multiple classes in single file
To make PSR-4 work properly, each class must be in its own file. This command makes it easy to spot multiple classes in single file:
Expand All @@ -65,7 +63,7 @@ vendor/bin/easy-ci find-multi-classes src
<br>
### 4. Update Namespace to match PSR-4 Root
#### Update Namespace to match PSR-4 Root
Is your class in wrong namespace? Make it match your PSR-4 root:
Expand Down
1 change: 0 additions & 1 deletion build/rector-downgrade-php-72.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
$rectorConfig->skip([
'*/Tests/*',
'*/tests/*',
__DIR__ . '/../../tests',
]);
};
2 changes: 1 addition & 1 deletion build/target-repository/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "symplify/easy-ci",
"description": "Toolkit of commands that should not be missed in you CI",
"description": "Swiss knife in pocket of every upgrade architect",
"license": "MIT",
"require": {
"php": ">=7.2"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "symplify/easy-ci",
"description": "Toolkit of commands that should not be missed in you CI",
"description": "Swiss knife in pocket of every upgrade architect",
"license": "MIT",
"bin": [
"bin/easy-ci"
Expand Down
40 changes: 40 additions & 0 deletions src/Command/DumpEditorconfigCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Symplify\EasyCI\Command;

use Nette\Utils\FileSystem;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

final class DumpEditorconfigCommand extends Command
{
public function __construct(
private readonly SymfonyStyle $symfonyStyle,
) {
parent::__construct();
}

protected function configure(): void
{
$this->setName('dump-editorconfig');
$this->setDescription('Dump .editorconfig file to project root');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$projectEditorconfigFilePath = getcwd() . '/.editorconfig';
if (file_exists($projectEditorconfigFilePath)) {
$this->symfonyStyle->error('.editorconfig file already exists');
return self::FAILURE;
}

FileSystem::copy(__DIR__ . '/../../templates/.editorconfig', $projectEditorconfigFilePath);
$this->symfonyStyle->success('.editorconfig file was created');

return self::SUCCESS;
}
}
12 changes: 7 additions & 5 deletions src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symplify\EasyCI\Command\CheckCommentedCodeCommand;
use Symplify\EasyCI\Command\CheckConflictsCommand;
use Symplify\EasyCI\Command\DumpEditorconfigCommand;
use Symplify\EasyCI\Command\FindMultiClassesCommand;
use Symplify\EasyCI\Command\NamespaceToPSR4Command;
use Symplify\EasyCI\Command\ValidateFileLengthCommand;
Expand All @@ -26,11 +27,6 @@ public function create(): Container
$container = new Container();

// console
$container->singleton(
SymfonyStyle::class,
static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())
);

$container->singleton(Application::class, function (Container $container): Application {
$application = new Application('Easy CI toolkit');

Expand All @@ -41,6 +37,7 @@ public function create(): Container
$container->make(DetectUnitTestsCommand::class),
$container->make(FindMultiClassesCommand::class),
$container->make(NamespaceToPSR4Command::class),
$container->make(DumpEditorconfigCommand::class),
];

$application->addCommands($commands);
Expand All @@ -51,6 +48,11 @@ public function create(): Container
return $application;
});

$container->singleton(
SymfonyStyle::class,
static fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())
);

return $container;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Testing/Command/DetectUnitTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ protected function configure(): void
{
$this->setName('detect-unit-tests');

$this->setDescription('Get list of tests in specific directory, that are considered "unit".
They depend only on bare PHPUnit test case, but not on KernelTestCase. Move the generated file to your phpunit.xml test group.');
$this->setDescription('Get list of tests in specific directory, that are considered "unit"');

$this->addArgument(
Option::SOURCES,
Expand Down
9 changes: 9 additions & 0 deletions templates/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

0 comments on commit 174f9a0

Please sign in to comment.