mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat/tasks: expose linter RULES and use it for listing (#2083)
Part of #2020 , follow up of #2081 .
This commit is contained in:
parent
60ab7121f8
commit
2f1e1e2e46
5 changed files with 15 additions and 29 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -980,6 +980,7 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"oxc_allocator",
|
||||
"oxc_ast",
|
||||
"oxc_linter",
|
||||
"oxc_parser",
|
||||
"oxc_semantic",
|
||||
"oxc_span",
|
||||
|
|
|
|||
|
|
@ -29,13 +29,11 @@ pub use crate::{
|
|||
fixer::{FixResult, Fixer, Message},
|
||||
options::{AllowWarnDeny, LintOptions},
|
||||
rule::RuleCategory,
|
||||
rules::RULES,
|
||||
service::LintService,
|
||||
settings::LintSettings,
|
||||
};
|
||||
pub(crate) use crate::{
|
||||
rules::{RuleEnum, RULES},
|
||||
settings::JsxA11y,
|
||||
};
|
||||
pub(crate) use crate::{rules::RuleEnum, settings::JsxA11y};
|
||||
pub(crate) use oxc_semantic::AstNode;
|
||||
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ oxc_allocator = { workspace = true }
|
|||
oxc_span = { workspace = true }
|
||||
oxc_ast = { workspace = true }
|
||||
oxc_parser = { workspace = true }
|
||||
oxc_linter = { workspace = true }
|
||||
oxc_semantic = { workspace = true }
|
||||
oxc_tasks_common = { workspace = true }
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ use std::collections::HashSet;
|
|||
pub const ORIGINAL_JS_SOURCE_URL: &str =
|
||||
"https://raw.githubusercontent.com/eslint/eslint/main/packages/js/src/configs/eslint-all.js";
|
||||
|
||||
pub const OUR_RULES_DIR: &str = "crates/oxc_linter/src/rules/eslint";
|
||||
|
||||
const UNSUPPORTED_RULES: &[&str] = &["yoda"];
|
||||
|
||||
pub fn find_to_be_implemented_rules(source_text: &str) -> Result<Vec<String>, String> {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,19 @@
|
|||
use oxc_linter::RULES;
|
||||
use std::collections::HashSet;
|
||||
use std::{fs::read_dir, path::Path};
|
||||
use ureq::Response;
|
||||
|
||||
mod eslint;
|
||||
|
||||
pub fn run(plugin_name: &str) -> Result<String, String> {
|
||||
let (js_source_url, find_to_be_implemented_rules, our_rules_dir) = match plugin_name {
|
||||
"eslint" => (
|
||||
eslint::ORIGINAL_JS_SOURCE_URL,
|
||||
eslint::find_to_be_implemented_rules,
|
||||
eslint::OUR_RULES_DIR,
|
||||
),
|
||||
let (js_source_url, find_to_be_implemented_rules) = match plugin_name {
|
||||
"eslint" => (eslint::ORIGINAL_JS_SOURCE_URL, eslint::find_to_be_implemented_rules),
|
||||
_ => return Err(format!("😢 Unknown plugin name: {plugin_name}")),
|
||||
};
|
||||
|
||||
let js_string = fetch_plugin_rules_js_string(js_source_url)?;
|
||||
let rules_to_be_implemented = find_to_be_implemented_rules(&js_string)?;
|
||||
let rules_implemented = list_implemented_rules(Path::new(our_rules_dir))?;
|
||||
|
||||
let rules_implemented = list_implemented_rules(plugin_name);
|
||||
|
||||
let list = render_markdown_todo_list(&rules_to_be_implemented, &rules_implemented);
|
||||
Ok(list)
|
||||
|
|
@ -32,21 +29,12 @@ fn fetch_plugin_rules_js_string(url: &str) -> Result<String, String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn list_implemented_rules(path: &Path) -> Result<Vec<String>, String> {
|
||||
let entries = match read_dir(path) {
|
||||
Ok(entries) => entries,
|
||||
Err(err) => return Err(err.to_string()),
|
||||
};
|
||||
|
||||
let mut rules = vec![];
|
||||
for entry in entries.flatten() {
|
||||
// This is file or directory
|
||||
let os_str = entry.file_name();
|
||||
let name = os_str.to_string_lossy().trim_end_matches(".rs").replace('_', "-");
|
||||
rules.push(name);
|
||||
}
|
||||
|
||||
Ok(rules)
|
||||
fn list_implemented_rules(plugin_name: &str) -> Vec<String> {
|
||||
RULES
|
||||
.iter()
|
||||
.filter(|rule| rule.plugin_name() == plugin_name)
|
||||
.map(|rule| rule.name().to_string())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn render_markdown_todo_list(theirs: &[String], ours: &[String]) -> String {
|
||||
|
|
|
|||
Loading…
Reference in a new issue