Skip to content

Releases: SergeyTeplyakov/ReSharperContractExtensions

Support for R# 10

24 Jan 01:10
Compare
Choose a tag to compare

This version is availabe at the gallery: https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/

What's new?

  • R# 10.0 support

R# 9.2 support

13 Oct 06:57
Compare
Choose a tag to compare

This version is availabe at the gallery: https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/0.9.2.5

What's new?

  • R# 9.2 support
  • Minor bug fixes
  • Support for nameof operator

Many thanks to @Diagonactic for help with R# 9.2 migration!

Indexers and suspicios preconditions

09 Nov 06:50
Compare
Choose a tag to compare

Where can I get it?

https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/0.9.0

What's new in 0.9.0

Indexers support

Now the tool supports preconditions and postconditions for indexers! (Thanks for @StevenLiekens for the suggestions)
indexer

Warnings for using preconditions in the async methods

Preconditions of any for should be avoided in the async method. The users would expect asynchronous error when the precondition fails. But with async method exception would never be thrown to the caller. The resulting task would be faulted instead.

This means that instead of using following code:

public async Task MethodAsync(string s)
{
  // Contract failure will not be raised to the caller!
  Contract.Requires(s != null); // the tool will worn now!
  await Task.Delay(42);
}

Following code should be used:

public /*async*/ Task MethodAsync(string s)
{
  // Now the precondition is "synchronous" and would be thrown back to the caller!
  Contract.Requires(s != null);
  return DoMethodAsync(s);
}

private async Task DoMethodAsync(string s)
{
  await Task.Delay(42);
}

The same issue would be for any form of preconditions: using Contract.Requires, if-throw etc.

asynccontractrequires

Warnings for using preconditions in the methods with iterator blocks

Iterator blocks (yield return) are implemented in the same way as async method. This means that those features share the same issues.

Argument validation in the iterator blocks are not synchronous: the code would be executed only on the first MoveNext() method of the iteartor:
iteratorprecondition

Basic support for CC errors and warnings

08 Aug 09:36
Compare
Choose a tag to compare

You may find new version at: https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/0.8.0

Support for Code Contract Compiler warnings and errors inside the editor

  1. Inconsistent preconditions visibility
    • Warn on Contract.Requires() when CustomException does not have ctor(string) or ctor(string, string) (#4).
    • Warn on Contfact.Requires() when CustomException is less visible then the enclosing method (#3).
    • Error when Contract.Requires less visible members in the predicate than the enclosing method.
  2. Errors for malformed method contracts
    • Error for Requires/Ensures after EndContractBlock (#21)
    • Error for Requires/Ensures in the middle of the method (#26, #22)
    • Error when Ensures placed before Requires (#29, #9)
    • Error for calling void-return method in the contract block (#5)
    • Warning for calling non-void return method in the contract block (#25)
    • Error on method calls as a source of contract error message (Contract.Requires(false, GetMessage())
    • Error on non-static internal strings used as a source of contract error message (#2)
    • Error on assignments in the contract block (#9)
    • Error on Assert/Assume calls in the contract block (#6)
    • Error on using Requires/Ensures in the try block (#10)
    • Warning on redundant EndContractBlock (for instance used after Contract.Requires/Ensures).
  3. Postcondition checks
    • Error for inconsistent method return type with Contract.Result (#34)
  4. Other features
    • Generated contract classes would be marked with ExlucdeFromCodeCoverageAttribute if this option is enabled in the plug-in options page. (#31)
    • Warn on redundant Contract.Requires on nullable arguments

Bug fixes

  • Generate call to base-class constructor if needed for newly generated contract class (#33)
  • Added support for contract classes for generic interfaces and abstract classes (#16)

Enum support and Contract conversions

01 Jul 19:50
Compare
Choose a tag to compare

New features

  • Added combo action that convert if-throw precondition check to Contract.Requires (both - gneric and non-generic versions);
  • Added combo action that convert between generic and non-generic Contract.Requires

Requires: Requires for enum (#1)

  • Added combo action that adds precondition check for enums and nullable enums with Contract.Requires(Enum.IsDefined(typeof(SomeEnumType), someEnumValue));
  • Added combo action that adds postcondition check that enum and nullable enum result is defined by Enum.IsDefiined method.

Binaries at R# Gallery

https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/0.7.51

Demo

Convert null-check preconditions from if-throw to Contract.Requires

Convert range check from if-throw to Contract.Requires

Add precondition check for enum argument

Add postcondition check for enum argument

Method Combo Requires

05 Jun 08:23
Compare
Choose a tag to compare

New features

  • Added combo actions that will add Contract.Requires for all method arguments
  • Added Plug-in Settings (available at R# Options page):
    • Use generic Contract.Requires<ArgumentNullException> by default
    • Check string arguments with Contract.Requires(!string.IsNullOrEmpty(arg)) by default for string arguments

Binaries at R# Gallery

https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/0.7.0

Demo

Add preconditions for all arguments

Check string arguments with string.IsNullOrEmpty

(Note, this feature should be turned on at plug-in settings page, available at R# Options)

0.6

31 May 13:59
Compare
Choose a tag to compare
0.6

New features

  • Added support for preconditions for property setters
  • Addes support for preconditions for property setters for abstract class and interfaces (Combo Requries)

Bug fixes

  • Fixed issue with invalid order of Contract.Invariant statements in the object invariant method.

This release available at R# Gallery: https://resharper-plugins.jetbrains.com/packages/ReSharper.ContractExtensions/