Comments (3)
The resolve_config exists today in the crate, but I don't have the global configuration part. It wouldn't be too much extra work to add.
This will get slightly easier once I have the plugin infrastructure in place.
Other Config File Formats
I don't want to have multiple ways of reading configuration in dprint and since I'm running this from node (deno in the future :)) I am just going to keep loading the config in JavaScript for now. That might change in the future though. So I'd recommend creating a config file specifically for deno, read that into key value pairs, then use the api above that I will add soon. Perhaps then one day I could adopt that back in here. Does that sound good?
Overall, I wouldn't mind adding the code for reading a json configuration file to dprint, but I don't think I'd use it.
Yes, that's perfect!
By the way, just ignore the projectType field and please don't add it to the dprint config in deno :P (I don't even have a sponsorship model in place at the moment)
Sure!
from dprint.
Most likely the configuration file would have the following structure:
{
// optional global config
lineWidth: 80,
indentWidth: 2,
useTabs: false,
newLineKind: "\n",
// optional language specific config
typescript: {
// potentially override global config for the language
indentWidth: 4,
// ...language specific config...
bracePosition: "nextLine",
// ...etc...
},
markdown: {
// ...etc...
},
// optional includes and excludes
includes: [
"**/*.{ts,tsx,js,jsx}"
],
excludes: [
"packages/playground/public/vs/**/*.*",
"packages/playground/build/**/*.*",
"build-website/**/*.*",
"**/dist/**/*.*",
"**/target/**/*.*",
"**/wasm/**/*.*"
]
}
So in dprint I could provide the following functionality:
// pseudocode...
use dprint_core::{resolve_global_config};
use dprint_plugin_typescript::{resolve_config};
let mut config_map: HashMap<String, String> = ...; // parse json to string key/value pairs
// assume exists for this example... probably want something better than re-deserializing this
// from a string...
let typescript_config_map = deserialize_to_hash_map(config_map.remove("typescript").unwrap());
// get the global config
let global_config_result = resolve_global_config(&config_map);
for diagnostic in global_config_result.diagnostics {
// includes stuff like excess properties and such
}
// resolve the typescript config
let config_result = resolve_config(&global_config_result.config, &typescript_config_map);
for diagnostic in config_result.diagnostics {
// do something...
}
// now format with config_result.config...
The resolve_config
exists today in the crate, but I don't have the global configuration part. It wouldn't be too much extra work to add.
This will get slightly easier once I have the plugin infrastructure in place.
Other Config File Formats
I don't want to have multiple ways of reading configuration in dprint and since I'm running this from node (deno in the future :)) I am just going to keep loading the config in JavaScript for now. That might change in the future though. So I'd recommend creating a config file specifically for deno, read that into key value pairs, then use the api above that I will add soon. Perhaps then one day I could adopt that back in here. Does that sound good?
Overall, I wouldn't mind adding the code for reading a json configuration file to dprint, but I don't think I'd use it.
By the way, just ignore the projectType
field and please don't add it to the dprint config in deno :P (I don't even have a sponsorship model in place at the moment)
from dprint.
@bartomieju released in 0.3.0-alpha.5
.
See here for docs and an example: https://docs.rs/dprint-plugin-typescript/0.3.0-alpha.5/dprint_plugin_typescript/configuration/fn.resolve_config.html
Note that all the configuration related stuff has been moved to a configuration
sub module. For setting your own defaults, I recommend just inserting into the hashmap if no key exists there.
Also, in the future this api will be easier to use... this is just stepping stones to the final plugin formatter.
Good luck and let me know if you need anything else for this! :)
from dprint.
Related Issues (20)
- "not include"s are ignored when paths are passed via CLI HOT 1
- dprint: /lib64/libm.so.6: version `GLIBC_2.29' not found HOT 1
- Future plugin system improvements HOT 1
- Regression - 0.43.2 finds fewer files than 0.43.1 HOT 5
- Feature: Formatting HTML files HOT 1
- LSP - Figure out completions for dprint.json files
- Document using lsp in various editors
- Can't remove BOM HOT 1
- CI GH Actions compile error HOT 5
- Possible to have `dprint` `biome` point to `biome.json` for configuration? HOT 3
- Can't Format Files In Hardlink Folder
- Support assigning a file to a formatter based on its shebang HOT 5
- Include / exclude behavior differs with `--stdin`
- JSON config schema file HOT 1
- Offline process plugin installation instructions
- Config - Ability to include subset of another arbitrary JSON file
- Programatic API for TS (Node/Bun/Deno/etc.) HOT 2
- CLI fails to run on android-arm64
- dprint hangs sometimes HOT 3
- Memory leak in dprint-core HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dprint.