Skip to content

Commit

Permalink
chore: upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Oct 31, 2021
1 parent e21f128 commit 113e95b
Show file tree
Hide file tree
Showing 9 changed files with 646 additions and 641 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,30 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.56.0
override: true
- uses: Swatinem/rust-cache@v1

- name: Install wasm32 target
if: matrix.config.kind == 'test_release'
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v1

- name: Build debug
if: matrix.config.kind == 'test_debug'
run: cargo build --verbose
run: cargo build
- name: Build release
if: matrix.config.kind == 'test_release'
run: cargo build --target wasm32-unknown-unknown --features wasm --release --verbose
run: cargo build --target wasm32-unknown-unknown --features wasm --release

- name: Test debug
if: matrix.config.kind == 'test_debug'
run: cargo test --verbose
run: cargo test
- name: Test release
if: matrix.config.kind == 'test_release'
run: cargo test --release --verbose
run: cargo test --release

- name: Get tag version
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "dprint-plugin-dockerfile"
version = "0.1.1"
authors = ["David Sherret <[email protected]>"]
edition = "2018"
edition = "2021"
homepage = "https://github.com/dprint/dprint-plugin-dockerfile"
keywords = ["formatting", "formatter", "docker", "dockerfile"]
license = "MIT"
Expand All @@ -26,7 +26,7 @@ tracing = ["dprint-core/tracing"]

[dependencies]
dockerfile-parser = { git = "https://github.com/dsherret/dockerfile-parser-rs", branch = "span-for-nodes" }
dprint-core = { version = "0.46.4", features = ["formatting"] }
dprint-core = { version = "0.47.0", features = ["formatting"] }
serde = { version = "1.0.88", features = ["derive"] }
serde_json = { version = "1.0", optional = true }

Expand Down
8 changes: 4 additions & 4 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"**/target"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.55.0.wasm",
"https://plugins.dprint.dev/json-0.13.0.wasm",
"https://plugins.dprint.dev/markdown-0.10.0.wasm",
"https://plugins.dprint.dev/toml-0.5.1.wasm",
"https://plugins.dprint.dev/typescript-0.59.0.wasm",
"https://plugins.dprint.dev/json-0.13.1.wasm",
"https://plugins.dprint.dev/markdown-0.11.1.wasm",
"https://plugins.dprint.dev/toml-0.5.2.wasm",
"https://plugins.dprint.dev/rustfmt-0.4.0.exe-plugin@c6bb223ef6e5e87580177f6461a0ab0554ac9ea6b54f78ea7ae8bf63b14f5bc2"
]
}
74 changes: 37 additions & 37 deletions src/format_text.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
use dockerfile_parser::Dockerfile;
use dprint_core::configuration::resolve_new_line_kind;
use dprint_core::formatting::PrintOptions;
use dprint_core::types::ErrBox;
use std::path::Path;

use crate::configuration::Configuration;
use crate::parser::parse_items;

pub fn format_text(_file_path: &Path, text: &str, config: &Configuration) -> Result<String, ErrBox> {
let node = parse_node(text)?;

Ok(dprint_core::formatting::format(
|| parse_items(&node, text, config),
config_to_print_options(text, config),
))
}

#[cfg(feature = "tracing")]
pub fn trace_file(_file_path: &Path, text: &str, config: &Configuration) -> dprint_core::formatting::TracingResult {
let node = parse_node(text).unwrap();

dprint_core::formatting::trace_printing(|| parse_items(node, text, config), config_to_print_options(text, config))
}

fn parse_node(text: &str) -> Result<Dockerfile, ErrBox> {
Ok(Dockerfile::parse(text)?)
}

fn config_to_print_options(text: &str, config: &Configuration) -> PrintOptions {
PrintOptions {
indent_width: 1,
max_width: config.line_width,
use_tabs: false,
new_line_text: resolve_new_line_kind(text, config.new_line_kind),
}
}
use dockerfile_parser::Dockerfile;
use dprint_core::configuration::resolve_new_line_kind;
use dprint_core::formatting::PrintOptions;
use dprint_core::types::ErrBox;
use std::path::Path;

use crate::configuration::Configuration;
use crate::parser::parse_items;

pub fn format_text(_file_path: &Path, text: &str, config: &Configuration) -> Result<String, ErrBox> {
let node = parse_node(text)?;

Ok(dprint_core::formatting::format(
|| parse_items(&node, text, config),
config_to_print_options(text, config),
))
}

#[cfg(feature = "tracing")]
pub fn trace_file(_file_path: &Path, text: &str, config: &Configuration) -> dprint_core::formatting::TracingResult {
let node = parse_node(text).unwrap();

dprint_core::formatting::trace_printing(|| parse_items(node, text, config), config_to_print_options(text, config))
}

