Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <a href="http://www.NDepend.com" rel="nofollow">static analysis tool NDepend</a> does pretty much what you are describing. Have a look at this default Code Query Rule that find methods that where <i>pure</i> (because tagged with a <i>PureAttribute</i>) and that are not <i>pure</i> anymore:</p> <pre><code>// &lt;Name&gt;Regression on pure methods&lt;/Name&gt; WARN IF Count &gt; 0 IN SELECT METHODS WHERE HasAttribute "OPTIONAL:NDepend.CQL.PureAttribute" AND ( ChangesObjectState OR ChangesTypeState ) AND NbLinesOfCode &gt; 0 // A method is pure if its execution doesn’t change // the value of any instance or static field. // Pure methods naturally simplify code by limiting // side-effects. // See some explanations on immutability - purity and // how NDepend supports it here: // http://codebetter.com/blogs/patricksmacchia/archive/2008/01/13/immutable-types-understand-them-and-use-them.aspx // NDepend.CQL.PureAttribute is defined in the // redistributable assembly $NDependInstallDir$\Lib\NDepend.CQL.dll // You can define your own attribute to tag 'pure' methods. </code></pre> <p>Notice that you can use your own <i>PureAttribute</i> instead of the one specified by default in the rule, just specify your attribute <i>namespace.nameAttribute</i>.</p> <p>Notice that the <a href="http://www.ndepend.com/Features.aspx#CQL" rel="nofollow">CQL (Code Query Language)</a> clauses <i>ChangesObjectState</i> and <i>ChangesTypeState</i> returns true for methods that assign an <i>instance (object)</i> or a <i>static (type)</i> field.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload