Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed eslint and linted files #8891

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"extends": [
"eslint:recommended"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- run: npm install
env:
FORCE_COLOR: 2
- run: npm run lint
env:
FORCE_COLOR: 2
- run: npm run test
env:
FORCE_COLOR: 2
105 changes: 66 additions & 39 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,68 @@
{
"editor.formatOnSave": false,
"json.schemas": [
{
"fileMatch": [
"data/**/*.json"
],
"url": "./schema/categories.json"
},
{
"fileMatch": [
"data/**/*.json"
],
"url": "./schema/feature.json"
},
{
"fileMatch": [
"config/genericWords.json"
],
"url": "./schema/genericWords.json"
},
{
"fileMatch": [
"features/**/*.geojson"
],
"url": "./schema/geojson.json"
},
{
"fileMatch": [
"config/replacements.json"
],
"url": "./schema/replacements.json"
},
{
"fileMatch": [
"config/trees.json"
],
"url": "./schema/trees.json"
}
]
"editor.formatOnSave": false,
"json.schemas": [
{
"fileMatch": [
"data/**/*.json"
],
"url": "./schema/categories.json"
},
{
"fileMatch": [
"data/**/*.json"
],
"url": "./schema/feature.json"
},
{
"fileMatch": [
"config/genericWords.json"
],
"url": "./schema/genericWords.json"
},
{
"fileMatch": [
"features/**/*.geojson"
],
"url": "./schema/geojson.json"
},
{
"fileMatch": [
"config/replacements.json"
],
"url": "./schema/replacements.json"
},
{
"fileMatch": [
"config/trees.json"
],
"url": "./schema/trees.json"
}
],
"cSpell.words": [
"aitodotai",
"Applebees",
"brandkey",
"fontawesome",
"fortawesome",
"honeybakedham",
"ideditor",
"idgen",
"Kebabai",
"mapbox",
"Multipolygon",
"multivalue",
"newid",
"nsimple",
"openstreetmap",
"operatorkey",
"osmkey",
"rapideditor",
"regexes",
"sparql",
"Taginfo",
"tagpair",
"wikibase",
"wiphala",
"xmlbuilder"
]
}
5 changes: 5 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
["@babel/plugin-syntax-import-attributes", { "deprecatedAssertSyntax": true }]
]
}
2 changes: 1 addition & 1 deletion lib/file_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs-extra';
import { globSync } from 'glob';
import JSON5 from 'json5';
import localeCompare from 'locale-compare';
import stringify from '@aitodotai/json-stringify-pretty-compact';
import stringify from 'json-stringify-pretty-compact';
const withLocale = localeCompare('en-US');

