-
-
Notifications
You must be signed in to change notification settings - Fork 93
chore: add the oxfmt formatter #1392
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca41867
add a formatter
CommanderStorm 0a6bcb7
change to es5 trailing commas
CommanderStorm 11b4afd
change to no trailing commas
CommanderStorm 8456102
remove flow-specific config
CommanderStorm 0e82940
remove deprecated stylistic eslint checks
CommanderStorm ca7882c
Merge branch 'main' into fmt
CommanderStorm f3ed5ae
run fmt after merge
CommanderStorm 7da7239
Update .oxfmtrc.jsonc
CommanderStorm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "$schema": "./node_modules/oxfmt/configuration_schema.json", | ||
| "tabWidth": 4, | ||
| "singleQuote": true, | ||
| "bracketSpacing": false, | ||
| "trailingComma": "none" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,3 @@ function help() { | |
| console.log('usage:'); | ||
| console.log(' gl-style-migrate style-v7.json > style-v8.json'); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,7 @@ function jsDocComment(property) { | |
| if (!lines.length) { | ||
| return undefined; | ||
| } | ||
| return [ | ||
| '/**', | ||
| ...lines.map(line => ` * ${line}`), | ||
| ' */', | ||
| ].join('\n'); | ||
| return ['/**', ...lines.map((line) => ` * ${line}`), ' */'].join('\n'); | ||
| } | ||
|
|
||
| function jsDocBlock(tag, value) { | ||
|
|
@@ -40,9 +36,11 @@ ${formatJSON(value)} | |
|
|
||
| function unionType(values) { | ||
| if (Array.isArray(values)) { | ||
| return values.map(v => JSON.stringify(v)).join(' | '); | ||
| return values.map((v) => JSON.stringify(v)).join(' | '); | ||
| } else { | ||
| return Object.keys(values).map(v => JSON.stringify(v)).join(' | '); | ||
| return Object.keys(values) | ||
| .map((v) => JSON.stringify(v)) | ||
| .join(' | '); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -60,7 +58,11 @@ function propertyType(property) { | |
| case 'enum': | ||
| return unionType(property.values); | ||
| case 'array': { | ||
| const elementType = propertyType(typeof property.value === 'string' ? {type: property.value, values: property.values} : property.value); | ||
| const elementType = propertyType( | ||
| typeof property.value === 'string' | ||
| ? {type: property.value, values: property.values} | ||
| : property.value | ||
| ); | ||
| if (property.length) { | ||
| return `[${Array(property.length).fill(elementType).join(', ')}]`; | ||
| } else { | ||
|
|
@@ -104,32 +106,37 @@ function objectDeclaration(key, properties) { | |
| function objectType(properties, indent) { | ||
| return `{ | ||
| ${Object.keys(properties) | ||
| .filter(k => k !== '*') | ||
| .flatMap(k => { | ||
| .filter((k) => k !== '*') | ||
| .flatMap((k) => { | ||
| const declarations = [propertyDeclaration(k, properties[k])]; | ||
| if (properties[k].transition) { | ||
| declarations.push(transitionPropertyDeclaration(k)); | ||
| } | ||
| return declarations; | ||
| }) | ||
| .map(declaration => { | ||
| .map((declaration) => { | ||
| return declaration | ||
| .split('\n') | ||
| .map(line => ` ${indent}${line}`) | ||
| .map((line) => ` ${indent}${line}`) | ||
| .join('\n'); | ||
| }) | ||
| .join(',\n')} | ||
| ${indent}}`; | ||
| } | ||
|
|
||
| function sourceTypeName(key) { | ||
| return key.replace(/source_(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}SourceSpecification`) | ||
| return key | ||
| .replace(/source_(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}SourceSpecification`) | ||
| .replace(/_dem/, 'DEM') | ||
| .replace(/Geojson/, 'GeoJSON'); | ||
| } | ||
|
|
||
| function layerTypeName(key) { | ||
| return key.split('-').map(k => k.replace(/(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}`)).concat('LayerSpecification').join(''); | ||
| return key | ||
| .split('-') | ||
| .map((k) => k.replace(/(.)(.*)/, (_, _1, _2) => `${_1.toUpperCase()}${_2}`)) | ||
| .concat('LayerSpecification') | ||
| .join(''); | ||
|
Comment on lines
+135
to
+139
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before: harder to read due to line length |
||
| } | ||
|
|
||
| function layerType(key) { | ||
|
|
@@ -165,9 +172,9 @@ function layerType(key) { | |
|
|
||
| const layerTypes = Object.keys(spec.layer.type.values); | ||
|
|
||
| writeFileSync('src/types.g.ts', | ||
| writeFileSync( | ||
| 'src/types.g.ts', | ||
|
Comment on lines
+175
to
+176
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before: weird indentation |
||
| `// Generated code; do not edit. Edit build/generate-style-spec.ts instead. | ||
| /* eslint-disable */ | ||
|
|
||
| export type ColorSpecification = string; | ||
|
|
||
|
|
@@ -394,21 +401,24 @@ ${objectDeclaration('ProjectionSpecification', spec.projection)} | |
|
|
||
| ${objectDeclaration('TerrainSpecification', spec.terrain)} | ||
|
|
||
| ${spec.source.map(key => { | ||
| let str = objectDeclaration(sourceTypeName(key), spec[key]); | ||
| if (sourceTypeName(key) === 'GeoJSONSourceSpecification') { | ||
| // This is done in order to overcome the type system's inability to express this type: | ||
| str = str.replace(/unknown/, 'GeoJSON.GeoJSON | string'); | ||
| } | ||
| return str; | ||
| }).join('\n\n')} | ||
| ${spec.source | ||
| .map((key) => { | ||
| let str = objectDeclaration(sourceTypeName(key), spec[key]); | ||
| if (sourceTypeName(key) === 'GeoJSONSourceSpecification') { | ||
| // This is done in order to overcome the type system's inability to express this type: | ||
| str = str.replace(/unknown/, 'GeoJSON.GeoJSON | string'); | ||
| } | ||
| return str; | ||
| }) | ||
| .join('\n\n')} | ||
|
|
||
| export type SourceSpecification = | ||
| ${spec.source.map(key => ` | ${sourceTypeName(key)}`).join('\n')} | ||
| ${spec.source.map((key) => ` | ${sourceTypeName(key)}`).join('\n')} | ||
|
|
||
| ${layerTypes.map(key => layerType(key)).join('\n\n')} | ||
| ${layerTypes.map((key) => layerType(key)).join('\n\n')} | ||
|
|
||
| export type LayerSpecification = | ||
| ${layerTypes.map(key => ` | ${layerTypeName(key)}`).join('\n')}; | ||
| ${layerTypes.map((key) => ` | ${layerTypeName(key)}`).join('\n')}; | ||
|
|
||
| `); | ||
| ` | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.