Skip to main content

LintConfig

Struct LintConfig 

Source
pub struct LintConfig {
    pub rules: HashMap<String, RuleConfig>,
    pub color: ColorConfig,
    pub parser: ParserConfig,
    pub include: IncludeConfig,
    pub target_nginx_version: Option<String>,
}
Expand description

Configuration for nginx-lint loaded from .nginx-lint.toml.

Use from_file to load from a specific path, or find_and_load to search the directory tree upward. A default LintConfig enables all rules except those listed in DISABLED_BY_DEFAULT.

Fields§

§rules: HashMap<String, RuleConfig>

Per-rule configuration keyed by rule name (e.g. "indent", "server-tokens-enabled").

§color: ColorConfig

Color output settings.

§parser: ParserConfig

Parser-level settings (e.g. additional block directives for extension modules).

§include: IncludeConfig

Include resolution settings (e.g. path mappings for include directives).

§target_nginx_version: Option<String>

Target nginx version (e.g. "1.31.0").

When set, rules whose declared version range does not include this version are automatically skipped. Stored as a raw string so an unparseable value does not fail config loading — the linter parses it lazily and emits a single warning if invalid.

Implementations§

Source§

impl LintConfig

Source

pub const DISABLED_BY_DEFAULT: &'static [&'static str]

Rules that are disabled by default

Source

pub const NATIVE_RULE_NAMES: &'static [&'static str]

Native lint rules implemented directly in the top-level crate (i.e. not packaged as plugins under plugins/builtin/).

Exposed as a pub const so the drift-detection test in the top-level crate (tests/known_rules_drift_test.rs) can distinguish “native rule” from “stale builtin plugin entry” without duplicating this list.

Source

pub const KNOWN_RULE_NAMES: &'static [&'static str]

All rule names recognised by nginx-lint config validate.

This is the union of NATIVE_RULE_NAMES and the builtin plugin names. The builtin plugin list lives in the top-level crate (nginx-lint) as BUILTIN_PLUGIN_NAMES; because this module is a downstream dependency it cannot reference that symbol directly, so the two lists are kept in sync by a drift-detection unit test in the top-level crate (tests/known_rules_drift_test.rs).

Order: native rules first, then builtin plugins in the same order as BUILTIN_PLUGIN_NAMES so review diffs against that file are obvious.

Source

pub fn from_file(path: &Path) -> Result<Self, ConfigError>

Load configuration from a file

Source

pub fn parse(content: &str) -> Result<Self, String>

Parse configuration from a TOML string

Source

pub fn find_and_load(dir: &Path) -> Option<(Self, PathBuf)>

Find and load .nginx-lint.toml from the given directory or its parents.

Returns the loaded config along with the path of the config file found.

Source

pub fn is_rule_enabled(&self, name: &str) -> bool

Check if a rule is enabled

Source

pub fn rule_explicitly_configured(&self, name: &str) -> bool

Whether the user explicitly wrote a [rules.<name>] section for this rule (irrespective of which options it contains). Used to distinguish “explicitly enabled” from “enabled by default” when warning about rules that fall outside the configured nginx version range.

Source

pub fn rule_skip_version_check(&self, name: &str) -> bool

Whether a rule has skip_version_check = true in its configuration.

Source

pub fn target_nginx_version(&self) -> Option<&str>

The configured target nginx version as a raw string, if any.

Source

pub fn get_rule_config(&self, name: &str) -> Option<&RuleConfig>

Get the configuration for a specific rule

Source

pub fn color_mode(&self) -> ColorMode

Get the color mode setting

Source

pub fn additional_block_directives(&self) -> &[String]

Get additional block directives from config

Source

pub fn include_path_mappings(&self) -> &[PathMapping]

Get include path mappings (applied in order to include patterns before resolving)

Source

pub fn json_schema() -> Value

Generate the JSON Schema for the configuration file.

The schema is derived from the Rust type definitions, so it automatically stays in sync with the actual configuration structure.

Source

pub fn include_prefix(&self) -> Option<&str>

Get include prefix (base directory for resolving relative include paths)

Source

pub fn additional_contexts(&self) -> Option<&HashMap<String, Vec<String>>>

Get additional contexts for invalid-directive-context rule

Source

pub fn directive_inheritance_excluded(&self) -> Option<&[String]>

Get excluded directives for directive-inheritance rule

Source

pub fn directive_inheritance_additional(&self) -> Option<&[AdditionalDirective]>

Get additional directives for directive-inheritance rule

Source

pub fn validate_file(path: &Path) -> Result<Vec<ValidationError>, ConfigError>

Validate a configuration file and return any errors

Trait Implementations§

Source§

impl Debug for LintConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for LintConfig

Source§

fn default() -> LintConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for LintConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for LintConfig

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,