Skip to main content

LintRule

Trait LintRule 

Source
pub trait LintRule: Send + Sync {
Show 16 methods // Required methods fn name(&self) -> &'static str; fn category(&self) -> &'static str; fn description(&self) -> &'static str; fn check(&self, config: &Config, path: &Path) -> Vec<LintError>; // Provided methods fn check_with_serialized_config( &self, config: &Config, path: &Path, _serialized_config: &str, ) -> Vec<LintError> { ... } fn wants_shared_config(&self) -> bool { ... } fn check_shared(&self, config: &Arc<Config>, path: &Path) -> Vec<LintError> { ... } fn wants_content(&self) -> bool { ... } fn check_with_content( &self, config: &Config, path: &Path, _content: &str, ) -> Vec<LintError> { ... } fn why(&self) -> Option<&str> { ... } fn bad_example(&self) -> Option<&str> { ... } fn good_example(&self) -> Option<&str> { ... } fn references(&self) -> Option<Vec<String>> { ... } fn severity(&self) -> Option<&str> { ... } fn min_nginx_version(&self) -> Option<&str> { ... } fn max_nginx_version(&self) -> Option<&str> { ... }
}
Expand description

A lint rule that can be checked against a parsed nginx configuration.

Every rule — whether implemented as a native Rust struct or as a WASM plugin — implements this trait. The four required methods supply metadata and the check logic; the optional methods provide documentation and plugin-specific overrides.

§Required methods

MethodPurpose
nameUnique rule identifier (e.g. "server-tokens-enabled")
categoryCategory for grouping (e.g. "security")
descriptionOne-line human-readable summary
checkRun the rule and return diagnostics

Required Methods§

Source

fn name(&self) -> &'static str

Unique identifier for this rule (e.g. "server-tokens-enabled").

Source

fn category(&self) -> &'static str

Category this rule belongs to (e.g. "security", "style").

Source

fn description(&self) -> &'static str

One-line human-readable description of what this rule checks.

Source

fn check(&self, config: &Config, path: &Path) -> Vec<LintError>

Run the rule against config (parsed from path) and return diagnostics.

Provided Methods§

Source

fn check_with_serialized_config( &self, config: &Config, path: &Path, _serialized_config: &str, ) -> Vec<LintError>

👎Deprecated since 0.16.0:

no longer called by the linter; the serialized config was only used by legacy core-module plugins. Implement check() or check_shared() instead.

Check with pre-serialized config JSON (optimization for WASM plugins)

This method allows passing a pre-serialized config JSON to avoid repeated serialization when running multiple plugins. Default implementation ignores the serialized config and calls check().

Source

fn wants_shared_config(&self) -> bool

Whether this rule wants the config as a shared Arc handle.

Rules that hand the config to another owner (e.g. WASM plugin rules, which store it in the sandbox’s resource table) should return true so the linter shares one Arc<Config> across all such rules instead of each rule deep-cloning the AST per check.

Source

fn check_shared(&self, config: &Arc<Config>, path: &Path) -> Vec<LintError>

Run the rule with a shared config handle.

The linter calls this instead of check when wants_shared_config returns true. Default implementation borrows the config and calls check().

Source

fn wants_content(&self) -> bool

Whether this rule wants the raw file content directly.

Rules that need to re-derive diagnostics from the source text itself (rather than the parsed Config) should return true so the linter hands them the content it already has in memory, instead of each rule independently re-reading the file from disk and re-parsing it.

Note: this does not compose with wants_shared_config — the default check_with_content delegates to check, not check_shared. No current rule needs both; a future one that does would need a custom override.

Source

fn check_with_content( &self, config: &Config, path: &Path, _content: &str, ) -> Vec<LintError>

Run the rule with the raw file content already available.

The linter calls this instead of check/check_shared when wants_content returns true and content is available. Default implementation ignores content and calls check().

Source

fn why(&self) -> Option<&str>

Get detailed explanation of why this rule exists

Source

fn bad_example(&self) -> Option<&str>

Get example of bad configuration

Source

fn good_example(&self) -> Option<&str>

Get example of good configuration

Source

fn references(&self) -> Option<Vec<String>>

Get reference URLs

Source

fn severity(&self) -> Option<&str>

Get severity level (for plugins)

Source

fn min_nginx_version(&self) -> Option<&str>

Minimum nginx version this rule applies to (inclusive).

None means the rule applies regardless of how old the nginx version is. Used by the linter’s version-based rule filter to decide whether to run this rule against a config whose target_nginx_version is set.

Source

fn max_nginx_version(&self) -> Option<&str>

Maximum nginx version this rule applies to (inclusive).

None means the rule applies regardless of how new the nginx version is.

Implementors§