/// The Plugin interface of codeint.
/// A change that breaks a Plugin built against this version needs a new version.
package codeint:plugin@0.5.0;
/// The interface a Language plugin exports: the file extensions it reads, and the Code model of each such file.
interface language {
/// Coverage counts for one function from Coverage reports.
record function-coverage {
/// The count of the function's lines listed by a Coverage report.
listed-lines: u32,
/// The count of those listed lines executed by tests.
executed-lines: u32,
}
/// One function of a source file.
/// A nested function is a function of its own and adds no decision points to the function around it.
record function {
/// The line where the function starts, counted from 1.
line: u32,
/// The line where the function ends, counted from 1; the same as `line` for a function on one line.
end-line: u32,
/// The decision points of the function, not counting those of nested functions.
decision-points: u32,
/// The source lines of the function, not counting lines of nested functions.
source-lines: u32,
/// The optional name of the function or method; `none` for anonymous lambdas and closures.
name: option<string>,
/// The nesting-weighted cognitive complexity of the function, not counting nested functions.
cognitive-complexity: u32,
/// Coverage counts for the function from Coverage reports; `none` when no Coverage report covers the function.
/// A Language plugin always returns `none`; codeint fills this in before Metrics run.
coverage: option<function-coverage>,
}
/// What a token is to clone detection, by the rules of the Language plugin.
enum token-kind {
/// A name the code chooses, such as a variable, function, parameter, type, or property name.
/// Clone detection treats every identifier as the same token.
identifier,
/// A literal value, such as a string, number, boolean, null, regular expression, or template text.
/// Clone detection treats every literal as the same token.
literal,
/// Any other token, such as a keyword, an operator, or punctuation.
/// Clone detection compares these by their text hash.
other,
/// Any token of a declaration that only imports or exports names, such as a TypeScript `import`, `export { a } from`, or `export { a }` declaration.
/// Which declarations count is a rule of the Language plugin.
/// Clone detection never matches these tokens, because a list of names repeats only its shape.
import-or-export,
}
/// The group a source file belongs to.
/// Every source file belongs to exactly one Source set, and every Metric reports each Source set separately.
enum source-set {
/// Code that ships, the default for a file that no other rule claims.
production,
/// Code that only tests run, such as a TypeScript `*.test.ts` file.
test,
/// Code that a tool writes, such as build output.
generated,
/// Third-party code copied into the repository.
vendored,
}
/// One token of a source file, so never whitespace or a comment.
record token {
/// Whether the token is an identifier, a literal, another token, or a token of an import or export declaration.
kind: token-kind,
/// The 64-bit FNV-1a hash of the token's UTF-8 text as written.
text-hash: u64,
/// The 1-based line on which the token starts.
line: u32,
}
/// A source line that matches a Flagged-line rule of the Language plugin.
record flagged-line {
/// The line number, counted from 1.
line: u32,
/// The stable identifier of the rule the line matched, such as `else-after-return`.
rule: string,
}
/// A source line that matches a Hazard-line rule of the Language plugin.
/// Never holds source text.
record hazard-line {
/// The line number, counted from 1.
line: u32,
/// The stable identifier of the rule the line matched, listed in `hazard-rules`.
rule: string,
}
/// One non-fatal diagnostic emitted while lowering a source file.
record file-diagnostic {
/// The 1-based line number where the diagnostic applies.
line: u32,
/// A stable machine-readable category for the diagnostic, such as `rejected-statement`.
kind: string,
/// A human-readable description of the diagnostic.
message: string,
}
/// The Code model of one source file.
record file-model {
/// The Source set of the file, chosen by the rules of the Language plugin.
source-set: source-set,
/// The lines that hold code, so not a blank line or a line with only comments.
source-lines: u32,
/// Every function of the file, in the order their first lines appear.
functions: list<function>,
/// Every token of the file, in source order.
tokens: list<token>,
/// Each Flagged line with the rule it matched; a line that matches two rules appears once per rule.
flagged-lines: list<flagged-line>,
/// Each Hazard line with the rule it matched; a line that matches two rules appears once per rule.
/// Empty when `has-hazard-rules` returns false.
hazard-lines: list<hazard-line>,
/// The module specifiers of the imports that run when the file runs, in source order, such as `./greet`.
/// Type-only imports are left out.
runtime-imports: list<string>,
/// Whether the file starts a program as shown by its source text, such as a Go `package main` file.
/// False unless the Language plugin sets it.
program-start: bool,
/// Whether the file is a language-specific Tooling file, such as a config or build script.
/// False unless the Language plugin sets it.
is-tooling-file: bool,
/// Non-fatal per-file diagnostics collected while lowering this file.
diagnostics: list<file-diagnostic>,
/// Optional opaque bytes passed back into `analyze-scope` for cross-file analysis.
/// `none` unless `has-scope-analysis` returns true.
scope-artifact: option<list<u8>>,
}
/// One runtime import to resolve: the file that imports, and the specifier it names.
record import-request {
/// The importing file, relative to the repository root, with forward slashes.
importer: string,
/// The module specifier exactly as the file writes it.
specifier: string,
}
/// Where a runtime import leads.
variant resolution {
/// The import names one or more files of the repository, relative to the root, with forward slashes.
/// An empty list is a Plugin error.
resolved(list<string>),
/// The import names a third-party package outside the repository; the payload is the canonical package name.
external(string),
/// The import names a standard-library or runtime built-in module.
builtin,
/// The import should name a file of the repository, but none matches; the payload says why.
unresolved(string),
}
/// How a package manifest declares an external dependency.
enum dep-kind {
/// A dependency required at runtime in production.
runtime,
/// A dependency used only during development or testing.
dev,
/// An optional or peer dependency.
optional,
}
/// One external dependency declared in a package manifest.
record declared-dep {
/// The package root folder relative to the repository root, with forward slashes, or empty for the repository root.
package-root: string,
/// The normalized package name as declared by the manifest.
name: string,
/// Whether the dependency is declared as runtime, dev, or optional.
kind: dep-kind,
}
/// Why a Language plugin cannot lower a file.
variant lower-error {
/// The file does not parse; the payload is the parser's message.
unparsable(string),
/// No rule of the Language plugin covers the file; the payload says why.
unsupported-file(string),
/// The file has more source lines than a `u32` holds.
too-large,
/// The file only declares types and holds no code to measure, such as a TypeScript `.d.ts` file.
declaration-only,
}
/// A file that a Language plugin reads to find workspace packages and resolve imports, such as a `package.json` or `tsconfig.json` file, as the host read it.
record manifest {
/// The path of the file, relative to the repository root, with forward slashes.
path: string,
/// The whole file.
text: string,
}
/// Why a Language plugin could not parse one manifest.
record workspace-error {
/// The path of the manifest that holds the problem, relative to the repository root.
path: string,
/// What is wrong with the manifest.
message: string,
}
/// Ownership mapping between a dependency manifest file and its Workspace package root.
record dependency-manifest-owner {
/// The package root folder relative to the repository root, with forward slashes, or empty for the repository root.
package-root: string,
/// The manifest path relative to the repository root, with forward slashes.
path: string,
}
/// An external dependency referenced inside a manifest or script rather than a source-file import.
record package-dependency {
/// The package root folder relative to the repository root, with forward slashes, or empty for the repository root.
package-root: string,
/// The normalized external package name referenced by the manifest.
name: string,
}
/// Consolidated manifest analysis for one repository snapshot in a single pass.
record manifest-analysis {
/// The root folder of each workspace member package, relative to the repository root, with forward slashes.
/// The repository root is never in the list; an empty list means the repository is one package.
workspace-packages: list<string>,
/// Manifests that could not be parsed and were skipped during analysis, with their exact paths and reasons.
invalid-manifests: list<workspace-error>,
/// Manifest files that own dependencies for a package root.
dependency-manifests: list<dependency-manifest-owner>,
/// External dependencies declared in the valid manifests.
declared-dependencies: list<declared-dep>,
/// External dependencies used by manifest scripts or configuration rather than source imports.
manifest-used-dependencies: list<package-dependency>,
/// Package roots whose dependencies inherit from the repository root package, such as npm workspace hoisting.
root-dependency-inheritance: list<string>,
}
/// Active Framework profiles for one Workspace package.
record package-framework-profiles {
/// The package root folder relative to the repository root, with forward slashes, or empty for the repository root.
package-root: string,
/// The active Framework profile names for this Workspace package.
active-profiles: list<string>,
}
/// One file's opaque scope artifact passed back into `analyze-scope`.
record file-scope-artifact {
/// The path of the file, relative to the repository root, with forward slashes.
path: string,
/// The settled Source set of the file.
source-set: source-set,
/// The opaque byte artifact returned by `lower` for this file.
artifact: list<u8>,
}
/// Extra Hazard lines discovered for one file during cross-file scope analysis.
record file-hazards {
/// The path of the file, relative to the repository root, with forward slashes.
path: string,
/// Additional Hazard lines for this file, each naming a rule in `hazard-rules`.
hazard-lines: list<hazard-line>,
}
/// One key-value field in a language-neutral scope summary.
record summary-field {
/// The stable machine-readable field key, such as `tables`.
key: string,
/// The string-encoded field value.
value: string,
}
/// A language-neutral summary emitted by cross-file scope analysis.
record scope-summary {
/// A stable kind identifier for this summary, such as `sql-schema`.
kind: string,
/// Key-value metadata fields for this summary.
fields: list<summary-field>,
}
/// Result of cross-file scope analysis for one `(package-root, dialect)` group.
record scope-analysis {
/// Additional Hazard lines discovered across files in the scope.
extra-hazards: list<file-hazards>,
/// Language-neutral summaries for this scope.
summaries: list<scope-summary>,
}
/// The file extensions the Language plugin reads, each without its leading dot, such as `ts`.
extensions: func() -> list<string>;
/// The stable names of Dialects this Language plugin accepts in `lower`, such as `postgresql` or `sqlite`.
/// Empty when the Language plugin has no selectable Dialects.
known-dialects: func() -> list<string>;
/// Lowers one file into its Code model.
/// `path` is relative to the repository root and uses forward slashes.
/// `text` is the whole file.
/// `dialect` is an optional Dialect name from `known-dialects`, or `none` for the plugin's default Dialect.
lower: func(path: string, text: string, dialect: option<string>) -> result<file-model, lower-error>;
/// The stable names of the Flagged line rules this Language plugin may emit.
flagged-line-rules: func() -> list<string>;
/// Chooses the files of one repository snapshot that the host reads once and passes to `analyze-manifests`, `resolve-imports`, and `entry-points`, because a Plugin cannot read files.
/// `repository-paths` lists every file of the snapshot, relative to the root, with forward slashes.
/// The result names only paths from `repository-paths`, such as each `package.json` and `tsconfig.json` file.
manifest-paths: func(repository-paths: list<string>) -> list<string>;
/// Analyzes the selected manifests in a single pass to discover workspace packages, skipped invalid manifests, dependency ownership, declared dependencies, manifest-used dependencies, and root-dependency inheritance.
/// `manifests` holds each file that `manifest-paths` chose, with its text.
analyze-manifests: func(manifests: list<manifest>) -> manifest-analysis;
/// Resolves runtime imports against the files of one repository snapshot.
/// `repository-paths` lists every file of the snapshot, relative to the root, with forward slashes.
/// `manifests` holds each file that `manifest-paths` chose, with its text.
/// `requests` lists the runtime imports to resolve.
/// `package-profiles` lists the active Framework profile names per Workspace package, so monorepos resolve imports in one pass.
/// The result holds one resolution per request, in request order.
resolve-imports: func(repository-paths: list<string>, manifests: list<manifest>, requests: list<import-request>, package-profiles: list<package-framework-profiles>) -> list<resolution>;
/// Discovers standard entry-point source files from the repository paths and selected manifests.
/// `repository-paths` lists every file of the snapshot, relative to the root, with forward slashes.
/// `manifests` holds each file that `manifest-paths` chose, with its text.
/// Every returned path must come from `repository-paths`.
entry-points: func(repository-paths: list<string>, manifests: list<manifest>) -> list<string>;
/// The published typical value of one Metric for codebases in the language of the Language plugin.
record reference-range {
/// The Metric, by its key in the report: `erosion`, `verbosity`, `duplication`, or `import_cycles`.
metric: string,
/// The positive integer version of the Metric that this Reference range was calibrated against.
metric-version: u32,
/// The lowest typical ratio, from 0 to 1.
low: f64,
/// The highest typical ratio, from `low` to 1.
high: f64,
/// Where the range was published and what it measured, shown next to the range.
source: string,
}
/// The Reference ranges measured in the language of this Language plugin, at most one per Metric.
/// A Metric without an entry has no published Reference range for this language.
/// codeint shows a range only next to values that this Language plugin measured.
reference-ranges: func() -> list<reference-range>;
/// How the host asks a Language plugin to select Framework profiles for one Workspace package.
variant framework-profile-selection {
/// Auto-detect every matching Framework profile from files and manifests.
auto,
/// Disable all Framework profiles for this Workspace package.
disabled,
/// Auto-detect Framework profiles, leaving out the named profiles.
exclude(list<string>),
/// Activate only the named Framework profiles for this Workspace package.
only(list<string>),
}
/// The resolved Framework profiles and package-level conventions for one Workspace package.
record framework-profile-result {
/// The stable names of the active Framework profiles for this Workspace package, each listed in `known-framework-profiles`.
active-profiles: list<string>,
/// Framework convention entry-point source files, each coming from `files`.
entry-points: list<string>,
/// Framework convention generated file paths, each coming from `files`.
generated-paths: list<string>,
/// Framework-specific Reference ranges for this Workspace package; empty means use the language's default `reference-ranges`.
reference-ranges: list<reference-range>,
/// An optional note explaining why framework Reference ranges were selected or fell back.
reference-range-note: option<string>,
}
/// The stable names of the Framework profiles this Language plugin knows.
/// Empty when the Language plugin defines no Framework profiles.
known-framework-profiles: func() -> list<string>;
/// Resolves active Framework profiles and package-level conventions for one Workspace package.
/// `package-root` is the package root folder relative to the repository root, with forward slashes, or empty for the repository root.
/// `files` lists the repository-relative file paths belonging to this Workspace package, with forward slashes.
/// `manifests` holds the manifests relevant to this Workspace package, with their text.
/// `selection` chooses automatic detection or an explicit per-package override.
resolve-framework-profiles: func(package-root: string, files: list<string>, manifests: list<manifest>, selection: framework-profile-selection) -> result<framework-profile-result, string>;
/// Whether this Language plugin defines Hazard line rules.
/// When false, the Hazards Metric is absent for this language rather than 0.
has-hazard-rules: func() -> bool;
/// The stable names of the Hazard line rules this Language plugin may emit.
/// Empty when `has-hazard-rules` returns false.
hazard-rules: func() -> list<string>;
/// Whether this language has runtime imports, manifests, and entry points.
/// When false, codeint never calls `manifest-paths`, `analyze-manifests`, `resolve-imports`,
/// or `entry-points`, and import Metrics are absent for this language.
has-imports: func() -> bool;
/// Whether this Language plugin performs cross-file scope analysis over opaque `scope-artifact` bytes.
has-scope-analysis: func() -> bool;
/// Runs cross-file scope analysis over one `(package-root, dialect)` group of lowered files.
/// `package-root` is the package root folder relative to the repository root, with forward slashes, or empty for the repository root.
/// `dialect` is the optional Dialect name active for this group.
/// `artifacts` holds each file's path, settled Source set, and opaque artifact bytes from `lower`.
analyze-scope: func(package-root: string, dialect: option<string>, artifacts: list<file-scope-artifact>) -> scope-analysis;
}
/// A Language plugin exports `language` and imports nothing.
world language-plugin {
export language;
}