Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/flavor-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flavor-cli"
version = "0.2.3"
version = "0.3.0"
edition = "2021"
license = "MIT"
description = "Personal check-only AST-backed code flavor lint CLI."
Expand Down
70 changes: 13 additions & 57 deletions crates/flavor-cli/src/plugins/language.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod dispatch;
mod failure;
mod function;
mod manifest;
mod name;
Expand All @@ -14,22 +13,21 @@ pub(crate) use python_manifest::PYTHON_MANIFEST;
use std::{collections::BTreeSet, path::Path};

use dispatch::check_dispatch_branches;
use failure::{check_failure_surface, failure_surface_signal};
use function::check_function_bodies;
use name::check_name_facts;
use shape::check_repeated_token_patterns;

use crate::{
config::{GuardConfig, NodeKind, RuleSettings},
model::{issue, Issue},
plugins::{AnalysisContext, FailureSurfaceSignal, PluginOutput, ProductSet, SourceFileScope},
plugins::{AnalysisContext, PluginOutput, ProductSet, SourceFileScope},
rules::{
DISPATCH_BRANCH_TOO_LONG, ERROR_FAILURE_SURFACE_MATURITY, NAMING_TOO_MANY_WORDS,
PAYLOAD_ALLOWED_INTRINSICS, PAYLOAD_MAX_BLOCKS, PAYLOAD_MAX_LINES,
PAYLOAD_PRIMITIVE_SOURCES, RUST_PARSE_ERROR, RUST_TESTS_IN_SOURCE,
SHAPE_REPEATED_TOKEN_PATTERN, SVELTE_COMPONENT_TOO_LONG, SVELTE_PARSE_ERROR,
SVELTE_SCRIPT_TOO_LONG, SVELTE_STYLE_TOO_LONG, SVELTE_TEMPLATE_TOO_COMPLEX,
TSX_NO_INTRINSICS, TSX_REQUIRES_PRIMITIVE, TS_PARSE_ERROR, VUE_PARSE_ERROR,
DISPATCH_BRANCH_TOO_LONG, NAMING_TOO_MANY_WORDS, PAYLOAD_ALLOWED_INTRINSICS,
PAYLOAD_MAX_BLOCKS, PAYLOAD_MAX_LINES, PAYLOAD_PRIMITIVE_SOURCES, RUST_PARSE_ERROR,
RUST_TESTS_IN_SOURCE, SHAPE_REPEATED_TOKEN_PATTERN, SVELTE_COMPONENT_TOO_LONG,
SVELTE_PARSE_ERROR, SVELTE_SCRIPT_TOO_LONG, SVELTE_STYLE_TOO_LONG,
SVELTE_TEMPLATE_TOO_COMPLEX, TSX_NO_INTRINSICS, TSX_REQUIRES_PRIMITIVE, TS_PARSE_ERROR,
VUE_PARSE_ERROR,
},
};
use flavor_core::{Fact, ProductDiagnostic};
Expand Down Expand Up @@ -106,15 +104,8 @@ pub(crate) fn analyze_typescript_source<'a>(context: &AnalysisContext<'a>) -> Pl
};

let mut issues = Vec::new();
let mut failure_surfaces = Vec::new();
analyze_typescript_products(
context.config,
scope,
&context.products,
&mut issues,
&mut failure_surfaces,
);
PluginOutput::with_failure_surfaces(issues, failure_surfaces)
analyze_typescript_products(context.config, scope, &context.products, &mut issues);
PluginOutput::issues(issues)
}

pub(crate) fn analyze_vue_source<'a>(context: &AnalysisContext<'a>) -> PluginOutput<'a> {
Expand All @@ -132,15 +123,8 @@ pub(crate) fn analyze_vue_source<'a>(context: &AnalysisContext<'a>) -> PluginOut
context.products.diagnostics("vue-sfc"),
"Vue SFC",
);
let mut failure_surfaces = Vec::new();
analyze_typescript_products(
context.config,
scope,
&context.products,
&mut issues,
&mut failure_surfaces,
);
PluginOutput::with_failure_surfaces(issues, failure_surfaces)
analyze_typescript_products(context.config, scope, &context.products, &mut issues);
PluginOutput::issues(issues)
}

pub(crate) fn analyze_svelte_source<'a>(context: &AnalysisContext<'a>) -> PluginOutput<'a> {
Expand All @@ -159,23 +143,15 @@ pub(crate) fn analyze_svelte_source<'a>(context: &AnalysisContext<'a>) -> Plugin
"Svelte",
);
check_svelte_shape(context.config, scope, &context.products, &mut issues);
let mut failure_surfaces = Vec::new();
analyze_typescript_products(
context.config,
scope,
&context.products,
&mut issues,
&mut failure_surfaces,
);
PluginOutput::with_failure_surfaces(issues, failure_surfaces)
analyze_typescript_products(context.config, scope, &context.products, &mut issues);
PluginOutput::issues(issues)
}

