-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chris Gilmer
committed
Nov 6, 2019
1 parent
12e22f5
commit c2e68f2
Showing
10 changed files
with
217 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"default": true, | ||
"first-header-h1": false, | ||
"first-line-h1": false, | ||
"line_length": false, | ||
"no-multiple-blanks": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
repos: | ||
|
||
- repo: git://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.2.3 | ||
hooks: | ||
- id: check-json | ||
- id: check-yaml | ||
- id: trailing-whitespace | ||
|
||
- repo: git://github.com/igorshubovych/markdownlint-cli | ||
rev: v0.17.0 | ||
hooks: | ||
- id: markdownlint | ||
entry: markdownlint --ignore .github/*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
|
||
- id: markdown-toc | ||
name: Insert a table of contents in Markdown files, like a README.md | ||
entry: markdown-toc | ||
args: [--bullets='*', -i] | ||
language: node | ||
additional_dependencies: [markdown-toc] | ||
files: \.md$ | ||
- id: circleci-validate | ||
name: Validate CircleCI config yaml | ||
description: Validate CircleCI config yaml | ||
entry: pre-commit-circleci-validate | ||
language: script | ||
files: '[.]circleci/config.yml$' | ||
pass_filenames: false | ||
|
||
- id: gen-docs | ||
name: Generate a Docs Index | ||
description: Generate a Docs Index | ||
entry: npx adr | ||
language: node | ||
types: ["file", "markdown"] | ||
pass_filenames: false | ||
|
||
- id: markdown-toc | ||
name: Generate a Table of Contents in Markdown files | ||
description: Generate a Table of Contents in Markdown files | ||
entry: npx md-toc | ||
language: node | ||
types: ["file", "markdown"] | ||
|
||
- id: mdspell | ||
name: Run spellcheck | ||
description: Run spellcheck | ||
entry: mdspell | ||
language: node | ||
args: ["--ignore-numbers", "--ignore-acronyms", "--en-us", "-r"] | ||
additional_dependencies: ["markdown-spellcheck"] | ||
types: ["file", "markdown"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2019, TrussWorks, Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Truss pre-commit hooks | ||
|
||
<!-- toc --> | ||
|
||
* [pre-commit-circleci-validate](#pre-commit-circleci-validate) | ||
* [pre-commit-gen-docs](#pre-commit-gen-docs) | ||
* [pre-commit-markdown-toc](#pre-commit-markdown-toc) | ||
* [pre-commit-mdspell](#pre-commit-mdspell) | ||
|
||
Regenerate with "scripts/pre-commit-markdown-toc" | ||
|
||
<!-- tocstop --> | ||
|
||
## circleci-validate | ||
|
||
Validate CircleCI config yaml located in `.circleci/config.yml`. In order for this to run you will need to install | ||
the `circleci` CLI tool locally with: | ||
|
||
```sh | ||
brew install circleci | ||
``` | ||
|
||
The script will not run the validation if the environment variable `CI` is set, which means you can safely run this | ||
on CircleCI and it will be a no-op. | ||
|
||
## gen-docs | ||
|
||
Generate a Docs Index using [adr-log](https://www.npmjs.com/package/adr-log). It will modify files with this | ||
code in it: | ||
|
||
```md | ||
<!-- adrlog --> | ||
<!-- adrlogstop --> | ||
``` | ||
|
||
## markdown-toc | ||
|
||
Generate a Table of Contents using [markdown-toc](https://www.npmjs.com/package/markdown-toc). It will modify files with this | ||
code in it: | ||
|
||
```md | ||
<!-- toc --> | ||
<!-- tocstop --> | ||
``` | ||
|
||
## mdspell | ||
|
||
Run spellcheck on markdown files using [markdown-spellcheck](https://www.npmjs.com/package/markdown-spellcheck). It | ||
will ignore words listed in a `.spelling` file in your repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"adr-log": "^2.1.1", | ||
"markdown-spellcheck": "^1.3.1", | ||
"markdown-toc": "^1.2.0" | ||
}, | ||
"name": "pre-commit-hooks", | ||
"private": true, | ||
"bin": { | ||
"md-toc": "./pre-commit-markdown-toc", | ||
"adr": "./pre-commit-gen-docs" | ||
}, | ||
"scripts": {}, | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
# Ignore this check when in CI since its moot | ||
[[ "${CI:-}" == "true" ]] || circleci config validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#! /usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
|
||
# Get the directory of this file inside pre-commit cache | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
ADR_BIN="${DIR}/../../node_modules/.bin/adr-log" | ||
|
||
# Rename ADR to whatever we want | ||
function rename { | ||
perl -i -pe "s/ \[ADR-/ [$1-/g;" index.md | ||
} | ||
|
||
# Remove the last line if its an empty newline | ||
function chomp { | ||
perl -pi -e 'chomp if eof;' "$1" | ||
} | ||
|
||
function update_index { | ||
pushd "${dir}" > /dev/null || return | ||
|
||
# Rebuild the index && remove both newlines that it adds | ||
node "${ADR_BIN}" -i && chomp index.md && chomp index.md | ||
|
||
# We need to rename ADR to a different name | ||
title=$(basename "$1") | ||
case "${title}" in | ||
# This is the default behavior | ||
# adr ) | ||
# rename ADR ;; | ||
rfc ) | ||
rename RFC ;; | ||
runbook ) | ||
rename Runbook ;; | ||
esac | ||
popd > /dev/null || return | ||
} | ||
|
||
for dir in docs/adr docs/rfc docs/runbook; do | ||
update_index "${dir}" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#! /usr/bin/env bash | ||
# Wrapper script to generate table of contents on Markdown files. | ||
# Markdown files must have the `<!-- toc -->` tag in them in order to receive | ||
# a TOC. | ||
# | ||
# This is intended to be called by a pre-commit hook to reduce overhead. | ||
# | ||
# Generated with https://github.com/jonschlinkert/markdown-toc | ||
|
||
set -eu -o pipefail | ||
|
||
# Get the directory of this file inside pre-commit cache | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
MDTOC_BIN="${DIR}/../../node_modules/.bin/markdown-toc" | ||
|
||
for filename in "$@"; do | ||
# Using backticks in this appended comment seems to make the script | ||
# indicated run after a 3/5 update to markdown-toc 1.2.0; | ||
# stick with quotes for now. | ||
regen=$'\n\nRegenerate with "pre-commit run -a markdown-toc"' | ||
|
||
node "${MDTOC_BIN}" --bullets='*' --append="${regen}" -i "${filename}" | ||
# yarn run --silent markdown-toc --bullets='*' --append="${regen}" -i "${filename}" | ||
done |