Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions build/target-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,27 +248,6 @@ vendor/bin/ecs list-checkers --output-format json

<br>

### Can I Use My [`.editorconfig`](https://editorconfig.org/)?

Mostly! By using `->withEditorConfig()` in `ecs.php`, ECS will automatically discover
the `.editorconfig` file in the project's root directory. It will use any
rules under `[*]` or `[*.php]` (the latter taking priority) and respect the
settings for:

- `indent_style`
- `end_of_line`
- `max_line_length`
- `trim_trailing_whitespace`
- `insert_final_newline`
- [`quote_type`](https://github.com/jednano/codepainter#quote_type-single-double-auto)
- Only `single` and `auto` are respected.
- Warning: this is a proposed field, but not fully standard.

These settings will take precedence over similar rules configured through sets
like PSR12, to avoid conflicting with other tooling using your `.editorconfig`.

<br>

## How to Migrate from another coding standard tool?

Do you use another tool and want to migrate? It's pretty straightforward - here is "how to":
Expand Down
1 change: 0 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

return ECSConfig::configure()
->withPaths([__DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/packages', __DIR__ . '/src', __DIR__ . '/tests'])
->withEditorConfig()
->withRootFiles()
->withSkip(['*/Source/*', '*/Fixture/*'])
->withPreparedSets(psr12: true, common: true);
99 changes: 8 additions & 91 deletions src/Configuration/ECSConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,13 @@
use Entropy\Console\Output\OutputColorizer;
use Entropy\Console\Output\OutputPrinter;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\EndFileNewlineSniff as GenericEndFileNewlineSniff;
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\EndFileNoNewlineSniff;
use PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff as Psr2EndFileNewlineSniff;
use PHP_CodeSniffer\Standards\Squiz\Sniffs\Strings\DoubleQuoteUsageSniff;
use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
use PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer;
use PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer;
use Symfony\Component\Finder\Finder;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\Config\Level\ArrayLevel;
use Symplify\EasyCodingStandard\Config\Level\ControlStructuresLevel;
use Symplify\EasyCodingStandard\Config\Level\DocblockLevel;
use Symplify\EasyCodingStandard\Config\Level\SpacesLevel;
use Symplify\EasyCodingStandard\Configuration\EditorConfig\EditorConfigFactory;
use Symplify\EasyCodingStandard\Configuration\EditorConfig\EndOfLine;
use Symplify\EasyCodingStandard\Configuration\EditorConfig\IndentStyle;
use Symplify\EasyCodingStandard\Configuration\EditorConfig\QuoteType;
use Symplify\EasyCodingStandard\Configuration\Levels\LevelRulesResolver;
use Symplify\EasyCodingStandard\Exception\Configuration\InitializationException;
use Symplify\EasyCodingStandard\Exception\Configuration\SuperfluousConfigurationException;
Expand Down Expand Up @@ -89,8 +76,6 @@ final class ECSConfigBuilder

private ?bool $reportingRealPath = null;

private ?bool $useEditorConfig = null;

/**
* To make sure each common set and its corresponding level are not
* duplicated, as both contain the same rules.
Expand All @@ -105,8 +90,6 @@ final class ECSConfigBuilder

public function __invoke(ECSConfig $ecsConfig): void
{
$this->applyEditorConfigSettings();

$this->assertLevelAndSetNotMixed($this->isArrayLevelUsed, SetList::ARRAY, 'array', 'withArrayLevel');

$this->assertLevelAndSetNotMixed(
Expand Down Expand Up @@ -382,10 +365,15 @@ public function withCache(?string $directory = null, ?string $namespace = null):
return $this;
}

public function withEditorConfig(bool $enabled = true): self
/**
* @deprecated EditorConfig support is deprecated, as it leaks project-wide settings into ECS. Configure the matching PHP-CS-Fixer rules explicitly instead.
*/
public function withEditorConfig(): self
{
$this->useEditorConfig = $enabled;

$outputPrinter = new OutputPrinter(new OutputColorizer());
$outputPrinter->warning(
'The "withEditorConfig()" method is deprecated, as it leaks project-wide settings into ECS. Configure the matching PHP-CS-Fixer rules explicitly instead.'
);
return $this;
}

Expand Down Expand Up @@ -547,75 +535,4 @@ private function assertLevelAndSetNotMixed(
));
}
}

private function applyEditorConfigSettings(): void
{
if (! $this->useEditorConfig) {
return;
}

/**
* PHP CS Fixer handles most of this, code sniffer just needs to stay
* out of out way. Luckily, we have a pass to make sure it does!
*
* This does introduce a quirk that if someone manually disables a Fixer
* rule, but does not enable the equivalent Sniffer rule, that
* EditorConfig setting won't be respected. But why would they do that?
*
* @see \Symplify\EasyCodingStandard\DependencyInjection\CompilerPass\RemoveMutualCheckersCompilerPass
*/
$editorConfig = new EditorConfigFactory()
->load();

if ($editorConfig->indentStyle !== null) {
$this->indentation = match ($editorConfig->indentStyle) {
IndentStyle::Space => Option::INDENTATION_SPACES,
IndentStyle::Tab => Option::INDENTATION_TAB,
default => Option::INDENTATION_SPACES,
};
}

if ($editorConfig->endOfLine !== null) {
$this->lineEnding = match ($editorConfig->endOfLine) {
EndOfLine::Posix => "\n",
EndOfLine::Legacy => "\r",
EndOfLine::Windows => "\r\n",
default => "\n",
};
}

if ($editorConfig->maxLineLength) {
$this->rulesWithConfiguration[LineLengthFixer::class] = [
...($this->rulesWithConfiguration[LineLengthFixer::class] ?? []),
'line_length' => $editorConfig->maxLineLength,
];
}

if ($editorConfig->trimTrailingWhitespace === true) {
$this->rules[] = NoTrailingWhitespaceFixer::class;
} elseif ($editorConfig->trimTrailingWhitespace === false) {
$this->skip = [...$this->skip, NoTrailingWhitespaceFixer::class, SuperfluousWhitespaceSniff::class];
}

if ($editorConfig->insertFinalNewline === true) {
$this->rules[] = SingleBlankLineAtEofFixer::class;
} elseif ($editorConfig->insertFinalNewline === false) {
$this->rules[] = EndFileNoNewlineSniff::class;
$this->skip[] = [
SingleBlankLineAtEofFixer::class,
Psr2EndFileNewlineSniff::class,
GenericEndFileNewlineSniff::class,
];
}

if ($editorConfig->quoteType === QuoteType::Auto) {
$this->rules[] = SingleQuoteFixer::class;
} elseif ($editorConfig->quoteType === QuoteType::Single) {
$this->rulesWithConfiguration[SingleQuoteFixer::class] = [
'strings_containing_single_quote_chars' => true,
];
} elseif ($editorConfig->quoteType === QuoteType::Double) {
$this->skip = [...$this->skip, SingleQuoteFixer::class, DoubleQuoteUsageSniff::class];
}
}
}
21 changes: 0 additions & 21 deletions src/Configuration/EditorConfig/EditorConfig.php

This file was deleted.

76 changes: 0 additions & 76 deletions src/Configuration/EditorConfig/EditorConfigFactory.php

This file was deleted.

14 changes: 0 additions & 14 deletions src/Configuration/EditorConfig/EndOfLine.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Configuration/EditorConfig/IndentStyle.php

This file was deleted.

17 changes: 0 additions & 17 deletions src/Configuration/EditorConfig/QuoteType.php

This file was deleted.

Loading
Loading