diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a76f587ced1ba..5f703fc8d05bc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: args: ['--fix=lf'] - id: trailing-whitespace - repo: https://github.com/google/pre-commit-tool-hooks - rev: v1.0.4 + rev: v1.1.1 hooks: - id: check-copyright args: @@ -34,6 +34,8 @@ repos: Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception exclude: '^src/jekyll/(Gemfile.lock|theme/.*)$' + - id: check-google-doc-style + - id: markdown-toc - repo: https://github.com/codespell-project/codespell rev: v1.17.1 hooks: @@ -42,14 +44,6 @@ repos: exclude: '^src/jekyll/Gemfile.lock$' - repo: local hooks: - - id: markdown-toc - name: Update table of contents - description: Runs https://github.com/jonschlinkert/markdown-toc - entry: src/scripts/pre_commit_toc.js - language: node - additional_dependencies: [markdown-toc] - files: .*\.md$ - exclude: ^src/jekyll/theme/ - id: proposal-list name: Update list of proposals description: Updates the list of proposals in proposals/README.md @@ -67,3 +61,8 @@ repos: hooks: - id: prettier exclude: ^src/jekyll/theme/ + # Run linters last, as formatters and other checks may fix issues. + - repo: https://gitlab.com/PyCQA/flake8 + rev: 3.8.4 + hooks: + - id: flake8 diff --git a/docs/design/README.md b/docs/design/README.md index a56cdba512acc..fcef086c207a7 100644 --- a/docs/design/README.md +++ b/docs/design/README.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Context and disclaimer](#context-and-disclaimer) - [Example code](#example-code) - [Basic syntax](#basic-syntax) diff --git a/docs/design/aliases.md b/docs/design/aliases.md index fd638ee081849..16711ac41f272 100644 --- a/docs/design/aliases.md +++ b/docs/design/aliases.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Alternatives](#alternatives) diff --git a/docs/design/blocks_and_statements.md b/docs/design/blocks_and_statements.md index 29be2319873f1..fbbd4e5939b1c 100644 --- a/docs/design/blocks_and_statements.md +++ b/docs/design/blocks_and_statements.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) diff --git a/docs/design/code_and_name_organization/README.md b/docs/design/code_and_name_organization/README.md index 14a7eaf030c2e..cf7fb413ac486 100644 --- a/docs/design/code_and_name_organization/README.md +++ b/docs/design/code_and_name_organization/README.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Goals and philosophy](#goals-and-philosophy) - [Overview](#overview) - [Sizing packages and libraries](#sizing-packages-and-libraries) diff --git a/docs/design/code_and_name_organization/source_files.md b/docs/design/code_and_name_organization/source_files.md index 5a515024ec2d0..2289c110ba604 100644 --- a/docs/design/code_and_name_organization/source_files.md +++ b/docs/design/code_and_name_organization/source_files.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Overview](#overview) - [Encoding](#encoding) - [References](#references) diff --git a/docs/design/control_flow.md b/docs/design/control_flow.md index ffb1da57081e3..77fa167afe0d5 100644 --- a/docs/design/control_flow.md +++ b/docs/design/control_flow.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Open questions](#open-questions) diff --git a/docs/design/functions.md b/docs/design/functions.md index 2b2c89f3ef532..e954d8187fd52 100644 --- a/docs/design/functions.md +++ b/docs/design/functions.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Basic functions](#basic-functions) diff --git a/docs/design/interoperability/README.md b/docs/design/interoperability/README.md index 2377a775d3940..7329af511c07f 100644 --- a/docs/design/interoperability/README.md +++ b/docs/design/interoperability/README.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) diff --git a/docs/design/lexical_conventions/README.md b/docs/design/lexical_conventions/README.md index 2d819389941c2..8903ab698e52f 100644 --- a/docs/design/lexical_conventions/README.md +++ b/docs/design/lexical_conventions/README.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Lexical elements](#lexical-elements) diff --git a/docs/design/lexical_conventions/numeric_literals.md b/docs/design/lexical_conventions/numeric_literals.md index 582896dbc4c50..68e210ac4895f 100644 --- a/docs/design/lexical_conventions/numeric_literals.md +++ b/docs/design/lexical_conventions/numeric_literals.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Overview](#overview) - [Details](#details) - [Integer literals](#integer-literals) diff --git a/docs/design/lexical_conventions/whitespace.md b/docs/design/lexical_conventions/whitespace.md index 91280fc354da8..dd323d01b69ad 100644 --- a/docs/design/lexical_conventions/whitespace.md +++ b/docs/design/lexical_conventions/whitespace.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Overview](#overview) diff --git a/docs/design/lexical_conventions/words.md b/docs/design/lexical_conventions/words.md index fb50908f5a5f1..cab177d71bf04 100644 --- a/docs/design/lexical_conventions/words.md +++ b/docs/design/lexical_conventions/words.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Overview](#overview) - [Alternatives](#alternatives) diff --git a/docs/design/metaprogramming.md b/docs/design/metaprogramming.md index bb8e4e969ddba..6c6a98e9d72d8 100644 --- a/docs/design/metaprogramming.md +++ b/docs/design/metaprogramming.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) diff --git a/docs/design/name_lookup.md b/docs/design/name_lookup.md index 8ca5beff8ebfe..d1e26049efa38 100644 --- a/docs/design/name_lookup.md +++ b/docs/design/name_lookup.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Unqualified name lookup](#unqualified-name-lookup) diff --git a/docs/design/naming_conventions.md b/docs/design/naming_conventions.md index 860762db78b51..127a9763ec1ec 100644 --- a/docs/design/naming_conventions.md +++ b/docs/design/naming_conventions.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) diff --git a/docs/design/operators.md b/docs/design/operators.md index 8655f31fde29f..f21873bb577e8 100644 --- a/docs/design/operators.md +++ b/docs/design/operators.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) diff --git a/docs/design/pattern_matching.md b/docs/design/pattern_matching.md index 67049b22f0d62..51c92e086af58 100644 --- a/docs/design/pattern_matching.md +++ b/docs/design/pattern_matching.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Pattern match control flow](#pattern-match-control-flow) diff --git a/docs/design/primitive_types.md b/docs/design/primitive_types.md index 0c57f9d3b765b..ff7c40333fbd2 100644 --- a/docs/design/primitive_types.md +++ b/docs/design/primitive_types.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Integers](#integers) diff --git a/docs/design/structs.md b/docs/design/structs.md index e8c3299468e59..de005b7abfac4 100644 --- a/docs/design/structs.md +++ b/docs/design/structs.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Open questions](#open-questions) diff --git a/docs/design/syntactic_conventions.md b/docs/design/syntactic_conventions.md index 0dae575207de8..b3b979a9e0159 100644 --- a/docs/design/syntactic_conventions.md +++ b/docs/design/syntactic_conventions.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Alternatives](#alternatives) diff --git a/docs/design/templates.md b/docs/design/templates.md index 2763faa663f93..8803090e5fb7f 100644 --- a/docs/design/templates.md +++ b/docs/design/templates.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Types with template parameters](#types-with-template-parameters) diff --git a/docs/design/tuples.md b/docs/design/tuples.md index d3b64bfdf06c6..9e38fda91189a 100644 --- a/docs/design/tuples.md +++ b/docs/design/tuples.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Indices as compile-time constants](#indices-as-compile-time-constants) diff --git a/docs/design/variables.md b/docs/design/variables.md index f52a922385c96..a56c626ca1389 100644 --- a/docs/design/variables.md +++ b/docs/design/variables.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [TODO](#todo) - [Overview](#overview) - [Declaring constants](#declaring-constants) diff --git a/docs/project/code_review.md b/docs/project/code_review.md index afea8020347e5..2d54f84cc9543 100644 --- a/docs/project/code_review.md +++ b/docs/project/code_review.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [High level goals of code review](#high-level-goals-of-code-review) - [What requires review?](#what-requires-review) - [Who should review?](#who-should-review) diff --git a/docs/project/contribution_tools.md b/docs/project/contribution_tools.md index 376297cba48f1..108c90cc27be7 100644 --- a/docs/project/contribution_tools.md +++ b/docs/project/contribution_tools.md @@ -9,10 +9,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception The Carbon language project has a number of tools used to assist in preparing contributions. -## Table of contents - +## Table of contents + - [Main tools](#main-tools) - [brew](#brew) - [pyenv and Python](#pyenv-and-python) diff --git a/docs/project/cpp_style_guide.md b/docs/project/cpp_style_guide.md index 4c86ee806ae0e..df3d5ffe3b744 100644 --- a/docs/project/cpp_style_guide.md +++ b/docs/project/cpp_style_guide.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Background](#background) - [Baseline](#baseline) - [Carbon-local guidance](#carbon-local-guidance) diff --git a/docs/project/goals.md b/docs/project/goals.md index 94ff0a0cc9084..8a61759d6eae8 100644 --- a/docs/project/goals.md +++ b/docs/project/goals.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Overview](#overview) - [Project goals](#project-goals) - [Community and culture](#community-and-culture) diff --git a/docs/project/principles/success_criteria.md b/docs/project/principles/success_criteria.md index 45b748d84ce06..0f3aa09055b0b 100644 --- a/docs/project/principles/success_criteria.md +++ b/docs/project/principles/success_criteria.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Principle](#principle) - [Applications of these principles](#applications-of-these-principles) - [Modern OS platforms, hardware architectures, and environments](#modern-os-platforms-hardware-architectures-and-environments) diff --git a/docs/project/pull_request_workflow.md b/docs/project/pull_request_workflow.md index 4a788790a3f26..c5baef1cbc723 100644 --- a/docs/project/pull_request_workflow.md +++ b/docs/project/pull_request_workflow.md @@ -6,10 +6,10 @@ Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception --> -## Table of contents - +## Table of contents + - [Trunk based development](#trunk-based-development) - [Green tests](#green-tests) - [Always use pull requests (with review) rather than pushing directly](#always-use-pull-requests-with-review-rather-than-pushing-directly) diff --git a/proposals/p0044.md b/proposals/p0044.md index 3aa92dcc05c77..5b4f0bb7c7e7b 100644 --- a/proposals/p0044.md +++ b/proposals/p0044.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/44) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Proposal](#proposal) diff --git a/proposals/p0051.md b/proposals/p0051.md index 872c3c6fa2aff..edde8743d980c 100644 --- a/proposals/p0051.md +++ b/proposals/p0051.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/51) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Proposal](#proposal) diff --git a/proposals/p0074.md b/proposals/p0074.md index 8cff57ccb7ce7..9ebfb2038b43b 100644 --- a/proposals/p0074.md +++ b/proposals/p0074.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/74) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Proposal](#proposal) diff --git a/proposals/p0083.md b/proposals/p0083.md index 8feee2883379f..f76c2f6327f1f 100644 --- a/proposals/p0083.md +++ b/proposals/p0083.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/83) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Goals](#goals) - [Background](#background) diff --git a/proposals/p0107.md b/proposals/p0107.md index 6869176ccbc83..00fe4686350e3 100644 --- a/proposals/p0107.md +++ b/proposals/p0107.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/107) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Proposal](#proposal) - [Out-of-scope issues](#out-of-scope-issues) diff --git a/proposals/p0113.md b/proposals/p0113.md index a02eda10fdb7a..b76e6482f2b5f 100644 --- a/proposals/p0113.md +++ b/proposals/p0113.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/113) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Proposal](#proposal) diff --git a/proposals/p0120.md b/proposals/p0120.md index 083176434e090..2e43844f25dfd 100644 --- a/proposals/p0120.md +++ b/proposals/p0120.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/120) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Proposal](#proposal) - [Justification](#justification) diff --git a/proposals/p0142.md b/proposals/p0142.md index aa2f302e40c6c..c57f6f92abb4f 100644 --- a/proposals/p0142.md +++ b/proposals/p0142.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/142) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Proposal](#proposal) diff --git a/proposals/p0143.md b/proposals/p0143.md index aa9046c200827..70dc61450e665 100644 --- a/proposals/p0143.md +++ b/proposals/p0143.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/143) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Proposal](#proposal) diff --git a/proposals/p0149.md b/proposals/p0149.md index 97de66da1ac02..c561d3e3d6cb9 100644 --- a/proposals/p0149.md +++ b/proposals/p0149.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/149) -## Table of contents - +## Table of contents + - [Problem](#problem) - [Background](#background) - [Common deviations](#common-deviations) diff --git a/proposals/template.md b/proposals/template.md index 0c26a7c755b07..c6e4d2826829e 100644 --- a/proposals/template.md +++ b/proposals/template.md @@ -8,10 +8,10 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception [Pull request](https://github.com/carbon-language/carbon-lang/pull/####) -## Table of contents - +## Table of contents + - [TODO: Initial proposal setup](#todo-initial-proposal-setup) - [Problem](#problem) - [Background](#background) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000..61bbd48cf3dbf --- /dev/null +++ b/setup.cfg @@ -0,0 +1,6 @@ +# 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 + +[flake8] +max-line-length = 80 diff --git a/src/scripts/new_proposal_test.py b/src/scripts/new_proposal_test.py index 495d01a24fcae..362907badf74b 100644 --- a/src/scripts/new_proposal_test.py +++ b/src/scripts/new_proposal_test.py @@ -57,9 +57,7 @@ def test_run_success(self): new_proposal._run(["true"]) def test_run_failure(self): - with mock.patch( - "new_proposal._exit", side_effect=_fake_exit - ) as mock_exit: + with mock.patch("new_proposal._exit", side_effect=_fake_exit): self.assertRaises(FakeExitError, new_proposal._run, ["false"]) diff --git a/src/scripts/pre_commit_toc.js b/src/scripts/pre_commit_toc.js deleted file mode 100755 index b27037bf8f142..0000000000000 --- a/src/scripts/pre_commit_toc.js +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env node - -/* -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 -*/ - -/* -Runs markdown-toc for pre-commits. This is necessary to handle multiple file -arguments, which markdown-toc does not. - -Humans should generally use markdown-toc following the install instructions -from https://github.com/jonschlinkert/markdown-toc. -*/ - -const mdtoc = require('markdown-toc'); -const fs = require('fs'); - -var error = 0; -const files = process.argv.slice(2); -for (var i = 0; i < files.length; ++i) { - const file = files[i]; - const oldContent = fs.readFileSync(file).toString(); - var newContent = oldContent; - - // Only process files with the toc indicator. - if (!oldContent.match(//m)) continue; - - // If there's a case-incorrect toc section, fix casing. - newContent = newContent.replace( - /\n## Table of contents\n\n\n/im, - '\n## Table of contents\n\n\n' - ); - if (oldContent != newContent) { - console.log(`Fixed "Table of contents" header in ${file}`); - } - - // Ensure the file properly labels the toc. - if (!newContent.match(/\n## Table of contents\n\n\n/m)) { - error = 1; - console.log( - `${file} has a toc without a "Table of contents" header. Use:\n` + - ' ## Table of contents\n\n \n' - ); - continue; - } - - // Do the toc substitution. Resulting indents will look like: - // - H1 - // - H2 - newContent = mdtoc.insert(newContent, { indent: ' ', bullets: '- ' }); - - if (oldContent != newContent) { - console.log(`Updating ${file}`); - fs.writeFileSync(file, newContent); - } -} -process.exit(error);