OxL Справочник OxL
РусскийEnglish

warning magic-literal

warning Стандарт: [IV.1]

Повторяющийся литерал в атрибутах или аргументах.

What it means#

The same duration, size, retry count or limit literal appears two or more times in attributes or arguments (part III.4, IV.1). Such values should be named once with a const, a config field or a dynamic value. A literal that occurs once and is self-explanatory is fine.

Example#

oxl✓ проверяется в CI
data User { name: str }

service Users {
  @timeout(3s) @public rpc get(id: u64) -> User
  @timeout(3s) @public rpc list(page: u32) -> List<User>      // <- magic-literal
}

impl Users {
  rpc get(id) { User{ name: "ann" } }
  rpc list(page) { [User{ name: "ann" }] }
}
error
magic-literal

How to fix#

oxl✓ проверяется в CI
data User { name: str }

pub const STD_TIMEOUT = 3s

service Users {
  @timeout(STD_TIMEOUT) @public rpc get(id: u64) -> User
  @timeout(STD_TIMEOUT) @public rpc list(page: u32) -> List<User>
}

impl Users {
  rpc get(id) { User{ name: "ann" } }
  rpc list(page) { [User{ name: "ann" }] }
}

Introduce a named constant (or a cluster { defaults { ... } } value shared by all rpc) and use it everywhere. The lint can be raised to an error with magic-literal = "error" in [lint].

See also#

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства