Skip to content

Commit e7c6260

Browse files
committed
Initial release
0 parents  commit e7c6260

10 files changed

+624
-0
lines changed

.cargo/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "wasm32-unknown-unknown"

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

Cargo.toml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "dprint-plugin-vue"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT"
6+
7+
[lib]
8+
crate-type = ["lib", "cdylib"]
9+
10+
[profile.release]
11+
opt-level = 3
12+
debug = false
13+
lto = true
14+
debug-assertions = false
15+
overflow-checks = false
16+
panic = "abort"
17+
18+
[dependencies]
19+
anyhow = "1.0.52"
20+
dprint-core = { version = "0.49", features = ["wasm"] }
21+
nom = "7.1"
22+
serde = { version = "1", features = ["derive"] }
23+
serde_json = "1"

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Maël Obréjan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

dprint.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"incremental": true,
3+
"typescript": {},
4+
"includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs}"],
5+
"excludes": [
6+
"target"
7+
],
8+
"plugins": [
9+
"https://plugins.dprint.dev/typescript-0.62.0.wasm",
10+
"./target/wasm32-unknown-unknown/release/dprint_plugin_vue.wasm"
11+
]
12+
}

src/configuration.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use dprint_core::configuration::get_unknown_property_diagnostics;
2+
use dprint_core::configuration::ConfigKeyMap;
3+
use dprint_core::configuration::GlobalConfiguration;
4+
use dprint_core::configuration::NewLineKind;
5+
use dprint_core::configuration::ResolveConfigurationResult;
6+
use dprint_core::configuration::DEFAULT_GLOBAL_CONFIGURATION;
7+
use serde::Serialize;
8+
9+
#[derive(Debug, Clone, Copy, Serialize)]
10+
#[serde(rename_all = "camelCase")]
11+
pub struct Configuration {
12+
pub line_width: u32,
13+
pub use_tabs: bool,
14+
pub indent_width: u8,
15+
pub new_line_kind: NewLineKind,
16+
}
17+
18+
impl Default for Configuration {
19+
fn default() -> Self {
20+
Self {
21+
line_width: DEFAULT_GLOBAL_CONFIGURATION.line_width,
22+
use_tabs: DEFAULT_GLOBAL_CONFIGURATION.use_tabs,
23+
indent_width: DEFAULT_GLOBAL_CONFIGURATION.indent_width,
24+
new_line_kind: DEFAULT_GLOBAL_CONFIGURATION.new_line_kind,
25+
}
26+
}
27+
}
28+
29+
pub fn resolve_config(
30+
config: ConfigKeyMap,
31+
_global_config: &GlobalConfiguration,
32+
) -> ResolveConfigurationResult<Configuration> {
33+
let mut diagnostics = Vec::new();
34+
35+
diagnostics.extend(get_unknown_property_diagnostics(config));
36+
37+
ResolveConfigurationResult {
38+
config: Configuration::default(),
39+
diagnostics,
40+
}
41+
}

src/lib.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
pub mod configuration;
2+
pub(crate) mod parser;
3+
pub(crate) mod plugin;
4+
5+
use crate::configuration::Configuration;
6+
use dprint_core::plugins::PluginHandler;
7+
use plugin::VuePluginHandler;
8+
9+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
10+
dprint_core::generate_plugin_code!(VuePluginHandler, VuePluginHandler::new());
11+
12+
#[cfg(test)]
13+
mod test {
14+
use std::path::PathBuf;
15+
16+
use dprint_core::plugins::PluginHandler;
17+
18+
use crate::{configuration::Configuration, plugin::VuePluginHandler};
19+
20+
#[test]
21+
fn ts() {
22+
let mut buffer = Vec::new();
23+
24+
let raw = include_str!("../test/ts.vue");
25+
let path = PathBuf::from("ts.vue");
26+
27+
let result = VuePluginHandler::new().format_text(
28+
&path,
29+
raw,
30+
&Configuration::default(),
31+
|path, data, _config| {
32+
buffer.push((path.to_owned(), data.clone()));
33+
34+
Ok(data)
35+
},
36+
);
37+
38+
assert_eq!(result.unwrap(), raw);
39+
40+
assert_eq!(
41+
buffer,
42+
vec![
43+
(
44+
PathBuf::from("file.ts"),
45+
String::from("import { ExclamationIcon } from '@heroicons/vue/solid';\nimport { Dialog, DialogOverlay, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue';\nimport { watch } from \"vue\";\n\nimport type { NewQuoteRequest, QuoteRequest, QuoteRequestId, QuoteRequestPatch } from \"@/resources/quoteRequests\";\nimport type { ApiError, AbortError, NetworkError } from \"@/error\";\nimport { usePassport } from \"@/passport\";\nimport { createQuoteRequest, retrieveQuoteRequest, updateQuoteRequest, destroyQuoteRequest } from \"@/resources/quoteRequests\";\n\n"),
46+
)
47+
]
48+
);
49+
}
50+
}

0 commit comments

Comments
 (0)