Skip to content
umakantp edited this page Sep 12, 2014 · 3 revisions

Requirements

To use SmartyLint all you need is PHP 5.2.4 or above

Installation

First get the repo from github and move to latest release.

git clone git://github.com/umakantp/SmartyLint.git

cd SmartyLint

git checkout v0.1.1

That's it. Now you are ready to use SmartyLint.

How to use?

Once you are in SmartyLint folder you can use smartyl command.

php smartyl --files=<path to smarty file or folder containing smarty files>

Once you run above command you would see progress on your screen. Each file is progress is displayed in form of dot (.) or W or E. Dot stands for NO ERROR or WARNING for that file. E stands for Error and W stands for Warning. After all files are scanned, you would see detailed report.

For help, you can use

php smartyl -h

For checking SmartyLint version, you can use

php smartyl -v

Ignore files and folders

You can do it using ignore rules file and passing it to smartyl command. Create a XML file which has root tag. should be inside rules tag. Then write file or folder name inside tag which should be inside ignore tag. You can have as many as tag for as many as files / folders you want to ignore.

e.g.

<?xml version="1.0"?> <rules> <ignore> <pattern>*/demo/*</pattern> <pattern>*/sample.tpl</pattern> <ignore> <rules>

You can also find sample file in SmartyLint source. Check it out on github. Then you can pass on this file to smartyl command. e.g. php smartyl --files=<path to folder which have tpl files> --ignore-rules=<path to ignore rules xml file>

Disable any rule.

Disabling any rule sould be very easy. As mentioned in above paragraph create ignore rules XML file. Inside tag you can create rule tag with 'name' attribute containing name of rule which you are suppose to disable. e.g.

<?xml version="1.0"?> <rules> <ignore> <rule name="Commenting.FileComment"/> <ignore> <rules>

Above example disabled Commenting.FileComment rule for all files. You can also disable any rule for specific file. e.g.

<?xml version="1.0"?> <rules> <ignore> <rule name="Commenting.Fixme.TaskFound"> <pattern>example.tpl</pattern> </rule> <ignore> <rules>

You can disable as many as rules and exclude as many as files you want to. You can also find sample file in SmartyLint source. Check it out on github. Then you can pass on this file to smartyl command.

e.g. php smartyl --files=<path to folder which have tpl files> --ignore-rules=<path to ignore rules xml file>

What all conventions are checked against smarty templates?

  • Should have one empty line at the bottom.
  • Should not have more than 1 empty line at the bottom
  • File comment and content should have one blank line in between.
  • There should be no TODO's and FixMe's in the code.
  • Never use HTML comments. You should use Smarty comments {**} instead.
  • No whitespace / empty spaces at the end of each line.
  • Have max only 2 empty lines in the content (i.e. 3 new lines in a row).
  • You should write file doc comment at the top in Java Doc format which contains short file description and all the variables used in that template.

**Note:- We will keep adding new conventions regulary which improves your smarty templates code quality. **