src/lint/private/cli

Search:
Group by:
Source   Edit  

Command-line arguments.

The executable takes optional positional arguments that override the config's sources and ignoredPatterns for this run. Each argument is one of:

src/foo.nim a file src/module/* a glob pattern src/foo.nim:10-12 a file, restricted to line ranges

With no arguments the config's sources are used.

Types

Options = object
  targets*: seq[Target]
  format*: string            ## `text` or `github`.
  help*: bool                ## `--help` or `-h` was given.
Everything the command line can say. Source   Edit  
Target = object
  path*: string              ## A file or a glob pattern.
  lines*: seq[tuple[first, last: int]] ## Empty means the whole file.
One thing to lint. Source   Edit  

Consts

helpText = """Usage: linter [options] [target...]

Lint the files selected by the config's `sources`, or the targets given on the
command line.

Targets:
  path/to/file.nim        a single file
  path/to/dir             a directory, linted recursively
  path/to/dir/*.nim       a glob pattern, expanded by Lint
  path/to/file.nim:10-12  a file, restricted to line ranges

  Targets replace the config's `sources` and every `ignoredPatterns`, including
  step-level ones. Quote glob patterns so the shell does not expand them first.

  Glob patterns are always written in UNIX form, with `/` as the separator, even
  on Windows.

Options:
  --format=text           human-readable report (default)
  --format=github         GitHub Actions workflow commands, for inline
                          annotations on a pull request
  -h, --help              show this message and exit

Exit codes:
  0  no errors; hints may still have been reported
  1  at least one finding was reported as an error
  2  a source file could not be parsed
  3  nothing to lint: no file matched the sources or the targets
  4  a check raised an exception
"""
Source   Edit  

Procs

proc inRanges(line: int; ranges: seq[tuple[first, last: int]]): bool {.
    ...raises: [], tags: [], forbids: [].}
True when line falls in any of ranges. An empty list matches everything. Source   Edit  
proc parseOptions(args: seq[string]): Options {....raises: [],
    tags: [ReadIOEffect], forbids: [].}
Parses the command line. Accepts --format=github and --format:github. Source   Edit  
proc parseTarget(arg: string): Target {....raises: [], tags: [], forbids: [].}

Splits an argument into a path and optional line ranges.

The split is on the last :, and only when the suffix parses as ranges, so paths containing colons (Windows drive letters) are left alone.

Source   Edit