Skip to content

Commit

Permalink
update linter
Browse files Browse the repository at this point in the history
mostly reducing the use of ambiguous abbreviations
  • Loading branch information
k-yle committed Jul 15, 2023
1 parent 2e8993d commit 123b80e
Show file tree
Hide file tree
Showing 65 changed files with 2,301 additions and 903 deletions.
2,304 changes: 1,806 additions & 498 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"all": "npm run preprocess && npm run conflate && npm run action && npm run upload",
"changelog": "ts-node src/changelog",
"changesetWatch": "ts-node src/changesetWatch",
"lint": "eslint --ignore-path .gitignore . && tsc",
"lint": "eslint --fix --ignore-path .gitignore . && tsc",
"pretest": "cp src/__tests__/bin/osmconvert src/__tests__/bin/osmconvert2 && chmod u+x src/__tests__/bin/osmconvert2",
"test": "jest"
},
Expand All @@ -43,8 +43,8 @@
"@types/through2": "^2.0.38",
"@types/unzipper": "^0.10.5",
"@types/which-polygon": "^2.2.0",
"eslint": "^8.37.0",
"eslint-config-kyle": "^11.4.1",
"eslint": "^8.45.0",
"eslint-config-kyle": "^12.0.1",
"jest": "^29.3.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
Expand All @@ -53,6 +53,7 @@
"eslintConfig": {
"extends": "kyle",
"rules": {
"@typescript-eslint/no-dynamic-delete": 0,
"camelcase": 0,
"no-param-reassign": 0
}
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { execSync } from 'child_process';
import { join } from 'path';
import { execSync } from 'node:child_process';
import { join } from 'node:path';
import { main as fetchAndSaveAddressIgnoreList } from '../preprocess/fetchAndSaveAddressIgnoreList';
import { main as preprocessLinz } from '../preprocess/processLinzData';
import { main as preprocessOsm } from '../preprocess/processOsmData';
import { main as stackLinzData } from '../preprocess/stackLinzData';
import { main as conflate } from '../conflate';
import { main as action } from '../action';

const j = (...files: string[]) => join(__dirname, ...files);
const joinPath = (...files: string[]) => join(__dirname, ...files);

async function time(f: () => unknown) {
const start = Date.now();
await f();
return (Date.now() - start) / 1000 / 60;
}

const exe = j(
const exe = joinPath(
'bin',
process.platform === 'win32' ? 'osmconvert.exe' : 'osmconvert2',
);
Expand All @@ -24,7 +24,7 @@ describe('end-to-end test', () => {
// convert the mock.xml file into mock.pbf
beforeAll(() => {
const std = execSync(
`${exe} ${j('mock/planet.xml')} -o=${j('mock/planet.pbf')}`,
`${exe} ${joinPath('mock/planet.xml')} -o=${joinPath('mock/planet.pbf')}`,
);
process.stdout.write(std);
});
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/mock/planet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@

<!-- location off a lot but has a recent check_date -->
<node id="40" version="1" changeset="1" lat="-36" lon="174.940" user="" uid="0" visible="true" timestamp="2012-05-19T11:22:33Z">
<tag k="check_date" v="2021-06-06" />
<tag k="check_date" v="2027-06-06" />
<tag k="addr:housenumber" v="40" />
<tag k="addr:street" v="Example Street" />
<tag k="addr:hamlet" v="Oakleigh" />
Expand All @@ -258,7 +258,7 @@

<!-- street name wrong but has a recent check_date -->
<node id="41" version="1" changeset="1" lat="-36.9" lon="174.941" user="" uid="0" visible="true" timestamp="2012-05-19T11:22:33Z">
<tag k="check_date" v="2021-06-06" />
<tag k="check_date" v="2027-06-06" />
<tag k="addr:housenumber" v="41" />
<tag k="addr:street" v="Example Lane" />
<tag k="addr:hamlet" v="Oakleigh" />
Expand Down
6 changes: 3 additions & 3 deletions src/action/createIndex.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { GeoJson, HandlerReturnWithBBox } from '../types';
import { calcCount, CDN_URL, mock, suburbsFolder } from './util';
import { hash } from '../common';

function toId(suburb: string) {
// macrons are url safe
return `${suburb.replace(/[^a-zA-ZāēīōūĀĒĪŌŪ0-9]/g, '')}_${hash(suburb)}`;
return `${suburb.replaceAll(/[^\dA-Za-zĀāĒēĪīŌōŪū]/g, '')}_${hash(suburb)}`;
}

export async function createIndex(
Expand Down
4 changes: 2 additions & 2 deletions src/action/generateStats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { Status, StatusReport, StatsFile } from '../types';
import { mock, outFolder } from './util';

Expand Down
30 changes: 19 additions & 11 deletions src/action/handlers/existsButDataWrong.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import {
Status,
StatusReport,
Expand All @@ -15,13 +15,19 @@ const toKey = (right: string, wrong: string, osmData: OsmAddr) =>
`${[right, wrong].sort().join('__')}__${osmData.street}`;

export async function existsButDataWrong(
arr: StatusReport[Status.EXISTS_BUT_WRONG_DATA],
array: StatusReport[Status.EXISTS_BUT_WRONG_DATA],
): Promise<HandlerReturn> {
const bySuburb = arr.reduce((ac, [linzId, [osmAddr, suburb, ...issues]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr, issues]);
return ac;
}, {} as Record<string, [linzId: string, osmAddr: OsmAddr, issues: Issue[], swap?: boolean][]>);
const bySuburb = array.reduce(
(ac, [linzId, [osmAddr, suburb, ...issues]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr, issues]);
return ac;
},
{} as Record<
string,
[linzId: string, osmAddr: OsmAddr, issues: Issue[], swap?: boolean][]
>,
);

let report = '';
const out: HandlerReturn = {};
Expand All @@ -38,14 +44,14 @@ export async function existsButDataWrong(
string,
{ index: number; linzId: string; osmData: OsmAddr }[]
> = {};
for (let i = 0; i < bySuburb[suburb].length; i += 1) {
const [linzId, osmData, issues] = bySuburb[suburb][i];
for (let index = 0; index < bySuburb[suburb].length; index += 1) {
const [linzId, osmData, issues] = bySuburb[suburb][index];

const [type, right, wrong] = issues[0].split('|');
if (issues.length === 1 && type === 'housenumber') {
const key = toKey(right, wrong, osmData);
maybeSwappablePairs[key] ||= [];
maybeSwappablePairs[key].push({ index: i, linzId, osmData });
maybeSwappablePairs[key].push({ index, linzId, osmData });
}
}

Expand All @@ -72,6 +78,8 @@ export async function existsButDataWrong(
}),
},
});

// eslint-disable-next-line unicorn/no-array-push-push -- to avoid destroying the git blame
features.push({
type: 'Feature',
id: b.osmData.osmId,
Expand Down
8 changes: 4 additions & 4 deletions src/action/handlers/handleCorrupted.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import {
GeoJsonFeature,
HandlerReturn,
Expand All @@ -25,10 +25,10 @@ type ByOsmId = {
};

export async function handleCorrupted(
arr: StatusReport[Status.CORRUPT],
array: StatusReport[Status.CORRUPT],
): Promise<HandlerReturn> {
let report = '';
const byOsmId = arr.reduce<ByOsmId>((ac, [linzId, [osmAddr, linzAddr]]) => {
const byOsmId = array.reduce<ByOsmId>((ac, [linzId, [osmAddr, linzAddr]]) => {
ac[osmAddr.osmId] ||= { osm: osmAddr, linz: [] };
ac[osmAddr.osmId].linz.push([linzId, linzAddr]);
return ac;
Expand Down
25 changes: 14 additions & 11 deletions src/action/handlers/handleCouldBeStacked.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { toStackId } from '../../common';
import { OsmId, Status, StatusReport } from '../../types';
import { outFolder } from '../util';
Expand All @@ -15,18 +15,21 @@ type BySuburb = {
};

export async function handleCouldBeStacked(
arr: StatusReport[Status.COULD_BE_STACKED],
array: StatusReport[Status.COULD_BE_STACKED],
): Promise<void> {
let report = '';

const bySuburb = arr.reduce((_ac, [linzId, [osmId, suburb, addr, meta]]) => {
const ac = _ac;
ac[suburb] ||= {};
ac[suburb][addr] ||= { meta, osmIds: [], linzIds: [] };
ac[suburb][addr].osmIds.push(osmId);
ac[suburb][addr].linzIds.push(linzId);
return ac;
}, {} as BySuburb);
const bySuburb = array.reduce(
(_ac, [linzId, [osmId, suburb, addr, meta]]) => {
const ac = _ac;
ac[suburb] ||= {};
ac[suburb][addr] ||= { meta, osmIds: [], linzIds: [] };
ac[suburb][addr].osmIds.push(osmId);
ac[suburb][addr].linzIds.push(linzId);
return ac;
},
{} as BySuburb,
);

for (const suburb in bySuburb) {
report += `\n${suburb}\n`;
Expand Down
19 changes: 11 additions & 8 deletions src/action/handlers/handleDeleted.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { OsmAddr, Status, StatusReport } from '../../types';
import { outFolder, toLink } from '../util';

export async function handleDeleted(
arr: StatusReport[Status.NEEDS_DELETE],
array: StatusReport[Status.NEEDS_DELETE],
): Promise<void> {
const bySuburb = arr.reduce((ac, [linzId, [suburb, osmAddr]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr]);
return ac;
}, {} as Record<string, [string, OsmAddr][]>);
const bySuburb = array.reduce(
(ac, [linzId, [suburb, osmAddr]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr]);
return ac;
},
{} as Record<string, [string, OsmAddr][]>,
);

let report = '';
for (const suburb in bySuburb) {
Expand Down
21 changes: 12 additions & 9 deletions src/action/handlers/handleDeletedOnBuilding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import {
GeoJsonFeature,
HandlerReturn,
Expand All @@ -15,13 +15,16 @@ import {
} from '../util';

export async function handleDeletedOnBuilding(
arr: StatusReport[Status.NEEDS_DELETE_ON_BUILDING],
array: StatusReport[Status.NEEDS_DELETE_ON_BUILDING],
): Promise<HandlerReturn> {
const bySuburb = arr.reduce((ac, [linzId, [suburb, osmAddr]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr]);
return ac;
}, {} as Record<string, [string, OsmAddr][]>);
const bySuburb = array.reduce(
(ac, [linzId, [suburb, osmAddr]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr]);
return ac;
},
{} as Record<string, [string, OsmAddr][]>,
);

let report = '';
for (const suburb in bySuburb) {
Expand All @@ -37,7 +40,7 @@ export async function handleDeletedOnBuilding(

const features: GeoJsonFeature[] = [];

for (const [, [, osmAddr]] of arr) {
for (const [, [, osmAddr]] of array) {
features.push({
type: 'Feature',
id: osmAddr.osmId,
Expand Down
19 changes: 11 additions & 8 deletions src/action/handlers/handleDeletedOnPOI.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import { OsmAddr, Status, StatusReport } from '../../types';
import { outFolder, toLink } from '../util';

export async function handleDeletedOnPOI(
arr: StatusReport[Status.NEEDS_DELETE_NON_TRIVIAL],
array: StatusReport[Status.NEEDS_DELETE_NON_TRIVIAL],
): Promise<void> {
const bySuburb = arr.reduce((ac, [linzId, [suburb, osmAddr]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr]);
return ac;
}, {} as Record<string, [string, OsmAddr][]>);
const bySuburb = array.reduce(
(ac, [linzId, [suburb, osmAddr]]) => {
ac[suburb] ||= [];
ac[suburb].push([linzId, osmAddr]);
return ac;
},
{} as Record<string, [string, OsmAddr][]>,
);

let report = '';
for (const suburb in bySuburb) {
Expand Down
26 changes: 16 additions & 10 deletions src/action/handlers/handleDuplicateLinzRef.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs';
import { join } from 'path';
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
import {
GeoJsonFeature,
HandlerReturn,
Expand All @@ -14,12 +14,12 @@ const toKey = (addr: LinzAddr | OsmAddr) =>
`${addr.housenumber} ${addr.street}${addr.suburb?.[0]}${addr.suburb?.[1]}`;

export async function handleDuplicateLinzRef(
arr: StatusReport[Status.MULTIPLE_EXIST],
array: StatusReport[Status.MULTIPLE_EXIST],
): Promise<HandlerReturn> {
const autofixable: Record<string, '✅' | '⚠️'> = {};
const features: GeoJsonFeature[] = [];

for (const [linzId, [linzAddr, osmAddrList]] of arr) {
for (const [linzId, [linzAddr, osmAddrList]] of array) {
const simpleNodes = osmAddrList.filter(
(x) => x.osmId[0] === 'n' && !x.isNonTrivial,
);
Expand Down Expand Up @@ -74,12 +74,18 @@ export async function handleDuplicateLinzRef(
}
}

const bySuburb = arr.reduce((ac, [linzId, [linzAddr, osmAddrList]]) => {
const suburb = linzAddr.suburb[1];
ac[suburb] ||= [];
ac[suburb].push([linzId, linzAddr, osmAddrList]);
return ac;
}, {} as Record<string, [linzId: string, linzAddr: LinzAddr, osmAddrList: OsmAddr[]][]>);
const bySuburb = array.reduce(
(ac, [linzId, [linzAddr, osmAddrList]]) => {
const suburb = linzAddr.suburb[1];
ac[suburb] ||= [];
ac[suburb].push([linzId, linzAddr, osmAddrList]);
return ac;
},
{} as Record<
string,
[linzId: string, linzAddr: LinzAddr, osmAddrList: OsmAddr[]][]
>,
);

let report = [
'✅ = issue can be autofixed',
Expand Down
Loading

0 comments on commit 123b80e

Please sign in to comment.