andkirby / commithook

CommitHooks code validation and auto-formatting commit message.
GNU General Public License v3.0
7 stars 3 forks source link

Integrate JSHint code validation for Javascript files #47

Closed andkirby closed 8 years ago

andkirby commented 8 years ago

Instruction https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-path-to-jshint

nodejs https://nodejs.org/en/

rhino https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Download_Rhino

jshint http://jshint.com/install/

andkirby commented 8 years ago

There is a problem with running JSHint via Rhino. https://github.com/jshint/jshint/issues/2308. I faced this problem which explained by link http://stackoverflow.com/questions/34581459/run-jshint-with-rhino-error-cannot-read-property-prototype-from-undefined

andkirby commented 8 years ago

Finding JSHint config file priorities:

  1. XML node
  2. PROJECT_DIR/.jshintrc
  3. PROJECT_DIR/packages.json
  4. XML node

Default config (from PhpStorm):

{
  "strict": true,
  "noempty": true,
  "noarg": true,
  "eqeqeq": true,
  "browser": true,
  "bitwise": true,
  "curly": true,
  "undef": true,
  "nonew": true,
  "forin": true
}

Config:

<config>
    <code>
        <interpreter>
           <nodejs>D:/s/nodejs/node.exe</nodejs>
        </interpreter>
    </code>
    <validators>
        <JsHint>
            <execution>
                <!--Path to executable file of JSHint file which should be interpreted by NodeJS-->
                <jshint>D:/s/jshint/bin/jshint</jshint>
                <command>%interpreter% --config=%config% %jshint%</command>
            </execution>
            <config>
                <file>
                    <!--If you have .jshintrc or packages.json in your project root it will be set automatically by CommitHook-->
                    <!--Default configuration from PhpStorm-->
                    <default>src/config/jshint/phpstorm-default.json</default>

                    <!--Custom configuration file-->
                    <!--You may use variables PROJECT_DIR or HOME-->
                    <!--Relative path will be considered as a path in project-->
                    <custom/>
                </file>
            </config>
        </JsHint>
    </validators>
</config>
andkirby commented 8 years ago

https://github.com/jshint/jshint/blob/master/examples/.jshintrc Config example.