Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,75 +1,68 @@
|
||||
import Feature, {createStyleFunction} from '../../../src/ol/Feature.js';
|
||||
import Point from '../../../src/ol/geom/Point.js';
|
||||
import {isEmpty} from '../../../src/ol/obj.js';
|
||||
import Style from '../../../src/ol/style/Style.js';
|
||||
import {isEmpty} from '../../../src/ol/obj.js';
|
||||
|
||||
|
||||
describe('ol.Feature', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
|
||||
it('creates a new feature', function() {
|
||||
describe('ol.Feature', function () {
|
||||
describe('constructor', function () {
|
||||
it('creates a new feature', function () {
|
||||
const feature = new Feature();
|
||||
expect(feature).to.be.a(Feature);
|
||||
});
|
||||
|
||||
it('takes properties', function() {
|
||||
it('takes properties', function () {
|
||||
const feature = new Feature({
|
||||
foo: 'bar'
|
||||
foo: 'bar',
|
||||
});
|
||||
expect(feature.get('foo')).to.be('bar');
|
||||
});
|
||||
|
||||
it('can store the feature\'s commonly used id', function() {
|
||||
it("can store the feature's commonly used id", function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
});
|
||||
|
||||
it('will set the default geometry', function() {
|
||||
it('will set the default geometry', function () {
|
||||
const feature = new Feature({
|
||||
geometry: new Point([10, 20]),
|
||||
foo: 'bar'
|
||||
foo: 'bar',
|
||||
});
|
||||
const geometry = feature.getGeometry();
|
||||
expect(geometry).to.be.a(Point);
|
||||
expect(feature.get('geometry')).to.be(geometry);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#get()', function() {
|
||||
|
||||
it('returns values set at construction', function() {
|
||||
describe('#get()', function () {
|
||||
it('returns values set at construction', function () {
|
||||
const feature = new Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
b: 'second',
|
||||
});
|
||||
expect(feature.get('a')).to.be('first');
|
||||
expect(feature.get('b')).to.be('second');
|
||||
});
|
||||
|
||||
it('returns undefined for unset attributes', function() {
|
||||
it('returns undefined for unset attributes', function () {
|
||||
const feature = new Feature();
|
||||
expect(feature.get('a')).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns values set by set', function() {
|
||||
it('returns values set by set', function () {
|
||||
const feature = new Feature();
|
||||
feature.set('a', 'b');
|
||||
expect(feature.get('a')).to.be('b');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getProperties()', function() {
|
||||
|
||||
it('returns an object with all attributes', function() {
|
||||
describe('#getProperties()', function () {
|
||||
it('returns an object with all attributes', function () {
|
||||
const point = new Point([15, 30]);
|
||||
const feature = new Feature({
|
||||
foo: 'bar',
|
||||
ten: 10,
|
||||
geometry: point
|
||||
geometry: point,
|
||||
});
|
||||
|
||||
const attributes = feature.getProperties();
|
||||
@@ -82,43 +75,40 @@ describe('ol.Feature', function() {
|
||||
expect(attributes.ten).to.be(10);
|
||||
});
|
||||
|
||||
it('is empty by default', function() {
|
||||
it('is empty by default', function () {
|
||||
const feature = new Feature();
|
||||
const properties = feature.getProperties();
|
||||
expect(isEmpty(properties)).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('#getGeometry()', function() {
|
||||
|
||||
describe('#getGeometry()', function () {
|
||||
const point = new Point([15, 30]);
|
||||
|
||||
it('returns undefined for unset geometry', function() {
|
||||
it('returns undefined for unset geometry', function () {
|
||||
const feature = new Feature();
|
||||
expect(feature.getGeometry()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns null for null geometry (constructor)', function() {
|
||||
it('returns null for null geometry (constructor)', function () {
|
||||
const feature = new Feature(null);
|
||||
expect(feature.getGeometry()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns null for null geometry (setGeometry())', function() {
|
||||
it('returns null for null geometry (setGeometry())', function () {
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(null);
|
||||
expect(feature.getGeometry()).to.be(null);
|
||||
});
|
||||
|
||||
it('gets the geometry set at construction', function() {
|
||||
it('gets the geometry set at construction', function () {
|
||||
const feature = new Feature({
|
||||
geometry: point
|
||||
geometry: point,
|
||||
});
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
it('gets any geometry set by setGeometry', function() {
|
||||
it('gets any geometry set by setGeometry', function () {
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
@@ -127,32 +117,29 @@ describe('ol.Feature', function() {
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#set()', function() {
|
||||
|
||||
it('sets values', function() {
|
||||
describe('#set()', function () {
|
||||
it('sets values', function () {
|
||||
const feature = new Feature({
|
||||
a: 'first',
|
||||
b: 'second'
|
||||
b: 'second',
|
||||
});
|
||||
feature.set('a', 'new');
|
||||
expect(feature.get('a')).to.be('new');
|
||||
});
|
||||
|
||||
it('can be used to set the geometry', function() {
|
||||
it('can be used to set the geometry', function () {
|
||||
const point = new Point([3, 4]);
|
||||
const feature = new Feature({
|
||||
geometry: new Point([1, 2])
|
||||
geometry: new Point([1, 2]),
|
||||
});
|
||||
feature.set('geometry', point);
|
||||
expect(feature.get('geometry')).to.be(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
it('can be used to set attributes with arbitrary names', function() {
|
||||
|
||||
it('can be used to set attributes with arbitrary names', function () {
|
||||
const feature = new Feature();
|
||||
|
||||
feature.set('toString', 'string');
|
||||
@@ -164,24 +151,21 @@ describe('ol.Feature', function() {
|
||||
|
||||
feature.set('geometry', new Point([1, 2]));
|
||||
expect(feature.getGeometry()).to.be.a(Point);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setGeometry()', function() {
|
||||
|
||||
describe('#setGeometry()', function () {
|
||||
const point = new Point([15, 30]);
|
||||
|
||||
it('sets the default geometry', function() {
|
||||
it('sets the default geometry', function () {
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.get('geometry')).to.be(point);
|
||||
});
|
||||
|
||||
it('replaces previous default geometry', function() {
|
||||
it('replaces previous default geometry', function () {
|
||||
const feature = new Feature({
|
||||
geometry: point
|
||||
geometry: point,
|
||||
});
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
|
||||
@@ -189,14 +173,12 @@ describe('ol.Feature', function() {
|
||||
feature.setGeometry(point2);
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setGeometryName()', function() {
|
||||
|
||||
describe('#setGeometryName()', function () {
|
||||
const point = new Point([15, 30]);
|
||||
|
||||
it('sets property where to to look at geometry', function() {
|
||||
it('sets property where to to look at geometry', function () {
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
@@ -207,13 +189,13 @@ describe('ol.Feature', function() {
|
||||
feature.setGeometryName('altGeometry');
|
||||
expect(feature.getGeometry()).to.be(point2);
|
||||
|
||||
feature.on('change', function() {
|
||||
feature.on('change', function () {
|
||||
expect().fail();
|
||||
});
|
||||
point.setCoordinates([0, 2]);
|
||||
});
|
||||
|
||||
it('changes property listener', function() {
|
||||
it('changes property listener', function () {
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(point);
|
||||
const point2 = new Point([1, 2]);
|
||||
@@ -226,26 +208,24 @@ describe('ol.Feature', function() {
|
||||
expect(spy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
it('can use a different geometry name', function() {
|
||||
it('can use a different geometry name', function () {
|
||||
const feature = new Feature();
|
||||
feature.setGeometryName('foo');
|
||||
const point = new Point([10, 20]);
|
||||
feature.setGeometry(point);
|
||||
expect(feature.getGeometry()).to.be(point);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setId()', function() {
|
||||
|
||||
it('sets the feature identifier', function() {
|
||||
describe('#setId()', function () {
|
||||
it('sets the feature identifier', function () {
|
||||
const feature = new Feature();
|
||||
expect(feature.getId()).to.be(undefined);
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
});
|
||||
|
||||
it('accepts a string or number', function() {
|
||||
it('accepts a string or number', function () {
|
||||
const feature = new Feature();
|
||||
feature.setId('foo');
|
||||
expect(feature.getId()).to.be('foo');
|
||||
@@ -253,79 +233,75 @@ describe('ol.Feature', function() {
|
||||
expect(feature.getId()).to.be(2);
|
||||
});
|
||||
|
||||
it('dispatches the "change" event', function(done) {
|
||||
it('dispatches the "change" event', function (done) {
|
||||
const feature = new Feature();
|
||||
feature.on('change', function() {
|
||||
feature.on('change', function () {
|
||||
expect(feature.getId()).to.be('foo');
|
||||
done();
|
||||
});
|
||||
feature.setId('foo');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStyleFunction()', function() {
|
||||
|
||||
const styleFunction = function(feature, resolution) {
|
||||
describe('#getStyleFunction()', function () {
|
||||
const styleFunction = function (feature, resolution) {
|
||||
return null;
|
||||
};
|
||||
|
||||
it('returns undefined after construction', function() {
|
||||
it('returns undefined after construction', function () {
|
||||
const feature = new Feature();
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('returns the function passed to setStyle', function() {
|
||||
it('returns the function passed to setStyle', function () {
|
||||
const feature = new Feature();
|
||||
feature.setStyle(styleFunction);
|
||||
expect(feature.getStyleFunction()).to.be(styleFunction);
|
||||
});
|
||||
|
||||
it('does not get confused with user "styleFunction" property', function() {
|
||||
it('does not get confused with user "styleFunction" property', function () {
|
||||
const feature = new Feature();
|
||||
feature.set('styleFunction', 'foo');
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('does not get confused with "styleFunction" option', function() {
|
||||
it('does not get confused with "styleFunction" option', function () {
|
||||
const feature = new Feature({
|
||||
styleFunction: 'foo'
|
||||
styleFunction: 'foo',
|
||||
});
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#setStyle()', function() {
|
||||
|
||||
describe('#setStyle()', function () {
|
||||
const style = new Style();
|
||||
|
||||
const styleFunction = function(feature, resolution) {
|
||||
const styleFunction = function (feature, resolution) {
|
||||
return resolution;
|
||||
};
|
||||
|
||||
it('accepts a single style', function() {
|
||||
it('accepts a single style', function () {
|
||||
const feature = new Feature();
|
||||
feature.setStyle(style);
|
||||
const func = feature.getStyleFunction();
|
||||
expect(func()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('accepts an array of styles', function() {
|
||||
it('accepts an array of styles', function () {
|
||||
const feature = new Feature();
|
||||
feature.setStyle([style]);
|
||||
const func = feature.getStyleFunction();
|
||||
expect(func()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('accepts a style function', function() {
|
||||
it('accepts a style function', function () {
|
||||
const feature = new Feature();
|
||||
feature.setStyle(styleFunction);
|
||||
expect(feature.getStyleFunction()).to.be(styleFunction);
|
||||
expect(feature.getStyleFunction()(feature, 42)).to.be(42);
|
||||
});
|
||||
|
||||
it('accepts null', function() {
|
||||
it('accepts null', function () {
|
||||
const feature = new Feature();
|
||||
feature.setStyle(style);
|
||||
feature.setStyle(null);
|
||||
@@ -333,25 +309,23 @@ describe('ol.Feature', function() {
|
||||
expect(feature.getStyleFunction()).to.be(undefined);
|
||||
});
|
||||
|
||||
it('dispatches a change event', function() {
|
||||
it('dispatches a change event', function () {
|
||||
const feature = new Feature();
|
||||
const spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
feature.setStyle(style);
|
||||
expect(spy.callCount).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getStyle()', function() {
|
||||
|
||||
describe('#getStyle()', function () {
|
||||
const style = new Style();
|
||||
|
||||
const styleFunction = function(feature, resolution) {
|
||||
const styleFunction = function (feature, resolution) {
|
||||
return null;
|
||||
};
|
||||
|
||||
it('returns what is passed to setStyle', function() {
|
||||
it('returns what is passed to setStyle', function () {
|
||||
const feature = new Feature();
|
||||
|
||||
expect(feature.getStyle()).to.be(null);
|
||||
@@ -364,29 +338,26 @@ describe('ol.Feature', function() {
|
||||
|
||||
feature.setStyle(styleFunction);
|
||||
expect(feature.getStyle()).to.be(styleFunction);
|
||||
|
||||
});
|
||||
|
||||
it('does not get confused with "style" option to constructor', function() {
|
||||
it('does not get confused with "style" option to constructor', function () {
|
||||
const feature = new Feature({
|
||||
style: 'foo'
|
||||
style: 'foo',
|
||||
});
|
||||
|
||||
expect(feature.getStyle()).to.be(null);
|
||||
});
|
||||
|
||||
it('does not get confused with user set "style" property', function() {
|
||||
it('does not get confused with user set "style" property', function () {
|
||||
const feature = new Feature();
|
||||
feature.set('style', 'foo');
|
||||
|
||||
expect(feature.getStyle()).to.be(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#clone', function() {
|
||||
|
||||
it('correctly clones features', function() {
|
||||
describe('#clone', function () {
|
||||
it('correctly clones features', function () {
|
||||
const feature = new Feature();
|
||||
feature.setProperties({'fookey': 'fooval'});
|
||||
feature.setId(1);
|
||||
@@ -410,7 +381,7 @@ describe('ol.Feature', function() {
|
||||
expect(clone.get('barkey')).to.be('barval');
|
||||
});
|
||||
|
||||
it('correctly clones features with no geometry and no style', function() {
|
||||
it('correctly clones features with no geometry and no style', function () {
|
||||
const feature = new Feature();
|
||||
feature.set('fookey', 'fooval');
|
||||
|
||||
@@ -421,47 +392,43 @@ describe('ol.Feature', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setGeometry()', function() {
|
||||
|
||||
it('dispatches a change event when geometry is set to null',
|
||||
function() {
|
||||
const feature = new Feature({
|
||||
geometry: new Point([0, 0])
|
||||
});
|
||||
const spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
feature.setGeometry(null);
|
||||
expect(spy.callCount).to.be(1);
|
||||
describe('#setGeometry()', function () {
|
||||
it('dispatches a change event when geometry is set to null', function () {
|
||||
const feature = new Feature({
|
||||
geometry: new Point([0, 0]),
|
||||
});
|
||||
const spy = sinon.spy();
|
||||
feature.on('change', spy);
|
||||
feature.setGeometry(null);
|
||||
expect(spy.callCount).to.be(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ol.Feature.createStyleFunction()', function() {
|
||||
describe('ol.Feature.createStyleFunction()', function () {
|
||||
const style = new Style();
|
||||
|
||||
it('creates a feature style function from a single style', function() {
|
||||
it('creates a feature style function from a single style', function () {
|
||||
const styleFunction = createStyleFunction(style);
|
||||
expect(styleFunction()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('creates a feature style function from an array of styles', function() {
|
||||
it('creates a feature style function from an array of styles', function () {
|
||||
const styleFunction = createStyleFunction([style]);
|
||||
expect(styleFunction()).to.eql([style]);
|
||||
});
|
||||
|
||||
it('passes through a function', function() {
|
||||
const original = function(feature, resolution) {
|
||||
it('passes through a function', function () {
|
||||
const original = function (feature, resolution) {
|
||||
return [style];
|
||||
};
|
||||
const styleFunction = createStyleFunction(original);
|
||||
expect(styleFunction).to.be(original);
|
||||
});
|
||||
|
||||
it('throws on (some) unexpected input', function() {
|
||||
expect(function() {
|
||||
it('throws on (some) unexpected input', function () {
|
||||
expect(function () {
|
||||
createStyleFunction({bogus: 'input'});
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user