Build Time Javascript Code Analysis
Installing an automatic build process for your projects is very common today and best practice. In the java world Maven is a very popular build tool and has proven its matureness over the years. Using maven to build your client-side project has the following advantages:- Find potential problems in your code. Bugs might be identified and breaking code conventions can be detected early.
- Run the build automatically on a regular base
- Easily handle refactorings and other small changes
- Ability to do continuous integration
- Increase confidence in code quality for each build
Introduce wro4j maven plugin
Since version 1.3.5, wro4j maven plugin provides a new goal called jshint which can help you to start auditing and enforcing JS code through a mechanism like JSHint.In order to use it you have to follow several simple steps.
Project layout
By default, wro4j maven plugin relies on a typical maven project layout. This structure can be different, depending on your project. The implicit wro4j maven plugin settings will assume you are using this structure. By default it will search for a file called wro.xml at the following location src/main/webapp/WEB-INF/wro.xml. The location of this file is configurable. You'll find more about all available configuration below. The purpose of wro.xml file is to describe the way static resources are grouped and the order in which these should be processed. By default the plugin will process each resource one by one.Configure pom.xml
Add wro4j maven plugin to the list of plugins in your web project:${wro4j.version} - is the latest wro4j version (1.3.5). The goal which instructs wro4j to run jshint tool is called jshint. Besides this goal, wro4j maven plugin provides also run goal which performs the compression of the resources (both js & css), but this is not in the scope of this post.ro.isdc.wro4j wro4j-maven-plugin ${wro4j.version} compile jshint devel,evil,noarg
This plugin allows you configure the options used by jshint. Specifying these options is optional. For the complete list of available options, visit the JsHint project homepage. As you can see in the above example, options configuration contains a comma separated values.
Detailed plugin configurations
- options - comma separated values used to instruct jsHint how to analyze the js code.
- failNever - boolean flag. When true - the project build will succeed even if there are errors reported by jsHint. By default this value is false.
- ignoreMissingResources - if false, the build will fail if at least one resource is missing or cannot be accessed, otherwise only a warning will be displayed.
- targetGroups - (optional) a comma separated list of groups you want to build. If you do not specify this parameter, a file for each defined group will be generated.
- wroManagerFactory - Optional attribute, used to specify a custom implementation of MavenContextAwareManagerFactory interface. When this tag is not specified, a default implementation is used. This attribute is useful if you want to configure other processors than default one.
- wroFile - the location of wro.xml file which defines how resources are grouped. By default its value is this: ${basedir}/src/main/webapp/WEB-INF/wro.xml . If you have a different project structure or a different location of wro.xml, then you should change the value of this parameter.
- contextFolder - defines the location of web application context, useful for locating resources relative to servletContext. By default its value is: ${basedir}/src/main/webapp/
[error] 1 errors found while processing resource: classpath:ro/isdc/wro/maven/plugin/js/undef.js Errors are: [ro.isdc.wro.extensions.processor.algorithm.jshint.JsError@19d75ee[ line=4 character=4 reason='jQuery' is not defined. evidence=})(jQuery); ]]These informations should be enough to help you to fix any problems you may have.
can you please specify how can I generate a result file namely jshint.xml after running above mentioned plugin? to use that in jenkins violations for creating reports?
ReplyDeleteThank you
The violations reports is a feature which is available since version 1.5.0 (latest version is 1.6.1). The path of generated reports is target/wro4j-reports/jshint.xml
ReplyDeleteIt is possible to change the default path of the file containing reports by adding "reportFile" configuration property.
thank you Alex! much appreciated !
ReplyDeleteis there a way to put jshint options in an external file ?
thx,
dan
It is not possible to keep jshint options inside an external file out of the box. But you can create a feature request here: http://code.google.com/p/wro4j/issues/list
ReplyDeleteHi Alex, Is it possible to customize the rules to be run for jshint?
ReplyDeleteIf by rules you mean "jshint options" than you can add them using 'options' tag (this is described on blog):
ReplyDeletedevel,evil,noarg
With the limited functionality offered through the wro4j plugin, is there any benefit to using this instead of jslint4java?
ReplyDeleteAlso, is there a way to use a different reporter? The one provided is a bit odd to look at after coming from a vanilla JSLint output.
Thanks!
I did also have one other question/gripe. It looks like this implementation of JSHint only reports problems with 1 file at a time, instead of with all resources. Is there a way to have it continue scanning and reporting past the first file in which it encounters problems?
ReplyDeleteYou can set failNever to true (defaulted to false) option in order to see all errors reported by jshint.
ReplyDeleteI don't have much knowledge about features supported by jslint4java. If there are missing features, just let me know. The wro4j maven plugin has several goals, including jshint, csslint & run responsible for implementing various optimization techniques and code analysis using jshint and csslint.
Thanks for the fast response! Using neverFail does let me see all the issues, but it also does not fail the build. My desire is to see all of the errors that JSHint finds, and then fail the build afterward.
ReplyDeleteThe latest release (wro4j-1.6.3) has additional configuration called "failThreshold" which takes a number as argument and is used as a threshold of maximum accepted jshint errors before the build fails. This can be used as alternative approach to see more than one jshint error.
ReplyDeleteThanks! I didn't know about that.
ReplyDeletejavascript examples on javascript code examples can help you learn javascript language
ReplyDeleteThis looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyDeleteSelenium Training in Chennai Tamil Nadu | Selenium Training Institute in Chennai anna nagar | selenium training in chennai velachery
Selenium Training in Bangalore with placements | Best Selenium Training in Bangalore marathahalli
java training in chennai | java training in chennai Velachery |java training in chennai anna nagar
Awesome information.
ReplyDeletesuch an useful article.
thanks for posting.keep sharing.
Best java training in Bengaluru
Nice blog, thanks for sharing. Please Update more blog about this, this is really informative for me as well
ReplyDeleteaws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
Very Nice Blog. Thanks for sharing such a nice Blog.
ReplyDeleteaws Training in Bangalore
python Training in Bangalore
hadoop Training in Bangalore
angular js Training in Bangalore
bigdata analytics Training in Bangalore
python Training in Bangalore
aws Training in Bangalore
آهنگ سینا پارسیان عصای موسی
ReplyDeletecms web design company in usa
ReplyDeletedigital marketing company in usa
ecommerce service company in usa
shopify website development in usa
prestashop development in usa
http://warez-is-mylife.blogspot.com/2014/04/hl-1240-driver.html
ReplyDeletehttp://warez-on-this-blog.blogspot.com/2014/04/fingerprint-scanner-software-for.html
http://warez-on-this-blog.blogspot.com/2014/04/brother-hl-2270dw-driver-windows-7-64.html
https://www.blogger.com/comment.g?blogID=7718864591129889508&postID=5303043290385522431
https://watean.blogspot.com/2011/04/blog-post.html
https://www.blogger.com/comment.g?blogID=7540687028464774748&postID=4217292489864687592
https://www.blogger.com/comment.g?blogID=6175704474342810828&postID=8977332047704062896
https://www.blogger.com/comment.g?blogID=6043156720447404006&postID=8650680275560613902
https://webdrgons.blogspot.com/2015/02/web-designing-services_20.html
https://webideare.blogspot.com/2017/06/key-elements-for-e-commerce-website.html
https://webmappingtutorial.blogspot.com/2014/11/openlayers-layer-creation.html
http://webmappingtutorial.blogspot.com/2014/11/openlayers-layer-creation.html
https://web-resource-optimization.blogspot.com/2011/03/build-time-javascript-code-analysis.html
https://weboxe.blogspot.com/2017/01/website-development-in-chandigarh.html
http://websitedevelopmentservice.blogspot.com/2016/01/web-design-services-chennai.html
http://web-site-development-solutions.blogspot.com/2010/09/ecommerce-web-development-analysis-and.html
http://web-site-development-solutions.blogspot.com/2010/10/significance-of-css-in-web-development.html
http://websitekesebanaye.blogspot.com/2015/07/e-commerce-website-kese-banaye.html
http://www.weelittlemiracles.com/2012/04/make-easter-story-wreath-free.html
http://www.weimarer-bowlingfuechse.de/gaestebuch.php?
ReplyDeleteSpecial school
Donate to children in need
Great post! I am actually getting ready to across this information, i am very happy to this commands. Also great blog here with all of the valuable information about best digital marketing services in usa. Well done, its a great knowledge. We also have a website that provides Professional SEO Services in USA
ReplyDeleteThanks for sharing this informative blog. The way you write this blog is very interesting. If you are looking for Research Proposal Help then, BookMyEasy has experts who help you in dissertation and thesis writing.
ReplyDelete천안콜걸
ReplyDelete강원도콜걸
공주콜걸
서천콜걸
강원도콜걸
논산콜걸
춘천콜걸
고양콜걸
ReplyDelete거창콜걸
고양콜걸
일산콜걸
파주콜걸
합천콜걸
과천콜걸
과천콜걸
With the limited functionality offered through the wro4j plugin, is there any benefit to using this instead of jslint4java? godaddy promo code july 2023Also, is there a way to use a different reporter? The one provided is a bit odd to look at after coming from a vanilla JSLint output.
ReplyDeleteGreat article. worth it.
ReplyDeletejava classes in Pune
This article on "Build Time JavaScript Code Analysis with JSHint" is incredibly helpful! It clearly outlines the importance of maintaining code quality and how integrating JSHint into the build process can streamline that effort. The step-by-step setup instructions make it easy to follow, even for those who might be new to using code analysis tools. It would be great to see some examples of common issues JSHint catches in real projects. Overall, a valuable resource for any developer looking to enhance their JavaScript code quality!
ReplyDeleteDigital Marketing Training In Ameerpet