fn parse_node(text: &str) -> Result<Dockerfile, ErrBox> {
Ok(Dockerfile::parse(text)?)
}

fn config_to_print_options(text: &str, config: &Configuration) -> PrintOptions {
PrintOptions {
indent_width: 1,
max_width: config.line_width,
use_tabs: false,
new_line_text: resolve_new_line_kind(text, config.new_line_kind),
}
}
142 changes: 71 additions & 71 deletions src/parser/context.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
use std::collections::HashSet;
use std::rc::Rc;

use dockerfile_parser::Dockerfile;
use dockerfile_parser::Span;

use super::helpers::parse_comments;
use super::helpers::Node;
use crate::configuration::Configuration;

pub struct Context<'a> {
pub config: &'a Configuration,
pub dockerfile: &'a Dockerfile,
pub text: &'a str,
pub handled_comments: HashSet<usize>,
current_node: Option<Node<'a>>,
parent_stack: Vec<Node<'a>>,
pub parse_string_content: bool,
}

impl<'a> Context<'a> {
pub fn new(text: &'a str, dockerfile: &'a Dockerfile, config: &'a Configuration) -> Self {
Self {
config,
text,
dockerfile,
handled_comments: HashSet::new(),
current_node: None,
parent_stack: Vec::new(),
parse_string_content: false,
}
}

pub fn span_text(&self, span: &Span) -> &str {
&self.text[span.start..span.end]
}

pub fn set_current_node(&mut self, node: Node<'a>) {
if let Some(parent) = self.current_node.take() {
self.parent_stack.push(parent);
}
self.current_node = Some(node);
}

pub fn pop_current_node(&mut self) {
self.current_node = self.parent_stack.pop();
}

pub fn parent(&self) -> Option<&Node<'a>> {
self.parent_stack.last()
}

pub fn parse_nodes_with_comments(&mut self, start_pos: usize, end_pos: usize, nodes: impl Iterator<Item = Node<'a>>) -> Vec<Node<'a>> {
let mut result = Vec::new();
let mut last_pos = start_pos;
for node in nodes {
let text = &self.text[last_pos..node.span().start];
for comment in parse_comments(text, last_pos) {
result.push(Node::CommentRc(Rc::new(comment)));
}
let node_end = node.span().end;
result.push(node);
last_pos = node_end;
}
let text = &self.text[last_pos..end_pos];
for comment in parse_comments(text, last_pos) {
result.push(Node::CommentRc(Rc::new(comment)));
}
result
}
}
use std::collections::HashSet;
use std::rc::Rc;

use dockerfile_parser::Dockerfile;
use dockerfile_parser::Span;

use super::helpers::parse_comments;
use super::helpers::Node;
use crate::configuration::Configuration;

pub struct Context<'a> {
pub config: &'a Configuration,
pub dockerfile: &'a Dockerfile,
pub text: &'a str,
pub handled_comments: HashSet<usize>,
current_node: Option<Node<'a>>,
parent_stack: Vec<Node<'a>>,
pub parse_string_content: bool,
}

impl<'a> Context<'a> {
pub fn new(text: &'a str, dockerfile: &'a Dockerfile, config: &'a Configuration) -> Self {
Self {
config,
text,
dockerfile,
handled_comments: HashSet::new(),
current_node: None,
parent_stack: Vec::new(),
parse_string_content: false,
}
}

pub fn span_text(&self, span: &Span) -> &str {
&self.text[span.start..span.end]
}

pub fn set_current_node(&mut self, node: Node<'a>) {
if let Some(parent) = self.current_node.take() {
self.parent_stack.push(parent);
}
self.current_node = Some(node);
}

pub fn pop_current_node(&mut self) {
self.current_node = self.parent_stack.pop();
}

pub fn parent(&self) -> Option<&Node<'a>> {
self.parent_stack.last()
}

pub fn parse_nodes_with_comments(&mut self, start_pos: usize, end_pos: usize, nodes: impl Iterator<Item = Node<'a>>) -> Vec<Node<'a>> {
let mut result = Vec::new();
let mut last_pos = start_pos;
for node in nodes {
let text = &self.text[last_pos..node.span().start];
for comment in parse_comments(text, last_pos) {
result.push(Node::CommentRc(Rc::new(comment)));
}
let node_end = node.span().end;
result.push(node);
last_pos = node_end;
}
let text = &self.text[last_pos..end_pos];
for comment in parse_comments(text, last_pos) {
result.push(Node::CommentRc(Rc::new(comment)));
}
result
}
}
Loading

0 comments on commit 113e95b

Please sign in to comment.