-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Adds a linter command for templates #3804
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
Conversation
Checking a single file is very limited. Checking a whole directory would be more useful, wouldn't it? |
@@ -0,0 +1,77 @@ | |||
<?php | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing license header
I think you should provide a way to validate all templates for a given bundle, something like:
|
Wouldnt it be better to throw some kind of exception if the lint is erroneous? |
@Tobion @willdurand You can do that by combining unix tools. |
Updated. |
@marcw it would be indeed nice to have support for a bundle/directory out of the box as some of the Symfony2 users might not be running unix or know the right commands to make this work. I could help you with a PR in your repo if you want. |
if ($filename && !is_readable($filename)) { | ||
$output->writeln(sprintf('<error>File %s is not readable</error>', $filename)); | ||
|
||
return 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 is a reserved error (misuse of shell builtins). For user-defined errors, you must use exist codes in the range of 64 - 113. But as we are not using those anywhere else, what about just using exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know. thanks.
@marcw as the console component will catch them and convert them into the right error code, also will display what went wrong instead of just dieing. |
Updated with all comments and requested features. |
Commits ------- 8726ade Adds more features to twig:lint command 1d7e9d9 Adds a linter command for templates Discussion ---------- Adds a linter command for templates Let's this PR be stoffed. ;) --------------------------------------------------------------------------- by Tobion at 2012-04-06T15:48:18Z Checking a single file is very limited. Checking a whole directory would be more useful, wouldn't it? --------------------------------------------------------------------------- by willdurand at 2012-04-06T17:56:57Z I think you should provide a way to validate all templates for a given bundle, something like: php app/console twig:lint @MySuperBundle --------------------------------------------------------------------------- by henrikbjorn at 2012-04-06T18:03:45Z Wouldnt it be better to throw some kind of exception if the lint is erroneous? --------------------------------------------------------------------------- by marcw at 2012-04-07T11:22:34Z @Tobion @willdurand You can do that by combining unix tools. @henrikbjorn Why ? --------------------------------------------------------------------------- by marcw at 2012-04-07T11:27:11Z Updated. --------------------------------------------------------------------------- by dlsniper at 2012-04-07T13:15:53Z @marcw it would be indeed nice to have support for a bundle/directory out of the box as some of the Symfony2 users might not be running unix or know the right commands to make this work. I could help you with a PR in your repo if you want. --------------------------------------------------------------------------- by henrikbjorn at 2012-04-07T18:55:34Z @marcw as the console component will catch them and convert them into the right error code, also will display what went wrong instead of just dieing. --------------------------------------------------------------------------- by marcw at 2012-04-08T09:15:37Z Updated with all comments and requested features.
} else { | ||
$dir = $this->getApplication()->getKernel()->locateResource($filename); | ||
$files = Finder::create()->files()->in($dir)->name('*.twig'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else {
if (!is_dir($filename)) {
$filename = $this->getApplication()->getKernel()->locateResource($filename);
}
$files = Finder::create()->files()->in($filename)->name('*.twig');
}
I wonder if
This command only checks the syntax. And does not perform code analysis. So something like |
@Tobion |
I associate |
|
Because PHP chose the wrong name we do not need to make the same mistake. PHP is also not consistent with its naming: http://www.php.net/manual/en/function.php-check-syntax.php |
Commits ------- df5590e [TwigBundle] Fix return code in LintComand 604a79a [TwigBundle] Fix line start in twig:lint command 91936b5 [TwigBundle] Fancy output for twig:lint Discussion ---------- [TwigBundle] Fancy output for twig:lint Previous PR : #3804 @marcw @fabpot Since no exception is raised, the return code is always 0. Do I add ``return rand(64, 113)`` ? Screenshot : http://twitpic.com/9qql09 --------------------------------------------------------------------------- by travisbot at 2012-05-29T21:18:33Z This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1470256) (merged 91936b5 into adf07f1). --------------------------------------------------------------------------- by travisbot at 2012-05-29T21:21:54Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1470353) (merged 604a79a into adf07f1). --------------------------------------------------------------------------- by fabpot at 2012-05-30T16:45:24Z @alexandresalome just return 1 in case of a problem. --------------------------------------------------------------------------- by travisbot at 2012-06-06T20:06:04Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1550631) (merged df5590e into adf07f1).
Let's this PR be stoffed. ;)