Set up pre-commit (#73)

Added here:

- .pre-commit-config.yaml
- docs/project/contribution_tools.md
- src/scripts/pre-commit-toc.js
- CONTRIBUTING.md
- proposals/* (just to switch TOC formats)

The rest consists of auto-generated fixes.

The switch from doctoc to markdown-toc is because doctoc wants to put a TOC in every file, whereas markdown-toc only does it if you have an insertion point.

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
Jon Meow
2020-06-16 09:09:10 -07:00
committed by GitHub
co-authored by Chandler Carruth
parent a3e8a5e389
commit f1e4323fda
9 changed files with 174 additions and 33 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/usr/local/bin/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');
const files = process.argv.slice(2);
for (var i = 0; i < files.length; ++i) {
const oldContent = fs.readFileSync(files[i]).toString();
const newContent = mdtoc.insert(oldContent, { bullets: '-' });
if (oldContent != newContent) {
console.log(`Updating ${files[i]}`);
fs.writeFileSync(files[i], newContent);
}
}
View File