sc-lint 0.8.3

Top-level CLI composition root for the sc-lint tool family.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
use std::path::PathBuf;

use clap::Parser;
use clap::Subcommand;
use clap::ValueEnum;
use serde::Serialize;

use crate::profile_plan::Platform;
use crate::profile_plan::PlatformScope;

#[derive(Debug, Clone, Parser)]
#[command(name = "sc-lint")]
#[command(about = "Stable top-level CLI for the sc-lint tool family")]
#[command(
    after_long_help = "Documentation guides: `sc-lint docs` (overview), `installation`, `using-sc-lint`, `configuration`, `just-setup`, `ci`, `upgrade`, `troubleshooting`, `best-practices`, and one guide for each `sc-lint-*` package: `sc-lint`, `sc-lint-analyzer-support`, `sc-lint-attributes`, `sc-lint-boundary`, `sc-lint-directives`, `sc-lint-portability`, `sc-lint-runtime`, and `sc-lint-schema`. Use `sc-lint docs --path` for the installed bundle path."
)]
#[command(disable_version_flag = true)]
pub struct Cli {
    #[arg(long, global = true)]
    pub json: bool,
    #[arg(long, global = true)]
    pub version: bool,
    #[arg(long, global = true, value_name = "path")]
    pub root: Option<PathBuf>,
    #[arg(long, global = true, value_name = "path")]
    pub config: Option<PathBuf>,
    #[arg(long, global = true, value_name = "path")]
    pub log_root: Option<PathBuf>,
    #[arg(long, global = true)]
    pub log_console: bool,
    #[command(subcommand)]
    pub(crate) command: Option<Command>,
}

#[derive(Debug, Clone, Subcommand)]
pub enum Command {
    Lint {
        #[arg(value_enum)]
        target: LintTarget,
        /// Run the explicitly configured consumer profile instead of the source-maintainer profile.
        #[arg(long)]
        consumer: bool,
        /// Run only the named consumer lint step or named lint profile (`all` runs every step in declaration order).
        #[arg(long, requires = "consumer")]
        profile: Option<String>,
        /// Consumer platform selection: `host` (default) runs unannotated and host-tagged steps; `all` also reports unsupported cross-platform steps; `linux`, `macos` or `windows` adds that platform's steps.
        #[arg(long = "platform-scope", value_enum, requires = "consumer")]
        platform_scope: Option<PlatformScopeArg>,
        /// Run only these rules (`<RULE-ID|family>[,...]`); forwarded unchanged to sc-boundary, sc-portability or sc-runtime.
        #[arg(long = "rule-filter", conflicts_with = "consumer")]
        rule_filter: Option<String>,
        /// Stop starting new cargo-lane and `after_all` steps after the first failure; running steps finish.
        #[arg(long = "fail-fast", requires = "consumer")]
        fail_fast: bool,
    },
    View {
        #[arg(value_enum)]
        target: ViewTarget,
    },
    Check {
        #[arg(value_enum)]
        target: CheckTarget,
    },
    Clippy {
        #[arg(value_enum)]
        target: ClippyTarget,
    },
    Compatibility {
        #[command(subcommand)]
        command: CompatibilityCommand,
    },
    /// Install or repair the managed sc-lint release required by sc-lint.toml.
    Setup {
        /// Report the selected release and install location without changing either.
        #[arg(long)]
        dry_run: bool,
    },
    /// Inspect or update the managed sc-lint release required by sc-lint.toml.
    Upgrade {
        /// Report whether the configured minimum version requires an update.
        #[arg(long)]
        check: bool,
        /// Report the selected release and install location without changing either.
        #[arg(long)]
        dry_run: bool,
    },
    /// Materialize the product-owned consumer integration files.
    Init {
        /// Generate the canonical thin Just integration.
        #[arg(long)]
        just: bool,
        /// Verify that the generated integration is current without changing files.
        #[arg(long)]
        check: bool,
        /// Report the changes that would be made without changing files.
        #[arg(long)]
        dry_run: bool,
    },
    /// Discover and print the installed offline documentation bundle.
    Docs {
        /// Guide to print or resolve. Without a guide, print the overview.
        #[arg(value_enum)]
        guide: Option<DocsGuide>,
        /// Print the installed filesystem path instead of guide contents.
        #[arg(long)]
        path: bool,
    },
    /// Run the explicitly configured consumer test profile.
    Test {
        /// Selector to run, then the arguments appended to its command. Omitted
        /// runs `default` (every row of a `[[tool.sc-lint.test]]` list). Flags
        /// (`--fail-fast`, `--list`, `--config`, `--json`) must precede the
        /// selector; everything after it is forwarded verbatim. One positional,
        /// so clap stops parsing flags at the selector.
        #[arg(
            value_name = "SELECTOR [ARGS]",
            trailing_var_arg = true,
            allow_hyphen_values = true
        )]
        selector_and_args: Vec<String>,
        /// Print the declared selectors instead of running them.
        #[arg(long, conflicts_with_all = ["selector_and_args", "fail_fast"])]
        list: bool,
        /// Same as `lint --consumer --fail-fast`.
        #[arg(long = "fail-fast")]
        fail_fast: bool,
    },
    Version,
    Ci,
}

/// Command-line spelling of a consumer `--platform-scope`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum PlatformScopeArg {
    #[value(name = "host")]
    Host,
    #[value(name = "all")]
    All,
    #[value(name = "linux")]
    Linux,
    #[value(name = "macos")]
    Macos,
    #[value(name = "windows")]
    Windows,
}

impl From<PlatformScopeArg> for PlatformScope {
    fn from(value: PlatformScopeArg) -> Self {
        match value {
            PlatformScopeArg::Host => Self::Host,
            PlatformScopeArg::All => Self::All,
            PlatformScopeArg::Linux => Self::Named(Platform::Linux),
            PlatformScopeArg::Macos => Self::Named(Platform::MacOS),
            PlatformScopeArg::Windows => Self::Named(Platform::Windows),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum DocsGuide {
    #[value(name = "README.md")]
    Overview,
    #[value(name = "installation", alias = "setup")]
    Installation,
    #[value(name = "using-sc-lint")]
    UsingScLint,
    Configuration,
    #[value(name = "just-setup")]
    JustSetup,
    Ci,
    Upgrade,
    Troubleshooting,
    #[value(name = "best-practices")]
    BestPractices,
    #[value(name = "sc-lint")]
    ScLint,
    #[value(name = "sc-lint-attributes")]
    ScLintAttributes,
    #[value(name = "sc-lint-analyzer-support")]
    ScLintAnalyzerSupport,
    #[value(name = "sc-lint-boundary")]
    ScLintBoundary,
    #[value(name = "sc-lint-directives")]
    ScLintDirectives,
    #[value(name = "sc-lint-portability")]
    ScLintPortability,
    #[value(name = "sc-lint-runtime")]
    ScLintRuntime,
    #[value(name = "sc-lint-schema")]
    ScLintSchema,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct DocsGuideMetadata {
    pub(crate) name: &'static str,
    pub(crate) path: &'static str,
}

impl DocsGuide {
    pub(crate) const fn metadata(self) -> DocsGuideMetadata {
        match self {
            Self::Overview => DocsGuideMetadata {
                name: "README.md",
                path: "README.md",
            },
            Self::Installation => DocsGuideMetadata {
                name: "installation",
                path: "installation.md",
            },
            Self::UsingScLint => DocsGuideMetadata {
                name: "using-sc-lint",
                path: "using-sc-lint.md",
            },
            Self::Configuration => DocsGuideMetadata {
                name: "configuration",
                path: "configuration.md",
            },
            Self::JustSetup => DocsGuideMetadata {
                name: "just-setup",
                path: "just-setup.md",
            },
            Self::Ci => DocsGuideMetadata {
                name: "ci",
                path: "ci.md",
            },
            Self::Upgrade => DocsGuideMetadata {
                name: "upgrade",
                path: "upgrade.md",
            },
            Self::Troubleshooting => DocsGuideMetadata {
                name: "troubleshooting",
                path: "troubleshooting.md",
            },
            Self::BestPractices => DocsGuideMetadata {
                name: "best-practices",
                path: "best-practices.md",
            },
            Self::ScLint => DocsGuideMetadata {
                name: "sc-lint",
                path: "packages/sc-lint.md",
            },
            Self::ScLintAttributes => DocsGuideMetadata {
                name: "sc-lint-attributes",
                path: "packages/sc-lint-attributes.md",
            },
            Self::ScLintAnalyzerSupport => DocsGuideMetadata {
                name: "sc-lint-analyzer-support",
                path: "packages/sc-lint-analyzer-support.md",
            },
            Self::ScLintBoundary => DocsGuideMetadata {
                name: "sc-lint-boundary",
                path: "packages/sc-lint-boundary.md",
            },
            Self::ScLintDirectives => DocsGuideMetadata {
                name: "sc-lint-directives",
                path: "packages/sc-lint-directives.md",
            },
            Self::ScLintPortability => DocsGuideMetadata {
                name: "sc-lint-portability",
                path: "packages/sc-lint-portability.md",
            },
            Self::ScLintRuntime => DocsGuideMetadata {
                name: "sc-lint-runtime",
                path: "packages/sc-lint-runtime.md",
            },
            Self::ScLintSchema => DocsGuideMetadata {
                name: "sc-lint-schema",
                path: "packages/sc-lint-schema.md",
            },
        }
    }
}

#[derive(Debug, Clone, Subcommand)]
pub enum CompatibilityCommand {
    /// Verify the installed sc-lint binary satisfies sc-lint.toml.
    Check {
        /// Binary to probe. Defaults to `sc-lint` resolved from PATH.
        #[arg(long, value_name = "path")]
        binary: Option<PathBuf>,
    },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, ValueEnum)]
#[serde(rename_all = "snake_case")]
pub enum LintProfile {
    Fast,
    Full,
    Ci,
}

impl LintProfile {
    pub const fn command_suffix(self) -> &'static str {
        match self {
            Self::Fast => "fast",
            Self::Full => "full",
            Self::Ci => "ci",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum OutputMode {
    Human,
    Json,
}

impl OutputMode {
    pub const fn from_json_flag(json: bool) -> Self {
        if json { Self::Json } else { Self::Human }
    }

    pub const fn is_json(self) -> bool {
        matches!(self, Self::Json)
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum LintTarget {
    #[value(name = "sc-boundary")]
    ScBoundary,
    #[value(name = "sc-portability")]
    ScPortability,
    #[value(name = "sc-runtime")]
    ScRuntime,
    #[value(name = "function-length")]
    FunctionLength,
    #[value(name = "line-counts")]
    LineCounts,
    #[value(name = "identity-literals")]
    IdentityLiterals,
    #[value(name = "fast")]
    Fast,
    #[value(name = "full")]
    Full,
    #[value(name = "ci")]
    Ci,
}

impl LintTarget {
    pub const fn command_suffix(self) -> &'static str {
        match self {
            Self::ScBoundary => "sc-boundary",
            Self::ScPortability => "sc-portability",
            Self::ScRuntime => "sc-runtime",
            Self::FunctionLength => "function-length",
            Self::LineCounts => "line-counts",
            Self::IdentityLiterals => "identity-literals",
            Self::Fast => "fast",
            Self::Full => "full",
            Self::Ci => "ci",
        }
    }

    pub const fn profile(self) -> Option<LintProfile> {
        match self {
            Self::Fast => Some(LintProfile::Fast),
            Self::Full => Some(LintProfile::Full),
            Self::Ci => Some(LintProfile::Ci),
            Self::ScBoundary
            | Self::ScPortability
            | Self::ScRuntime
            | Self::FunctionLength
            | Self::LineCounts
            | Self::IdentityLiterals => None,
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum ViewTarget {
    #[value(name = "graph")]
    Graph,
    #[value(name = "findings")]
    Findings,
}

impl ViewTarget {}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum CheckTarget {
    #[value(name = "native")]
    Native,
    #[value(name = "xwin")]
    Xwin,
}

impl CheckTarget {
    pub const fn command_suffix(self) -> &'static str {
        match self {
            Self::Native => "native",
            Self::Xwin => "xwin",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum ClippyTarget {
    #[value(name = "native")]
    Native,
    #[value(name = "xwin")]
    Xwin,
}

impl ClippyTarget {
    pub const fn command_suffix(self) -> &'static str {
        match self {
            Self::Native => "native",
            Self::Xwin => "xwin",
        }
    }
}