Configuration
Shape the limits in .linecop.yaml.
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: falseVersion
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:
totalcounts every line, including comments and blanks. This is the default.codecounts only code lines.code-commentscounts 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
defaultkeeps{file: 500}. falsestarts 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 optionalmessage. falsefor 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: 4Groups
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 undersrc. - Entries are alternatives. A group with two paths matches either path.
pathis a.gitignoreline matched from the config’s root.!negation is not supported; useignoreon 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:
whereis a boolean over group names andlanguages.<name>.- Operators are
&&,||, and!, with parentheses. applyis a restriction name, an array of restriction names, orignore.- Every matching rule overlays its restrictions in order.
ignorestops 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-blockmeasures one comment block, with line and byte caps.comment-linesmeasures all comment lines in a file, with a line cap only.gapapplies to comment blocks and sets how many blank lines may sit between blocks before they count as one.containsis a case-sensitive filter for a custom comment scope.messageis the sentence reported for the measure.- A custom scope needs
select(comment-blockorcomment-lines) and amessage. - The
filescope measures the whole file and takes onlymessage.
scopes:
comment-block:
gap: 0
message: compact or move the comment
todo:
select: comment-block
contains: TODO
gap: 0
message: too many TODO commentsA 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: docsDiscovery 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=]LINESappends a rule that caps every file or one language.--ignore PATTERNappends an ignore rule.--countoverrides the config’s count mode.--hiddenoverrides the config’s hidden flag.--no-configskips 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.rssrc/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.