-
Notifications
You must be signed in to change notification settings - Fork 32
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
feature/sniffs_system - twigcs #35
base: master
Are you sure you want to change the base?
Conversation
…s.. renaming some things
…DisallowTabIndentSniff + refactoring for tests
@adrienrn Woa, this is pretty cool! I need to properly sit down to go through this though. :) |
Update: Added some major things (more powerful config, external sniffs) and some minor ones (time / memory metrics, better output). An example of the twigcs.yml of a project could be: paths:
- 'Resources/views'
exclude:
- 'node_modules'
- 'Resources/public'
ruleset:
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\DeprecatedTemplateNotationSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\DisallowCommentedCodeSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\DisallowDumpSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\DisallowIncludeTagSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\DisallowTabIndentSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureBlankAtEOFSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureHashKeyQuotesSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureHashSpacingSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureHashTrailingCommaSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureQuotesStyleSniff'
options:
style: 'TYPE_SINGLE_QUOTES'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureTranslationArgumentsSniff'
-
class: 'Asm89\Twig\Lint\Standards\Generic\Sniffs\EnsureWhitespaceExpressionSniff' I also added the possibility to load custom sniffs; using the You can add it to your ruleset: []
standardPaths:
'\Acme\TwigCS':
- '/home/vagrant/work/acme-twigcs/src' Working on some proper "standard" next to easy things up. |
Conflicts: src/Asm89/Twig/Lint/Command/LintCommand.php src/Asm89/Twig/Lint/StubbedEnvironment.php tests/Asm89/Twig/Lint/Test/StubbedEnvironmentTest.php
@adrienrn see my comment here you better make your repo https://github.com/adrienrn/twig-lint |
Here's
twigcs
- Twig Code Sniffer - which intend to be a "sniff engine" to check more thoroughly twig templates including whitespaces, trailing commas or missing parameters to functions/filters, etc.If it sounds familiar, it's because it's heavily inspired on PHP_CodeSniffer.
I tried to not change anything to the current
lint
command. Everything should work as it was before.Internals
There's two kind of sniffs:
You define a set of rules (
src/Twig/Lint/Ruleset.php
) with options in atwigcs.yml
file at the root of your twig project.Once loaded, the Linter class (
src/Twig/Lint/Linter.php
) will process every requested files against that set of rules and produce a Report object (src/Twig/Lint/Report.php
) with rule violations, context and statistics.Running
twigcs
against the test fixtures files would produce:Check the many PHPUnit tests I've made to dig further!
Todos
twigcs.yml
:set_error_handler
. The StubbedCore makes it difficult but Allow 2 words tests tokens #24 should make it easier.twigcs.yml
will be a clutter; and it would be nice to have a "standard" syntax like PSR-2 for twig, share by everyone.Why?
In the end, I did it to integrate this to my CI process, using PHPstan or Codacy.
All of my many twig projects are maintained by many people (including freelance developers) and with the activity growing, I don't have time anymore to spend that much time reading pull requests 😔.
I created my own tokenizer / preprocessor out of the official lexer because it was not possible to detect space and all punctuations otherwise, see those issues:
Final notes!
If it's too much, I'll continue this on my fork or create a separate repository. :)