Skip to content

Commit 6b10eda

Browse files
authored
Merge 1e42061 into 6337fb9
2 parents 6337fb9 + 1e42061 commit 6b10eda

File tree

12 files changed

+411
-11
lines changed

12 files changed

+411
-11
lines changed

crates/lib-core/src/parser/segments/base.rs

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ impl SegmentBuilder {
4141
SegmentBuilder::token(id, raw, SyntaxKind::Symbol).finish()
4242
}
4343

44+
pub fn raw(id: u32, raw: &str) -> ErasedSegment {
45+
SegmentBuilder::token(id, raw, SyntaxKind::Raw).finish()
46+
}
47+
4448
pub fn node(
4549
id: u32,
4650
syntax_kind: SyntaxKind,
@@ -139,6 +143,11 @@ impl ErasedSegment {
139143
}
140144
}
141145

146+
/// Return true if this segment has no children
147+
pub fn is_raw(&self) -> bool {
148+
self.segments().is_empty()
149+
}
150+
142151
pub fn segments(&self) -> &[ErasedSegment] {
143152
match &self.value.kind {
144153
NodeOrTokenKind::Node(node) => &node.segments,

crates/lib-core/src/templaters/base.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ impl TemplatedFileInner {
233233
self.templated_str.is_some()
234234
}
235235

236+
pub fn raw_sliced_iter(&self) -> impl Iterator<Item = &RawFileSlice> {
237+
self.raw_sliced.iter()
238+
}
239+
236240
/// Get the line number and position of a point in the source file.
237241
/// Args:
238242
/// - char_pos: The character position in the relevant file.
@@ -540,8 +544,8 @@ pub enum RawFileSliceType {
540544
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
541545
pub struct RawFileSlice {
542546
/// Source string
543-
raw: String,
544-
pub(crate) slice_type: String,
547+
pub raw: String,
548+
pub slice_type: String,
545549
/// Offset from beginning of source string
546550
pub source_idx: usize,
547551
slice_subtype: Option<RawFileSliceType>,

crates/lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ name = "depth_map"
3838
harness = false
3939

4040
[features]
41+
default = ["python"]
4142
python = ["pyo3", "sqruff-lib-core/serde"]
4243

4344
[dependencies]

crates/lib/src/core/linter/linted_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use sqruff_lib_core::errors::{SQLBaseError, SqlError};
77
use sqruff_lib_core::parser::segments::fix::FixPatch;
88
use sqruff_lib_core::templaters::base::{RawFileSlice, TemplatedFile};
99

10-
#[derive(Debug, Default)]
10+
#[derive(Debug, Default, Clone)]
1111
pub struct LintedFile {
1212
pub path: String,
1313
pub patches: Vec<FixPatch>,

crates/lib/src/core/rules/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum RuleGroups {
3434
Ambiguous,
3535
Capitalisation,
3636
Convention,
37+
Jinja,
3738
Layout,
3839
References,
3940
Structure,
@@ -180,7 +181,8 @@ pub trait Rule: CloneRule + dyn_clone::DynClone + Debug + 'static + Send + Sync
180181
tree: ErasedSegment,
181182
config: &FluffConfig,
182183
) -> Vec<SQLLintError> {
183-
let mut root_context = RuleContext::new(tables, dialect, config, tree.clone());
184+
let mut root_context =
185+
RuleContext::new(tables, dialect, config, tree.clone(), &templated_file);
184186
let mut vs = Vec::new();
185187

186188
// TODO Will to return a note that rules were skipped

crates/lib/src/core/rules/context.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::core::config::FluffConfig;
1313
pub struct RuleContext<'a> {
1414
pub tables: &'a Tables,
1515
pub dialect: &'a Dialect,
16-
pub templated_file: Option<TemplatedFile>,
16+
pub templated_file: &'a TemplatedFile,
1717
pub path: Option<String>,
1818
pub config: &'a FluffConfig,
1919

@@ -41,13 +41,14 @@ impl<'a> RuleContext<'a> {
4141
dialect: &'a Dialect,
4242
config: &'a FluffConfig,
4343
segment: ErasedSegment,
44+
templated_file: &'a TemplatedFile,
4445
) -> Self {
4546
Self {
4647
tables,
4748
dialect,
4849
config,
4950
segment,
50-
templated_file: <_>::default(),
51+
templated_file,
5152
path: <_>::default(),
5253
parent_stack: <_>::default(),
5354
raw_stack: <_>::default(),

crates/lib/src/rules.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod aliasing;
77
pub mod ambiguous;
88
pub mod capitalisation;
99
pub mod convention;
10+
pub mod jinja;
1011
pub mod layout;
1112
pub mod references;
1213
pub mod structure;
@@ -19,7 +20,8 @@ pub fn rules() -> Vec<ErasedRule> {
1920
convention::rules(),
2021
layout::rules(),
2122
references::rules(),
22-
structure::rules()
23+
structure::rules(),
24+
jinja::rules(),
2325
)
2426
.collect_vec()
2527
}

crates/lib/src/rules/jinja.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::core::rules::base::ErasedRule;
2+
3+
pub mod jj01;
4+
5+
pub fn rules() -> Vec<ErasedRule> {
6+
use crate::core::rules::base::Erased as _;
7+
8+
vec![jj01::RuleJJ01.erased()]
9+
}

0 commit comments

Comments
 (0)