瀏覽代碼

Update pre-commits, add and address flake8 (#195)

Adopts new copyright and markdown toc checks.

The new toc check generates the toc header, so that's why all the md files changed (this had felt better to me for the long-term, more auto-generated content)
Jon Meow 5 年之前
父節點
當前提交
79a9b51d07
共有 44 個文件被更改,包括 95 次插入151 次删除
  1. 8 9
      .pre-commit-config.yaml
  2. 2 2
      docs/design/README.md
  3. 2 2
      docs/design/aliases.md
  4. 2 2
      docs/design/blocks_and_statements.md
  5. 2 2
      docs/design/code_and_name_organization/README.md
  6. 2 2
      docs/design/code_and_name_organization/source_files.md
  7. 2 2
      docs/design/control_flow.md
  8. 2 2
      docs/design/functions.md
  9. 2 2
      docs/design/interoperability/README.md
  10. 2 2
      docs/design/lexical_conventions/README.md
  11. 2 2
      docs/design/lexical_conventions/numeric_literals.md
  12. 2 2
      docs/design/lexical_conventions/whitespace.md
  13. 2 2
      docs/design/lexical_conventions/words.md
  14. 2 2
      docs/design/metaprogramming.md
  15. 2 2
      docs/design/name_lookup.md
  16. 2 2
      docs/design/naming_conventions.md
  17. 2 2
      docs/design/operators.md
  18. 2 2
      docs/design/pattern_matching.md
  19. 2 2
      docs/design/primitive_types.md
  20. 2 2
      docs/design/structs.md
  21. 2 2
      docs/design/syntactic_conventions.md
  22. 2 2
      docs/design/templates.md
  23. 2 2
      docs/design/tuples.md
  24. 2 2
      docs/design/variables.md
  25. 2 2
      docs/project/code_review.md
  26. 2 2
      docs/project/contribution_tools.md
  27. 2 2
      docs/project/cpp_style_guide.md
  28. 2 2
      docs/project/goals.md
  29. 2 2
      docs/project/principles/success_criteria.md
  30. 2 2
      docs/project/pull_request_workflow.md
  31. 2 2
      proposals/p0044.md
  32. 2 2
      proposals/p0051.md
  33. 2 2
      proposals/p0074.md
  34. 2 2
      proposals/p0083.md
  35. 2 2
      proposals/p0107.md
  36. 2 2
      proposals/p0113.md
  37. 2 2
      proposals/p0120.md
  38. 2 2
      proposals/p0142.md
  39. 2 2
      proposals/p0143.md
  40. 2 2
      proposals/p0149.md
  41. 2 2
      proposals/template.md
  42. 6 0
      setup.cfg
  43. 1 3
      src/scripts/new_proposal_test.py
  44. 0 59
      src/scripts/pre_commit_toc.js

+ 8 - 9
.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

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Context and disclaimer](#context-and-disclaimer)
     -   [Example code](#example-code)
 -   [Basic syntax](#basic-syntax)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Alternatives](#alternatives)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Goals and philosophy](#goals-and-philosophy)
 -   [Overview](#overview)
     -   [Sizing packages and libraries](#sizing-packages-and-libraries)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Overview](#overview)
 -   [Encoding](#encoding)
 -   [References](#references)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 -   [Open questions](#open-questions)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Basic functions](#basic-functions)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Lexical elements](#lexical-elements)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Overview](#overview)
 -   [Details](#details)
     -   [Integer literals](#integer-literals)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Overview](#overview)
 
 <!-- tocstop -->

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Overview](#overview)
 -   [Alternatives](#alternatives)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Unqualified name lookup](#unqualified-name-lookup)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 
 <!-- tocstop -->

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Pattern match control flow](#pattern-match-control-flow)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Integers](#integers)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 -   [Open questions](#open-questions)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
 -   [Alternatives](#alternatives)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Types with template parameters](#types-with-template-parameters)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Indices as compile-time constants](#indices-as-compile-time-constants)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO](#todo)
 -   [Overview](#overview)
     -   [Declaring constants](#declaring-constants)

+ 2 - 2
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
-
 <!-- toc -->
 
+## 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)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Main tools](#main-tools)
     -   [brew](#brew)
     -   [pyenv and Python](#pyenv-and-python)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Background](#background)
 -   [Baseline](#baseline)
 -   [Carbon-local guidance](#carbon-local-guidance)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Overview](#overview)
 -   [Project goals](#project-goals)
     -   [Community and culture](#community-and-culture)

+ 2 - 2
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
-
 <!-- toc -->
 
+## 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)

+ 2 - 2
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
-
 <!-- toc -->
 
+## 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)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
 -   [Proposal](#proposal)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
 -   [Proposal](#proposal)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
 -   [Proposal](#proposal)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Goals](#goals)
 -   [Background](#background)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Proposal](#proposal)
     -   [Out-of-scope issues](#out-of-scope-issues)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
 -   [Proposal](#proposal)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Proposal](#proposal)
 -   [Justification](#justification)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
 -   [Proposal](#proposal)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
 -   [Proposal](#proposal)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [Problem](#problem)
 -   [Background](#background)
     -   [Common deviations](#common-deviations)

+ 2 - 2
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
-
 <!-- toc -->
 
+## Table of contents
+
 -   [TODO: Initial proposal setup](#todo-initial-proposal-setup)
 -   [Problem](#problem)
 -   [Background](#background)

+ 6 - 0
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

+ 1 - 3
src/scripts/new_proposal_test.py

@@ -60,9 +60,7 @@ class TestNewProposal(unittest.TestCase):
         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"])
 
 

+ 0 - 59
src/scripts/pre_commit_toc.js

@@ -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(/<!-- toc -->/m)) continue;
-
-  // If there's a case-incorrect toc section, fix casing.
-  newContent = newContent.replace(
-    /\n## Table of contents\n\n<!-- toc -->\n/im,
-    '\n## Table of contents\n\n<!-- toc -->\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<!-- toc -->\n/m)) {
-    error = 1;
-    console.log(
-      `${file} has a toc without a "Table of contents" header. Use:\n` +
-        '  ## Table of contents\n\n  <!-- toc -->\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);