fn analyze_typescript_products(
config: &GuardConfig,
scope: SourceFileScope<'_>,
products: &ProductSet,
issues: &mut Vec<Issue>,
failure_surfaces: &mut Vec<FailureSurfaceSignal>,
) {
let parse_rule = config.rule(scope.relative, NodeKind::File, TS_PARSE_ERROR);
push_parse_issues(
Expand All @@ -198,26 +174,6 @@ fn analyze_typescript_products(
products.facts("typescript", "dispatch.branch"),
"switch case",
);

let failure_rule = config.rule(
scope.relative,
NodeKind::File,
ERROR_FAILURE_SURFACE_MATURITY,
);
check_failure_surface(
issues,
&failure_rule,
scope.path,
products.facts("typescript", "error.raw_failure"),
products.facts("typescript", "error.structured_failure"),
);
if let Some(signal) = failure_surface_signal(
scope.path,
products.facts("typescript", "error.raw_failure"),
products.facts("typescript", "error.structured_failure"),
) {
failure_surfaces.push(signal);
}
}

fn check_rust_tests<'a>(
Expand Down
100 changes: 0 additions & 100 deletions crates/flavor-cli/src/plugins/language/failure.rs

This file was deleted.

78 changes: 1 addition & 77 deletions crates/flavor-cli/src/plugins/language/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use crate::{
config::SourceKind,
plugins::{FactUse, GrammarUse, PluginManifest, ScopeDecl, ScopeKind},
rules::{
DISPATCH_BRANCH_TOO_LONG, ERROR_FAILURE_SURFACE_AGGREGATE, ERROR_FAILURE_SURFACE_MATURITY,
NAMING_TOO_MANY_WORDS, RUST_PARSE_ERROR, RUST_TESTS_IN_SOURCE,
DISPATCH_BRANCH_TOO_LONG, NAMING_TOO_MANY_WORDS, RUST_PARSE_ERROR, RUST_TESTS_IN_SOURCE,
SHAPE_REPEATED_TOKEN_PATTERN, SVELTE_COMPONENT_TOO_LONG, SVELTE_PARSE_ERROR,
SVELTE_SCRIPT_TOO_LONG, SVELTE_STYLE_TOO_LONG, SVELTE_TEMPLATE_TOO_COMPLEX,
TSX_NO_INTRINSICS, TSX_REQUIRES_PRIMITIVE, TS_PARSE_ERROR, VUE_PARSE_ERROR,
Expand Down Expand Up @@ -84,8 +83,6 @@ const RUST_FACTS: &[FactUse] = &[

const TYPESCRIPT_RULES: &[&str] = &[
DISPATCH_BRANCH_TOO_LONG,
ERROR_FAILURE_SURFACE_AGGREGATE,
ERROR_FAILURE_SURFACE_MATURITY,
NAMING_TOO_MANY_WORDS,
TS_PARSE_ERROR,
TSX_NO_INTRINSICS,
Expand Down Expand Up @@ -128,29 +125,6 @@ const TYPESCRIPT_FACTS: &[FactUse] = &[
"dispatch.branch",
&["payload.lines", "span", "line"],
),
fact(
"typescript",
"error.raw_failure",
&[
"payload.kind",
"payload.mechanism",
"payload.constructor",
"payload.callee",
"span",
"line",
],
),
fact(
"typescript",
"error.structured_failure",
&[
"payload.kind",
"payload.mechanism",
"payload.callee",
"span",
"line",
],
),
fact(
"tsx",
"jsx.element",
Expand All @@ -175,8 +149,6 @@ const TYPESCRIPT_FACTS: &[FactUse] = &[

const VUE_RULES: &[&str] = &[
DISPATCH_BRANCH_TOO_LONG,
ERROR_FAILURE_SURFACE_AGGREGATE,
ERROR_FAILURE_SURFACE_MATURITY,
NAMING_TOO_MANY_WORDS,
TS_PARSE_ERROR,
TSX_NO_INTRINSICS,
Expand Down Expand Up @@ -229,29 +201,6 @@ const VUE_FACTS: &[FactUse] = &[
"dispatch.branch",
&["payload.lines", "span", "line"],
),
fact(
"typescript",
"error.raw_failure",
&[
"payload.kind",
"payload.mechanism",
"payload.constructor",
"payload.callee",
"span",
"line",
],
),
fact(
"typescript",
"error.structured_failure",
&[
"payload.kind",
"payload.mechanism",
"payload.callee",
"span",
"line",
],
),
fact(
"tsx",
"jsx.element",
Expand All @@ -276,8 +225,6 @@ const VUE_FACTS: &[FactUse] = &[

const SVELTE_RULES: &[&str] = &[
DISPATCH_BRANCH_TOO_LONG,
ERROR_FAILURE_SURFACE_AGGREGATE,
ERROR_FAILURE_SURFACE_MATURITY,
NAMING_TOO_MANY_WORDS,
SVELTE_COMPONENT_TOO_LONG,
SVELTE_PARSE_ERROR,
Expand Down Expand Up @@ -358,29 +305,6 @@ const SVELTE_FACTS: &[FactUse] = &[
"dispatch.branch",
&["payload.lines", "span", "line"],
),
fact(
"typescript",
"error.raw_failure",
&[
"payload.kind",
"payload.mechanism",
"payload.constructor",
"payload.callee",
"span",
"line",
],
),
fact(
"typescript",
"error.structured_failure",
&[
"payload.kind",
"payload.mechanism",
"payload.callee",
"span",
"line",
],
),
fact(
"tsx",
"jsx.element",
Expand Down
Loading