Skip to main content

Rule

Struct Rule 

Source
pub struct Rule {
    pub file: Option<PathBuf>,
    pub line: usize,
    pub name: String,
    pub pattern: Pattern,
    pub source: String,
    pub message: String,
    pub severity: Severity,
    pub fix: Option<String>,
    pub files: Vec<String>,
    pub unless: Vec<Pattern>,
    pub record: Option<RecordUnit>,
    pub meta: Vec<(String, String)>,
}
Expand description

One rule of a pattern file: a named pattern with what a finding of it says, how serious it is, the fix that replaces the match, the inputs it reads, the record it holds and the metadata a pipeline filters on. The rule is also a sub-pattern under its name, so \{name} reads it and a test line checks it.

Fields§

§file: Option<PathBuf>

The pattern file the rule is in, where the set was declared from one.

§line: usize

The line the rule opens on, from one.

§name: String

The rule’s name, the id a finding is reported under.

§pattern: Pattern

What the rule matches.

§source: String

The pattern as written.

§message: String

What a finding says: a report template rendered at each match, with the match’s registers and their typed slices, its position, and ${rule} and ${severity}.

§severity: Severity

How serious a finding is; a warning where the rule says nothing.

§fix: Option<String>

The rewrite template a fix renders in the match’s place, where the rule has one.

§files: Vec<String>

The globs the inputs the rule reads are kept by (*.py) or dropped by (!test_*), as -g takes them; every input where there are none.

§unless: Vec<Pattern>

The patterns the record must not hold for the rule to fire.

§record: Option<RecordUnit>

What a record is, for a rule that fires on a record holding the pattern and none of unless: a line where a rule names unless and no record; nothing for a rule that fires on each match.

§meta: Vec<(String, String)>

The meta.KEY = VALUE lines, in order.

Implementations§

Source§

impl Rule

Source

pub fn on_records(&self) -> bool

Whether the rule fires on a record rather than on each match: it names a record or a pattern the record must not hold.

Source

pub fn record_unit(&self) -> RecordUnit

What a record is for this rule: what it names, or a line where it names only what the record must not hold.

Source

pub fn tags(&self) -> Vec<String>

The values meta.tags lists, comma-separated.

Trait Implementations§

Source§

impl Clone for Rule

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Rule

§

impl RefUnwindSafe for Rule

§

impl Send for Rule

§

impl Sync for Rule

§

impl Unpin for Rule

§

impl UnsafeUnpin for Rule

§

impl UnwindSafe for Rule

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.