Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 2.95 KB

File metadata and controls

64 lines (44 loc) · 2.95 KB

Blink mode (experimental)

--blink hands the run over to the ecs-go Go binary instead of the PHP engine:

vendor/bin/ecs check --blink          # report only (like a normal check)
vendor/bin/ecs check --blink --fix    # rewrite files in place
vendor/bin/ecs check src --blink      # limit to a path - pass the path before the flag

Pass any explicit path before the flags (check src --blink), as with --fix; a path written after a boolean flag is consumed as that flag's value.

ECS resolves the configuration from ecs.php (paths, rules and skips) exactly as usual, dumps it to a temporary JSON file, and hands that file to ecs-go via --ecs-config. ecs-go maps each ECS rule onto its own fixer by class name, applies the shared paths and skips, and reports every rule it could not map. The check/fix split maps onto ecs-go directly:

  • --blink runs ecs-go --ecs-config <config.json> - reports without writing.
  • --blink --fix runs ecs-go --ecs-config <config.json> --fix - rewrites in place.

The exit code of ecs-go is passed through.

Dumping the config

The JSON ecs-go consumes can also be inspected on its own:

vendor/bin/ecs dump-config        # print the resolved paths, rules and skips as JSON

The shape is:

{
  "paths": ["/abs/src"],
  "rules": [
    { "class": "PhpCsFixer\\Fixer\\ArrayNotation\\ArraySyntaxFixer", "config": { "syntax": "short" } },
    { "class": "PhpCsFixer\\Fixer\\CastNotation\\LowercaseCastFixer", "config": {} }
  ],
  "skips": [
    { "path": "*/Legacy/*" },
    { "class": "PhpCsFixer\\Fixer\\Import\\OrderedImportsFixer" },
    { "class": "PhpCsFixer\\Fixer\\CastNotation\\LowercaseCastFixer", "paths": ["*/tests/*"] }
  ]
}

Configured fixer options are read off the fixer instance; sniff properties are not extracted yet.

Binary resolution

The ecs-go binary is looked up in this order:

  1. the ECS_BLINK_BIN environment variable, if it points to an existing file;
  2. the binary bundled with ECS in bin/ as blink-<platform> (Linux, macOS and Windows, amd64 and arm64);
  3. vendor/bin/ecs-go, if present;
  4. ecs-go on the PATH.

If none is found, --blink fails with an error explaining how to provide the binary.

Prototype caveat

This is an RFC-stage prototype. ecs-go reads the rules and skips from your ecs.php (not just the paths), and because every ecs-go fixer is named by its PHP-CS-Fixer class, the rules map straight across by name. Every rule ecs-go has no fixer for is reported and skipped, and a configured rule runs with ecs-go's built-in behaviour (its configuration is not modelled yet) and is noted in the report. So a blink run is never silently narrower than your config, but it is not yet equivalent to a full ECS run.

Bundled binary

The release build cross-compiles ecs-go from its main branch and ships it in bin/ as blink-<platform>, so --blink works out of the box on Linux, macOS and Windows - no Go toolchain needed.