{"id":23180828,"url":"https://github.com/friendsoftwig/twigcs","last_synced_at":"2025-05-14T10:07:50.177Z","repository":{"id":1776448,"uuid":"44731354","full_name":"friendsoftwig/twigcs","owner":"friendsoftwig","description":"The missing checkstyle for twig!","archived":false,"fork":false,"pushed_at":"2024-12-23T20:52:30.000Z","size":13262,"stargazers_count":348,"open_issues_count":24,"forks_count":33,"subscribers_count":33,"default_branch":"main","last_synced_at":"2025-05-10T14:42:12.228Z","etag":null,"topics":["checkstyle","composer","library","php","twig"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/friendsoftwig.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-22T08:12:53.000Z","updated_at":"2025-05-06T05:35:07.000Z","dependencies_parsed_at":"2023-07-05T15:45:55.637Z","dependency_job_id":"73086c6a-d4fe-42f2-992f-47a772c5c7f7","html_url":"https://github.com/friendsoftwig/twigcs","commit_stats":{"total_commits":324,"total_committers":33,"mean_commits":9.818181818181818,"dds":0.617283950617284,"last_synced_commit":"888185d6f743fe49d9cb61552c38527c717d9053"},"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendsoftwig%2Ftwigcs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendsoftwig%2Ftwigcs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendsoftwig%2Ftwigcs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/friendsoftwig%2Ftwigcs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/friendsoftwig","download_url":"https://codeload.github.com/friendsoftwig/twigcs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253595429,"owners_count":21933386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["checkstyle","composer","library","php","twig"],"created_at":"2024-12-18T08:13:24.644Z","updated_at":"2025-05-14T10:07:50.142Z","avatar_url":"https://github.com/friendsoftwig.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twigcs\n\n[![Integrate](https://github.com/friendsoftwig/twigcs/workflows/Integrate/badge.svg)](https://github.com/friendsoftwig/twigcs/actions)\n\n[![Code Coverage](https://codecov.io/github/friendsoftwig/twigcs/branch/main/graph/badge.svg)](https://codecov.io/github/friendsoftwig/twigcs)\n\n[![Latest Stable Version](https://poser.pugx.org/friendsoftwig/twigcs/v/stable)](https://packagist.org/packages/friendsoftwig/twigcs)\n[![Total Downloads](https://poser.pugx.org/friendsoftwig/twigcs/downloads)](https://packagist.org/packages/friendsoftwig/twigcs)\n[![Monthly Downloads](http://poser.pugx.org/friendsoftwig/twigcs/d/monthly)](https://packagist.org/packages/friendsoftwig/twigcs)\n\nThe missing checkstyle for twig!\n\nTwigcs aims to be what [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) is to php. It checks your codebase for\nviolations on coding standards.\n\n## How to install\n\nRun\n\n```bash\ncomposer require --dev friendsoftwig/twigcs\n```\n\nto install `friendsoftwig/twigcs` with [`composer`](https://getcomposer.org).\n\nRun\n\n```bash\nphive install friendsoftwig/twigcs\n```\n\nto install `friendsoftwig/twigcs` with [`phive`](https://phar.io).\n\n## How to run\n\nBasically, just run:\n\n```bash\ntwigcs /path/to/views\n```\n\nOn Symfony projects, you can run, for instance:\n\n```bash\ntwigcs /project/dir/app/Resources/views\n```\n\nYou will get a summary of the violations in the console. The exit code of the command is based on the severity\nof any violation found. By default, twigcs only tolerates info, this can be changed at run time:\n\n```bash\ntwigcs /path/to/views --severity error   # Allows info and warnings\ntwigcs /path/to/views --severity warning # Allows info\ntwigcs /path/to/views --severity info    # Disallows info\ntwigcs /path/to/views --severity ignore  # Allows everything\n```\n\nWith the example above, info is still displayed but not altering the exit code.\n\nYou can also exclude relative subfolders of path like this:\n\n```bash\ntwigcs /path/to/views --exclude vendor\n```\n\nTips: You can use multiple _exclude_ parameters.\n\n## Restricting output\n\nBy default TwigCS will output all lines that have violations regardless of whether they match the severity level\nspecified or not. If you only want to see violations that are greater than or equal to the severity level you've specified\nyou can use the `--display` option. For example.\n\n```bash\ntwigcs /path/to/views --severity error --display blocking\n```\n\nWould only display errors and not warnings.\n\nAlternatively you can use `--display all` which is the default behaviour as described above.\n\n## Continuous Integration\n\nTwigcs can be used with your favorite CI server. The command itself will return a consistent exit code telling\nthe CI job if it failed or succeeded. You can also have a nice xml report (checkstyle format):\n\n```bash\ntwigcs /path/to/views --reporter checkstyle \u003e /path/to/report.xml\n```\n\n## Reporters\n\nTwigcs currently supports to following reporters:\n\n```bash\ntwigcs /path/to/views --reporter console\ntwigcs /path/to/views --reporter checkstyle\ntwigcs /path/to/views --reporter junit\ntwigcs /path/to/views --reporter emacs\ntwigcs /path/to/views --reporter json\ntwigcs /path/to/views --reporter csv\ntwigcs /path/to/views --reporter githubAction\ntwigcs /path/to/views --reporter gitlab\n```\n\n## Using older twig versions\n\nBy default twigcs is using Twig 3. This means that features like `filter` tags or filtered loops using `if` are not supported\nanymore. You can use an older twig version using the `twig-version` option:\n\n```bash\ntwigcs /path/to/views --twig-version 2\n```\n\n## Custom coding standard\n\nAt the moment the only available standard is the [official one from twig](https://twig.symfony.com/doc/3.x/coding_standards.html).\n\nYou can create a class implementing `RulesetInterface` and supply it as a `--ruleset` option to the CLI script:\n\n```bash\ntwigcs /path/to/views --ruleset \\MyApp\\TwigCsRuleset\n```\n\n_Note:_ `twigcs` needs to be used via composer and the ruleset class must be reachable via composer's autoloader for this feature to work.\nAlso note that depending on your shell, you might need to escape backslashes in the fully qualified class name:\n\n```bash\ntwigcs /path/to/views --ruleset \\\\MyApp\\\\TwigCsRuleset\n```\n\nFor more complex needs, have a look at the [custom ruleset documentation](doc/ruleset.md).\n\n## File-based configuration\n\nUsing configuration, you can easily store per-project settings:\n\n```php\n// ~/.twig_cs.dist.php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse FriendsOfTwig\\Twigcs;\n\nreturn Twigcs\\Config\\Config::create()\n    -\u003esetName('my-config')\n    -\u003esetSeverity('warning')\n    -\u003esetReporter('json')\n    -\u003esetRuleSet(Twigcs\\Ruleset\\Official::class)\n    -\u003esetSpecificRuleSets([ // Every file matching the pattern will use a different ruleset.\n        '*/template.html.twig' =\u003e Acme\\Project\\CustomRuleset::class,\n    ])\n;\n```\n\nThis configuration will be applied if you call twigcs from the `~/` directory. If you run twigcs from outside this directory,\nyou must use the `--config` option:\n\n```\ncd ~/dirA\ntwigcs --config ~/dirB/.twig_cs.dist.php # Will lint templates in ~/dirA with the config of ~/dirB\n```\n\nBy default, the files\n\n- `.twig_cs.php`\n- `.twig_cs`\n- `.twig_cs.dist.php`\n- `.twig_cs.dist`\n\nare looked up in your current working directory (CWD).\n\nYou can also provide finders inside config files, they will completely replace the path in the CLI:\n\n```php\n// ~/.twig_cs.dist.php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse FriendsOfTwig\\Twigcs;\n\n$finderA = Twigcs\\Finder\\TemplateFinder::create()-\u003ein(__DIR__.'/dirA');\n$finderB = Twigcs\\Finder\\TemplateFinder::create()-\u003ein(__DIR__.'/dirB');\n\nreturn Twigcs\\Config\\Config::create()\n    // ...\n    -\u003eaddFinder($finderA)\n    -\u003eaddFinder($finderB)\n    -\u003esetName('my-config')\n;\n```\n\nIn this case, calling `twigcs` from the `~/` directory of the config will run the linter on the directories pointed by the finders.\nIf you explicitly supply a path to the CLI, it will be added to the list of linted directories:\n\n```\ntwigcs ~/dirC # This will lint ~/dirA, ~/dirB and ~/dirC using the configuration file of the current directory.\n```\n\n## Template resolution\n\nUsing file based configuration, you can provide a way for twigcs to resolve template. This enables better unused variable/macro detection. Here's the\nsimplest example when you have only one directory of templates.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse FriendsOfTwig\\Twigcs;\n\nreturn Twigcs\\Config\\Config::create()\n    // ...\n    -\u003esetTemplateResolver(new Twigcs\\TemplateResolver\\FileResolver(__DIR__))\n    -\u003esetRuleSet(FriendsOfTwig\\Twigcs\\Ruleset\\Official::class)\n;\n```\n\nHere is a more complex example that uses a chain resolver and a namespaced resolver to handle vendor templates:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse FriendsOfTwig\\Twigcs;\n\nreturn Twigcs\\Config\\Config::create()\n    -\u003esetFinder($finder)\n    -\u003esetTemplateResolver(new Twigcs\\TemplateResolver\\ChainResolver([\n        new Twigcs\\TemplateResolver\\FileResolver(__DIR__ . '/templates'),\n        new Twigcs\\TemplateResolver\\NamespacedResolver([\n            'acme' =\u003e  new Twigcs\\TemplateResolver\\FileResolver(__DIR__ . '/vendor/Acme/AcmeLib/templates')\n        ]),\n    ]))\n;\n```\n\nThis handles twig namespaces of the form `@acme/\u003ctemplatepath\u003e`.\n\n## Upgrading\n\nIf you're upgrading from 3.x to 4.x or later, please read the [upgrade guide](doc/upgrade.md).\n\n## Community\n\nJoin us on [Symfony Devs](https://symfony.com/slack) via the **twigcs** channel.\n\n## Changelog\n\nPlease have a look at [`CHANGELOG.md`](CHANGELOG.md).\n\n## Contributing\n\nThe `main` branch is the development branch. If you find any bug or false positive during style checking, please\nopen an issue or submit a pull request.\n\nWhen creating or changing a class, don't forget to add you as an `@author` at the top of the file.\n\nPlease have a look at [`CONTRIBUTING.md`](.github/CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendsoftwig%2Ftwigcs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffriendsoftwig%2Ftwigcs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffriendsoftwig%2Ftwigcs/lists"}