Skip to content

Commit 6256e45

Browse files
authored
Add pre-commit (#637)
* Initial pre-commit config * Updates to pre commit * New prettier config * Fix type * Add comment * At another comment to * Tweak pretty or config * More pre commit fixes * Improve comment * Improve comment * Add prettier recommended extension * Fix typescript errors * Add black to vscode settings * Change prettier version * Don't autofix PRs * Add simple docs * Tweak editor config * At a comment * Removes something we didn't need * Remove marked down line length * Attempt to fix eslint in pre comet * Fix * Another fix * Try to fix eslint * Bump versions * Update lock file * Tweak package * unset editorconfig for vendor * Exclude vendor * Tweak editorconfig * Add more rules * Remove lint from pre commit * Sort hooks * Run shed last
1 parent 7378bcb commit 6256e45

File tree

12 files changed

+639
-622
lines changed

12 files changed

+639
-622
lines changed

.editorconfig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_size = 2
9+
indent_style = space
10+
max_line_length = 80
11+
trim_trailing_whitespace = true
12+
13+
[*.json]
14+
indent_style = tab
15+
16+
[*.py]
17+
indent_style = space
18+
indent_size = 4
19+
20+
[*.{yml,yaml}]
21+
# Trailing whitespace breaks yaml files if you use a multiline string
22+
# with a line that has trailing white space. Many of our recorded
23+
# tests use strings with trailing white space to represent the final
24+
# document contents. For example
25+
# src/test/suite/fixtures/recorded/languages/ruby/changeCondition.yml
26+
trim_trailing_whitespace = false
27+
28+
[Makefile]
29+
indent_style = tab
30+
31+
[src/vendor/**]
32+
charset = unset
33+
end_of_line = unset
34+
indent_size = unset
35+
indent_style = unset
36+
trim_trailing_whitespace = unset
37+
insert_final_newline = unset
38+
max_line_length = unset

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4+
"extends": [
5+
"prettier"
6+
],
47
"parserOptions": {
58
"ecmaVersion": 6,
69
"sourceType": "module"
@@ -10,7 +13,6 @@
1013
],
1114
"rules": {
1215
"@typescript-eslint/naming-convention": "warn",
13-
"@typescript-eslint/semi": "warn",
1416
"@typescript-eslint/no-unused-vars": [
1517
"warn",
1618
{

.pre-commit-config.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
minimum_pre_commit_version: "2.9.0"
2+
ci:
3+
autofix_prs: false
4+
exclude: ^src/vendor/
5+
repos:
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.1.0
8+
hooks:
9+
- id: check-added-large-files
10+
- id: check-case-conflict
11+
- id: check-executables-have-shebangs
12+
- id: check-merge-conflict
13+
- id: check-shebang-scripts-are-executable
14+
- id: check-symlinks
15+
- id: destroyed-symlinks
16+
- id: detect-private-key
17+
- id: end-of-file-fixer
18+
- id: fix-byte-order-marker
19+
- id: mixed-line-ending
20+
- id: trailing-whitespace
21+
# Trailing whitespace breaks yaml files if you use a multiline string
22+
# with a line that has trailing white space. Many of our recorded
23+
# tests use strings with trailing white space to represent the final
24+
# document contents. For example
25+
# src/test/suite/fixtures/recorded/languages/ruby/changeCondition.yml
26+
exclude: ^src/test/suite/fixtures/recorded/.*/[^/]*\.yml$
27+
- repo: https://github.com/pre-commit/mirrors-prettier
28+
rev: "v2.6.2"
29+
hooks:
30+
- id: prettier
31+
- repo: https://github.com/ikamensh/flynt/
32+
rev: "0.76"
33+
hooks:
34+
- id: flynt
35+
- repo: https://github.com/Zac-HD/shed
36+
rev: 0.9.5
37+
hooks:
38+
- id: shed
39+
# TODO: bump to --py310-plus when Talon moves to Python 3.10.
40+
args: [--refactor, --py39-plus]
41+
types_or: [python, markdown, rst]

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/src/vendor
2+
3+
# We use our own format for our recorded yaml tests to keep them compact
4+
/src/test/suite/fixtures/recorded/**/*.yml

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// See http://go.microsoft.com/fwlink/?LinkId=827846
33
// for the documentation about the extensions.json format
44
"recommendations": [
5-
"dbaeumer.vscode-eslint"
5+
"dbaeumer.vscode-eslint",
6+
"esbenp.prettier-vscode"
67
]
78
}

.vscode/settings.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"search.exclude": {
77
"out": true // set this to false to include "out" folder in search results
88
},
9-
"[typescript]": {
10-
"editor.defaultFormatter": "esbenp.prettier-vscode"
11-
},
9+
"python.formatting.provider": "black",
10+
"editor.defaultFormatter": "esbenp.prettier-vscode",
1211
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1312
"typescript.tsc.autoDetect": "off",
1413
"cSpell.words": [
@@ -21,4 +20,4 @@
2120
"pojo",
2221
"subword"
2322
]
24-
}
23+
}

