Repository: astral-sh/ruff
File: crates/ruff_db/src/diagnostic/render.rs (Rust)

Code before:
          ::: fruits:2:1
           |
         2 | banana
           | ------ secondary fruits 2
           |
        ",
        );
    }

    /// A small harness for setting up an environment specifically for testing
    /// diagnostic rendering.
    pub(super) struct TestEnvironment {
        db: TestDb,
        config: DisplayDiagnosticConfig,
    }

    impl TestEnvironment {
        /// Create a new test harness.
        ///
        /// This uses the default diagnostic rendering configuration.
        pub(super) fn new() -> TestEnvironment {
            TestEnvironment {
                db: TestDb::new(),
                config: DisplayDiagnosticConfig::default(),
            }
        }

        /// Set the number of contextual lines to include for each snippet
        /// in diagnostic rendering.
        fn context(&mut self, lines: usize) {
            // Kind of annoying. I considered making `DisplayDiagnosticConfig`
            // be `Copy` (which it could be, at time of writing, 2025-03-07),
            // but it seems likely to me that it will grow non-`Copy`
            // configuration. So just deal with this inconvenience for now.
            let mut config = std::mem::take(&mut self.config);
            config = config.context(lines);
            self.config = config;
        }

        /// Set the output format to use in diagnostic rendering.
        pub(super) fn format(&mut self, format: DiagnosticFormat) {
            let mut config = std::mem::take(&mut self.config);
            config = config.format(format);
            self.config = config;
        }

        /// Enable preview functionality for diagnostic rendering.
        #[allow(
            dead_code,
            reason = "This is currently only used for JSON but will be needed soon for other formats"
        )]

Review comment (suggestion):
better for avoid snapshot modifications (ruff lint codes after ty name) in this PR:
```suggestion
                config: DisplayDiagnosticConfig::new("ruff"),
```


Code after:
           | ^^^^^^^^^^ primary fruits 10
           |
          ::: fruits:2:1
           |
         2 | banana
           | ------ secondary fruits 2
           |
        ",
        );
    }

    /// A small harness for setting up an environment specifically for testing
    /// diagnostic rendering.
    pub(super) struct TestEnvironment {
        db: TestDb,
        config: DisplayDiagnosticConfig,
    }

    impl TestEnvironment {
        /// Create a new test harness.
        ///
        /// This uses the default diagnostic rendering configuration.
        pub(super) fn new() -> TestEnvironment {
            TestEnvironment {
                db: TestDb::new(),
                config: DisplayDiagnosticConfig::new("ty"),
            }
        }

        /// Set the number of contextual lines to include for each snippet
        /// in diagnostic rendering.
        fn context(&mut self, lines: usize) {
            // Kind of annoying. I considered making `DisplayDiagnosticConfig`
            // be `Copy` (which it could be, at time of writing, 2025-03-07),
            // but it seems likely to me that it will grow non-`Copy`
            // configuration. So just deal with this inconvenience for now.
            let config = self.config.clone();
            self.config = config.context(lines);
        }

        /// Set the output format to use in diagnostic rendering.
        pub(super) fn format(&mut self, format: DiagnosticFormat) {
            let config = self.config.clone();
            self.config = config.format(format);
        }

        /// Enable preview functionality for diagnostic rendering.
        #[allow(
            dead_code,
            reason = "This is currently only used for JSON but will be needed soon for other formats"
        )]