mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:31:24 +01:00
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:
committed by
GitHub
co-authored by
Chandler Carruth
parent
a3e8a5e389
commit
f1e4323fda
Executable
+28
@@ -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);
|
||||
}
|
||||
}
|
||||
Executable → Regular
Reference in New Issue
Block a user