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:
+92
-149
@@ -1,11 +1,15 @@
|
||||
/**
|
||||
* @module ol/format/OWS
|
||||
*/
|
||||
import {readHref} from './XLink.js';
|
||||
import XML from './XML.js';
|
||||
import {
|
||||
makeObjectPropertyPusher,
|
||||
makeObjectPropertySetter,
|
||||
makeStructureNS,
|
||||
pushParseAndPop,
|
||||
} from '../xml.js';
|
||||
import {readHref} from './XLink.js';
|
||||
import {readString} from './xsd.js';
|
||||
import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pushParseAndPop} from '../xml.js';
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -13,19 +17,16 @@ import {makeObjectPropertyPusher, makeObjectPropertySetter, makeStructureNS, pus
|
||||
*/
|
||||
const NAMESPACE_URIS = [null, 'http://www.opengis.net/ows/1.1'];
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
|
||||
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
|
||||
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata)
|
||||
});
|
||||
|
||||
const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ServiceIdentification': makeObjectPropertySetter(readServiceIdentification),
|
||||
'ServiceProvider': makeObjectPropertySetter(readServiceProvider),
|
||||
'OperationsMetadata': makeObjectPropertySetter(readOperationsMetadata),
|
||||
});
|
||||
|
||||
class OWS extends XML {
|
||||
constructor() {
|
||||
@@ -50,175 +51,144 @@ class OWS extends XML {
|
||||
* @return {Object} Object
|
||||
*/
|
||||
readFromNode(node) {
|
||||
const owsObject = pushParseAndPop({},
|
||||
PARSERS, node, []);
|
||||
const owsObject = pushParseAndPop({}, PARSERS, node, []);
|
||||
return owsObject ? owsObject : null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ADDRESS_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'DeliveryPoint': makeObjectPropertySetter(readString),
|
||||
'City': makeObjectPropertySetter(readString),
|
||||
'AdministrativeArea': makeObjectPropertySetter(readString),
|
||||
'PostalCode': makeObjectPropertySetter(readString),
|
||||
'Country': makeObjectPropertySetter(readString),
|
||||
'ElectronicMailAddress': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ADDRESS_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'DeliveryPoint': makeObjectPropertySetter(readString),
|
||||
'City': makeObjectPropertySetter(readString),
|
||||
'AdministrativeArea': makeObjectPropertySetter(readString),
|
||||
'PostalCode': makeObjectPropertySetter(readString),
|
||||
'Country': makeObjectPropertySetter(readString),
|
||||
'ElectronicMailAddress': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const ALLOWED_VALUES_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Value': makeObjectPropertyPusher(readValue),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const ALLOWED_VALUES_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Value': makeObjectPropertyPusher(readValue)
|
||||
});
|
||||
|
||||
const CONSTRAINT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'AllowedValues': makeObjectPropertySetter(readAllowedValues),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONSTRAINT_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'AllowedValues': makeObjectPropertySetter(readAllowedValues)
|
||||
});
|
||||
|
||||
const CONTACT_INFO_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Phone': makeObjectPropertySetter(readPhone),
|
||||
'Address': makeObjectPropertySetter(readAddress),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const CONTACT_INFO_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Phone': makeObjectPropertySetter(readPhone),
|
||||
'Address': makeObjectPropertySetter(readAddress)
|
||||
});
|
||||
|
||||
const DCP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'HTTP': makeObjectPropertySetter(readHttp),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const DCP_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'HTTP': makeObjectPropertySetter(readHttp)
|
||||
});
|
||||
|
||||
const HTTP_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Get': makeObjectPropertyPusher(readGet),
|
||||
'Post': undefined, // TODO
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const HTTP_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Get': makeObjectPropertyPusher(readGet),
|
||||
'Post': undefined // TODO
|
||||
});
|
||||
|
||||
const OPERATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'DCP': makeObjectPropertySetter(readDcp),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const OPERATION_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'DCP': makeObjectPropertySetter(readDcp)
|
||||
});
|
||||
|
||||
const OPERATIONS_METADATA_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Operation': readOperation,
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const OPERATIONS_METADATA_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Operation': readOperation
|
||||
});
|
||||
|
||||
const PHONE_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Voice': makeObjectPropertySetter(readString),
|
||||
'Facsimile': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const PHONE_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Voice': makeObjectPropertySetter(readString),
|
||||
'Facsimile': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
const REQUEST_METHOD_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Constraint': makeObjectPropertyPusher(readConstraint),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const REQUEST_METHOD_PARSERS = makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Constraint': makeObjectPropertyPusher(readConstraint)
|
||||
});
|
||||
|
||||
const SERVICE_CONTACT_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'IndividualName': makeObjectPropertySetter(readString),
|
||||
'PositionName': makeObjectPropertySetter(readString),
|
||||
'ContactInfo': makeObjectPropertySetter(readContactInfo),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_CONTACT_PARSERS =
|
||||
makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'IndividualName': makeObjectPropertySetter(readString),
|
||||
'PositionName': makeObjectPropertySetter(readString),
|
||||
'ContactInfo': makeObjectPropertySetter(readContactInfo)
|
||||
});
|
||||
|
||||
const SERVICE_IDENTIFICATION_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'AccessConstraints': makeObjectPropertySetter(readString),
|
||||
'Fees': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'ServiceTypeVersion': makeObjectPropertySetter(readString),
|
||||
'ServiceType': makeObjectPropertySetter(readString),
|
||||
});
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_IDENTIFICATION_PARSERS =
|
||||
makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'Abstract': makeObjectPropertySetter(readString),
|
||||
'AccessConstraints': makeObjectPropertySetter(readString),
|
||||
'Fees': makeObjectPropertySetter(readString),
|
||||
'Title': makeObjectPropertySetter(readString),
|
||||
'ServiceTypeVersion': makeObjectPropertySetter(readString),
|
||||
'ServiceType': makeObjectPropertySetter(readString)
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object<string, Object<string, import("../xml.js").Parser>>}
|
||||
*/
|
||||
// @ts-ignore
|
||||
const SERVICE_PROVIDER_PARSERS =
|
||||
makeStructureNS(
|
||||
NAMESPACE_URIS, {
|
||||
'ProviderName': makeObjectPropertySetter(readString),
|
||||
'ProviderSite': makeObjectPropertySetter(readHref),
|
||||
'ServiceContact': makeObjectPropertySetter(readServiceContact)
|
||||
});
|
||||
|
||||
const SERVICE_PROVIDER_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'ProviderName': makeObjectPropertySetter(readString),
|
||||
'ProviderSite': makeObjectPropertySetter(readHref),
|
||||
'ServiceContact': makeObjectPropertySetter(readServiceContact),
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
@@ -226,22 +196,18 @@ const SERVICE_PROVIDER_PARSERS =
|
||||
* @return {Object|undefined} The address.
|
||||
*/
|
||||
function readAddress(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
ADDRESS_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, ADDRESS_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The values.
|
||||
*/
|
||||
function readAllowedValues(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
ALLOWED_VALUES_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, ALLOWED_VALUES_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -252,34 +218,27 @@ function readConstraint(node, objectStack) {
|
||||
if (!name) {
|
||||
return undefined;
|
||||
}
|
||||
return pushParseAndPop({'name': name},
|
||||
CONSTRAINT_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({'name': name}, CONSTRAINT_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The contact info.
|
||||
*/
|
||||
function readContactInfo(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
CONTACT_INFO_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, CONTACT_INFO_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The DCP.
|
||||
*/
|
||||
function readDcp(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
DCP_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, DCP_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -290,11 +249,14 @@ function readGet(node, objectStack) {
|
||||
if (!href) {
|
||||
return undefined;
|
||||
}
|
||||
return pushParseAndPop({'href': href},
|
||||
REQUEST_METHOD_PARSERS, node, objectStack);
|
||||
return pushParseAndPop(
|
||||
{'href': href},
|
||||
REQUEST_METHOD_PARSERS,
|
||||
node,
|
||||
objectStack
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -304,7 +266,6 @@ function readHttp(node, objectStack) {
|
||||
return pushParseAndPop({}, HTTP_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -312,76 +273,59 @@ function readHttp(node, objectStack) {
|
||||
*/
|
||||
function readOperation(node, objectStack) {
|
||||
const name = node.getAttribute('name');
|
||||
const value = pushParseAndPop({},
|
||||
OPERATION_PARSERS, node, objectStack);
|
||||
const value = pushParseAndPop({}, OPERATION_PARSERS, node, objectStack);
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
const object = /** @type {Object} */
|
||||
(objectStack[objectStack.length - 1]);
|
||||
const object = /** @type {Object} */ (objectStack[objectStack.length - 1]);
|
||||
object[name] = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The operations metadata.
|
||||
*/
|
||||
function readOperationsMetadata(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
OPERATIONS_METADATA_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, OPERATIONS_METADATA_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The phone.
|
||||
*/
|
||||
function readPhone(node, objectStack) {
|
||||
return pushParseAndPop({},
|
||||
PHONE_PARSERS, node, objectStack);
|
||||
return pushParseAndPop({}, PHONE_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The service identification.
|
||||
*/
|
||||
function readServiceIdentification(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, SERVICE_IDENTIFICATION_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, SERVICE_IDENTIFICATION_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The service contact.
|
||||
*/
|
||||
function readServiceContact(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, SERVICE_CONTACT_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, SERVICE_CONTACT_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @return {Object|undefined} The service provider.
|
||||
*/
|
||||
function readServiceProvider(node, objectStack) {
|
||||
return pushParseAndPop(
|
||||
{}, SERVICE_PROVIDER_PARSERS, node,
|
||||
objectStack);
|
||||
return pushParseAndPop({}, SERVICE_PROVIDER_PARSERS, node, objectStack);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
@@ -391,5 +335,4 @@ function readValue(node, objectStack) {
|
||||
return readString(node);
|
||||
}
|
||||
|
||||
|
||||
export default OWS;
|
||||
|
||||
Reference in New Issue
Block a user