Skip to content

Commit

Permalink
linting, dependencies, @OverRide messaging (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhaufe authored Jan 29, 2022
1 parent 4541444 commit 0b0e371
Show file tree
Hide file tree
Showing 37 changed files with 1,555 additions and 2,252 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@
"accessibility": "no-public"
}
],
"@typescript-eslint/member-ordering": "error",
// buggy: https://github.com/typescript-eslint/typescript-eslint/issues/2409
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-param-reassign": "off",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
Expand Down Expand Up @@ -347,7 +348,7 @@
"header/header": [2, "block", [
"!",
" * @license",
" * Copyright (C) 2021 Final Hill LLC",
" * Copyright (C) 2022 Final Hill LLC",
" * SPDX-License-Identifier: AGPL-3.0-only",
" * @see <https://spdx.org/licenses/AGPL-3.0-only.html>",
" "
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Fixed bug in README Stack example
* Updated README instructions on webpage installation
* Updated dependencies
* Updated headers for 2022
* Linting fixes
* Added better error messaging for `@override` issues

## v0.22.0

Expand Down
3,591 changes: 1,446 additions & 2,145 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@
"author": "Michael L Haufe <michael.haufe@final-hill.com> (https://final-hill.com)",
"license": "AGPL-3.0-only",
"devDependencies": {
"@types/jest": "^26.0.24",
"@types/node": "^15.14.9",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.13",
"@typescript-eslint/eslint-plugin": "^5.10.1",
"@typescript-eslint/parser": "^5.10.1",
"eslint": "^8.8.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.25.2",
"jest": "^27.2.5",
"eslint-plugin-import": "^2.25.4",
"jest": "^27.4.7",
"jest-junit": "^13.0.0",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0"
"typescript": "^4.5.5",
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2"
},
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion src/AssertionError.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
9 changes: 5 additions & 4 deletions src/Contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down Expand Up @@ -49,9 +49,6 @@ export class Contract<T extends AnyObject> {
[checkedMode]: boolean;
readonly [extend]?: Contract<T>;
readonly assertions: ContractOptions<T> = Object.create(null);
get [invariant](): Invariant<T> {
return this.#invariant;
}

constructor(assertions: Partial<ContractOptions<T>> = Object.create(null)) {
this[extend] = assertions[extend];
Expand All @@ -72,6 +69,10 @@ export class Contract<T extends AnyObject> {

deepFreeze(this.assertions);
}

get [invariant](): Invariant<T> {
return this.#invariant;
}
}

export {checkedMode, extend, invariant};
13 changes: 7 additions & 6 deletions src/Contracted.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down Expand Up @@ -57,11 +57,6 @@ function Contracted<
abstract class InnerContracted extends Base {
// prevents multiple @Contracted decorators from being applied
static readonly [isContracted] = true;
// FIXME: dirty hack. Possibly resolved by moving to contracts as classes
// The static getter is used by the construction invariant check
// The instance getter is used by the feature declarations
static get [innerContract](){ return contract; }
get [innerContract](){ return contract; }

constructor(...args: any[]) {
super(...args);
Expand Down Expand Up @@ -92,6 +87,12 @@ function Contracted<

return this;
}

// FIXME: dirty hack. Possibly resolved by moving to contracts as classes
// The static getter is used by the construction invariant check
// The instance getter is used by the feature declarations
static get [innerContract](){ return contract; }
get [innerContract](){ return contract; }
}

const classRegistration = CLASS_REGISTRY.getOrCreate(InnerContracted);
Expand Down
2 changes: 1 addition & 1 deletion src/Messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/assert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/iff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/implies.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/CLASS_REGISTRY.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
20 changes: 10 additions & 10 deletions src/lib/ClassRegistration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down Expand Up @@ -96,6 +96,15 @@ class ClassRegistration {
.map(key => new Feature(this, key, Object.getOwnPropertyDescriptor(proto,key)!));
}

/**
* Returns the features associated with the registered class.
*
* @returns {Set<Feature>} The set of features
*/
get features(): Feature[] {
return [...this.#features];
}

/**
* Returns a reference to the parent class
*/
Expand Down Expand Up @@ -180,15 +189,6 @@ class ClassRegistration {
return this.features.find(({name}) => name === propertyKey) ??
this.parentRegistration?.findFeature(propertyKey);
}

/**
* Returns the features associated with the registered class.
*
* @returns {Set<Feature>} The set of features
*/
get features(): Feature[] {
return [...this.#features];
}
}

export default ClassRegistration;
2 changes: 1 addition & 1 deletion src/lib/ClassType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
52 changes: 21 additions & 31 deletions src/lib/Feature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand All @@ -27,21 +27,6 @@ class Feature {
return this.classRegistration.ancestryFeatures().filter(feature => feature.name === this.name)[0];
}

/**
* Returns a reference to the descriptor
*/
get descriptor() {
return this.#descriptor;
}

/**
* Updates the descriptor
* @param {PropertyDescriptor} desc - The new descriptor
*/
set descriptor(desc: PropertyDescriptor) {
this.#descriptor = desc;
}

/**
* Returns a reference to the getter if it exists
*/
Expand Down Expand Up @@ -95,21 +80,6 @@ class Feature {
'accessor';
}

/**
* Returns the original feature descriptor which was replaced by the `override` decorator
*/
get overriddenOriginalDescriptor(): PropertyDescriptor| undefined {
return this.#overriddenOriginalDescriptor;
}

/**
* Sets the feature descriptor. Used by the `override` decorator.
* @param {PropertyDescriptor} value - The descriptor to save
*/
set overriddenOriginalDescriptor(value: PropertyDescriptor | undefined) {
this.#overriddenOriginalDescriptor = value;
}

/**
* Returns a reference to the setter if it exists
*/
Expand All @@ -125,6 +95,26 @@ class Feature {
get value(): any {
return this.#descriptor.value;
}

/**
* The original feature descriptor which was replaced by the `override` decorator
*/
get overriddenOriginalDescriptor(): PropertyDescriptor| undefined {
return this.#overriddenOriginalDescriptor;
}
set overriddenOriginalDescriptor(value: PropertyDescriptor | undefined) {
this.#overriddenOriginalDescriptor = value;
}

/**
* Returns a reference to the descriptor
*/
get descriptor() {
return this.#descriptor;
}
set descriptor(desc: PropertyDescriptor) {
this.#descriptor = desc;
}
}

export default Feature;
2 changes: 1 addition & 1 deletion src/lib/assertDemands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/assertEnsures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/assertInvariants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/deepFreeze.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/takeWhile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/unChecked.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
7 changes: 5 additions & 2 deletions src/override.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down Expand Up @@ -32,7 +32,10 @@ function override(target: Record<PropertyKey, any>, propertyKey: PropertyKey, de

const ancFeature = feature.ancestorFeature;

assert(ancFeature != null && feature.memberType === ancFeature.memberType, MSG_NO_MATCHING_FEATURE);
assert(
ancFeature != null && feature.memberType === ancFeature.memberType,
`${MSG_NO_MATCHING_FEATURE} '${registration.Class.name}.prototype.${String(propertyKey)}'`
);
assert(!feature.hasOverrides, MSG_DUPLICATE_OVERRIDE);
feature.hasOverrides = true;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/Contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* @license
* Copyright (C) 2021 Final Hill LLC
* Copyright (C) 2022 Final Hill LLC
* SPDX-License-Identifier: AGPL-3.0-only
* @see <https://spdx.org/licenses/AGPL-3.0-only.html>
*/
Expand Down
Loading

0 comments on commit 0b0e371

Please sign in to comment.