Skip to content

Commit

Permalink
Add pre-commit (cursorless-dev#637)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pokey authored Apr 24, 2022
1 parent 7378bcb commit 6256e45
Show file tree
Hide file tree
Showing 12 changed files with 639 additions and 622 deletions.
38 changes: 38 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://EditorConfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
max_line_length = 80
trim_trailing_whitespace = true

[*.json]
indent_style = tab

[*.py]
indent_style = space
indent_size = 4

[*.{yml,yaml}]
# Trailing whitespace breaks yaml files if you use a multiline string
# with a line that has trailing white space. Many of our recorded
# tests use strings with trailing white space to represent the final
# document contents. For example
# src/test/suite/fixtures/recorded/languages/ruby/changeCondition.yml
trim_trailing_whitespace = false

[Makefile]
indent_style = tab

[src/vendor/**]
charset = unset
end_of_line = unset
indent_size = unset
indent_style = unset
trim_trailing_whitespace = unset
insert_final_newline = unset
max_line_length = unset
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"prettier"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
Expand All @@ -10,7 +13,6 @@
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{
Expand Down
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
minimum_pre_commit_version: "2.9.0"
ci:
autofix_prs: false
exclude: ^src/vendor/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: destroyed-symlinks
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
# Trailing whitespace breaks yaml files if you use a multiline string
# with a line that has trailing white space. Many of our recorded
# tests use strings with trailing white space to represent the final
# document contents. For example
# src/test/suite/fixtures/recorded/languages/ruby/changeCondition.yml
exclude: ^src/test/suite/fixtures/recorded/.*/[^/]*\.yml$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.6.2"
hooks:
- id: prettier
- repo: https://github.com/ikamensh/flynt/
rev: "0.76"
hooks:
- id: flynt
- repo: https://github.com/Zac-HD/shed
rev: 0.9.5
hooks:
- id: shed
# TODO: bump to --py310-plus when Talon moves to Python 3.10.
args: [--refactor, --py39-plus]
types_or: [python, markdown, rst]
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src/vendor

# We use our own format for our recorded yaml tests to keep them compact
/src/test/suite/fixtures/recorded/**/*.yml
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
7 changes: 3 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"python.formatting.provider": "black",
"editor.defaultFormatter": "esbenp.prettier-vscode",
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"cSpell.words": [
Expand All @@ -21,4 +20,4 @@
"pojo",
"subword"
]
}
}
7 changes: 7 additions & 0 deletions docs/contributing/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ locally you need to run the extension in debug mode. To do so you need to run
the `workbench.action.debug.selectandstart` command and then select either "Run
Extension" or "Extension Tests".

### Code formatting

