Skip to main content

ktrs_lint/editorconfig/
code_style.rs

1//! Port of ktlint-rule-engine-core `editorconfig/CodeStyleEditorConfigProperty.kt`.
2
3use std::sync::LazyLock;
4
5use ktrs_editorconfig::{EnumValue, PropertyType};
6
7use crate::editorconfig::editor_config_property::EditorConfigProperty;
8use crate::editorconfig::value_parsers::safe_enum_value_parser;
9
10/// `CodeStyleValue` (`android_studio`, `intellij_idea`, `ktlint_official`).
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
12pub enum CodeStyleValue {
13    AndroidStudio,
14    IntellijIdea,
15    KtlintOfficial,
16}
17
18impl EnumValue for CodeStyleValue {
19    const ENUM_TYPE_NAME: &'static str =
20        "io.github.ktlint.core.rule.engine.core.api.editorconfig.CodeStyleValue";
21    const ENTRIES: &'static [Self] = &[
22        CodeStyleValue::AndroidStudio,
23        CodeStyleValue::IntellijIdea,
24        CodeStyleValue::KtlintOfficial,
25    ];
26
27    fn name(self) -> &'static str {
28        match self {
29            CodeStyleValue::AndroidStudio => "android_studio",
30            CodeStyleValue::IntellijIdea => "intellij_idea",
31            CodeStyleValue::KtlintOfficial => "ktlint_official",
32        }
33    }
34}
35
36crate::enum_property_value_type!(CodeStyleValue);
37
38pub static CODE_STYLE_PROPERTY_TYPE: PropertyType<CodeStyleValue> = PropertyType {
39    name: "ktlint_code_style",
40    description: "The code style ('ktlint_official', 'intellij_idea' or 'android_studio') to be applied. By default the 'ktlint_official' code style is used",
41    parser: safe_enum_value_parser::<CodeStyleValue>,
42    possible_values: &["android_studio", "intellij_idea", "ktlint_official"],
43    lower_casing: true,
44};
45
46pub static CODE_STYLE_PROPERTY: LazyLock<EditorConfigProperty<CodeStyleValue>> =
47    LazyLock::new(|| EditorConfigProperty {
48        android_studio_code_style_default_value: CodeStyleValue::AndroidStudio,
49        intellij_idea_code_style_default_value: CodeStyleValue::IntellijIdea,
50        ktlint_official_code_style_default_value: CodeStyleValue::KtlintOfficial,
51        ..EditorConfigProperty::new(&CODE_STYLE_PROPERTY_TYPE, CodeStyleValue::KtlintOfficial)
52    });