Configuration

Shape the limits in .linecop.yaml.

linecop v0.9.1 Manual

Manual contents

A .linecop.yaml file describes one tree: the cap every file starts with, the cap sets a rule can apply, and the files to ignore. The format is version 1, the version key is optional, and unknown keys are errors.

A complete file

version: 1
count: total
default:
file:
lines: 500
bytes: 40000
comment-block:
lines: 4
bytes: 400
comment-lines: 40

restrictions:
source:
file:
lines: 300
message: split the module
comment-block: 4
comment-lines: 40
docs:
file: 200

groups:
vendored:
- path: "vendor/**"
rust:
- language: Rust
tests:
- path: "**/*_test.rs"
- path: "tests/**"

rules:
- where: vendored
apply: ignore
- where: "languages.Rust && !vendored"
apply: source
- where: tests
apply: source
- where: languages.Markdown
apply: docs

scopes:
comment-block:
gap: 0
message: compact or move the comment
todo:
select: comment-block
contains: TODO
gap: 0
message: too many TODO comments

root: .
hidden: false

Version

version defaults to 1. Another value is an error, and linecop rejects the old v0 keys (limits, overrides, count_mode, include_hidden). There is no migration command. The v1 shape is the only shape this binary reads.

Count

count decides what the file gauge measures:

  • total counts every line, including comments and blanks. This is the default.
  • code counts only code lines.
  • code-comments counts code and comment lines, without blanks.

The count mode applies to the file gauge. Scope gauges measure their own selections.

Default

default is the cap set every file starts from:

  • An omitted default keeps {file: 500}.
  • false starts from an empty set, so a file with no rule has no caps.
  • A map replaces the default set. Each key selects a measure, and each value is a cap.
  • A cap is a line count or a map with lines, bytes, and an optional message.
  • false for one measure disables that measure.

file measures the whole file. comment-block and comment-lines are the built-in scope measures. A custom scope name is available after scopes defines it.

Restrictions

restrictions names partial cap sets that a rule may apply. A restriction is never false. It is a map of measures, and each measure is a cap or false.

A rule overlays its restriction field by field. A changed cap takes its own message. A cap without one falls back to scopes.<measure>.message, then to the built-in sentence. For the file cap, scopes.file.message is that fallback.

restrictions:
source:
file:
lines: 300
message: split the module
comment-block: 4

Groups

groups names lists of selectors. A selector has path, language, or both:

  • The two keys both have to match. { path: "src/**", language: Rust } matches Rust files under src.
  • Entries are alternatives. A group with two paths matches either path.
  • path is a .gitignore line matched from the config’s root. ! negation is not supported; use ignore on a rule instead.

The group name is what a where expression uses. A rule does not need a group when it tests a language directly.

Rules

rules is an ordered list of { where, apply } entries:

  • where is a boolean over group names and languages.<name>.
  • Operators are &&, ||, and !, with parentheses.
  • apply is a restriction name, an array of restriction names, or ignore.
  • Every matching rule overlays its restrictions in order.
  • ignore stops the file. Later rules do not apply, and the file gets no caps.
rules:
- where: vendored
apply: ignore
- where: "languages.Rust && !vendored"
apply: source
- where: tests
apply: [source, docs]

Scopes

scopes tunes the built-in measures or defines a custom one:

  • comment-block measures one comment block, with line and byte caps.
  • comment-lines measures all comment lines in a file, with a line cap only.
  • gap applies to comment blocks and sets how many blank lines may sit between blocks before they count as one.
  • contains is a case-sensitive filter for a custom comment scope.
  • message is the sentence reported for the measure.
  • A custom scope needs select (comment-block or comment-lines) and a message.
  • The file scope measures the whole file and takes only message.
scopes:
comment-block:
gap: 0
message: compact or move the comment
todo:
select: comment-block
contains: TODO
gap: 0
message: too many TODO comments

A comment cap on a language outside the comment-cap table, such as JSON or Markdown, exits with code 2. A byte cap on comment-lines is an error, because that measure counts lines only.

Root and hidden

root is the directory the config describes, relative to the config file. Group paths match from that root, and a run with no path argument scans it. root: . is the config file’s directory.

hidden scans dot-prefixed files and directories. VCS metadata stays excluded. The --hidden option overrides the config for one run.

The .config/ form

A config may live at .config/linecop.yaml. Set root to the directory the selectors should read from, usually the repository one level up:

version: 1
root: ..
default: 500

restrictions:
docs:
file: 200

rules:
- where: languages.Markdown
apply: docs

Discovery finds .linecop.yaml and .config/linecop.yaml in the same walk, so a repository can keep the file out of its root without changing how paths match.

Command-line overrides

The command line applies after the config:

  • --limit [LANG=]LINES appends a rule that caps every file or one language.
  • --ignore PATTERN appends an ignore rule.
  • --count overrides the config’s count mode.
  • --hidden overrides the config’s hidden flag.
  • --no-config skips the file and starts from the built-in 500-line default.
  • --config - reads the config from stdin.

The usage page lists every option and the exit codes.

Check one resolution

linecop explain prints the count mode, the default, every matching rule with its selector and caps, and the effective caps:

$ linecop explain src/checkout.rs
src/checkout.rs  Rust
  count: total
  default: file.lines = 40
  rule 3: where languages.Rust -> source
    source: comment-block.lines = 4, comment-lines.lines = 12, file.lines = 20
  effective: comment-block.lines = 4, comment-lines.lines = 12, file.lines = 20

The schema page covers the generated schema and editor support.