Skip to content

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

Merged
merged 2 commits into from
Apr 8, 2012
Merged

Conversation

marcw
Copy link
Contributor

@marcw marcw commented Apr 6, 2012

Let's this PR be stoffed. ;)

@Tobion
Copy link
Contributor

Tobion commented Apr 6, 2012

Checking a single file is very limited. Checking a whole directory would be more useful, wouldn't it?

@@ -0,0 +1,77 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing license header

@willdurand
Copy link
Contributor

I think you should provide a way to validate all templates for a given bundle, something like:

php app/console twig:lint @MySuperBundle

@henrikbjorn
Copy link
Contributor

Wouldnt it be better to throw some kind of exception if the lint is erroneous?

@marcw
Copy link
Contributor Author

marcw commented Apr 7, 2012

@Tobion @willdurand You can do that by combining unix tools.
@henrikbjorn Why ?

@marcw
Copy link
Contributor Author

marcw commented Apr 7, 2012

Updated.

@dlsniper
Copy link
Contributor

dlsniper commented Apr 7, 2012

@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;
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know. thanks.

@henrikbjorn
Copy link
Contributor

@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.

@marcw
Copy link
Contributor Author

marcw commented Apr 8, 2012

Updated with all comments and requested features.

fabpot added a commit that referenced this pull request Apr 8, 2012
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.
@fabpot fabpot merged commit 8726ade into symfony:master Apr 8, 2012
} else {
$dir = $this->getApplication()->getKernel()->locateResource($filename);
$files = Finder::create()->files()->in($dir)->name('*.twig');
}
Copy link
Contributor

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');
}

@Tobion
Copy link
Contributor

Tobion commented Apr 8, 2012

I wonder if lint is the correct name for the command. Lint means

the process of flagging suspicious language usage. Lint-like tools generally perform static analysis of source code.

This command only checks the syntax. And does not perform code analysis. So something like twig:check-syntax is more appropriate.

@stloyd
Copy link
Contributor

stloyd commented Apr 8, 2012

@Tobion twig:check-syntax looks quite strange =) IMO better would be twig:validate.

@Tobion
Copy link
Contributor

Tobion commented Apr 8, 2012

I associate validate with a check that verifies if the test object makes sense. But since HTML validators also only validate the syntax, a twig:validate would really fit.

@willdurand
Copy link
Contributor

lint is fine, what kind of static code analysis php -l does?

@Tobion
Copy link
Contributor

Tobion commented Apr 8, 2012

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
All the available Javascript linters perform some sort of code analysis like checking for unused parameters/variables.

fabpot added a commit that referenced this pull request Jun 8, 2012
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants