Skip to content

Commit

Permalink
Linting: Update linter to enforce ES 2018 features (#25470)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
epreston authored Feb 15, 2023
1 parent 742b033 commit b2fdb55
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 58 deletions.
61 changes: 61 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
}
52 changes: 0 additions & 52 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
6 changes: 3 additions & 3 deletions src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
14 changes: 13 additions & 1 deletion src/animation/AnimationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -357,5 +368,6 @@ export {
sortedArray,
flattenJSON,
subclip,
makeClipAdditive
makeClipAdditive,
AnimationUtils
};
8 changes: 7 additions & 1 deletion src/extras/DataUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ function fromHalfFloat( val ) {

}

const DataUtils = {
toHalfFloat: toHalfFloat,
fromHalfFloat: fromHalfFloat,
};

export {
toHalfFloat,
fromHalfFloat
fromHalfFloat,
DataUtils
};
28 changes: 27 additions & 1 deletion src/math/MathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -318,4 +343,5 @@ export {
setQuaternionFromProperEuler,
normalize,
denormalize,
MathUtils
};

0 comments on commit b2fdb55

Please sign in to comment.