Skip to content

Commit

Permalink
[GLJS-1146] Add ESLint rule to forbid object spread syntax (internal-…
Browse files Browse the repository at this point in the history
…2093)
  • Loading branch information
underoot committed Jan 30, 2025
1 parent d1a8172 commit a511c0d
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@
"rules": {
"no-restricted-syntax": [
"error",
{
"selector": "ObjectExpression > SpreadElement",
"message": "Spread syntax is not allowed for object assignments. Use Object.assign() or other methods instead."
},
{
"selector": "AwaitExpression",
"message": "Async/await syntax is not allowed."
Expand Down
3 changes: 1 addition & 2 deletions 3d-style/render/draw_model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import type {DynamicDefinesType} from '../../src/render/program/program_uniforms
import type VertexBuffer from '../../src/gl/vertex_buffer';
import type {CutoffParams} from '../../src/render/cutoff';
import type {LUT} from "../../src/util/lut";
import type EvaluationParameters from '../../src/style/evaluation_parameters';

export default drawModels;

Expand Down Expand Up @@ -576,7 +575,7 @@ function drawVectorLayerModels(painter: Painter, source: SourceCache, layer: Mod

const modelIdUnevaluatedProperty = layer._unevaluatedLayout._values['model-id'];

const evaluationParameters = {...layer.layout.get("model-id").parameters} as EvaluationParameters;
const evaluationParameters = Object.assign({}, layer.layout.get("model-id").parameters);

const layerIndex = painter.style.order.indexOf(layer.fqid);

Expand Down
2 changes: 1 addition & 1 deletion src/gl/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Context {
this.pixelStoreUnpack = new PixelStoreUnpack(this);
this.pixelStoreUnpackPremultiplyAlpha = new PixelStoreUnpackPremultiplyAlpha(this);
this.pixelStoreUnpackFlipY = new PixelStoreUnpackFlipY(this);
this.options = options ? {...options} : {};
this.options = options ? Object.assign({}, options) : {};

if (!this.options.extTextureFilterAnisotropicForceOff) {
this.extTextureFilterAnisotropic = (
Expand Down
2 changes: 1 addition & 1 deletion src/source/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class Tile {

if (data.resourceTiming) this.resourceTiming = data.resourceTiming;

this.buckets = {...this.buckets, ...deserializeBucket(data.buckets, painter.style)};
this.buckets = Object.assign({}, this.buckets, deserializeBucket(data.buckets, painter.style));

if (data.featureIndex) {
this.latestFeatureIndex = data.featureIndex;
Expand Down
12 changes: 5 additions & 7 deletions src/style/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2233,12 +2233,11 @@ class Style extends Evented<MapEvents> {
return;
}

this.options.set(fqid, {
...expressions,
this.options.set(fqid, Object.assign({}, expressions, {
value: expression,
default: defaultExpression,
minValue, maxValue, stepValue, type, values
});
}));

this.updateConfigDependencies(key);
}
Expand Down Expand Up @@ -3096,7 +3095,7 @@ class Style extends Evented<MapEvents> {
const targets: QrfTarget[] = [];

if (params && params.target) {
targets.push({...params, targetId, filter});
targets.push(Object.assign({}, params, {targetId, filter}));
} else {
// Query all root-level featuresets
const featuresetDescriptors = this.getFeaturesetDescriptors();
Expand Down Expand Up @@ -3140,11 +3139,10 @@ class Style extends Evented<MapEvents> {
return;
}

querySourceCache.layers[styleLayer.fqid].targets.push({
...target,
querySourceCache.layers[styleLayer.fqid].targets.push(Object.assign({}, target, {
namespace: selector.namespace,
properties: selector.properties
});
}));
};

for (const target of targets) {
Expand Down
2 changes: 1 addition & 1 deletion src/tracked-parameters/tracked_parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export class TrackedParameters implements ITrackedParameters {
})()}`;

// Add button to TweakPane UI
currentScope.addBinding(containerObject, name, {...description, label: modifiedLabel});
currentScope.addBinding(containerObject, name, Object.assign({}, description, {label: modifiedLabel}));
}

refreshUI() {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export class Map extends Camera {
this._requestManager = new RequestManager(options.transformRequest, options.accessToken, options.testMode);
this._silenceAuthErrors = !!options.testMode;
if (options.contextCreateOptions) {
this._contextCreateOptions = {...options.contextCreateOptions};
this._contextCreateOptions = Object.assign({}, options.contextCreateOptions);
} else {
this._contextCreateOptions = {};
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/vectortile_to_geojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Feature implements GeoJSONFeature {

clone(): Feature {
const feature = new Feature(this._vectorTileFeature, this._z, this._x, this._y, this.id);
if (this.state) feature.state = {...this.state};
if (this.layer) feature.layer = {...this.layer};
if (this.state) feature.state = Object.assign({}, this.state);
if (this.layer) feature.layer = Object.assign({}, this.layer);
if (this.source) feature.source = this.source;
if (this.sourceLayer) feature.sourceLayer = this.sourceLayer;
return feature;
Expand Down Expand Up @@ -130,7 +130,7 @@ export class TargetFeature extends Feature {
*/
constructor(feature: Feature, variant: FeatureVariant) {
super(feature._vectorTileFeature, feature._z, feature._x, feature._y, feature.id);
if (feature.state) this.state = {...feature.state};
if (feature.state) this.state = Object.assign({}, feature.state);

this.target = variant.target;
this.namespace = variant.namespace;
Expand Down

0 comments on commit a511c0d

Please sign in to comment.