nette/coding-standard

Maintainers

Package info

github.com/nette/coding-standard

pkg:composer/nette/coding-standard

Statistics

Installs: 930 636

Dependents: 17

Suggesters: 0

Stars: 41

v3.5.1 2026-04-13 14:24 UTC

README

Downloads this Month Latest Stable Version License

This is set of sniffs and fixers that checks and fixes code of Nette Framework against Coding Standard in Documentation.

Installation and Usage

Install the tool globally:

composer global require nette/coding-standard

Check coding standard in folders src and tests:

ecs check src tests

And fix it:

ecs fix src tests

The PHP version preset is automatically detected from your project's composer.json. If auto-detection is not possible, you can specify it manually:

ecs check src tests --preset php81

Custom Configuration

You can tweak rules per-project by placing ncs.php (PHP CS Fixer) and/or ncs.xml (PHP_CodeSniffer) in your project root. Both are discovered automatically and merged on top of the preset.

ncs.php returns an associative array of fixer overrides:

<?php
return [
	'strict_comparison' => false,
	'PhpCsFixerCustomFixers/commented_out_function' => false, // don't comment out dump(), var_dump(), ...
];

ncs.xml is a PHP_CodeSniffer ruleset. It does not need to reference the version preset – it is automatically combined with it. Use $presets/ to reference any bundled preset:

<?xml version="1.0"?>
<ruleset name="MyProject">
	<!-- Optional: enable use function/const imports -->
	<rule ref="$presets/optimize-fn.xml"/>

	<!-- Disable a rule -->
	<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
</ruleset>

Ad-hoc Configuration via --config-file

For one-off runs (e.g. when you want to keep dump() calls intact during debugging) you can point to an additional config file without committing it to the project:

ecs fix src --config-file ./my-overrides.php

The tool is selected by extension: .php applies to PHP CS Fixer, .xml to PHP_CodeSniffer. You can pass --config-file twice to configure both tools. Project-level ncs.php/ncs.xml are still used; values from --config-file take precedence.

GitHub Actions

# .github/workflows/coding-style.yml
steps:
    - uses: actions/checkout@v4
    - uses: shivammathur/setup-php@v2
      with:
          php-version: 8.1

    - run: composer create-project nette/coding-standard temp/coding-standard
    - run: php temp/coding-standard/ecs check src tests