Browse Source

Expand lint scripts (#25251)

* Expand lint test

* npm run lint-fix

* More fixes

* Revert some files

* Restore one more file

* Remaining fixes

* Revert linting changes to manual

* Revert lint test changes

* Return `lint-fix` to linting core, addons, and docs
Levi Pesin 2 years ago
parent
commit
a583db2ee7

+ 1 - 1
docs/page.js

@@ -165,7 +165,7 @@ function onDocumentLoad() {
 
 		}
 
-		prettyPrint();
+		prettyPrint(); // eslint-disable-line no-undef
 
 	};
 

+ 2 - 2
editor/js/Sidebar.Animation.js

@@ -23,11 +23,11 @@ function SidebarAnimation( editor ) {
 		const name = new UIText( animation.name ).setWidth( '200px' );
 		container.add( name );
 
-		const button = new UIButton( getButtonText( action  ) );
+		const button = new UIButton( getButtonText( action ) );
 		button.onClick( function () {
 
 			action.isRunning() ? action.stop() : action.play();
-			button.setTextContent( getButtonText( action  ) );
+			button.setTextContent( getButtonText( action ) );
 
 		} );
 

+ 1 - 1
editor/js/Sidebar.Material.MapProperty.js

@@ -55,7 +55,7 @@ function SidebarMaterialMapProperty( editor, property, name ) {
 	let rangeMin, rangeMax;
 
 	if ( property === 'iridescenceThicknessMap' ) {
-		
+
 		const range = new UIDiv().setMarginLeft( '3px' );
 		container.add( range );
 

+ 2 - 2
editor/sw.js

@@ -268,8 +268,8 @@ async function networkFirst( request ) {
 		if ( request.url.endsWith( 'editor/' ) || request.url.endsWith( 'editor/index.html' ) ) { // copied from coi-serviceworker
 
 			const newHeaders = new Headers( response.headers );
-			newHeaders.set( "Cross-Origin-Embedder-Policy", "require-corp" );
-			newHeaders.set( "Cross-Origin-Opener-Policy", "same-origin" );
+			newHeaders.set( 'Cross-Origin-Embedder-Policy', 'require-corp' );
+			newHeaders.set( 'Cross-Origin-Opener-Policy', 'same-origin' );
 
 			response = new Response( response.body, { status: response.status, statusText: response.statusText, headers: newHeaders } );
 

+ 51 - 15
examples/jsm/loaders/PLYLoader.js

@@ -299,7 +299,11 @@ class PLYLoader extends Loader {
 
 		function mapElementAttributes( properties ) {
 
-			const elementNames = properties.map(  property => { return property.name } );
+			const elementNames = properties.map( property => {
+
+				return property.name;
+
+			} );
 
 			function findAttrName( names ) {
 
@@ -564,20 +568,52 @@ class PLYLoader extends Loader {
 				switch ( type ) {
 
 					// corespondences for non-specific length types here match rply:
-					case 'int8':	case 'char':	return { read: ( at ) => { return dataview.getInt8( at ) }, size: 1 };
-					case 'uint8':	case 'uchar':	return { read: ( at ) => { return dataview.getUint8( at ) }, size: 1 };
-					case 'int16':	case 'short':	return { read: ( at ) => { return dataview.getInt16( at, little_endian ) }, size: 2 };
-					case 'uint16':	case 'ushort':	return { read: ( at ) => { return dataview.getUint16( at, little_endian ) }, size: 2 };
-					case 'int32':	case 'int':		return { read: ( at ) => { return dataview.getInt32( at, little_endian ) }, size: 4 };
-					case 'uint32':	case 'uint':	return { read: ( at ) => { return dataview.getUint32( at, little_endian ) }, size: 4 };
-					case 'float32': case 'float':	return { read: ( at ) => { return dataview.getFloat32( at, little_endian ) }, size: 4 };
-					case 'float64': case 'double':	return { read: ( at ) => { return dataview.getFloat64( at, little_endian ) }, size: 8 };
+					case 'int8':	case 'char':	return { read: ( at ) => {
+
+						return dataview.getInt8( at );
+
+					}, size: 1 };
+					case 'uint8':	case 'uchar':	return { read: ( at ) => {
+
+						return dataview.getUint8( at );
+
+					}, size: 1 };
+					case 'int16':	case 'short':	return { read: ( at ) => {
+
+						return dataview.getInt16( at, little_endian );
+
+					}, size: 2 };
+					case 'uint16':	case 'ushort':	return { read: ( at ) => {
+
+						return dataview.getUint16( at, little_endian );
+
+					}, size: 2 };
+					case 'int32':	case 'int':		return { read: ( at ) => {
+
+						return dataview.getInt32( at, little_endian );
+
+					}, size: 4 };
+					case 'uint32':	case 'uint':	return { read: ( at ) => {
+
+						return dataview.getUint32( at, little_endian );
+
+					}, size: 4 };
+					case 'float32': case 'float':	return { read: ( at ) => {
+
+						return dataview.getFloat32( at, little_endian );
+
+					}, size: 4 };
+					case 'float64': case 'double':	return { read: ( at ) => {
+
+						return dataview.getFloat64( at, little_endian );
+
+					}, size: 8 };
 
 				}
 
 			}
 
-			for ( let i = 0, l = properties.length; i < l; i++ ) {
+			for ( let i = 0, l = properties.length; i < l; i ++ ) {
 
 				const property = properties[ i ];
 
@@ -594,7 +630,7 @@ class PLYLoader extends Loader {
 
 			}
 
-		};
+		}
 
 		function parseBinary( data, header ) {
 
@@ -638,9 +674,9 @@ class PLYLoader extends Loader {
 
 			do {
 
-				const c = String.fromCharCode( bytes[ i++ ] );
+				const c = String.fromCharCode( bytes[ i ++ ] );
 
-				if ( c !== "\n" && c !== "\r" ) {
+				if ( c !== '\n' && c !== '\r' ) {
 
 					line += c;
 
@@ -656,9 +692,9 @@ class PLYLoader extends Loader {
 
 				}
 
-			}  while ( cont && i < bytes.length );
+			} while ( cont && i < bytes.length );
 
-			return lines.join( "\r" ) + "\r";
+			return lines.join( '\r' ) + '\r';
 
 		}
 

+ 1 - 1
examples/jsm/loaders/lwo/IFFParser.js

@@ -1084,7 +1084,7 @@ DataViewReader.prototype = {
 			result = this._textDecoder.decode( new Uint8Array( this.dv.buffer, start, length ) );
 
 			// account for null byte in length
-			length++;
+			length ++;
 
 			// if string with terminating nullbyte is uneven, extra nullbyte is added, skip that too
 			length += length % 2;

+ 1 - 1
examples/jsm/renderers/webgpu/WebGPUGeometries.js

@@ -67,7 +67,7 @@ class WebGPUGeometries {
 	}
 
 	getIndex( geometry, wireframe = false ) {
- 
+
 		let index = geometry.index;
 
 		if ( wireframe ) {

+ 16 - 5
package.json

@@ -69,7 +69,12 @@
       "QUnit": "readonly",
       "Ammo": "readonly",
       "XRRigidTransform": "readonly",
-      "XRMediaBinding": "readonly"
+      "XRMediaBinding": "readonly",
+      "CodeMirror": "readonly",
+      "esprima": "readonly",
+      "jsonlint": "readonly",
+      "Benchmark": "readonly",
+      "Bench": "readonly"
     },
     "rules": {
       "no-throw-literal": [
@@ -97,10 +102,16 @@
     "build": "rollup -c utils/build/rollup.config.js",
     "build-module": "rollup -c utils/build/rollup.config.js --configOnlyModule",
     "dev": "concurrently --names \"ROLLUP,HTTP\" -c \"bgBlue.bold,bgGreen.bold\" \"rollup -c utils/build/rollup.config.js -w -m inline\" \"servez -p 8080 --ssl\"",
-    "lint": "eslint src --ext js",
-    "lint-examples": "eslint examples/jsm examples/*.html --ext js,html --ignore-pattern libs --ignore-pattern ifc",
-    "lint-docs": "eslint docs --ext html",
-    "lint-fix": "npm run lint -- --fix && npm run lint-examples -- --fix && npm run lint-docs -- --fix",
+    "lint-core": "eslint src",
+    "lint-addons": "eslint examples/jsm --ext .js --ignore-pattern libs --ignore-pattern ifc",
+    "lint-examples": "eslint examples --ext .html",
+    "lint-docs": "eslint docs --ignore-pattern prettify.js",
+    "lint-editor": "eslint editor --ignore-pattern libs",
+    "lint-manual": "eslint manual --ignore-pattern 3rdparty --ignore-pattern prettify.js --ignore-pattern shapefile.js",
+    "lint-test": "eslint test --ignore-pattern vendor",
+    "lint-utils": "eslint utils",
+    "lint": "npm run lint-core",
+    "lint-fix": "npm run lint-core -- --fix && npm run lint-addons -- --fix && npm run lint-docs -- --fix",
     "test-unit": "npm run unit --prefix test",
     "test-e2e": "node test/e2e/puppeteer.js",
     "test-e2e-cov": "node test/e2e/check-coverage.js",

+ 3 - 3
test/benchmark/benchmark.js

@@ -10,7 +10,7 @@ var BenchClass = function () {
 
 BenchClass.prototype.isTHREELoaded = function () {
 
-	return _.isObject( this.THREE );
+	return _.isObject( this.THREE ); // eslint-disable-line no-undef
 
 };
 
@@ -64,7 +64,7 @@ SuiteUI.prototype.render = function () {
 
 SuiteUI.prototype.run = function () {
 
-	this.runButton.click = _.noop;
+	this.runButton.click = _.noop; // eslint-disable-line no-undef
 	this.runButton.innerText = 'Running...';
 	this.suite.on( 'complete', this.complete.bind( this ) );
 	this.suite.run( {
@@ -77,7 +77,7 @@ SuiteUI.prototype.complete = function () {
 
 	this.runButton.style.display = 'none';
 	this.results.style.display = 'block';
-	var f = _.orderBy( this.suite, [ 'hz' ], [ 'desc' ] );
+	var f = _.orderBy( this.suite, [ 'hz' ], [ 'desc' ] ); // eslint-disable-line no-undef
 	for ( var i = 0; i < f.length; i ++ ) {
 
 		var x = f[ i ];

+ 8 - 0
test/benchmark/core/Vector3Components.js

@@ -108,6 +108,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	s.add( 'SwitchStatement', function () {
@@ -119,6 +121,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	s.add( 'IfAndReturnSeries', function () {
@@ -130,6 +134,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	s.add( 'IfReturnElseSeries', function () {
@@ -141,6 +147,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 } )();

+ 6 - 0
test/benchmark/core/Vector3Length.js

@@ -52,6 +52,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	suite.add( 'InlineCallTest', function () {
@@ -63,6 +65,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	suite.add( 'FunctionCallTest', function () {
@@ -74,6 +78,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 } )();

+ 6 - 0
test/benchmark/core/Vector3Storage.js

@@ -83,6 +83,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	suite.add( 'Vector3-Float32Array', function () {
@@ -103,6 +105,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 	suite.add( 'Vector3-Array', function () {
@@ -123,6 +127,8 @@
 
 		}
 
+		return result;
+
 	} );
 
 } )();

+ 2 - 2
test/e2e/deterministic-injection.js

@@ -34,7 +34,7 @@
 	const maxFrameId = 2;
 	window.requestAnimationFrame = function ( cb ) {
 
-		if ( ! _renderStarted ) {
+		if ( ! window._renderStarted ) {
 
 			setTimeout( function () {
 
@@ -52,7 +52,7 @@
 
 				} else {
 
-					_renderFinished = true;
+					window._renderFinished = true;
 
 				}
 

+ 10 - 7
test/unit/src/animation/AnimationAction.tests.js

@@ -445,21 +445,23 @@ export default QUnit.module( 'Animation', () => {
 		} );
 
 		QUnit.test( 'StartAt when already executed once', ( assert ) => {
+
 			var root = new Object3D();
 			var mixer = new AnimationMixer( root );
 			var track = new NumberKeyframeTrack( '.rotation[x]', [ 0, 750 ], [ 0, 270 ] );
 			var clip = new AnimationClip( 'clip1', 750, [ track ] );
-		
+
 			var animationAction = mixer.clipAction( clip );
 			animationAction.setLoop( LoopOnce );
 			animationAction.clampWhenFinished = true;
 			animationAction.play();
-			mixer.addEventListener('finished', () => {
-				animationAction.timeScale*=-1;
-				animationAction.paused=false;
-				animationAction.startAt(mixer.time+2000).play();
+			mixer.addEventListener( 'finished', () => {
+
+				animationAction.timeScale *= - 1;
+				animationAction.paused = false;
+				animationAction.startAt( mixer.time + 2000 ).play();
 
-			});
+			} );
 
 			mixer.update( 250 );
 			assert.equal( root.rotation.x, 90, 'first' );
@@ -488,7 +490,8 @@ export default QUnit.module( 'Animation', () => {
 			mixer.update( 250 );
 			assert.equal( root.rotation.x, 180, 'seventh' );
 			//console.log(mixer.time);
-		});
+
+		} );
 
 	} );
 

+ 3 - 3
test/unit/src/core/Object3D.tests.js

@@ -58,9 +58,9 @@ export default QUnit.module( 'Core', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var object = new Object3D();
-	
+
 			assert.strictEqual( object instanceof EventDispatcher, true, 'Object3D extends from EventDispatcher' );
-	
+
 		} );
 
 		// INSTANCING
@@ -550,7 +550,7 @@ export default QUnit.module( 'Core', () => {
 			parent.add( childName, childNothing );
 
 			assert.strictEqual( parent.getObjectsByProperty( 'name', 'foo' ).length, 3, 'Get amount of all childs by name "foo"' );
-			assert.strictEqual( parent.getObjectsByProperty( 'name', 'foo' ).some(obj => obj.name !== 'foo') , false, 'Get all childs by name "foo"' );
+			assert.strictEqual( parent.getObjectsByProperty( 'name', 'foo' ).some( obj => obj.name !== 'foo' ), false, 'Get all childs by name "foo"' );
 
 		} );
 

+ 1 - 1
test/unit/src/geometries/ShapeGeometry.tests.js

@@ -8,7 +8,7 @@ export default QUnit.module( 'Geometries', () => {
 
 	QUnit.module( 'ShapeGeometry', ( hooks ) => {
 
-		var geometries = undefined;
+		var geometries = undefined; // eslint-disable-line no-unused-vars
 		hooks.beforeEach( function () {
 
 			var triangleShape = new Shape();

+ 1 - 1
test/unit/src/geometries/TubeGeometry.tests.js

@@ -9,7 +9,7 @@ export default QUnit.module( 'Geometries', () => {
 
 	QUnit.module( 'TubeGeometry', ( hooks ) => {
 
-		var geometries = undefined;
+		var geometries = undefined; // eslint-disable-line no-unused-vars
 		hooks.beforeEach( function () {
 
 			var path = new LineCurve3( new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ) );

+ 1 - 1
test/unit/src/geometries/WireframeGeometry.tests.js

@@ -6,7 +6,7 @@ export default QUnit.module( 'Geometries', () => {
 
 	QUnit.module( 'WireframeGeometry', ( hooks ) => {
 
-		var geometries = undefined;
+		var geometries = undefined; // eslint-disable-line no-unused-vars
 		hooks.beforeEach( function () {
 
 			geometries = [

+ 1 - 1
test/unit/src/objects/Line.tests.js

@@ -11,7 +11,7 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var line = new Line();
-	
+
 			assert.strictEqual( line instanceof Object3D, true, 'Line extends from Object3D' );
 
 		} );

+ 2 - 2
test/unit/src/objects/LineLoop.tests.js

@@ -12,10 +12,10 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var lineLoop = new LineLoop();
-	
+
 			assert.strictEqual( lineLoop instanceof Object3D, true, 'LineLoop extends from Object3D' );
 			assert.strictEqual( lineLoop instanceof Line, true, 'LineLoop extends from Line' );
-	
+
 		} );
 
 		// INSTANCING

+ 1 - 1
test/unit/src/objects/LineSegments.tests.js

@@ -12,7 +12,7 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var lineSegments = new LineSegments();
-	
+
 			assert.strictEqual( lineSegments instanceof Object3D, true, 'LineSegments extends from Object3D' );
 			assert.strictEqual( lineSegments instanceof Line, true, 'LineSegments extends from Line' );
 

+ 1 - 1
test/unit/src/objects/Mesh.tests.js

@@ -16,7 +16,7 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var mesh = new Mesh();
-	
+
 			assert.strictEqual( mesh instanceof Object3D, true, 'Mesh extends from Object3D' );
 
 		} );

+ 1 - 1
test/unit/src/objects/Points.tests.js

@@ -11,7 +11,7 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'isPoints', ( assert ) => {
 
 			var points = new Points();
-	
+
 			assert.strictEqual( points instanceof Object3D, true, 'Points extends from Object3D' );
 
 		} );

+ 1 - 1
test/unit/src/objects/SkinnedMesh.tests.js

@@ -12,7 +12,7 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var skinnedMesh = new SkinnedMesh();
-	
+
 			assert.strictEqual( skinnedMesh instanceof Object3D, true, 'SkinnedMesh extends from Object3D' );
 			assert.strictEqual( skinnedMesh instanceof Mesh, true, 'SkinnedMesh extends from Mesh' );
 

+ 1 - 1
test/unit/src/objects/Sprite.tests.js

@@ -11,7 +11,7 @@ export default QUnit.module( 'Objects', () => {
 		QUnit.test( 'Extending', ( assert ) => {
 
 			var sprite = new Sprite();
-	
+
 			assert.strictEqual( sprite instanceof Object3D, true, 'Sprite extends from Object3D' );
 
 		} );