feat: add prettier config

This commit is contained in:
Brice Maron 2022-09-03 18:00:54 +02:00
parent 7d77b0ba4c
commit d3f453a4fb
12 changed files with 159 additions and 104 deletions

10
.editorconfig Normal file
View file

@ -0,0 +1,10 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
[*.ts]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

2
.git-blame-ignore-revs Normal file
View file

@ -0,0 +1,2 @@
# to be filled once final sha is known
# Prettier init

View file

@ -4,9 +4,11 @@ runs:
using: "composite" using: "composite"
steps: steps:
- name: Set up Node.js - name: Set up Node.js
uses: actions/setup-node@v1.4.6 uses: actions/setup-node@v3
with: with:
node-version: '16' node-version: "16"
cache: "npm"
cache-dependency-path: package-lock.json
- name: install deps - name: install deps
run: npm ci run: npm ci

View file

@ -6,7 +6,7 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup and validate themes - name: Setup and validate themes
uses: ./.github/actions/setup-and-validate uses: ./.github/actions/setup-and-validate

13
.prettierignore Normal file
View file

@ -0,0 +1,13 @@
node_modules
.git
langs/
vendor/
dist/
.cache
assets/generated/
assets/themes/
assets/layers/
Docs/Tools/stats/
Docs/Layers/
Docs/Schemas/
Docs/TagInfo/

4
.prettierrc.json Normal file
View file

@ -0,0 +1,4 @@
{
"semi": false,
"printWidth": 100
}

View file

