[][src]Macro rslint_core::declare_lint

macro_rules! declare_lint {
    ($($input:tt)*) => { ... };

A macro to easily generate rule boilerplate code.

This example is not tested
declare_lint! {
    /// A description of the rule here
    /// This will be used as the doc for the rule struct
    // The name of the group this rule belongs to.
    // Make sure this is kebab-case and unique.
    /// A description of the attribute here, used for config docs.
    pub config_attr: u8,
    pub another_attr: String

Rule name and docs

The macro's first argument is an identifier for the rule structure. This should always be a PascalCase name. You will have to either derive Default for the struct or implement it manually.

The macro also accepts any doc comments for the rule name. These comments are then used by an xtask script to generate markdown files for user facing docs. Each rule doc should include an Incorrect Code Examples header. It may also optionally include a Correct Code Examples. Do not include a Config header, it is autogenerated from config field docs.


After the rule code, the macro accepts fields for the struct. Any field which is public will be used for config, you can however disable this by using #[serde(skip)]. Every public (config) field should have a doc comment, the doc comments will be used for user facing documentation. Therefore try to be non technical and non rust specific with the doc comments. All config fields will be renamed to camelCase

This will generate a rule struct with RuleName, and use the optional config attributes defined for the config of the rule. You must make sure each config field is Deserializable.