Skip to content

Commit

Permalink
Expand no-simple-type-checking-assertions regex, see: phetsims/mean-s…
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Oct 20, 2022
1 parent b4c132f commit b4ac285
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 116 deletions.
2 changes: 0 additions & 2 deletions js/accessibility/pdom/ParallelDOM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,6 @@ export default class ParallelDOM extends PhetioObject {
* TODO: Support more than one group focus highlight (multiple ancestors could have groupFocusHighlight), see https://github.com/phetsims/scenery/issues/708
*/
public setGroupFocusHighlight( groupHighlight: Node | boolean ): void {
assert && assert( typeof groupHighlight === 'boolean' || groupHighlight instanceof Node );
this._groupFocusHighlight = groupHighlight;
}

Expand Down Expand Up @@ -2285,7 +2284,6 @@ export default class ParallelDOM extends PhetioObject {
value = unwrapProperty( value )!;
}

assert && assert( typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number' );
assert && providedOptions && assert( Object.getPrototypeOf( providedOptions ) === Object.prototype,
'Extra prototype on pdomAttribute options object is a code smell' );
assert && typeof value === 'string' && validate( value, Validation.STRING_WITHOUT_TEMPLATE_VARS_VALIDATOR );
Expand Down
46 changes: 23 additions & 23 deletions js/filters/ColorMatrixFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,29 @@ export default class ColorMatrixFilter extends Filter {
m20: number, m21: number, m22: number, m23: number, m24: number,
m30: number, m31: number, m32: number, m33: number, m34: number ) {

assert && assert( typeof m00 === 'number' && isFinite( m00 ), 'm00 should be a finite number' );
assert && assert( typeof m01 === 'number' && isFinite( m01 ), 'm01 should be a finite number' );
assert && assert( typeof m02 === 'number' && isFinite( m02 ), 'm02 should be a finite number' );
assert && assert( typeof m03 === 'number' && isFinite( m03 ), 'm03 should be a finite number' );
assert && assert( typeof m04 === 'number' && isFinite( m04 ), 'm04 should be a finite number' );

assert && assert( typeof m10 === 'number' && isFinite( m10 ), 'm10 should be a finite number' );
assert && assert( typeof m11 === 'number' && isFinite( m11 ), 'm11 should be a finite number' );
assert && assert( typeof m12 === 'number' && isFinite( m12 ), 'm12 should be a finite number' );
assert && assert( typeof m13 === 'number' && isFinite( m13 ), 'm13 should be a finite number' );
assert && assert( typeof m14 === 'number' && isFinite( m14 ), 'm14 should be a finite number' );

assert && assert( typeof m20 === 'number' && isFinite( m20 ), 'm20 should be a finite number' );
assert && assert( typeof m21 === 'number' && isFinite( m21 ), 'm21 should be a finite number' );
assert && assert( typeof m22 === 'number' && isFinite( m22 ), 'm22 should be a finite number' );
assert && assert( typeof m23 === 'number' && isFinite( m23 ), 'm23 should be a finite number' );
assert && assert( typeof m24 === 'number' && isFinite( m24 ), 'm24 should be a finite number' );

assert && assert( typeof m30 === 'number' && isFinite( m30 ), 'm30 should be a finite number' );
assert && assert( typeof m31 === 'number' && isFinite( m31 ), 'm31 should be a finite number' );
assert && assert( typeof m32 === 'number' && isFinite( m32 ), 'm32 should be a finite number' );
assert && assert( typeof m33 === 'number' && isFinite( m33 ), 'm33 should be a finite number' );
assert && assert( typeof m34 === 'number' && isFinite( m34 ), 'm34 should be a finite number' );
assert && assert( isFinite( m00 ), 'm00 should be a finite number' );
assert && assert( isFinite( m01 ), 'm01 should be a finite number' );
assert && assert( isFinite( m02 ), 'm02 should be a finite number' );
assert && assert( isFinite( m03 ), 'm03 should be a finite number' );
assert && assert( isFinite( m04 ), 'm04 should be a finite number' );

assert && assert( isFinite( m10 ), 'm10 should be a finite number' );
assert && assert( isFinite( m11 ), 'm11 should be a finite number' );
assert && assert( isFinite( m12 ), 'm12 should be a finite number' );
assert && assert( isFinite( m13 ), 'm13 should be a finite number' );
assert && assert( isFinite( m14 ), 'm14 should be a finite number' );

assert && assert( isFinite( m20 ), 'm20 should be a finite number' );
assert && assert( isFinite( m21 ), 'm21 should be a finite number' );
assert && assert( isFinite( m22 ), 'm22 should be a finite number' );
assert && assert( isFinite( m23 ), 'm23 should be a finite number' );
assert && assert( isFinite( m24 ), 'm24 should be a finite number' );

assert && assert( isFinite( m30 ), 'm30 should be a finite number' );
assert && assert( isFinite( m31 ), 'm31 should be a finite number' );
assert && assert( isFinite( m32 ), 'm32 should be a finite number' );
assert && assert( isFinite( m33 ), 'm33 should be a finite number' );
assert && assert( isFinite( m34 ), 'm34 should be a finite number' );

super();

Expand Down
6 changes: 4 additions & 2 deletions js/input/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ export default class Input extends PhetioObject {
if ( relatedTargetElement && this.isTargetUnderPDOM( relatedTargetElement as HTMLElement ) ) {

const relatedTarget = ( domEvent.relatedTarget as unknown as Element );
assert && assert( relatedTarget instanceof window.Element );
// TODO: Sam we were unsure if this code might interact with JS code that may create problems in the future. Thoughts? https://github.com/phetsims/chipper/issues/1344
assert && assert( relatedTarget instanceof window.Element ); // eslint-disable-line no-simple-type-checking-assertions
const trailIndices = relatedTarget.getAttribute( PDOMUtils.DATA_PDOM_UNIQUE_ID );
assert && assert( trailIndices, 'should not be null' );

Expand Down Expand Up @@ -1182,7 +1183,8 @@ export default class Input extends PhetioObject {
}
else {
const target = ( domEvent.target as unknown as Element );
assert && assert( target instanceof window.Element );
// TODO: Sam we were unsure if this code might interact with JS code that may create problems in the future. Thoughts?
assert && assert( target instanceof window.Element ); // eslint-disable-line no-simple-type-checking-assertions
if ( target && this.isTargetUnderPDOM( target as HTMLElement ) ) {
const trailIndices = target.getAttribute( PDOMUtils.DATA_PDOM_UNIQUE_ID );
assert && assert( trailIndices, 'should not be null' );
Expand Down
4 changes: 2 additions & 2 deletions js/layout/constraints/FlowConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ export default class FlowConstraint extends FlowConfigurable( NodeLayoutConstrai
}

public set spacing( value: number ) {
assert && assert( typeof value === 'number' && isFinite( value ) );
assert && assert( isFinite( value ) );

if ( this._spacing !== value ) {
this._spacing = value;
Expand All @@ -429,7 +429,7 @@ export default class FlowConstraint extends FlowConfigurable( NodeLayoutConstrai
}

public set lineSpacing( value: number ) {
assert && assert( typeof value === 'number' && isFinite( value ) );
assert && assert( isFinite( value ) );

if ( this._lineSpacing !== value ) {
this._lineSpacing = value;
Expand Down
14 changes: 7 additions & 7 deletions js/layout/nodes/AlignBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export default class AlignBox extends SuperType {
* box.
*/
public setMargin( margin: number ): this {
assert && assert( typeof margin === 'number' && isFinite( margin ) && margin >= 0,
assert && assert( isFinite( margin ) && margin >= 0,
'margin should be a finite non-negative number' );

if ( this._leftMargin !== margin ||
Expand Down Expand Up @@ -386,7 +386,7 @@ export default class AlignBox extends SuperType {
* right sides of this box.
*/
public setXMargin( xMargin: number ): this {
assert && assert( typeof xMargin === 'number' && isFinite( xMargin ) && xMargin >= 0,
assert && assert( isFinite( xMargin ) && xMargin >= 0,
'xMargin should be a finite non-negative number' );

if ( this._leftMargin !== xMargin || this._rightMargin !== xMargin ) {
Expand Down Expand Up @@ -419,7 +419,7 @@ export default class AlignBox extends SuperType {
* bottom sides of this box.
*/
public setYMargin( yMargin: number ): this {
assert && assert( typeof yMargin === 'number' && isFinite( yMargin ) && yMargin >= 0,
assert && assert( isFinite( yMargin ) && yMargin >= 0,
'yMargin should be a finite non-negative number' );

if ( this._topMargin !== yMargin || this._bottomMargin !== yMargin ) {
Expand Down Expand Up @@ -452,7 +452,7 @@ export default class AlignBox extends SuperType {
* the box.
*/
public setLeftMargin( leftMargin: number ): this {
assert && assert( typeof leftMargin === 'number' && isFinite( leftMargin ) && leftMargin >= 0,
assert && assert( isFinite( leftMargin ) && leftMargin >= 0,
'leftMargin should be a finite non-negative number' );

if ( this._leftMargin !== leftMargin ) {
Expand Down Expand Up @@ -483,7 +483,7 @@ export default class AlignBox extends SuperType {
* the container.
*/
public setRightMargin( rightMargin: number ): this {
assert && assert( typeof rightMargin === 'number' && isFinite( rightMargin ) && rightMargin >= 0,
assert && assert( isFinite( rightMargin ) && rightMargin >= 0,
'rightMargin should be a finite non-negative number' );

if ( this._rightMargin !== rightMargin ) {
Expand Down Expand Up @@ -514,7 +514,7 @@ export default class AlignBox extends SuperType {
* container.
*/
public setTopMargin( topMargin: number ): this {
assert && assert( typeof topMargin === 'number' && isFinite( topMargin ) && topMargin >= 0,
assert && assert( isFinite( topMargin ) && topMargin >= 0,
'topMargin should be a finite non-negative number' );

if ( this._topMargin !== topMargin ) {
Expand Down Expand Up @@ -545,7 +545,7 @@ export default class AlignBox extends SuperType {
* container.
*/
public setBottomMargin( bottomMargin: number ): this {
assert && assert( typeof bottomMargin === 'number' && isFinite( bottomMargin ) && bottomMargin >= 0,
assert && assert( isFinite( bottomMargin ) && bottomMargin >= 0,
'bottomMargin should be a finite non-negative number' );

if ( this._bottomMargin !== bottomMargin ) {
Expand Down
9 changes: 6 additions & 3 deletions js/nodes/DOM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ export default class DOM extends Node {
public constructor( element: Element | JQuery, options?: DOMOptions ) {
assert && assert( options === undefined || Object.getPrototypeOf( options ) === Object.prototype,
'Extra prototype on Node options object is a code smell' );
assert && assert( element instanceof window.Element || element.jquery,
'DOM nodes need to be passed an HTML/DOM element or a jQuery selection like $( ... )' );

// TODO: Sam we were unsure if this code might interact with JS code that may create problems in the future. Thoughts? https://github.com/phetsims/chipper/issues/1344
assert && assert( element instanceof window.Element || element.jquery, 'DOM nodes need to be passed an HTML/DOM element or a jQuery selection like $( ... )' ); // eslint-disable-line no-simple-type-checking-assertions

// unwrap from jQuery if that is passed in, for consistency
if ( isJQueryElement( element ) ) {
element = element[ 0 ];
assert && assert( element instanceof window.Element );

// TODO: Sam we were unsure if this code might interact with JS code that may create problems in the future. Thoughts? https://github.com/phetsims/chipper/issues/1344
assert && assert( element instanceof window.Element ); // eslint-disable-line no-simple-type-checking-assertions
}

super();
Expand Down
20 changes: 7 additions & 13 deletions js/nodes/Imageable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
*/
public setImage( image: ImageableImage ): this {
assert && assert( image, 'image should be available' );
assert && assert( typeof image === 'string' ||
image instanceof HTMLImageElement ||
image instanceof HTMLCanvasElement ||
Array.isArray( image ), 'image is not of the correct type' );

// Generally, if a different value for image is provided, it has changed
let hasImageChanged = this._image !== image;
Expand Down Expand Up @@ -376,7 +372,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* @param width - Expected width of the image's unloaded content
*/
public setInitialWidth( width: number ): this {
assert && assert( typeof width === 'number' && width >= 0 && ( width % 1 === 0 ), 'initialWidth should be a non-negative integer' );
assert && assert( width >= 0 && ( width % 1 === 0 ), 'initialWidth should be a non-negative integer' );

if ( width !== this._initialWidth ) {
this._initialWidth = width;
Expand Down Expand Up @@ -419,7 +415,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* @param height - Expected height of the image's unloaded content
*/
public setInitialHeight( height: number ): this {
assert && assert( typeof height === 'number' && height >= 0 && ( height % 1 === 0 ), 'initialHeight should be a non-negative integer' );
assert && assert( height >= 0 && ( height % 1 === 0 ), 'initialHeight should be a non-negative integer' );

if ( height !== this._initialHeight ) {
this._initialHeight = height;
Expand Down Expand Up @@ -521,7 +517,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* @param level - A non-negative integer representing the number of mipmap levels to precompute.
*/
public setMipmapInitialLevel( level: number ): this {
assert && assert( typeof level === 'number' && level % 1 === 0 && level >= 0,
assert && assert( level % 1 === 0 && level >= 0,
'mipmapInitialLevel should be a non-negative integer' );

if ( this._mipmapInitialLevel !== level ) {
Expand Down Expand Up @@ -556,7 +552,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* @param level - A non-negative integer representing the maximum mipmap level to compute.
*/
public setMipmapMaxLevel( level: number ): this {
assert && assert( typeof level === 'number' && level % 1 === 0 && level >= 0,
assert && assert( level % 1 === 0 && level >= 0,
'mipmapMaxLevel should be a non-negative integer' );

if ( this._mipmapMaxLevel !== level ) {
Expand Down Expand Up @@ -700,7 +696,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* Returns the desired mipmap level (0-indexed) that should be used for the particular scale
*/
public getMipmapLevelFromScale( scale: number, additionalBias = 0 ): number {
assert && assert( typeof scale === 'number' && scale > 0, 'scale should be a positive number' );
assert && assert( scale > 0, 'scale should be a positive number' );

// If we are shown larger than scale, ALWAYS choose the highest resolution
if ( scale >= 1 ) {
Expand Down Expand Up @@ -742,8 +738,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* @returns - Matching <canvas> for the level of detail
*/
public getMipmapCanvas( level: number ): HTMLCanvasElement {
assert && assert( typeof level === 'number' &&
level >= 0 &&
assert && assert( level >= 0 &&
level < this._mipmapCanvases.length &&
( level % 1 ) === 0 );

Expand All @@ -763,8 +758,7 @@ const Imageable = <SuperType extends Constructor>( type: SuperType ) => { // esl
* @returns - Matching data URL for the level of detail
*/
public getMipmapURL( level: number ): string {
assert && assert( typeof level === 'number' &&
level >= 0 &&
assert && assert( level >= 0 &&
level < this._mipmapCanvases.length &&
( level % 1 ) === 0 );

Expand Down
2 changes: 1 addition & 1 deletion js/nodes/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class Line extends Path {
}
else {
// new Line( x1, y1, x2, y2, [options] )
assert && assert( typeof x1 === 'number' &&
assert && assert( x1 !== undefined &&
typeof y1 === 'number' &&
typeof x2 === 'number' &&
typeof y2 === 'number' );
Expand Down
Loading

0 comments on commit b4ac285

Please sign in to comment.