Git Product home page Git Product logo

final-hill / decorator-contracts Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 1.0 1.63 MB

Decorator Contracts is a library that provides the ability to create and assign Code Contracts to ECMAScript and TypeScript classes. This enables enforcement of the Liskov substitution principle and the Open-closed principle of SOLID to support Design By Contract™.

License: GNU Affero General Public License v3.0

JavaScript 1.38% TypeScript 98.62%
behavioral-subtyping assertion code-contracts decorators demands design-by-contract encapsulation exception-handling invariant liskov-substitution-principle

decorator-contracts's People

Contributors

dependabot[bot] avatar mlhaufe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

huanhulan

decorator-contracts's Issues

Assertions must return a boolean in all modes

Overview

Performing assertions across a code-base can be redundant and time-consuming. To mitigate this impact on efficiency, a means of disabling assertion checks must be provided. The intent being that during development and debugging the assertions would be executed, but in a production environment the checks would not be performed and instead simply return true.

This should not be a global flag, but a granular one to provide flexibility

Tasks

  • Add Unit Test
  • Implementation
  • Update README

Migrate from Azure to Github

There is more public familiarity with GitHub than Azure, plus there is more simplicity currently. Now that Microsoft owns GitHub there is less of a desire to remain in the old location in order to leverage to benefits.

Tasks

Feature: Contracts Constructor

import Contracts from '@thenewobjective/decorator-contracts'

let checkedContracts = new Contracts(true),
    uncheckedContracts = new Contracts(false)
  • The contracts constructor accepts a single boolean parameter called "checkMode". #24

Feature: invariant

  • The 'invariant' declaration must be documented. #27
  • The invariant decorator must be class decorator only. #28
  • There can be multiple invariant decorators assigned to a class. #29
  • The subclasses of a contracted class must obey the invariants #30
  • A truthy invariant does not throw an exception when evaluated. #31
  • A falsy invariant throws an exception when evaluated. #32
  • An invariant is evaluated after it's associated class is constructed. #33
  • An invariant is evaluated before and after every method call on the associated class. #34
  • Public properties must be forbidden. #35
  • A class feature with a decorator must not be functional until the @invariant is defined. #36
  • The invariant decorator has a checked mode and unchecked mode. #37
  • In checked mode the invariant is evaluated #38
  • In unchecked mode the invariant is not evaluated. #39
  • A subclass with its own invariants must enforce all ancestor invariants. #40
  • @invariant supports use with no arguments. #41
  • There can be multiple invariants assigned to a contract #178

Suggest VSCode extensions

Azure Pipelines: "ms-azure-devops.azure-pipelines"
Azure Repos: "ms-vsts.team"
EditorConfig for VS Code: "editorconfig.editorconfig"
TSLint: "ms-vscode.vscode-typescript-tslint-plugin"
markdownlint: "davidanson.vscode-markdownlint"

A subclass with its own invariants must enforce all ancestor invariants

"""
The notions of “stronger” and “weaker” are formally defined from logic: P1 is said to be stronger than P2, and P2 weaker than P1, if P1 implies P2 and they are not equal. As every proposition implies True, and False implies every proposition, it is indeed legitimate to speak of True as the weakest and False as the strongest of all possible assertions.
""" -- Meyer p. 358

The class invariant must not be weaker than the invariant in the superclass. Practically this means that all invariant assertions across classes in the hierarchy are ANDed together.

  • Implement functionality
  • Implement Unit Tests
  • Update README

Feature: override

References

Requirements

  • The 'override' decorator must be documented. #43
  • A subclass with an overriding member missing @OverRide is an error. #48
  • Accessors must support @OverRide. #50
  • Contravariance of method arguments in the subtype. #51
  • In production mode the @OverRide decorator is a no-op. #45
  • Only a single @OverRide can be assigned to a member per class. #54
  • The 'override' decorator must not be functional until the invariant decorator is defined. #53
  • The 'override' decorator must have a Contracted class in it's ancestry #170
  • The override decorator is a non-static member decorator only. #44
  • The parameter names and positions of an overridden method must match its ancestor's. #52
  • TypeScript support? #49
  • Using @OverRide on a class member with no ancestor member is an error. #46
  • Using @OverRide on a method with an ancestor with a different parameter count is an error. #47

Public properties must be forbidden

To guarantee invariants remain valid, public property definitions are forbidden. All interactions with a contracted class must be done through a method or accessor.

  • Create Unit Test
  • Freeze class
  • Update README

Linting must be enabled

Linting must be enabled to enforce code conventions and provide additional semantic checks

  • Remove unused dependencies

Assertions must be toggleable

Description

Redundant checking can negatively impact efficiency. A flag should be provided to toggle the execution of assertions in a module.

Disabled in unchecked mode
Enabled in checked mode

Tasks

  • Expose a flag on the module that toggles between implementations

Azure build pipelines MUST be managed in the project

  • Add friendly names to the yaml files

Current appearance:

image

The yaml 'name' property doesn't seem to do anything in the portal:

image

But there is a portal feature available to accomplish this task on the detail screen:

image

This isn't reflected in the file it seems

  • CI trigger for build should only occur on master branch
  • Disable CI Trigger on Validation build
  • Export Azure pipeline YAML file into project

Accessors must support @override

@invariant
class Foo {
  private _value_: number = 0
  get value(){ return this._value }
  set value(x: number){ this._value_ = x }
} 

class Bar extends Foo {
  @override
  set value(x: number){
     console.log('set value')
    super.value = x
  }
}

Tasks

  • Create Unit Test
  • Implementation
  • Update README

Publish Unit test results Azure DevOps

@invariant supports use with no arguments

Overview

Method decorators are registered but not active until this class decorator can associate them with the contractHandler and/or enforce their usage. This requirement simply allows an empty @invariant decorator to be used.

@invariant
class MyClass {
...
}

Tasks

  • Implementation
  • Implement overload so that parenthesis is not required
  • Implement Unit Test
  • Update README

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.