Skip to content

Commit 50b7f07

Browse files
chore: add the oxfmt formatter (#1392)
* add a formatter * change to es5 trailing commas * change to no trailing commas * remove flow-specific config * remove deprecated stylistic eslint checks * run fmt after merge * Update .oxfmtrc.jsonc
1 parent 2aac6f2 commit 50b7f07

File tree

162 files changed

+7600
-4796
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+7600
-4796
lines changed

.oxfmtrc.jsonc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"tabWidth": 4,
4+
"singleQuote": true,
5+
"bracketSpacing": false,
6+
"trailingComma": "none"
7+
}

bin/gl-style-migrate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ function help() {
1616
console.log('usage:');
1717
console.log(' gl-style-migrate style-v7.json > style-v8.json');
1818
}
19-

bin/gl-style-validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import rw from 'rw';
55
import {validateStyle as validate} from '../src/validate_style';
66

77
const argv = minimist(process.argv.slice(2), {
8-
boolean: 'json',
8+
boolean: 'json'
99
});
1010

1111
if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {

build/bump-version-changelog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const changelogPath = 'CHANGELOG.md';
1313
let changelog = readFileSync(changelogPath, 'utf8');
1414
changelog = changelog.replace('## main', `## ${process.argv[2]}`);
1515
changelog = changelog.replaceAll('- _...Add new stuff here..._\n', '');
16-
changelog = `## main
16+
changelog =
17+
`## main
1718
1819
### ✨ Features and improvements
1920
- _...Add new stuff here..._

build/generate-docs.ts

Lines changed: 76 additions & 70 deletions
Large diffs are not rendered by default.

build/generate-style-spec.ts

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ function jsDocComment(property) {
2424
if (!lines.length) {
2525
return undefined;
2626
}
27-
return [
28-
'/**',
29-
...lines.map(line => ` * ${line}`),
30-
' */',
31-
].join('\n');
27+
return ['/**', ...lines.map((line) => ` * ${line}`), ' */'].join('\n');
3228
}
3329

3430
function jsDocBlock(tag, value) {
@@ -40,9 +36,11 @@ ${formatJSON(value)}
4036

4137
function unionType(values) {
4238
if (Array.isArray(values)) {
43-
return values.map(v => JSON.stringify(v)).join(' | ');
39+
return values.map((v) => JSON.stringify(v)).join(' | ');
4440
} else {
45-
return Object.keys(values).map(v => JSON.stringify(v)).join(' | ');
41+
return Object.keys(values)
42+
.map((v) => JSON.stringify(v))
43+
.join(' | ');
4644
}
4745
}
4846

@@ -60,7 +58,11 @@ function propertyType(property) {
6058
case 'enum':
6159
return unionType(property.values);
6260
case 'array': {
63-
const elementType = propertyType(typeof property.value === 'string' ? {type: property.value, values: property.values} : property.value);
61+
const elementType = propertyType(
62+
typeof property.value === 'string'
63+
? {type: property.value, values: property.values}
64+
: property.value
65+
);
6466
if (property.length) {
6567
return `[${Array(property.length).fill(elementType).join(', ')}]`;
6668
} else {
@@ -104,32 +106,37 @@ function objectDeclaration(key, properties) {
104106
function objectType(properties, indent) {
105107
return `{
106108
${Object.keys(properties)
107-
.filter(k => k !== '*')
108-
.flatMap(k => {
109+
.filter((k) => k !== '*')
110+
.flatMap((k) => {
109111
const declarations = [propertyDeclaration(k, properties[k])];
110112
if (properties[k].transition) {
111113
declarations.push(transitionPropertyDeclaration(k));
112114
}
113115
return declarations;
114116
})
115-
.map(declaration => {
117+
.map((declaration) => {
116118
return declaration
117119
.split('\n')
118-
.map(line => ` ${indent}${line}`)
120+
.map((line) => ` ${indent}${line}`)
119121
.join('\n');
120122
})
121123
.join(',\n')}
122124
${indent}}`;
123125
}
124126

125127
function sourceTypeName(key) {
126-
return key.replace(/source_(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}SourceSpecification`)
128+
return key
129+
.replace(/source_(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}SourceSpecification`)
127130
.replace(/_dem/, 'DEM')
128131
.replace(/Geojson/, 'GeoJSON');
129132
}
130133

131134
function layerTypeName(key) {
132-
return key.split('-').map(k => k.replace(/(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}`)).concat('LayerSpecification').join('');
135+
return key
136+
.split('-')
137+
.map((k) => k.replace(/(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}`))
138+
.concat('LayerSpecification')
139+
.join('');
133140
}
134141

135142
function layerType(key) {
@@ -165,9 +172,9 @@ function layerType(key) {
165172

166173
const layerTypes = Object.keys(spec.layer.type.values);
167174

168-
writeFileSync('src/types.g.ts',
175+
writeFileSync(
176+
'src/types.g.ts',
169177
`// Generated code; do not edit. Edit build/generate-style-spec.ts instead.
170-
/* eslint-disable */
171178
172179
export type ColorSpecification = string;
173180
@@ -394,21 +401,24 @@ ${objectDeclaration('ProjectionSpecification', spec.projection)}
394401
395402
${objectDeclaration('TerrainSpecification', spec.terrain)}
396403
397-
${spec.source.map(key => {
398-
let str = objectDeclaration(sourceTypeName(key), spec[key]);
399-
if (sourceTypeName(key) === 'GeoJSONSourceSpecification') {
400-
// This is done in order to overcome the type system's inability to express this type:
401-
str = str.replace(/unknown/, 'GeoJSON.GeoJSON | string');
402-
}
403-
return str;
404-
}).join('\n\n')}
404+
${spec.source
405+
.map((key) => {
406+
let str = objectDeclaration(sourceTypeName(key), spec[key]);
407+
if (sourceTypeName(key) === 'GeoJSONSourceSpecification') {
408+
// This is done in order to overcome the type system's inability to express this type:
409+
str = str.replace(/unknown/, 'GeoJSON.GeoJSON | string');
410+
}
411+
return str;
412+
})
413+
.join('\n\n')}
405414
406415
export type SourceSpecification =
407-
${spec.source.map(key => ` | ${sourceTypeName(key)}`).join('\n')}
416+
${spec.source.map((key) => ` | ${sourceTypeName(key)}`).join('\n')}
408417
409-
${layerTypes.map(key => layerType(key)).join('\n\n')}
418+
${layerTypes.map((key) => layerType(key)).join('\n\n')}
410419
411420
export type LayerSpecification =
412-
${layerTypes.map(key => ` | ${layerTypeName(key)}`).join('\n')};
421+
${layerTypes.map((key) => ` | ${layerTypeName(key)}`).join('\n')};
413422
414-
`);
423+
`
424+
);

build/release-notes.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ const regex = /^## (\d+\.\d+\.\d+.*?)\n(.+?)(?=\n^## \d+\.\d+\.\d+.*?\n)/gms;
2020

2121
let releaseNotes = [];
2222
let match;
23-
24-
while (match = regex.exec(changelog)) {
23+
24+
while ((match = regex.exec(changelog))) {
2525
releaseNotes.push({
26-
'version': match[1],
27-
'changelog': match[2].trim(),
26+
version: match[1],
27+
changelog: match[2].trim()
2828
});
2929
}
3030

3131
const latest = releaseNotes[0];
3232
const previous = releaseNotes[1];
3333

34-
3534
// Print the release notes template.
3635

3736
const templatedReleaseNotes = `https://github.com/maplibre/maplibre-gl-style-spec
@@ -41,5 +40,4 @@ ${latest.changelog}
4140
4241
${semver.prerelease(latest.version) ? 'Pre-release version' : ''}`;
4342

44-
45-
process.stdout.write(templatedReleaseNotes.trimEnd());
43+
process.stdout.write(templatedReleaseNotes.trimEnd());

build/rollup_plugin_minify_style_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Plugin} from 'rollup';
22

33
function replacer(key: string, value: any) {
4-
return (key === 'doc' || key === 'example' || key === 'sdk-support') ? undefined : value;
4+
return key === 'doc' || key === 'example' || key === 'sdk-support' ? undefined : value;
55
}
66

77
export default function minifyStyleSpec(): Plugin {

build/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import jsonStringify from 'json-stringify-pretty-compact';
22

33
/**
44
* Formats a JSON value into a reasonably compact and readable JSON string.
5-
*
5+
*
66
* @param obj - object to be formatted
77
* @returns formatted JSON
88
*/

0 commit comments

Comments
 (0)