@ -44,7 +44,6 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> {
* layers: [ * layers: [
* { * {
* tagRenderings:[ * tagRenderings:[
*
* {id: "some-tr", * {id: "some-tr",
* question:{ * question:{
* en:"Question?" * en:"Question?"
@ -59,7 +58,6 @@ export class AddContextToTranslations<T> extends DesugaringStep<T> {
* layers: [ * layers: [
* { * {
* tagRenderings:[ * tagRenderings:[
*
* {id: "some-tr", * {id: "some-tr",
* question:{ * question:{
* _context: "prefix:context.layers.0.tagRenderings.some-tr.question" * _context: "prefix:context.layers.0.tagRenderings.some-tr.question"

View file

@ -1,15 +1,15 @@
import {UIEventSource} from "../../Logic/UIEventSource"; import { UIEventSource } from "../../Logic/UIEventSource";
import Combine from "../Base/Combine"; import Combine from "../Base/Combine";
import {FixedUiElement} from "../Base/FixedUiElement"; import { FixedUiElement } from "../Base/FixedUiElement";
import {OH} from "./OpeningHours"; import { OH } from "./OpeningHours";
import Translations from "../i18n/Translations"; import Translations from "../i18n/Translations";
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants";
import BaseUIElement from "../BaseUIElement"; import BaseUIElement from "../BaseUIElement";
import Toggle from "../Input/Toggle"; import Toggle from "../Input/Toggle";
import {VariableUiElement} from "../Base/VariableUIElement"; import { VariableUiElement } from "../Base/VariableUIElement";
import Table from "../Base/Table"; import Table from "../Base/Table";
import {Translation} from "../i18n/Translation"; import { Translation } from "../i18n/Translation";
import {OsmConnection} from "../../Logic/Osm/OsmConnection"; import { OsmConnection } from "../../Logic/Osm/OsmConnection";
export default class OpeningHoursVisualization extends Toggle { export default class OpeningHoursVisualization extends Toggle {
private static readonly weekdays: Translation[] = [ private static readonly weekdays: Translation[] = [
@ -158,7 +158,7 @@ export default class OpeningHoursVisualization extends Toggle {
} }
return new Table(undefined, return new Table(undefined,
[["&nbsp", header], ...weekdays], [["&nbsp", header], ...weekdays],
{contentStyle: [["width: 5%", `position: relative; height: ${headerHeight}`], ...weekdayStyles]} { contentStyle: [["width: 5%", `position: relative; height: ${headerHeight}`], ...weekdayStyles] }
).SetClass("w-full") ).SetClass("w-full")
.SetStyle("border-collapse: collapse; word-break; word-break: normal; word-wrap: normal") .SetStyle("border-collapse: collapse; word-break; word-break: normal; word-wrap: normal")
@ -179,6 +179,7 @@ export default class OpeningHoursVisualization extends Toggle {
startOfDay.setHours(0, 0, 0, 0); startOfDay.setHours(0, 0, 0, 0);
// @ts-ignore // @ts-ignore
const startpoint = (range.startDate - startOfDay) / 1000 - earliestOpen; const startpoint = (range.startDate - startOfDay) / 1000 - earliestOpen;
// prettier-ignore
// @ts-ignore // @ts-ignore
const width = (100 * (range.endDate - range.startDate) / 1000) / (latestclose - earliestOpen); const width = (100 * (range.endDate - range.startDate) / 1000) / (latestclose - earliestOpen);
const startPercentage = (100 * startpoint / availableArea); const startPercentage = (100 * startpoint / availableArea);
@ -270,7 +271,7 @@ export default class OpeningHoursVisualization extends Toggle {
return Translations.t.general.opening_hours.closed_permanently.Clone() return Translations.t.general.opening_hours.closed_permanently.Clone()
} }
const willOpenAt = `${opensAtDate.getDate()}/${opensAtDate.getMonth() + 1} ${OH.hhmm(opensAtDate.getHours(), opensAtDate.getMinutes())}` const willOpenAt = `${opensAtDate.getDate()}/${opensAtDate.getMonth() + 1} ${OH.hhmm(opensAtDate.getHours(), opensAtDate.getMinutes())}`
return Translations.t.general.opening_hours.closed_until.Subs({date: willOpenAt}) return Translations.t.general.opening_hours.closed_until.Subs({ date: willOpenAt })
} }

View file

@ -1,38 +1,38 @@
import {Store, Stores, UIEventSource} from "../../Logic/UIEventSource"; import { Store, Stores, UIEventSource } from "../../Logic/UIEventSource";
import Combine from "../Base/Combine"; import Combine from "../Base/Combine";
import {InputElement, ReadonlyInputElement} from "../Input/InputElement"; import { InputElement, ReadonlyInputElement } from "../Input/InputElement";
import ValidatedTextField from "../Input/ValidatedTextField"; import ValidatedTextField from "../Input/ValidatedTextField";
import {FixedInputElement} from "../Input/FixedInputElement"; import { FixedInputElement } from "../Input/FixedInputElement";
import {RadioButton} from "../Input/RadioButton"; import { RadioButton } from "../Input/RadioButton";
import {Utils} from "../../Utils"; import { Utils } from "../../Utils";
import CheckBoxes from "../Input/Checkboxes"; import CheckBoxes from "../Input/Checkboxes";
import InputElementMap from "../Input/InputElementMap"; import InputElementMap from "../Input/InputElementMap";
import {SaveButton} from "./SaveButton"; import { SaveButton } from "./SaveButton";
import {VariableUiElement} from "../Base/VariableUIElement"; import { VariableUiElement } from "../Base/VariableUIElement";
import Translations from "../i18n/Translations"; import Translations from "../i18n/Translations";
import {FixedUiElement} from "../Base/FixedUiElement"; import { FixedUiElement } from "../Base/FixedUiElement";
import {Translation} from "../i18n/Translation"; import { Translation } from "../i18n/Translation";
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants";
import {SubstitutedTranslation} from "../SubstitutedTranslation"; import { SubstitutedTranslation } from "../SubstitutedTranslation";
import {TagsFilter} from "../../Logic/Tags/TagsFilter"; import { TagsFilter } from "../../Logic/Tags/TagsFilter";
import {Tag} from "../../Logic/Tags/Tag"; import { Tag } from "../../Logic/Tags/Tag";
import {And} from "../../Logic/Tags/And"; import { And } from "../../Logic/Tags/And";
import {TagUtils, UploadableTag} from "../../Logic/Tags/TagUtils"; import { TagUtils, UploadableTag } from "../../Logic/Tags/TagUtils";
import BaseUIElement from "../BaseUIElement"; import BaseUIElement from "../BaseUIElement";
import {DropDown} from "../Input/DropDown"; import { DropDown } from "../Input/DropDown";
import InputElementWrapper from "../Input/InputElementWrapper"; import InputElementWrapper from "../Input/InputElementWrapper";
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"; import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction";
import TagRenderingConfig, {Mapping} from "../../Models/ThemeConfig/TagRenderingConfig"; import TagRenderingConfig, { Mapping } from "../../Models/ThemeConfig/TagRenderingConfig";
import {Unit} from "../../Models/Unit"; import { Unit } from "../../Models/Unit";
import VariableInputElement from "../Input/VariableInputElement"; import VariableInputElement from "../Input/VariableInputElement";
import Toggle from "../Input/Toggle"; import Toggle from "../Input/Toggle";
import Img from "../Base/Img"; import Img from "../Base/Img";
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"; import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
import Title from "../Base/Title"; import Title from "../Base/Title";
import {OsmConnection} from "../../Logic/Osm/OsmConnection"; import { OsmConnection } from "../../Logic/Osm/OsmConnection";
import {GeoOperations} from "../../Logic/GeoOperations"; import { GeoOperations } from "../../Logic/GeoOperations";
import {SearchablePillsSelector} from "../Input/SearchableMappingsSelector"; import { SearchablePillsSelector } from "../Input/SearchableMappingsSelector";
import {OsmTags} from "../../Models/OsmFeature"; import { OsmTags } from "../../Models/OsmFeature";
/** /**
* Shows the question element. * Shows the question element.
@ -91,7 +91,7 @@ export default class TagRenderingQuestion extends Combine {
const save = () => { const save = () => {
const selection = TagUtils.FlattenMultiAnswer(TagUtils.FlattenAnd( inputElement.GetValue().data, tags.data)); const selection = TagUtils.FlattenMultiAnswer(TagUtils.FlattenAnd(inputElement.GetValue().data, tags.data));
if (selection) { if (selection) {
(state?.changes) (state?.changes)
.applyAction(new ChangeTagAction( .applyAction(new ChangeTagAction(
@ -229,7 +229,7 @@ export default class TagRenderingQuestion extends Combine {
if (configuration.multiAnswer) { if (configuration.multiAnswer) {
return TagRenderingQuestion.GenerateMultiAnswer(configuration, inputEls, ff, applicableMappings.map(mp => mp.ifnot)) return TagRenderingQuestion.GenerateMultiAnswer(configuration, inputEls, ff, applicableMappings.map(mp => mp.ifnot))
} else { } else {
return new RadioButton(inputEls, {selectFirstAsDefault: false}) return new RadioButton(inputEls, { selectFirstAsDefault: false })
} }
} }
@ -267,7 +267,6 @@ export default class TagRenderingQuestion extends Combine {
* freeform: { * freeform: {
* key:"key" * key:"key"
* }, * },
*
* mappings: [ * mappings: [
* { * {
* if:"x=y", * if:"x=y",
@ -298,7 +297,6 @@ export default class TagRenderingQuestion extends Combine {
* freeform: { * freeform: {
* key:"key" * key:"key"
* }, * },
*
* mappings: [ * mappings: [
* { * {
* if:"x=y", * if:"x=y",
@ -338,7 +336,7 @@ export default class TagRenderingQuestion extends Combine {
const ff = configuration.freeform const ff = configuration.freeform
let onEmpty: BaseUIElement = undefined let onEmpty: BaseUIElement = undefined
if (ff !== undefined) { if (ff !== undefined) {
onEmpty = new VariableUiElement(searchValue.map(search => configuration.render.Subs({[ff.key]: search}))) onEmpty = new VariableUiElement(searchValue.map(search => configuration.render.Subs({ [ff.key]: search })))
} }
const mode = configuration.multiAnswer ? "select-many" : "select-one"; const mode = configuration.multiAnswer ? "select-many" : "select-one";
@ -357,7 +355,7 @@ export default class TagRenderingQuestion extends Combine {
return Translations.t.general.useSearch; return Translations.t.general.useSearch;
} }
return new Combine([ return new Combine([
Translations.t.general.useSearchForMore.Subs({total: applicableMappings.length}), Translations.t.general.useSearchForMore.Subs({ total: applicableMappings.length }),
new SearchablePillsSelector(priority, { new SearchablePillsSelector(priority, {
selectedElements: tooMuchElementsValue, selectedElements: tooMuchElementsValue,
hideSearchBar: true, hideSearchBar: true,
@ -637,7 +635,7 @@ export default class TagRenderingQuestion extends Combine {
// Add a length check // Add a length check
input?.GetValue().addCallbackD((v: string | undefined) => { input?.GetValue().addCallbackD((v: string | undefined) => {
if (v?.length >= 255) { if (v?.length >= 255) {
feedback.setData(Translations.t.validation.tooLong.Subs({count: v.length})) feedback.setData(Translations.t.validation.tooLong.Subs({ count: v.length }))
} }
}) })

View file

@ -1,15 +1,16 @@
<html> <html>
<body>
The custom generator has moved (temporarily), go to
<a href="https://pietervdvn.github.io/mc/legacy/070/customGenerator.html">
Redirecting you to the development version</a
>
<body> <script>
window.location.replace(
The custom generator has moved (temporarily), go to <a "https://pietervdvn.github.io/mc/legacy/070/customGenerator.html" +
href='https://pietervdvn.github.io/mc/legacy/070/customGenerator.html'</a> window.location.search +
Redirecting you to the development version window.location.hash
);
<script> </script>
window.location.replace("https://pietervdvn.github.io/mc/legacy/070/customGenerator.html" + window.location.search + window.location.hash); </body>
</script>
</body>
</html> </html>

28
package-lock.json generated
View file

@ -9,7 +9,6 @@
"version": "0.0.5", "version": "0.0.5",
"license": "GPL", "license": "GPL",
"dependencies": { "dependencies": {
"@parcel/service-worker": "^2.6.0",
"@turf/boolean-intersects": "^6.5.0", "@turf/boolean-intersects": "^6.5.0",
"@turf/buffer": "^6.5.0", "@turf/buffer": "^6.5.0",
"@turf/collect": "^6.5.0", "@turf/collect": "^6.5.0",
@ -49,6 +48,7 @@
"devDependencies": { "devDependencies": {
"@babel/polyfill": "^7.10.4", "@babel/polyfill": "^7.10.4",
"@babel/preset-env": "7.13.8", "@babel/preset-env": "7.13.8",
"@parcel/service-worker": "^2.6.0",
"@types/chai": "^4.3.0", "@types/chai": "^4.3.0",
"@types/geojson": "^7946.0.10", "@types/geojson": "^7946.0.10",
"@types/leaflet-markercluster": "^1.0.3", "@types/leaflet-markercluster": "^1.0.3",
@ -66,6 +66,7 @@
"fs": "0.0.1-security", "fs": "0.0.1-security",
"mocha": "^9.2.2", "mocha": "^9.2.2",
"parcel": "^1.2.4", "parcel": "^1.2.4",
"prettier": "2.7.1",
"read-file": "^0.2.0", "read-file": "^0.2.0",
"sharp": "^0.30.5", "sharp": "^0.30.5",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
@ -1542,6 +1543,7 @@
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.6.0.tgz", "resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.6.0.tgz",
"integrity": "sha512-rOKRPoipOsg5XsYbag0mQ0WtVTscHjblL/zc0VA6O3ju5hgLAPVM4UmfdljuRVgRoMHSCV7wz1qAh9okvNqdjw==", "integrity": "sha512-rOKRPoipOsg5XsYbag0mQ0WtVTscHjblL/zc0VA6O3ju5hgLAPVM4UmfdljuRVgRoMHSCV7wz1qAh9okvNqdjw==",
"dev": true,
"engines": { "engines": {
"node": ">= 12.0.0", "node": ">= 12.0.0",
"parcel": "^2.6.0" "parcel": "^2.6.0"
@ -12630,6 +12632,21 @@
"node": ">= 0.8.0" "node": ">= 0.8.0"
} }
}, },
"node_modules/prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true,
"bin": {
"prettier": "bin-prettier.js"
},
"engines": {
"node": ">=10.13.0"
},
"funding": {
"url": "https://github.com/prettier/prettier?sponsor=1"
}
},
"node_modules/process": { "node_modules/process": {
"version": "0.11.10", "version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
@ -17943,7 +17960,8 @@
"@parcel/service-worker": { "@parcel/service-worker": {
"version": "2.6.0", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.6.0.tgz", "resolved": "https://registry.npmjs.org/@parcel/service-worker/-/service-worker-2.6.0.tgz",
"integrity": "sha512-rOKRPoipOsg5XsYbag0mQ0WtVTscHjblL/zc0VA6O3ju5hgLAPVM4UmfdljuRVgRoMHSCV7wz1qAh9okvNqdjw==" "integrity": "sha512-rOKRPoipOsg5XsYbag0mQ0WtVTscHjblL/zc0VA6O3ju5hgLAPVM4UmfdljuRVgRoMHSCV7wz1qAh9okvNqdjw==",
"dev": true
}, },
"@parcel/utils": { "@parcel/utils": {
"version": "1.11.0", "version": "1.11.0",
@ -26760,6 +26778,12 @@
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
}, },
"prettier": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz",
"integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==",
"dev": true
},
"process": { "process": {
"version": "0.11.10", "version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",

View file

@ -42,6 +42,7 @@
"generate:charging-stations": "cd ./assets/layers/charging_station && ts-node csvToJson.ts && cd -", "generate:charging-stations": "cd ./assets/layers/charging_station && ts-node csvToJson.ts && cd -",
"prepare-deploy": "npm run generate:service-worker && ./scripts/build.sh", "prepare-deploy": "npm run generate:service-worker && ./scripts/build.sh",
"gittag": "ts-node scripts/printVersion.ts | bash", "gittag": "ts-node scripts/printVersion.ts | bash",
"format": "npx prettier --write '**/*.ts'",
"lint": "tslint --project . -c tslint.json '**.ts' ", "lint": "tslint --project . -c tslint.json '**.ts' ",
"clean:tests": "(find . -type f -name \"*.doctest.ts\" | xargs rm)", "clean:tests": "(find . -type f -name \"*.doctest.ts\" | xargs rm)",
"clean": "rm -rf .cache/ && (find *.html | grep -v \"\\(404\\|index\\|land\\|test\\|preferences\\|customGenerator\\|professional\\|automaton\\|import_helper\\|import_viewer\\|theme\\).html\" | xargs rm) && (ls | grep \"^index_[a-zA-Z_-]\\+\\.ts$\" | xargs rm) && (ls | grep \".*.webmanifest$\" | grep -v \"manifest.webmanifest\" | xargs rm)", "clean": "rm -rf .cache/ && (find *.html | grep -v \"\\(404\\|index\\|land\\|test\\|preferences\\|customGenerator\\|professional\\|automaton\\|import_helper\\|import_viewer\\|theme\\).html\" | xargs rm) && (ls | grep \"^index_[a-zA-Z_-]\\+\\.ts$\" | xargs rm) && (ls | grep \".*.webmanifest$\" | grep -v \"manifest.webmanifest\" | xargs rm)",
@ -51,7 +52,7 @@
"weblate-add-upstream": "git remote add weblate-github git@github.com:weblate/MapComplete.git", "weblate-add-upstream": "git remote add weblate-github git@github.com:weblate/MapComplete.git",
"weblate-fix": "git remote update weblate-github; git merge weblate-github/weblate-mapcomplete-core; git merge weblate-github/weblate-mapcomplete-layers; git merge weblate-github/weblate-mapcomplete-layer-translations", "weblate-fix": "git remote update weblate-github; git merge weblate-github/weblate-mapcomplete-core; git merge weblate-github/weblate-mapcomplete-layers; git merge weblate-github/weblate-mapcomplete-layer-translations",
"weblate-fix-heavy": "git remote rm weblate-layers; git remote add weblate-layers https://hosted.weblate.org/git/mapcomplete/layers/; git remote update weblate-layers; git merge weblate-layers/master", "weblate-fix-heavy": "git remote rm weblate-layers; git remote add weblate-layers https://hosted.weblate.org/git/mapcomplete/layers/; git remote update weblate-layers; git merge weblate-layers/master",
"housekeeping": "npm run generate && npm run generate:docs && npm run generate:contributor-list && git add Docs/* && git commit assets/ langs/ Docs/ -m 'Housekeeping...'", "housekeeping": "npm run generate && npm run generate:docs && npm run generate:contributor-list && npm run format && git add *.ts && git add Docs/* && git commit assets/ langs/ Docs/ -m 'Housekeeping...'",
"parseSchools": "ts-node scripts/schools/amendSchoolData.ts", "parseSchools": "ts-node scripts/schools/amendSchoolData.ts",
"steal": "ts-node scripts/thieves/stealLanguages.ts" "steal": "ts-node scripts/thieves/stealLanguages.ts"
}, },
@ -68,7 +69,6 @@
"not op_mini all" "not op_mini all"
], ],
"dependencies": { "dependencies": {
"@parcel/service-worker": "^2.6.0",
"@turf/boolean-intersects": "^6.5.0", "@turf/boolean-intersects": "^6.5.0",
"@turf/buffer": "^6.5.0", "@turf/buffer": "^6.5.0",
"@turf/collect": "^6.5.0", "@turf/collect": "^6.5.0",
@ -108,6 +108,7 @@
"devDependencies": { "devDependencies": {
"@babel/polyfill": "^7.10.4", "@babel/polyfill": "^7.10.4",
"@babel/preset-env": "7.13.8", "@babel/preset-env": "7.13.8",
"@parcel/service-worker": "^2.6.0",
"@types/chai": "^4.3.0", "@types/chai": "^4.3.0",
"@types/geojson": "^7946.0.10", "@types/geojson": "^7946.0.10",
"@types/leaflet-markercluster": "^1.0.3", "@types/leaflet-markercluster": "^1.0.3",
@ -125,6 +126,7 @@
"fs": "0.0.1-security", "fs": "0.0.1-security",
"mocha": "^9.2.2", "mocha": "^9.2.2",
"parcel": "^1.2.4", "parcel": "^1.2.4",
"prettier": "2.7.1",
"read-file": "^0.2.0", "read-file": "^0.2.0",
"sharp": "^0.30.5", "sharp": "^0.30.5",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",