// Internal
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"build:features": "node scripts/build_features.js",
"build:index": "node scripts/build_index.js",
"tap": "c8 tap --reporter terse --no-cov tests/*.js",
"lint": "eslint scripts/*.js lib/*.js",
"lint": "eslint scripts/*.js lib/*.js tests/*.js",
"test": "run-s build tap",
"validate": "node scripts/validate.js",
"wikidata": "node scripts/build_wikidata.js"
Expand All @@ -105,7 +105,10 @@
"which-polygon": "^2.2.1"
},
"devDependencies": {
"@aitodotai/json-stringify-pretty-compact": "^1.3.0",
"json-stringify-pretty-compact": "^4.0.0",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-syntax-import-attributes": "^7.22.5",
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-brands-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
Expand All @@ -119,7 +122,7 @@
"chalk": "5.3.0",
"clear": "^0.1.0",
"esbuild": "^0.19.4",
"eslint": "^8.50.0",
"eslint": "^8.52.0",
"fs-extra": "^11.1.1",
"geojson-bounds": "^1.0.2",
"geojson-precision": "^1.0.0",
Expand Down
45 changes: 2 additions & 43 deletions scripts/build_features.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// External
import chalk from 'chalk';
import fs from 'node:fs';
import geojsonArea from '@mapbox/geojson-area';
import geojsonBounds from 'geojson-bounds';
import geojsonPrecision from 'geojson-precision';
import geojsonRewind from '@mapbox/geojson-rewind';
import { globSync } from 'glob';
import JSON5 from 'json5';
import jsonschema from 'jsonschema';
import path from 'node:path';
import localeCompare from 'locale-compare';
import stringify from '@aitodotai/json-stringify-pretty-compact';
import stringify from 'json-stringify-pretty-compact';
const withLocale = localeCompare('en-US');

// Internal
Expand Down Expand Up @@ -86,22 +84,6 @@ function collectFeatures() {
const id = path.basename(file).toLowerCase();
feature.id = id;

// // Warn if this feature is so small/complex it would better be represented as a circular area.
// const except = { 'new_york_city.geojson': true };
// if (!except[id]) {
// const coordLength = countCoordinates(feature.geometry.coordinates);
// let area = geojsonArea.geometry(feature.geometry) / 1e6; // m² to km²
// area = Number(area.toFixed(2));
// if (area < 2000 && coordLength > 15) {
// const extent = geojsonBounds.extent(feature);
// const lon = ((extent[0] + extent[2]) / 2).toFixed(4);
// const lat = ((extent[1] + extent[3]) / 2).toFixed(4);
// console.warn('');
// console.warn(chalk.yellow(`Warning - GeoJSON feature for small area (${area} km²). Consider circular include location instead: [${lon}, ${lat}]`));
// console.warn(' ' + chalk.yellow(file));
// }
// }

// sort properties
let obj = {};
if (feature.type) { obj.type = feature.type; }
Expand Down Expand Up @@ -146,37 +128,14 @@ function collectFeatures() {
});

// sort features by id, see: 800ca866f
features.sort((a, b) => withLocale(a.id, b.id))
features.sort((a, b) => withLocale(a.id, b.id));

const featureCount = Object.keys(files).length;
console.log(`🧩 features:\t${featureCount}`);
return features;
}


//
// countCoordinates()
// Counts the number of coordinates in a GeoJSON Polygon or MultiPolygon
//
function countCoordinates(coords) {
const a = Array.isArray(coords);
const b = a && Array.isArray(coords[0]);
const c = b && Array.isArray(coords[0][0]);
const d = c && Array.isArray(coords[0][0][0]);

let length = 0;
if (d) { // Multipolygon
coords.forEach(polys => {
polys.forEach(rings => length += rings.length);
});
} else { // Polygon
coords.forEach(rings => length += rings.length);
}
return length;
}



//
// validateFile()
// Performs JSON schema validation on the file.
Expand Down
48 changes: 7 additions & 41 deletions scripts/build_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import JSON5 from 'json5';
import localeCompare from 'locale-compare';
import LocationConflation from '@rapideditor/location-conflation';
import safeRegex from 'safe-regex';
import stringify from '@aitodotai/json-stringify-pretty-compact';
import stringify from 'json-stringify-pretty-compact';
const withLocale = localeCompare('en-US');

// Internal
Expand All @@ -14,14 +14,12 @@ import { idgen } from '../lib/idgen.js';
import { Matcher } from '../lib/matcher.js';
import { simplify } from '../lib/simplify.js';
import { sortObject } from '../lib/sort_object.js';
import { stemmer } from '../lib/stemmer.js';
import { validate } from '../lib/validate.js';
import { writeFileWithMeta } from '../lib/write_file_with_meta.js';
const matcher = new Matcher();

// JSON
import treesJSON from '../config/trees.json' assert {type: 'json'};
const trees = treesJSON.trees;


// We use LocationConflation for validating and processing the locationSets
import featureCollectionJSON from '../dist/featureCollection.json' assert {type: 'json'};
Expand Down Expand Up @@ -348,7 +346,7 @@ function mergeItems() {
// Any country codes which should be replaced by more standard ones in the locationSets
const countryReplacements = {
'uk': 'gb', // Exceptionally reserved, United Kingdom is officially assigned the alpha-2 code GB
}
};

