Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Indent JSON files with 4 spaces #7480

Merged
merged 1 commit into from
Nov 26, 2023

Conversation

szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented Nov 26, 2023

As all JSON files are currently indented with 4 spaces.

From #7478 (comment)

@coveralls
Copy link

Coverage Status

coverage: 94.922%. remained the same
when pulling c417955 on szepeviktor:json4
into e1672a4 on PHP-CS-Fixer:master.

.editorconfig Show resolved Hide resolved
@keradus keradus changed the title Indent JSON files with 4 spaces chore: Indent JSON files with 4 spaces Nov 26, 2023
@keradus keradus merged commit 39596a3 into PHP-CS-Fixer:master Nov 26, 2023
25 checks passed
@szepeviktor szepeviktor deleted the json4 branch November 26, 2023 18:56
@szepeviktor
Copy link
Contributor Author

double indent detector for any file

<?php

const INDENT_CHAR = ' ';
const INDENT_SIZE = 4;
const END_OF_LINE = "\n";

$filePath = $argv[1];
$contents = file_get_contents($filePath);
if ($contents === false) {
    exit(11);
}

$currentIndent = 0;
foreach (explode(END_OF_LINE, $contents) as $lineNumber => $line) {
    $indent = strspn($line, INDENT_CHAR);
    if ($indent > $currentIndent + INDENT_SIZE) {
        error_log(sprintf("Indentation size doesn't match in %s:%d", $filePath, $lineNumber + 1));
        exit(10);
    }

    $currentIndent = $indent;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants