sc-lint 0.8.6

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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
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` (alias: `setup`), `using-sc-lint`, `configuration`, `just-setup`, `ci`, `upgrade`, `troubleshooting`, `best-practices`, `cli-reference`, 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`. The overview accepts `README`, `README.md`, or `overview`. Use `sc-lint docs --path` for the installed bundle path."
)]
#[command(disable_version_flag = true)]
pub struct Cli {
    /// Write the stable JSON envelope to stdout (errors are written to stderr).
    #[arg(long, global = true)]
    pub json: bool,
    /// Print the sc-lint and analyzer versions.
    #[arg(long, short = 'V', global = true)]
    pub version: bool,
    /// Repository root used by lint, view, check, clippy, compatibility check, test, and CI.
    #[arg(long, global = true, value_name = "PATH")]
    pub root: Option<PathBuf>,
    /// Read the consumer configuration from this path, relative to the repository root when relative.
    #[arg(long, global = true, value_name = "PATH")]
    pub config: Option<PathBuf>,
    /// Override the configured command log directory.
    #[arg(long, global = true, value_name = "PATH")]
    pub log_root: Option<PathBuf>,
    /// Enable console logging for this command.
    #[arg(long, global = true)]
    pub log_console: bool,
    #[command(subcommand)]
    pub(crate) command: Option<Command>,
}

#[derive(Debug, Clone, Subcommand)]
pub enum Command {
    /// Run one analyzer, maintainer lint profile, or configured consumer lint profile.
    Lint {
        #[arg(value_enum, value_name = "TARGET")]
        target: LintTarget,
        /// Run a configured consumer profile. Supported only with `ci`.
        #[arg(long)]
        consumer: bool,
        /// Select a consumer lint profile or step (`all` runs every step in declaration order); requires `--consumer`.
        #[arg(long, requires = "consumer")]
        profile: Option<String>,
        /// Consumer CI platform scope: `host` runs unannotated and host-tagged steps; `all` also reports unsupported cross-platform steps; a named platform adds its steps. Requires `--consumer`.
        #[arg(long = "platform-scope", value_enum, requires = "consumer")]
        platform_scope: Option<PlatformScopeArg>,
        /// Run these analyzer rules (`<RULE-ID|family>[,...]`); forwarded unchanged to the selected analyzer.
        #[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,
    },
    /// Show analyzer findings or the reserved graph view.
    View {
        #[arg(value_enum, value_name = "TARGET")]
        target: ViewTarget,
    },
    /// Run the native or Windows cross-target cargo check.
    Check {
        #[arg(value_enum, value_name = "TARGET")]
        target: CheckTarget,
    },
    /// Run the native or Windows cross-target cargo clippy analysis.
    Clippy {
        #[arg(value_enum, value_name = "TARGET")]
        target: ClippyTarget,
    },
    /// Check the configured consumer installation and version requirement.
    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,
    },
    /// Seed consumer integration files and manage the bootstrap.
    Init {
        /// Generate the canonical thin Just integration.
        #[arg(long, required = true)]
        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,
    },
    /// Read an installed guide from the offline documentation bundle.
    #[command(
        after_help = "Guide aliases: `README.md` and `overview` select `README`; `setup` selects `installation`."
    )]
    Docs {
        /// Guide to print or resolve. Defaults to the overview (`README`).
        #[arg(value_enum)]
        guide: Option<DocsGuide>,
        /// Print the guide or bundle path without a label.
        #[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,
    },
    /// Print the product, backend, and contract versions.
    Version,
    /// Run the source-maintainer CI profile. Use `sc-lint lint ci --consumer` for a configured consumer profile.
    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", aliases = ["README.md", "overview"])]
    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 = "cli-reference")]
    CliReference,
    #[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::CliReference => DocsGuideMetadata {
                name: "cli-reference",
                path: "cli-reference/README.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",
        help = "Run the Rust dependency and manifest boundary analyzer"
    )]
    ScBoundary,
    #[value(
        name = "sc-portability",
        help = "Run the Rust cross-platform portability analyzer"
    )]
    ScPortability,
    #[value(
        name = "sc-runtime",
        help = "Run the Rust async and runtime-pattern analyzer"
    )]
    ScRuntime,
    #[value(
        name = "function-length",
        help = "Check configured function-length limits"
    )]
    FunctionLength,
    #[value(
        name = "line-counts",
        help = "Check configured source line-count limits"
    )]
    LineCounts,
    #[value(
        name = "identity-literals",
        help = "Check configured identity and sentinel literals"
    )]
    IdentityLiterals,
    #[value(name = "fast", help = "Run the source-maintainer fast lint profile")]
    Fast,
    #[value(
        name = "full",
        help = "Run the complete source-maintainer lint profile"
    )]
    Full,
    #[value(
        name = "ci",
        help = "Run the source-maintainer profile, or the configured consumer profile with `--consumer`"
    )]
    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", help = "Reserved graph view; not implemented yet")]
    Graph,
    #[value(
        name = "findings",
        help = "Show findings through the installed Python adapter"
    )]
    Findings,
}

impl ViewTarget {}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum CheckTarget {
    #[value(name = "native", help = "Run cargo check for the current host")]
    Native,
    #[value(
        name = "xwin",
        help = "Run cargo check for x86_64-pc-windows-msvc with cargo-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", help = "Run cargo clippy for the current host")]
    Native,
    #[value(
        name = "xwin",
        help = "Run cargo clippy for x86_64-pc-windows-msvc with cargo-xwin"
    )]
    Xwin,
}

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