Skip to content

Commit

Permalink
fix eslint errors & disable no-explicit-any rule
Browse files Browse the repository at this point in the history
  • Loading branch information
jahow committed Feb 28, 2024
1 parent 88455ea commit 9363be0
Show file tree
Hide file tree
Showing 46 changed files with 186 additions and 185 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ module.exports = {
"require-extensions"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
}
}
4 changes: 4 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ module.exports = {
},
setupFilesAfterEnv: ['./test-setup.ts'],
coveragePathIgnorePatterns: ['.(xml)$'],
// this is required because imports end in ".js"
moduleNameMapper: {
'^(..?/.+).jsx?$': '$1',
},
};
58 changes: 28 additions & 30 deletions src/ogc-api/endpoint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
import OgcApiEndpoint from './endpoint';
import OgcApiEndpoint from './endpoint.js';
import { readFile, stat } from 'fs/promises';
import * as path from 'path';
import { EndpointError } from '../shared/errors';
import { EndpointError } from '../shared/errors.js';

const FIXTURES_ROOT = path.join(__dirname, '../../fixtures/ogc-api');

// setup fetch to read local fixtures
beforeAll(() => {
window.fetch = (urlOrInfo) =>
new Promise(async (resolve) => {
const url = new URL(
urlOrInfo instanceof URL || typeof urlOrInfo === 'string'
? urlOrInfo
: urlOrInfo.url
);
const queryPath = url.pathname;
const format = url.searchParams.get('f') || 'html';
const filePath = `${path.join(FIXTURES_ROOT, queryPath)}.${format}`;
try {
await stat(filePath);
} catch (e) {
resolve({
ok: false,
status: 400,
headers: new Headers(),
json: () => Promise.resolve({ links: [] }),
} as Response);
return;
}
const contents = await readFile(filePath, {
encoding: 'utf8',
});
resolve({
ok: true,
window.fetch = async (urlOrInfo) => {
const url = new URL(
urlOrInfo instanceof URL || typeof urlOrInfo === 'string'
? urlOrInfo
: urlOrInfo.url
);
const queryPath = url.pathname;
const format = url.searchParams.get('f') || 'html';
const filePath = `${path.join(FIXTURES_ROOT, queryPath)}.${format}`;
try {
await stat(filePath);
} catch (e) {
return {
ok: false,
status: 400,
headers: new Headers(),
json: () => Promise.resolve(JSON.parse(contents)),
} as Response);
json: () => Promise.resolve({ links: [] }),
} as Response;
}
const contents = await readFile(filePath, {
encoding: 'utf8',
});
return {
ok: true,
headers: new Headers(),
json: () => Promise.resolve(JSON.parse(contents)),
} as Response;
};
});

describe('OgcApiEndpoint', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/ogc-api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import {
parseCollections,
parseConformance,
parseEndpointInfo,
} from './info';
} from './info.js';
import {
ConformanceClass,
OgcApiCollectionInfo,
OgcApiCollectionItem,
OgcApiDocument,
OgcApiEndpointInfo,
} from './model';
} from './model.js';
import {
fetchCollectionRoot,
fetchDocument,
fetchLink,
fetchRoot,
getLinkUrl,
} from './link-utils';
import { EndpointError } from '../shared/errors';
} from './link-utils.js';
import { EndpointError } from '../shared/errors.js';

/**
* Represents an OGC API endpoint advertising various collections and services.
Expand Down
2 changes: 1 addition & 1 deletion src/ogc-api/info.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseCollectionParameters } from './info';
import { parseCollectionParameters } from './info.js';

describe('info parsing utilities', () => {
describe('parseCollectionParameters', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/ogc-api/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
OgcApiCollectionInfo,
OgcApiDocument,
OgcApiEndpointInfo,
} from './model';
import { assertHasLinks } from './link-utils';
import { EndpointError } from '../shared/errors';
} from './model.js';
import { assertHasLinks } from './link-utils.js';
import { EndpointError } from '../shared/errors.js';

export function parseEndpointInfo(rootDoc: OgcApiDocument): OgcApiEndpointInfo {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/ogc-api/link-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OgcApiDocument } from './model';
import { EndpointError } from '../shared/errors';
import { getFetchOptions } from '../shared/http-utils';
import { OgcApiDocument } from './model.js';
import { EndpointError } from '../shared/errors.js';
import { getFetchOptions } from '../shared/http-utils.js';

export function fetchDocument<T extends OgcApiDocument>(
url: string
Expand Down
2 changes: 1 addition & 1 deletion src/ogc-api/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Geometry } from 'geojson';
import { BoundingBox, CrsCode, MimeType } from '../shared/models';
import { BoundingBox, CrsCode, MimeType } from '../shared/models.js';

export type ConformanceClass = string;

Expand Down
2 changes: 1 addition & 1 deletion src/shared/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
setCacheExpiryDuration,
storeCacheEntry,
useCache,
} from './cache';
} from './cache.js';

const factory = jest.fn(() => ({ fresh: true }));
let NOW;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function purgeEntries() {
const cache = await getCache();
if (!cache) return;
const keys = await cache.keys();
for (let key of keys) {
for (const key of keys) {
const resp = await cache.match(key);
if (parseInt(resp.headers.get('x-expiry')) <= Date.now())
await cache.delete(key);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/crs-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasInvertedCoordinates, simplifyEpsgUrn } from './crs-utils';
import { hasInvertedCoordinates, simplifyEpsgUrn } from './crs-utils.js';

describe('CRS utils', () => {
describe('hasInvertedCoordinates', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/crs-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CrsCode } from './models';
import { CrsCode } from './models.js';

// This list was taken from GDAL
// and may not be completely up-to-date
Expand Down
8 changes: 4 additions & 4 deletions src/shared/encoding.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { queryXmlDocument } from './http-utils';
import { readInfoFromCapabilities } from '../wms/capabilities';
const { join } = require('path');
const { readFileSync } = require('fs');
import { queryXmlDocument } from './http-utils.js';
import { readInfoFromCapabilities } from '../wms/capabilities.js';
import { join } from 'path';
import { readFileSync } from 'fs';

const global = window as any;

Expand Down
2 changes: 0 additions & 2 deletions src/shared/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { parseXmlString, XmlParseError } from './xml-utils';

/**
* A list of encodings that will be used in order when decoding a string
* Note: a string might be successfully decoded with e.g. utf-8 but still
Expand Down
10 changes: 5 additions & 5 deletions src/shared/http-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { EndpointError } from './errors';
import { EndpointError } from './errors.js';
import {
queryXmlDocument,
setFetchOptions,
setQueryParams,
sharedFetch,
} from './http-utils';
import { fetchDocument } from '../ogc-api/link-utils';
import WfsEndpoint from '../wfs/endpoint';
// @ts-ignore
} from './http-utils.js';
import { fetchDocument } from '../ogc-api/link-utils.js';
import WfsEndpoint from '../wfs/endpoint.js';
// @ts-expect-error ts-migrate(7016)
import capabilities200 from '../../fixtures/wfs/capabilities-pigma-2-0-0.xml';

const global = window as any;
Expand Down
8 changes: 4 additions & 4 deletions src/shared/http-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseXmlString } from './xml-utils';
import { EndpointError } from './errors';
import { decodeString } from './encoding';
import { FetchOptions } from './models';
import { parseXmlString } from './xml-utils.js';
import { EndpointError } from './errors.js';
import { decodeString } from './encoding.js';
import { FetchOptions } from './models.js';

const fetchPromises: Map<string, Promise<Response>> = new Map();

Expand Down
12 changes: 6 additions & 6 deletions src/wfs/capabilities.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { parseXmlString } from '../shared/xml-utils';
// @ts-ignore
import { parseXmlString } from '../shared/xml-utils.js';
// @ts-expect-error ts-migrate(7016)
import capabilities100 from '../../fixtures/wfs/capabilities-pigma-1-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import capabilities110 from '../../fixtures/wfs/capabilities-pigma-1-1-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import capabilities200 from '../../fixtures/wfs/capabilities-pigma-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import capabilities200_noFormats from '../../fixtures/wfs/capabilities-geo2france-2-0-0.xml';
import {
readFeatureTypesFromCapabilities,
readInfoFromCapabilities,
readVersionFromCapabilities,
} from './capabilities';
} from './capabilities.js';

describe('WFS capabilities', () => {
describe('readVersionFromCapabilities', () => {
Expand Down
8 changes: 4 additions & 4 deletions src/wfs/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
getElementName,
getElementText,
getRootElement,
} from '../shared/xml-utils';
import { simplifyEpsgUrn } from '../shared/crs-utils';
} from '../shared/xml-utils.js';
import { simplifyEpsgUrn } from '../shared/crs-utils.js';
import { XmlDocument, XmlElement } from '@rgrove/parse-xml';
import { BoundingBox, GenericEndpointInfo, MimeType } from '../shared/models';
import { WfsFeatureTypeInternal, WfsVersion } from './model';
import { BoundingBox, GenericEndpointInfo, MimeType } from '../shared/models.js';
import { WfsFeatureTypeInternal, WfsVersion } from './model.js';

/**
* Will read a WFS version from the capabilities doc
Expand Down
14 changes: 7 additions & 7 deletions src/wfs/endpoint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import capabilities200 from '../../fixtures/wfs/capabilities-pigma-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getfeature200hits from '../../fixtures/wfs/getfeature-hits-pigma-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getfeature200full from '../../fixtures/wfs/getfeature-props-pigma-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import describefeaturetype200 from '../../fixtures/wfs/describefeaturetype-pigma-2-0-0-xsd.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import capabilitiesStates from '../../fixtures/wfs/capabilities-states-2-0-0.xml';
import WfsEndpoint from './endpoint';
import { useCache } from '../shared/cache';
import WfsEndpoint from './endpoint.js';
import { useCache } from '../shared/cache.js';

jest.mock('../shared/cache', () => ({
useCache: jest.fn((factory) => factory()),
Expand Down
16 changes: 8 additions & 8 deletions src/wfs/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { parseWfsCapabilities, queryWfsFeatureTypeDetails } from '../worker';
import { queryXmlDocument, setQueryParams } from '../shared/http-utils';
import { parseFeatureTypeInfo } from './featuretypeinfo';
import { useCache } from '../shared/cache';
import { generateDescribeFeatureTypeUrl, generateGetFeatureUrl } from './url';
import { stripNamespace } from '../shared/xml-utils';
import { parseWfsCapabilities, queryWfsFeatureTypeDetails } from '../worker/index.js';
import { queryXmlDocument, setQueryParams } from '../shared/http-utils.js';
import { parseFeatureTypeInfo } from './featuretypeinfo.js';
import { useCache } from '../shared/cache.js';
import { generateDescribeFeatureTypeUrl, generateGetFeatureUrl } from './url.js';
import { stripNamespace } from '../shared/xml-utils.js';
import {
BoundingBox,
CrsCode,
GenericEndpointInfo,
MimeType,
} from '../shared/models';
} from '../shared/models.js';
import {
WfsFeatureTypeBrief,
WfsFeatureTypeInternal,
WfsFeatureTypeSummary,
WfsVersion,
} from './model';
} from './model.js';

/**
* Represents a WFS endpoint advertising several feature types
Expand Down
20 changes: 10 additions & 10 deletions src/wfs/featureprops.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureCities100 from '../../fixtures/wfs/getfeature-props-cities-1-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureCities110 from '../../fixtures/wfs/getfeature-props-cities-1-1-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureCities200 from '../../fixtures/wfs/getfeature-props-cities-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureStates100 from '../../fixtures/wfs/getfeature-props-states-1-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureStates110 from '../../fixtures/wfs/getfeature-props-states-1-1-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureStates200 from '../../fixtures/wfs/getfeature-props-states-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureStates200Geojson from '../../fixtures/wfs/getfeature-props-states-2-0-0.json';
import {
computeFeaturePropsDetails,
parseFeatureProps,
parseFeaturePropsGeojson,
} from './featureprops';
import { parseXmlString } from '../shared/xml-utils';
import { WfsFeatureTypeFull } from './model';
} from './featureprops.js';
import { parseXmlString } from '../shared/xml-utils.js';
import { WfsFeatureTypeFull } from './model.js';

describe('feature props utils', () => {
describe('parseFeatureProps and parseFeaturePropsGeojson', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/wfs/featureprops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
getElementText,
getRootElement,
stripNamespace,
} from '../shared/xml-utils';
} from '../shared/xml-utils.js';
import { XmlDocument, XmlElement } from '@rgrove/parse-xml';
import {
WfsFeatureTypeFull,
WfsFeatureTypePropsDetails,
WfsFeatureWithProps,
WfsVersion,
} from './model';
} from './model.js';

/**
* Returns an array of features with their id and properties
Expand Down
14 changes: 7 additions & 7 deletions src/wfs/featuretypeinfo.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureHits110 from '../../fixtures/wfs/getfeature-hits-pigma-1-1-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import getFeatureHits200 from '../../fixtures/wfs/getfeature-hits-pigma-2-0-0.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import describeFeatureType110 from '../../fixtures/wfs/describefeaturetype-pigma-1-1-0-xsd.xml';
// @ts-ignore
// @ts-expect-error ts-migrate(7016)
import describeFeatureType200 from '../../fixtures/wfs/describefeaturetype-pigma-2-0-0-xsd.xml';
import { parseFeatureTypeInfo } from './featuretypeinfo';
import { parseXmlString } from '../shared/xml-utils';
import { WfsFeatureTypeFull, WfsFeatureTypeInternal } from './model';
import { parseFeatureTypeInfo } from './featuretypeinfo.js';
import { parseXmlString } from '../shared/xml-utils.js';
import { WfsFeatureTypeFull, WfsFeatureTypeInternal } from './model.js';

describe('feature type info', () => {
describe('parseFeatureTypeInfo', () => {
Expand Down
Loading

0 comments on commit 9363be0

Please sign in to comment.