mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-10 12:28:25 +00:00
Diagnostic rendering was part of the data model: `Loc::FormatLocation` and `Loc::FormatSnippet` wrote plain text to a stream, so no capability, color, or terminal width could reach them. A diagnostic is now one message with labels, contexts, and location information attached, and `Diagnostics::Renderer` draws it into a `Terminal::Buffer`. The design is in `toolchain/docs/diagnostics_rendering.md` (#7668), authoring in `toolchain/docs/diagnostics.md`. Before: ``` example.carbon:6:3: error: 1 argument passed to function expecting 0 arguments Run0(1); ^~~~~~~ example.carbon:3:1: note: calling function declared here fn Run0() {} ^~~~~~~~~~~ ``` After: ``` error: 1 argument passed to function expecting 0 arguments ╭─┤ example.carbon:6:3 ┆ 3 │ fn Run0() {} · ─────┬───── · ╰──┤ calling function declared here ┆ -> 6 │ Run0(1); · ─────── ╰──────────── ``` `--no-diagnostic-snippets` gives a compact form, `example.carbon:6:3-9`. File tests use it; the rendering tests under `toolchain/diagnostics/testdata` ask for snippets. C++ interop diagnostics are data now rather than text Clang drew: `SemIR::ClangSourceLocId` names a `clang::SourceRange`, and a Clang location is marked as the point it names. `StreamConsumer` moves to a `:renderer` target that `:emitter` does not depend on, keeping `common/terminal` out of `consumer.h`. Capabilities come from the file behind the error stream, so tests get plain ASCII. `renderer_fuzzer` draws diagnostics built from fuzzer bytes with every capability combination, since a shape the renderer doesn't expect must never be why the compiler dies while reporting a problem. TODOs mark the follow-ups: line weights and crossing lines, wrapping that keeps a quoted type whole, and ordering diagnostics that share a byte offset. Also: `IncorrectExtension`'s hint moves into its message, since its note had no location of its own, and `strip_noise` in `check_diagnostics.py` blanks multi-line `#define`s instead of deleting them. Assisted-by: Claude Code
295 lines
8.9 KiB
YAML
295 lines
8.9 KiB
YAML
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
# Update versions with:
|
|
# pre-commit autoupdate --freeze && pre-commit run -a
|
|
# See https://pre-commit.com for more information
|
|
# See https://pre-commit.com/hooks.html for more hooks
|
|
|
|
default_language_version:
|
|
python: python3 # Defaults to python2, so override it.
|
|
|
|
repos:
|
|
- repo: builtin
|
|
hooks:
|
|
- id: check-added-large-files
|
|
- id: check-case-conflict
|
|
- id: check-executables-have-shebangs
|
|
- id: check-merge-conflict
|
|
- id: check-symlinks
|
|
exclude: ^bazel-execroot$
|
|
- id: check-yaml
|
|
- id: detect-private-key
|
|
- id: end-of-file-fixer
|
|
exclude: '^(.*/fuzzer_corpus/.*|.*\.svg)$'
|
|
- id: mixed-line-ending
|
|
args: ['--fix=lf']
|
|
exclude: '^(.*/fuzzer_corpus/.*|.*\.svg)$'
|
|
- id: trailing-whitespace
|
|
exclude: '^(.*/fuzzer_corpus/.*|.*/testdata/.*\.golden|.*\.svg)$'
|
|
|
|
# Run markdown linting early so that doc style and table-of-contents see the
|
|
# linted state.
|
|
- repo: https://github.com/rvben/rumdl-pre-commit
|
|
rev: v0.2.58
|
|
hooks:
|
|
- id: rumdl
|
|
args: [--fix]
|
|
|
|
- repo: https://github.com/google/pre-commit-tool-hooks
|
|
rev: efaea7c61c774c0b1a9805fd999e754a2d19dbd1 # frozen: v1.2.5
|
|
hooks:
|
|
- id: check-google-doc-style
|
|
exclude: |
|
|
(?x)^(
|
|
.*\.agents/.*|
|
|
.*AGENTS.md
|
|
)$
|
|
- id: markdown-toc
|
|
|
|
# Re-run markdown linting to fix any issues caused by doc style and TOC. This
|
|
# is very fast, so it shouldn't be problematic to run twice.
|
|
- repo: https://github.com/rvben/rumdl-pre-commit
|
|
rev: v0.2.58
|
|
hooks:
|
|
- id: rumdl
|
|
args: [--fix]
|
|
|
|
- repo: local
|
|
hooks:
|
|
- id: fix-cc-deps
|
|
name: Fix missing C++ deps
|
|
entry: scripts/fix_cc_deps.py
|
|
language: python
|
|
files: ^.*/(BUILD|[^/]+\.(h|cpp))$
|
|
pass_filenames: false
|
|
|
|
# Formatters should be run late so that they can re-format any prior changes.
|
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
rev: 0c7b6c989466a93942def1f84baf36ddfcd60c83 # frozen: v0.15.14
|
|
hooks:
|
|
- id: ruff-check
|
|
args: [--fix]
|
|
- id: ruff-format
|
|
|
|
- repo: local
|
|
hooks:
|
|
- id: ty
|
|
name: ty
|
|
entry: ty check --no-progress
|
|
language: python
|
|
additional_dependencies:
|
|
- ty==0.0.46
|
|
- rich
|
|
- 'gql>=2.0.0,<3.0.0'
|
|
- PyGitHub
|
|
- types-requests
|
|
- requests
|
|
types: [python]
|
|
pass_filenames: false
|
|
|
|
- repo: local
|
|
hooks:
|
|
- id: prettier
|
|
name: prettier
|
|
language: node
|
|
# TODO: Not upgrading to/past 3.4.0 due to list indent changes that may
|
|
# get fixed. See: https://github.com/prettier/prettier/issues/16929
|
|
additional_dependencies: ['prettier@3.3.3']
|
|
types_or: [html, javascript, json, yaml]
|
|
entry: npx prettier@3.3.3 --write --log-level=warn
|
|
- repo: local
|
|
hooks:
|
|
- id: buildifier
|
|
name: Bazel buildifier
|
|
entry: scripts/run_buildifier.py
|
|
# Beyond just formatting, explicitly fix lint warnings.
|
|
args: ['--lint=fix', '--warnings=all']
|
|
language: python
|
|
files: |
|
|
(?x)^(
|
|
.*BUILD.*|
|
|
.*MODULE.bazel.*|
|
|
.*WORKSPACE.*|
|
|
.*\.bzl
|
|
)$
|
|
- id: check-bazel-mod-deps
|
|
# Check this after buildifier because buildifier may modify inputs, and
|
|
# MODULE.bazel.lock includes line/column details.
|
|
name: Check bazel mod deps
|
|
entry: scripts/bazel_mod_deps.py
|
|
language: python
|
|
files: |
|
|
(?x)^(
|
|
.*MODULE.bazel.*|
|
|
.*WORKSPACE.*
|
|
)$
|
|
- id: clang-format
|
|
name: clang-format
|
|
entry: clang-format
|
|
types_or: [c++, def]
|
|
language: python
|
|
args: ['-i']
|
|
additional_dependencies: ['clang-format==21.1.8']
|
|
|
|
- repo: local
|
|
hooks:
|
|
- id: check-header-guards
|
|
# This should run after clang-format, which may reformat a guard.
|
|
name: Check header guards
|
|
entry: scripts/check_header_guards.py
|
|
language: python
|
|
files: ^.*\.h$
|
|
- id: check-sha-filenames
|
|
# This may rename files, so it's deliberately between formatters and
|
|
# linters.
|
|
name: Check fuzzer SHA filenames
|
|
entry: scripts/check_sha_filenames.py
|
|
language: python
|
|
files: ^.*/fuzzer_corpus/.*$
|
|
- id: check-proposal-names
|
|
name: Check proposal names
|
|
entry: proposals/scripts/check_proposal_names.py
|
|
language: python
|
|
files: ^proposals/p.*\.md$
|
|
# This edits files other than the ones passed to it, so we need each
|
|
# chunk of files to be run through the script serially.
|
|
require_serial: true
|
|
# This also renames files, invalidating the list of files provided to
|
|
# subsequent checks so we fail-fast if this makes changes.
|
|
fail_fast: true
|
|
- id: build-textmate-grammar
|
|
name: Build TextMate grammar
|
|
entry: scripts/update_tm_language.py
|
|
language: system
|
|
files: ^utils/vscode/carbon\.tmLanguage\.json$
|
|
pass_filenames: false
|
|
- id: check-toolchain-diagnostics
|
|
name: Check toolchain diagnostics
|
|
entry: toolchain/diagnostics/check_diagnostics.py
|
|
language: python
|
|
files: |
|
|
(?x)^(
|
|
toolchain/.*\.cpp|
|
|
toolchain/.*\.h|
|
|
toolchain/.*/testdata/.*|
|
|
toolchain/diagnostics/check_diagnostics\.py|
|
|
toolchain/diagnostics/kind\.def
|
|
)$
|
|
pass_filenames: false
|
|
|
|
# Run linters last, as formatters and other checks may fix issues.
|
|
- repo: local
|
|
hooks:
|
|
- id: forbid-llvm-googletest
|
|
name: Checks for deps on LLVM's version of GoogleTest
|
|
entry: scripts/forbid_llvm_googletest.py
|
|
language: python
|
|
files: ^.*/BUILD$
|
|
pass_filenames: false
|
|
- repo: https://github.com/codespell-project/codespell
|
|
rev: 2ccb47ff45ad361a21071a7eedda4c37e6ae8c5a # frozen: v2.4.2
|
|
hooks:
|
|
- id: codespell
|
|
args: ['-I', '.codespell_ignore', '--uri-ignore-words-list', '*']
|
|
# Test data may contain intentional misspellings, as well as short,
|
|
# meaningless identifiers that codespell incorrectly identifies as
|
|
# typos but that we would want to detect in other contexts.
|
|
exclude: |
|
|
(?x)^(
|
|
.*/testdata/.*|
|
|
.*/fuzzer_corpus/.*
|
|
)$
|
|
- repo: https://github.com/google/pre-commit-tool-hooks
|
|
rev: efaea7c61c774c0b1a9805fd999e754a2d19dbd1 # frozen: v1.2.5
|
|
hooks:
|
|
- id: check-copyright
|
|
args:
|
|
- --copyright
|
|
- |+
|
|
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
Exceptions. See /LICENSE for license information.
|
|
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
- --custom_format
|
|
- '\.(carbon|c|json|scss|ypp)(\.tmpl)?$'
|
|
- ''
|
|
- '// '
|
|
- ''
|
|
- --custom_format
|
|
- '\.(js|ts|mjs)$'
|
|
- '/*'
|
|
- ' * '
|
|
- ' */'
|
|
- --custom_format
|
|
- '\.(l|lpp|y)$'
|
|
- '/*'
|
|
- ''
|
|
- '*/'
|
|
- --custom_format
|
|
- '\.(plist|tmLanguage)$'
|
|
- '<!--'
|
|
- ''
|
|
- '\-->'
|
|
- --custom_format
|
|
- '\.vim$'
|
|
- ''
|
|
- '" '
|
|
- ''
|
|
- --custom_format
|
|
- '\.scm$'
|
|
- ''
|
|
- '; '
|
|
- ''
|
|
- --custom_format
|
|
- '\.lua$'
|
|
- ''
|
|
- '\-- '
|
|
- ''
|
|
exclude: |
|
|
(?x)^(
|
|
.bazelversion|
|
|
.github/pull_request_template.md|
|
|
.python-version|
|
|
LICENSE.*|
|
|
compile_flags.txt|
|
|
github_tools/requirements.txt|
|
|
third_party/.*|
|
|
utils/vscode/esbuild.js|
|
|
website/.ruby-version|
|
|
website/Gemfile.lock|
|
|
.*\.def|
|
|
.*\.png|
|
|
.*\.svg|
|
|
.*/fuzzer_corpus/.*|
|
|
.*/testdata/.*\.golden
|
|
)$
|
|
- id: check-links
|
|
- repo: local
|
|
hooks:
|
|
- id: check-build-graph
|
|
name: Check build graph
|
|
entry: scripts/check_build_graph.py
|
|
language: python
|
|
pass_filenames: false
|
|
files: |
|
|
(?x)^(
|
|
.*BUILD.*|
|
|
.*MODULE.bazel.*|
|
|
.*WORKSPACE.*|
|
|
.*\.bzl
|
|
)$
|
|
|
|
# This excludes third-party code, and patches to third-party code.
|
|
exclude: |
|
|
(?x)^(
|
|
\.jj/.*|
|
|
MODULE.bazel.lock|
|
|
.*package-lock\.json|
|
|
bazel/bazel_clang_tidy/.*\.patch|
|
|
bazel/google_benchmark/.*\.patch|
|
|
bazel/libpfm/.*\.patch|
|
|
bazel/llvm_project/.*\.patch|
|
|
third_party/examples/.*/carbon/.*|
|
|
)$
|