On Github ArturDorochowicz / presentation-enforcing-quality-with-tools
using (var smtp = new SmtpClient { Host = "smtp.gmail.com" }) { smtp.Send("from@from.com", "to@to.com", "subject", "body"); }
$(MSBuildExtensionPath)\Microsoft\VisualStudio\v11.0\CodeAnalysis\Microsoft.CodeAnalysis.Targets
Install StyleCop.MSBuild NuGet package into each project where the analysis is desired
PM> Install-Package StyleCop.MSBuild
Recommended settings should be added to each project file manually
<PropertyGroup> <StyleCopEnabled>false</StyleCopEnabled> <StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings> </PropertyGroup>StyleCopEnabled = false - it's probably a bit too cumbersome to have StyleCop run on each build. StyleCopTreatErrorsAsWarnings = false - since we want to enforce the quality and break the build when violations are found.
Integration makes it easier to configure StyleCop, but is irrelevant for the analysis during the build.
Installer at stylecop.codeplex.com includes Visual Studio extension, JetBrains ReSharper plugin as well as StyleCop MSBuild targets.
Installed StyleCop MSBuild targets are irrelevant here due to the use of NuGet package for analysis during the build.By default StyleCop searches for configuration files — Settings.StyleCop — from the project directory up.
Multiple files are merged from top to bottom allowing for the recommended setup:
The default rule set includes all of the rules
Consider disabling some of them:
Selectively suppress violations with Code Analysis' SuppressMessage attribute
[System.Diagnostics.CodeAnalysis.SuppressMessage( "StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "Optional, but you should always provide one.")] public class MyClass { static void PrivateBeforePublic() { } public static void Public() { } }
StyleCop Visual Studio extension allows to exclude individual files from the analysis
<Compile Include="ThisFileIsExludedFromStyleCop.cs"> <ExcludeFromStyleCop>True</ExcludeFromStyleCop> </Compile>
Use ExcludeFromStyleCop tool for mass exclusion
ExcludeFromStyleCop tool needs to be compiled - it's made available in source code form only.The plugin does not use Settings.StyleCop files — matching configuration needs to be established again in ReSharper options.
The division of StyleCop settings into solution and project level settings files can be matched with ReSharper team-shared solution level and project level settings and committing them to source control.
ReSharper Settings - JetBrains blog Share StyleCop compatible ReSharper settings between different machines - József Kanczler
Example command line
msbuild MySolution.sln /target:Build /property:Configuration=Release /property:StyleCopEnabled=true
function calculateCost(order) { return order.getProductsTotal() + order.getShippingCost(); }
mkdir node_modules npm install grunt npm install grunt-cli npm install grunt-contrib-jshint copy path\to\node.exe node_modules\.bin\JSHint npm package contains the analysis library as well as a node command line interface. However, we choose to use JSHint via Grunt - a popular "JavaScript Task Runner". 1. Create node_modules directory in the solution directory. When npm is run somewhere inside the solution directory, it will search up for existing node_modules directory and install the package there. 2. Need to have npm (and of course node) installed on the developer's machine for the installation of the packages. 3. Grunt packages 0.4.1 and earlier don't have a patch for a longstanding issue with redirected output in node on Windows. We want version 0.4.2+. See: https://github.com/gruntjs/grunt/issues/921 4. Normally grunt-cli would be installed as a global module (npm install grunt-cli -g). Here it's needed on the build server, therefore it's installed locally and committed to the source control. Commit node_modules to source control.
{ // Enforcing "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()` "undef" : true, // Require all non-global variables to be declared (prevents global leaks) "strict" : true, // Requires all functions run in ES5 Strict Mode /* ... */ // Relaxing "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons) "debug" : false, // Allow debugger statements e.g. browser breakpoints. "evil" : false, // Tolerate use of `eval` and `new Function()` /* ... */ // Environments "browser" : true, // Web Browser (window, document, etc) // Custom Globals "globals" : {} // additional predefined global variables }
http://www.jshint.com/docs/options Defaults: https://github.com/jshint/jshint/blob/master/examples/.jshintrc
JSHint picks up .jshintrc files for configuration options. In general, start with enabling all enforcing options and disabling all relaxing options, then adjust to the needs of the project. Multiple .jshintrc files may exist in different directories. JSHint picks the nearest one (traversing directories up) relative to the file being linted. (Does it merge .jshintrc files???)# Exclude libraries, third party code # and other files that shouldn't be checked Scripts/lib/** # Prevent checking VS compilation output directories bin/** obj/**JSHint picks up .jshintignore for files to exclude from the analysis. This is similar to .gitignore.
module.exports = function (grunt) { grunt.initConfig({ jshint: { all: ['**/*.js'], options: { jshintrc: true } } }); grunt.loadTasks('../../node_modules/grunt-contrib-jshint/tasks'); };Gruntfile.js is specific to the web project. Paths are relative to the project directory.
Inline configuration in script file — override has function scope
/* jshint undef: true, unused: true */ /* global MY_GLOBAL */
Ignore a piece of code altogether
// Code here will be linted with JSHint. /* jshint ignore:start */ // Code here will be ignored by JSHint. /* jshint ignore:end */
See the accompanying JSHint sample for details
Extensions for JSHint/JSLint analysis
Only Web Essentials 2013 uses .jshintrc and .jshintignore files. In other cases settings will need to be established again in the extension.
Example command line
msbuild MySolution.sln /target:Build /property:Configuration=Release /property:JSHintEnabled=true
https://github.com/ArturDorochowicz/presentation-enforcing-quality-with-tools