docs/contributing/CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ locally you need to run the extension in debug mode. To do so you need to run
1818
the `workbench.action.debug.selectandstart` command and then select either "Run
1919
Extension" or "Extension Tests".
2020

21+
### Code formatting
22+
23+
We use [`pre-commit`](https://pre-commit.com/) to automate autoformatting.
24+
Autoformatters will automatically run on PRs in CI, but you can also run them
25+
locally or install pre-commit hooks as described in the `pre-commit`
26+
documentation.
27+
2128
### Running docs site locally
2229

2330
Run the `workbench.action.debug.selectandstart` command and then select

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,17 @@
513513
"@types/semver": "^7.3.9",
514514
"@types/sinon": "^10.0.2",
515515
"@types/vscode": "^1.61.0",
516-
"@typescript-eslint/eslint-plugin": "^5.11.0",
517-
"@typescript-eslint/parser": "^5.11.0",
516+
"@typescript-eslint/eslint-plugin": "^5.20.0",
517+
"@typescript-eslint/parser": "^5.20.0",
518518
"esbuild": "^0.11.12",
519-
"eslint": "^7.15.0",
519+
"eslint": "^8.13.0",
520+
"eslint-config-prettier": "^8.5.0",
520521
"fast-xml-parser": "^3.20.0",
521522
"glob": "^7.1.7",
522523
"js-yaml": "^4.1.0",
523524
"mocha": "^8.1.3",
524525
"npm-license-crawler": "^0.2.1",
526+
"prettier": "2.6.2",
525527
"semver": "^7.3.5",
526528
"sinon": "^11.1.1",
527529
"typescript": "^4.5.5",
@@ -532,4 +534,4 @@
532534
"immutability-helper": "^3.1.1",
533535
"lodash": "^4.17.21"
534536
}
535-
}
537+
}

src/core/updateSelections/updateSelections.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function getSelectionInfo(
6666
*/
6767
export function selectionsToSelectionInfos(
6868
document: TextDocument,
69-
selectionMatrix: Selection[][],
69+
selectionMatrix: (readonly Selection[])[],
7070
rangeBehavior: DecorationRangeBehavior = DecorationRangeBehavior.ClosedClosed
7171
): FullSelectionInfo[][] {
7272
return selectionMatrix.map((selections) =>
@@ -118,7 +118,7 @@ export async function callFunctionAndUpdateSelections(
118118
rangeUpdater: RangeUpdater,
119119
func: () => Thenable<unknown>,
120120
document: TextDocument,
121-
selectionMatrix: Selection[][]
121+
selectionMatrix: (readonly Selection[])[]
122122
): Promise<Selection[][]> {
123123
const selectionInfoMatrix = selectionsToSelectionInfos(
124124
document,
@@ -173,7 +173,7 @@ export async function performEditsAndUpdateSelections(
173173
rangeUpdater: RangeUpdater,
174174
editor: TextEditor,
175175
edits: Edit[],
176-
originalSelections: Selection[][]
176+
originalSelections: (readonly Selection[])[]
177177
) {
178178
const document = editor.document;
179179
const selectionInfoMatrix = selectionsToSelectionInfos(

src/util/addDecorationsToEditor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ export function addDecorationsToEditors(
2020
) {
2121
hatTokenMap.clear();
2222

23-
var editors: vscode.TextEditor[];
23+
var editors: readonly vscode.TextEditor[];
2424

2525
if (vscode.window.activeTextEditor == null) {
2626
editors = vscode.window.visibleTextEditors;
2727
} else {
28-
editors = vscode.window.visibleTextEditors.filter(
29-
(editor) => editor !== vscode.window.activeTextEditor
30-
);
31-
editors.unshift(vscode.window.activeTextEditor);
28+
editors = [
29+
vscode.window.activeTextEditor,
30+
...vscode.window.visibleTextEditors.filter(
31+
(editor) => editor !== vscode.window.activeTextEditor
32+
),
33+
];
3234
}
3335

3436
const tokens = concat(

0 commit comments

Comments
 (0)