We use [`pre-commit`](https://pre-commit.com/) to automate autoformatting.
Autoformatters will automatically run on PRs in CI, but you can also run them
locally or install pre-commit hooks as described in the `pre-commit`
documentation.

### Running docs site locally

Run the `workbench.action.debug.selectandstart` command and then select
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,17 @@
"@types/semver": "^7.3.9",
"@types/sinon": "^10.0.2",
"@types/vscode": "^1.61.0",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"esbuild": "^0.11.12",
"eslint": "^7.15.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"fast-xml-parser": "^3.20.0",
"glob": "^7.1.7",
"js-yaml": "^4.1.0",
"mocha": "^8.1.3",
"npm-license-crawler": "^0.2.1",
"prettier": "2.6.2",
"semver": "^7.3.5",
"sinon": "^11.1.1",
"typescript": "^4.5.5",
Expand All @@ -532,4 +534,4 @@
"immutability-helper": "^3.1.1",
"lodash": "^4.17.21"
}
}
}
6 changes: 3 additions & 3 deletions src/core/updateSelections/updateSelections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getSelectionInfo(
*/
export function selectionsToSelectionInfos(
document: TextDocument,
selectionMatrix: Selection[][],
selectionMatrix: (readonly Selection[])[],
rangeBehavior: DecorationRangeBehavior = DecorationRangeBehavior.ClosedClosed
): FullSelectionInfo[][] {
return selectionMatrix.map((selections) =>
Expand Down Expand Up @@ -118,7 +118,7 @@ export async function callFunctionAndUpdateSelections(
rangeUpdater: RangeUpdater,
func: () => Thenable<unknown>,
document: TextDocument,
selectionMatrix: Selection[][]
selectionMatrix: (readonly Selection[])[]
): Promise<Selection[][]> {
const selectionInfoMatrix = selectionsToSelectionInfos(
document,
Expand Down Expand Up @@ -173,7 +173,7 @@ export async function performEditsAndUpdateSelections(
rangeUpdater: RangeUpdater,
editor: TextEditor,
edits: Edit[],
originalSelections: Selection[][]
originalSelections: (readonly Selection[])[]
) {
const document = editor.document;
const selectionInfoMatrix = selectionsToSelectionInfos(
Expand Down
12 changes: 7 additions & 5 deletions src/util/addDecorationsToEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ export function addDecorationsToEditors(
) {
hatTokenMap.clear();

var editors: vscode.TextEditor[];
var editors: readonly vscode.TextEditor[];

if (vscode.window.activeTextEditor == null) {
editors = vscode.window.visibleTextEditors;
} else {
editors = vscode.window.visibleTextEditors.filter(
(editor) => editor !== vscode.window.activeTextEditor
);
editors.unshift(vscode.window.activeTextEditor);
editors = [
vscode.window.activeTextEditor,
...vscode.window.visibleTextEditors.filter(
(editor) => editor !== vscode.window.activeTextEditor
),
];
}

const tokens = concat(
Expand Down
8 changes: 4 additions & 4 deletions third-party-licenses.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"module name","licenses","repository","licenseUrl","parents"
"@docusaurus/[email protected].15","MIT","https://github.com/facebook/docusaurus","https://github.com/facebook/docusaurus/raw/master/LICENSE","website"
"@docusaurus/[email protected].15","MIT","https://github.com/facebook/docusaurus","https://github.com/facebook/docusaurus/raw/master/LICENSE","website"
"@docusaurus/[email protected].17","MIT","https://github.com/facebook/docusaurus","https://github.com/facebook/docusaurus/raw/master/LICENSE","website"
"@docusaurus/[email protected].17","MIT","https://github.com/facebook/docusaurus","https://github.com/facebook/docusaurus/raw/master/LICENSE","website"
"@mdx-js/[email protected]","MIT","https://github.com/mdx-js/mdx","https://github.com/mdx-js/mdx/raw/master/license","website"
"@types/[email protected].168","MIT","https://github.com/DefinitelyTyped/DefinitelyTyped","https://github.com/DefinitelyTyped/DefinitelyTyped/raw/master/LICENSE","cursorless"
"@types/[email protected].181","MIT","https://github.com/DefinitelyTyped/DefinitelyTyped","https://github.com/DefinitelyTyped/DefinitelyTyped/raw/master/LICENSE","cursorless"
"[email protected]","MIT","https://github.com/lukeed/clsx","https://github.com/lukeed/clsx/raw/master/license","website"
"[email protected]","MIT","https://github.com/kolodny/immutability-helper","https://github.com/kolodny/immutability-helper/raw/master/LICENSE","cursorless"
"[email protected]","MIT","https://github.com/syntax-tree/mdast-util-find-and-replace","https://github.com/syntax-tree/mdast-util-find-and-replace/raw/master/license","website"
"prism-react-renderer@1.2.1","MIT","https://github.com/FormidableLabs/prism-react-renderer","https://github.com/FormidableLabs/prism-react-renderer/raw/master/LICENSE","website"
"prism-react-renderer@1.3.1","MIT","https://github.com/FormidableLabs/prism-react-renderer","https://github.com/FormidableLabs/prism-react-renderer/raw/master/LICENSE","website"
"[email protected]","MIT","https://github.com/facebook/react","https://github.com/facebook/react/raw/master/LICENSE","website"
"[email protected]","MIT","https://github.com/facebook/react","https://github.com/facebook/react/raw/master/LICENSE","website"
"[email protected]","MIT","https://github.com/syntax-tree/unist-util-visit","https://github.com/syntax-tree/unist-util-visit/raw/master/license","website"
Loading

0 comments on commit 6256e45

Please sign in to comment.