Skip to content

Commit f74e053

Browse files
committed
Set up Prettier for reformatting if documentation and config files
1 parent b5732fb commit f74e053

9 files changed

+117
-26
lines changed

.editorconfig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ end_of_line = lf
1111
trim_trailing_whitespace = true
1212
insert_final_newline = true
1313
indent_style = space
14-
indent_size = 4
14+
indent_size = 2
1515
max_line_length = 80
1616

17-
[*.yml]
18-
indent_size = 2
17+
[*.{py,pyi}]
18+
indent_size = 4
1919

2020
# Documentation.
2121
[*.md]

.githooks/pre-commit

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,57 @@ set -e
66
# Check if this is the initial commit
77
if git rev-parse --verify HEAD >/dev/null 2>&1
88
then
9-
against=HEAD
9+
against=HEAD
1010
else
11-
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
11+
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
1212
fi
1313

1414
# Use git diff-index to check for whitespace errors
15-
if ! git diff-index --check --cached $against
15+
if ! git diff-index --check --cached $against -- ':!*.snap' .
1616
then
17-
echo "Aborting commit due to whitespace errors."
18-
exit 1
17+
echo "Aborting commit due to whitespace errors."
18+
exit 1
1919
fi
2020

2121
NEW_FILES=$(git --no-pager diff --name-only --cached --diff-filter=ACM)
2222
PY_FILES=$(echo "$NEW_FILES" | { grep .py || true; })
2323

24-
if [ -n "$PY_FILES" ];
24+
# Only keep staged files that are added (A), copied (C) or modified (M).
25+
STAGED=$(git --no-pager diff --name-only --cached --diff-filter=ACM)
26+
# Files which are only partly staged (eg. git add --patch).
27+
PATCH_STAGED=$(git --no-pager diff --name-only --diff-filter=ACM $STAGED)
28+
# Files which are fully staged.
29+
FULLY_STAGED=$(comm -23 <(echo "$STAGED") <(echo "$PATCH_STAGED"))
30+
31+
PRETTIER_STAGED=$(grep -E '.(md|css|scss|js|json|json5|yaml|yml|html)$' <<< "$STAGED" || true)
32+
PRETTIER_FULLY_STAGED=$(grep -E '.(md|css|scss|js|json|json5|yaml|yml|html)$' <<< "$FULLY_STAGED" || true)
33+
PY_STAGED=$(grep .py$ <<< "$STAGED" || true)
34+
PY_FULLY_STAGED=$(grep .py$ <<< "$FULLY_STAGED" || true)
35+
36+
# Uncomment, and add more variables to the list, for debugging help.
37+
# tr ' ' '\n' <<< "STAGED $STAGED PATCH_STAGED $PATCH_STAGED FULLY_STAGED $FULLY_STAGED JS_STAGED $JS_STAGED
38+
39+
# Format and re-stage fully staged files only.
40+
41+
if [ -n "$PRETTIER_FULLY_STAGED" ];
42+
then
43+
npx prettier --write $PRETTIER_FULLY_STAGED
44+
git add $PRETTIER_FULLY_STAGED
45+
fi
46+
47+
if [ -n "$PRETTIER_STAGED" ];
48+
then
49+
npx prettier --check $PRETTIER_STAGED
50+
fi
51+
52+
if [ -n "$PY_FULLY_STAGED" ];
53+
then
54+
black $PY_FULLY_STAGED
55+
git add $PY_FULLY_STAGED
56+
fi
57+
58+
if [ -n "$PY_STAGED" ];
2559
then
26-
make test-ci
60+
black --check $PY_STAGED
61+
make test-ci
2762
fi

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
14

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
.tox
3+
.venv
4+
coverage_html_report
5+
.pytest_cache
6+
.mypy_cache
7+
example.html
8+
example.md

.travis.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@ language: python
55
cache:
66
pip: true
77
directories:
8-
- .tox
8+
- .tox
99
jobs:
1010
include:
11-
- env: TOXENV=py36-lower_bound_deps
12-
python: 3.6
13-
- env: TOXENV=py37-lower_bound_deps
14-
python: 3.7
15-
- env: TOXENV=py38-lower_bound_deps
16-
python: 3.8
17-
- env: TOXENV=py36-upper_bound_deps
18-
python: 3.6
19-
- env: TOXENV=py37-upper_bound_deps
20-
python: 3.7
21-
- env: TOXENV=py38-upper_bound_deps
22-
python: 3.8
11+
- env: TOXENV=py36-lower_bound_deps
12+
python: 3.6
13+
- env: TOXENV=py37-lower_bound_deps
14+
python: 3.7
15+
- env: TOXENV=py38-lower_bound_deps
16+
python: 3.8
17+
- env: TOXENV=py36-upper_bound_deps
18+
python: 3.6
19+
- env: TOXENV=py37-upper_bound_deps
20+
python: 3.7
21+
- env: TOXENV=py38-upper_bound_deps
22+
python: 3.8
23+
- language: node_js
24+
install:
25+
- npm install --no-optional --no-audit --progress=false
26+
script:
27+
- npm run lint
2328
install:
24-
- pip install tox coveralls==1.10.0
29+
- pip install tox coveralls==1.10.0
2530
script:
26-
- make test-ci
31+
- make test-ci
2732
after_success:
28-
- coveralls
33+
- coveralls
2934
notifications:
3035
email: false

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ lint: ## Lint the project.
1717
format: ## Format project files.
1818
isort --recursive *.py **/*.py
1919
black **/*.py
20+
npm run format
2021

2122
test: ## Test the project.
2223
python -m unittest discover

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "draftjs_exporter",
3+
"version": "0.0.0-dev",
4+
"private": true,
5+
"description": "Library to convert rich text from Draft.js raw ContentState to HTML",
6+
"license": "MIT",
7+
"devDependencies": {
8+
"prettier": "2.0.5"
9+
},
10+
"scripts": {
11+
"lint": "prettier --check '**/?(.)*.{md,css,scss,js,json,json5,yaml,yml,html}'",
12+
"format": "prettier --write '**/?(.)*.{md,css,scss,js,json,json5,yaml,yml,html}'"
13+
}
14+
}

prettier.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// See https://prettier.io/docs/en/options.html.
2+
module.exports = {
3+
printWidth: 80,
4+
tabWidth: 2,
5+
useTabs: false,
6+
semi: true,
7+
singleQuote: false,
8+
trailingComma: "all",
9+
bracketSpacing: true,
10+
jsxBracketSameLine: false,
11+
arrowParens: "always",
12+
proseWrap: "preserve",
13+
};

0 commit comments

Comments
 (0)