浏览代码

Linting: Update linter to enforce ES 2018 features (#25470)

* Separate Out eslintConfig

move eslintConfig to its own file to keep package.json clean
modifications and commits not bound to or carry the risk of dependency changes.
This commit is the equivalent configuration as the starting point.

* Update Three.js

Convert ES 2020 imports into 2018.

* Update .eslintrc.json

Set project to ES 2018

* Add Public Interface Export Objects

MathUtils, AnimationUtils, and DataUtils need to be updated to export their namespaces.  Privately, individual functions are exported to support the other parts of the library, publicly they are namespaced with an object wrapper.
Ed Preston 2 年之前
父节点
当前提交
b2fdb55fe9
共有 6 个文件被更改,包括 111 次插入58 次删除
  1. 61 0
      .eslintrc.json
  2. 0 52
      package.json
  3. 3 3
      src/Three.js
  4. 13 1
      src/animation/AnimationUtils.js
  5. 7 1
      src/extras/DataUtils.js
  6. 27 1
      src/math/MathUtils.js

+ 61 - 0
.eslintrc.json

@@ -0,0 +1,61 @@
+{
+  "root": true,
+  "env": {
+    "browser": true,
+    "node": true,
+    "es2018": true
+  },
+  "parserOptions": {
+    "ecmaVersion": 2018,
+    "sourceType": "module"
+  },
+  "extends": [
+    "mdcs",
+    "plugin:compat/recommended"
+  ],
+  "plugins": [
+    "html",
+    "import"
+  ],
+  "settings": {
+    "polyfills": [
+      "WebGL2RenderingContext"
+    ]
+  },
+  "globals": {
+    "__THREE_DEVTOOLS__": "readonly",
+    "potpack": "readonly",
+    "fflate": "readonly",
+    "OIMO": "readonly",
+    "Stats": "readonly",
+    "XRWebGLBinding": "readonly",
+    "XRWebGLLayer": "readonly",
+    "GPUShaderStage": "readonly",
+    "GPUBufferUsage": "readonly",
+    "GPUTextureUsage": "readonly",
+    "GPUMapMode": "readonly",
+    "QUnit": "readonly",
+    "Ammo": "readonly",
+    "XRRigidTransform": "readonly",
+    "XRMediaBinding": "readonly",
+    "CodeMirror": "readonly",
+    "esprima": "readonly",
+    "jsonlint": "readonly"
+  },
+  "rules": {
+    "no-throw-literal": [
+      "error"
+    ],
+    "quotes": [
+      "error",
+      "single"
+    ],
+    "prefer-const": [
+      "error",
+      {
+        "destructuring": "any",
+        "ignoreReadBeforeAssign": false
+      }
+    ]
+  }
+}

+ 0 - 52
package.json

@@ -38,58 +38,6 @@
     "example": "examples",
     "test": "test"
   },
-  "eslintConfig": {
-    "root": true,
-    "extends": [
-      "mdcs",
-      "plugin:compat/recommended"
-    ],
-    "plugins": [
-      "html",
-      "import"
-    ],
-    "settings": {
-      "polyfills": [
-        "WebGL2RenderingContext"
-      ]
-    },
-    "globals": {
-      "__THREE_DEVTOOLS__": "readonly",
-      "potpack": "readonly",
-      "fflate": "readonly",
-      "OIMO": "readonly",
-      "Stats": "readonly",
-      "XRWebGLBinding": "readonly",
-      "XRWebGLLayer": "readonly",
-      "GPUShaderStage": "readonly",
-      "GPUBufferUsage": "readonly",
-      "GPUTextureUsage": "readonly",
-      "GPUMapMode": "readonly",
-      "QUnit": "readonly",
-      "Ammo": "readonly",
-      "XRRigidTransform": "readonly",
-      "XRMediaBinding": "readonly",
-      "CodeMirror": "readonly",
-      "esprima": "readonly",
-      "jsonlint": "readonly"
-    },
-    "rules": {
-      "no-throw-literal": [
-        "error"
-      ],
-      "quotes": [
-        "error",
-        "single"
-      ],
-      "prefer-const": [
-        "error",
-        {
-          "destructuring": "any",
-          "ignoreReadBeforeAssign": false
-        }
-      ]
-    }
-  },
   "browserslist": [
     "> 1%, not dead, not ie 11, not op_mini all"
   ],

+ 3 - 3
src/Three.js

@@ -86,7 +86,7 @@ export { BooleanKeyframeTrack } from './animation/tracks/BooleanKeyframeTrack.js
 export { PropertyMixer } from './animation/PropertyMixer.js';
 export { PropertyBinding } from './animation/PropertyBinding.js';
 export { KeyframeTrack } from './animation/KeyframeTrack.js';
-export * as AnimationUtils from './animation/AnimationUtils.js';
+export { AnimationUtils } from './animation/AnimationUtils.js';
 export { AnimationObjectGroup } from './animation/AnimationObjectGroup.js';
 export { AnimationMixer } from './animation/AnimationMixer.js';
 export { AnimationClip } from './animation/AnimationClip.js';
@@ -111,7 +111,7 @@ export { DiscreteInterpolant } from './math/interpolants/DiscreteInterpolant.js'
 export { CubicInterpolant } from './math/interpolants/CubicInterpolant.js';
 export { Interpolant } from './math/Interpolant.js';
 export { Triangle } from './math/Triangle.js';
-export * as MathUtils from './math/MathUtils.js';
+export { MathUtils } from './math/MathUtils.js';
 export { Spherical } from './math/Spherical.js';
 export { Cylindrical } from './math/Cylindrical.js';
 export { Plane } from './math/Plane.js';
@@ -150,7 +150,7 @@ export { Path } from './extras/core/Path.js';
 export { ShapePath } from './extras/core/ShapePath.js';
 export { CurvePath } from './extras/core/CurvePath.js';
 export { Curve } from './extras/core/Curve.js';
-export * as DataUtils from './extras/DataUtils.js';
+export { DataUtils } from './extras/DataUtils.js';
 export { ImageUtils } from './extras/ImageUtils.js';
 export { ShapeUtils } from './extras/ShapeUtils.js';
 export { PMREMGenerator } from './extras/PMREMGenerator.js';

+ 13 - 1
src/animation/AnimationUtils.js

@@ -349,6 +349,17 @@ function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targe
 
 }
 
+const AnimationUtils = {
+	arraySlice: arraySlice,
+	convertArray: convertArray,
+	isTypedArray: isTypedArray,
+	getKeyframeOrder: getKeyframeOrder,
+	sortedArray: sortedArray,
+	flattenJSON: flattenJSON,
+	subclip: subclip,
+	makeClipAdditive: makeClipAdditive
+};
+
 export {
 	arraySlice,
 	convertArray,
@@ -357,5 +368,6 @@ export {
 	sortedArray,
 	flattenJSON,
 	subclip,
-	makeClipAdditive
+	makeClipAdditive,
+	AnimationUtils
 };

+ 7 - 1
src/extras/DataUtils.js

@@ -164,7 +164,13 @@ function fromHalfFloat( val ) {
 
 }
 
+const DataUtils = {
+	toHalfFloat: toHalfFloat,
+	fromHalfFloat: fromHalfFloat,
+};
+
 export {
 	toHalfFloat,
-	fromHalfFloat
+	fromHalfFloat,
+	DataUtils
 };

+ 27 - 1
src/math/MathUtils.js

@@ -291,7 +291,32 @@ function normalize( value, array ) {
 
 }
 
-
+const MathUtils = {
+	DEG2RAD: DEG2RAD,
+	RAD2DEG: RAD2DEG,
+	generateUUID: generateUUID,
+	clamp: clamp,
+	euclideanModulo: euclideanModulo,
+	mapLinear: mapLinear,
+	inverseLerp: inverseLerp,
+	lerp: lerp,
+	damp: damp,
+	pingpong: pingpong,
+	smoothstep: smoothstep,
+	smootherstep: smootherstep,
+	randInt: randInt,
+	randFloat: randFloat,
+	randFloatSpread: randFloatSpread,
+	seededRandom: seededRandom,
+	degToRad: degToRad,
+	radToDeg: radToDeg,
+	isPowerOfTwo: isPowerOfTwo,
+	ceilPowerOfTwo: ceilPowerOfTwo,
+	floorPowerOfTwo: floorPowerOfTwo,
+	setQuaternionFromProperEuler: setQuaternionFromProperEuler,
+	normalize: normalize,
+	denormalize: denormalize
+};
 
 export {
 	DEG2RAD,
@@ -318,4 +343,5 @@ export {
 	setQuaternionFromProperEuler,
 	normalize,
 	denormalize,
+	MathUtils
 };