const START = '🏗 ' + chalk.yellow(`Merging items...`);
const END = '👍 ' + chalk.green(`done merging`);
Expand Down Expand Up @@ -510,7 +508,7 @@ function mergeItems() {
} else if (/[\u1700-\u171F]/.test(name)) { // Tagalog
if (!item.locationSet) item.locationSet = { include: ['ph'] };
setLanguageTags(tags, 'tl');
} else if (/[\u3040-\u30FF]/.test(name)) { // Hirgana or Katakana
} else if (/[\u3040-\u30FF]/.test(name)) { // Hiragana or Katakana
if (!item.locationSet) item.locationSet = { include: ['jp'] };
setLanguageTags(tags, 'ja');
} else if (/[\u3130-\u318F]/.test(name)) { // Hangul
Expand Down Expand Up @@ -587,11 +585,11 @@ function mergeItems() {
}

function normalizeCountryCode(countries, country) {
const index = countries.indexOf(country.toLowerCase())
const index = countries.indexOf(country.toLowerCase());
if (index >= 0) {
const replace = countryReplacements[country.toLowerCase()];
if (replace && replace !== undefined) {
countries[index] = replace.toLowerCase()
countries[index] = replace.toLowerCase();
}
}
}
Expand All @@ -613,7 +611,6 @@ function checkItems(t) {
let warnFormatWikidata = [];
let warnMissingTag = [];
let warnFormatTag = [];
let seenName = {};

let total = 0; // total items
let totalWd = 0; // total items with wikidata
Expand All @@ -625,7 +622,7 @@ function checkItems(t) {
const items = _cache.path[tkv].items;
if (!Array.isArray(items) || !items.length) return;

const [t, k, v] = tkv.split('/', 3); // tkv = "tree/key/value"
const [, k, v] = tkv.split('/', 3); // tkv = "tree/key/value"
const kv = `${k}/${v}`;

items.forEach(item => {
Expand Down Expand Up @@ -698,37 +695,6 @@ function checkItems(t) {
warnFormatTag.push([display(item), `${osmkey} = ${val}`]);
}
});


// TODO ?
// // Warn about "new" (no wikidata) items that may duplicate an "existing" (has wikidata) item.
// // The criteria for this warning is:
// // - One of the items has no `brand:wikidata`
// // - The items have nearly the same name
// // - The items have the same locationSet (or the one without wikidata is worldwide)
// const name = tags.name || tags.brand;
// const stem = stemmer(name) || name;
// const itemwd = tags[tree.mainTag];
// const itemls = loco.validateLocationSet(item.locationSet).id;

// if (!seenName[stem]) seenName[stem] = new Set();
// seenName[stem].add(item);

// if (seenName[stem].size > 1) {
// seenName[stem].forEach(other => {
// if (other.id === item.id) return; // skip self
// const otherwd = other.tags[tree.mainTag];
// const otherls = loco.validateLocationSet(other.locationSet).id;

// // pick one of the items without a wikidata tag to be the "duplicate"
// if (!itemwd && (itemls === otherls || itemls === '+[Q2]')) {
// warnDuplicate.push([display(item), display(other)]);
// } else if (!otherwd && (otherls === itemls || otherls === '+[Q2]')) {
// warnDuplicate.push([display(other), display(item)]);
// }
// });
// }

});
});

Expand Down
8 changes: 1 addition & 7 deletions scripts/build_wikidata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import JSON5 from 'json5';
import localeCompare from 'locale-compare';
import LocationConflation from '@rapideditor/location-conflation';
import shell from 'shelljs';
import stringify from '@aitodotai/json-stringify-pretty-compact';
import stringify from 'json-stringify-pretty-compact';
import wikibase from 'wikibase-sdk';
import wikibaseEdit from 'wikibase-edit';
const withLocale = localeCompare('en-US');
Expand Down Expand Up @@ -765,12 +765,6 @@ function delay(msec) {
}


// Clamp a number between min and max
function clamp(num, min, max) {
return Math.min(Math.max(num, min), max);
}


function utilQsString(obj) {
return Object.keys(obj).sort(withLocale).map(key => {
return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
Expand Down