forked from quarylabs/sqruff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,056 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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,54 @@ | ||
use std::io::Write; | ||
use std::path::Path; | ||
|
||
use minijinja::{context, Environment}; | ||
use serde::Serialize; | ||
use sqruff_lib::core::rules::base::ErasedRule; | ||
use sqruff_lib::rules::rules; | ||
|
||
use crate::commands::Cli; | ||
|
||
#[cfg(feature = "codegen-docs")] | ||
pub(crate) fn codegen_docs() { | ||
// CLI Docs | ||
let markdown: String = clap_markdown::help_markdown::<Cli>(); | ||
let file_cli = std::fs::File::create("docs/cli.md").unwrap(); | ||
let mut writer = std::io::BufWriter::new(file_cli); | ||
writer.write_all(markdown.as_bytes()).unwrap(); | ||
|
||
// Rules Docs | ||
let mut env = Environment::new(); | ||
let crate_dir = env!("CARGO_MANIFEST_DIR"); | ||
let template_path = | ||
Path::new(crate_dir).join("src").join("docs").join("generate_rule_docs_template.md"); | ||
let template = std::fs::read_to_string(template_path).expect("Failed to read template file"); | ||
env.add_template("rules", &template).unwrap(); | ||
|
||
let tmpl = env.get_template("rules").unwrap(); | ||
let rules = rules(); | ||
let rules = rules.into_iter().map(Rule::from).collect::<Vec<_>>(); | ||
let file_rules = std::fs::File::create("docs/rules.md").unwrap(); | ||
let mut writer = std::io::BufWriter::new(file_rules); | ||
writer.write_all(tmpl.render(context!(rules => rules)).unwrap().as_bytes()).unwrap(); | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize)] | ||
struct Rule { | ||
pub name: &'static str, | ||
pub code: &'static str, | ||
pub description: &'static str, | ||
pub fixable: bool, | ||
pub long_description: Option<&'static str>, | ||
} | ||
|
||
impl From<ErasedRule> for Rule { | ||
fn from(value: ErasedRule) -> Self { | ||
Rule { | ||
name: value.name(), | ||
code: value.code(), | ||
fixable: value.is_fix_compatible(), | ||
description: value.description(), | ||
long_description: value.long_description(), | ||
} | ||
} | ||
} |
This file contains 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,22 @@ | ||
# Rules | ||
|
||
The following rules are available in this create. This list is generated from the `rules` module in the source code and can be turned on or off and configured in the config file. | ||
|
||
## Rule Index | ||
|
||
| Rule Code | Rule Name | | ||
|-----------|-----------|{% for rule in rules %} | ||
| {{ rule.code }} | [{{ rule.name }}](#{{ rule.name }}) |{% endfor %} | ||
|
||
## Rule Details | ||
{% for rule in rules %} | ||
### {{ rule.name }} | ||
|
||
{{ rule.description }} | ||
|
||
**Code:** {{ rule.code }} | ||
|
||
**Fixable:** {% if rule.fixable %}Yes{% else %}No{% endif %} | ||
|
||
{% if rule.long_description %}{{ rule.long_description }}{% endif %} | ||
{% endfor %} |
This file contains 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 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 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 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 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 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 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.