You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ A high-level overview of tools you need to have installed:
16
16
- Yarn package manager. You'll need [`yarn`](https://classic.yarnpkg.com/en/docs/install) (classic). Install v1.22.19 with `npm install --global yarn`.
17
17
- Tree-Sitter CLI: provides [`tree-sitter`](https://github.com/tree-sitter/tree-sitter/tree/master/cli) binary for testing grammars. Install v0.22.2 with `npm install --global tree-sitter-cli`.
18
18
- Terraform CLI. Install [`terraform`](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) with `brew tap hashicorp/tap && brew install hashicorp/tap/terraform`.
19
-
- For snapshot testing review, you should install the cargo insta plugin: `curl -LsSf https://insta.rs/install.sh | sh` (https://insta.rs/docs/cli/)
19
+
- For snapshot testing review, you should install the cargo insta plugin: `curl -LsSf https://insta.rs/install.sh | sh` (<https://insta.rs/docs/cli/>)
20
20
21
21
## Building the Code
22
22
@@ -63,13 +63,13 @@ After making your changes, run the [./resources/edit_grammars.mjs](./resources/e
63
63
64
64
For example:
65
65
66
-
```
66
+
```sh
67
67
node ./resources/edit_grammars.mjs yaml
68
68
```
69
69
70
70
### Snippet contexts
71
71
72
-
Snippet contexts help when a snippet is a valid AST subtree, but needs to be in a larger tree to parse. For example, matching on a table name like `$schema.$table` in SQL is not valid SQL by itself, only when surrounded by something like `SELECT x from $schema.$table` is the snippet valid.
72
+
Snippet contexts help when a snippet is a valid AST subtree, but needs to be in a larger tree to parse. For example, matching on a table name like `$schema.$table` in SQL is not valid SQL by itself, only when surrounded by something like `SELECT x from $schema.$table` is the snippet valid.
73
73
74
74
Snippet contexts are defined by implementing the `snippet_context_strings` method in the `Language` trait. This method returns a list of strings that are used to match the snippet in the larger tree. For example, the SQL implementation returns `["SELECT 1 from ", ";"]` to match a table name in a SQL query.
75
75
@@ -100,9 +100,9 @@ These steps are done in our cloud environment and are not necessary for contribu
100
100
101
101
- grep for an existing language like `Sol` for solidity, and add it to all the `Language` enums you find.
102
102
- Add the language to `apps/web/src/views/project/details.tsx`, so repos with this language don’t get an “unsupported language” warning. (5 minutes)
103
-
- LSP target languages list: https://github.com/getgrit/rewriter/pull/7734/files#diff-f9d4f097b08d33241c5c8d15a2fbde0e37086c265ce0eba8decac20d5cd989c6R23
104
-
- VS Code client list: https://github.com/getgrit/rewriter/blob/f992490394a4807789504f1cea6a04b934ad3b24/apps/poolish/src/lsp-client.ts
105
-
- VS Code command palette triggers: https://github.com/getgrit/rewriter/pull/7734/files#diff-b38f1d6304993a250903310722206e6c89c58c52c2d1bd4b6fdd8f7218810570R103
103
+
- LSP target languages list: <https://github.com/getgrit/rewriter/pull/7734/files#diff-f9d4f097b08d33241c5c8d15a2fbde0e37086c265ce0eba8decac20d5cd989c6R23>
104
+
- VS Code client list: <https://github.com/getgrit/rewriter/blob/f992490394a4807789504f1cea6a04b934ad3b24/apps/poolish/src/lsp-client.ts>
105
+
- VS Code command palette triggers: <https://github.com/getgrit/rewriter/pull/7734/files#diff-b38f1d6304993a250903310722206e6c89c58c52c2d1bd4b6fdd8f7218810570R103>
106
106
- There are also `exhaustive` runtime checks that error if a switch case doesn’t handle a language, like `makeSingleLineComment`. Search for `exhaustive(lang` and fill those out too.
107
107
- Regenerate both DB/prisma types to add it to the DB schema and GraphQL types.
108
108
- Add the language to `language-selector.tsx`. Pick an icon from [https://react-icons.github.io](https://react-icons.github.io/), usually from the Simple Icons category.
Save the pattern to a [`grit.yaml`](https://docs.grit.io/guides/config) file and exclude test cases in a where clause:
59
59
60
-
```
60
+
```sh
61
61
cat << 'EOF' > .grit/grit.yaml
62
62
patterns:
63
63
- name: use_winston
@@ -72,7 +72,7 @@ grit apply use_winston
72
72
73
73
Run `grit check` to enforce your patterns as [custom lints](https://docs.grit.io/guides/ci).
74
74
75
-
```
75
+
```sh
76
76
grit check
77
77
```
78
78
@@ -107,13 +107,15 @@ GritQL comes from our experiences with conducting large scale refactors and migr
107
107
Usually, migrations start with exploratory work to figure out the scope of the problem—often using simple grep searches. These are easy to start with, but most migrations end up accumulating additional requirements like ensuring the right packages are imported and excluding cases which don’t have a viable migration path.
108
108
109
109
Eventually, any complex migration ends up being a full codemod program written with a tool like [jscodeshift](https://github.com/facebook/jscodeshift). This comes with its own problems:
110
+
110
111
- Most of the exploratory work has to be abandoned as you figure out how to represent your original regex search as an AST.
111
112
- Reading/writing a codemod requires mentally translating from AST names back to what source code actually looks like.
112
113
- Most frameworks are not composable, so you’re stuck copying patterns back and forth.
113
114
- Performance is often an afterthought, so iterating on a large codemod can be painfully slow.
114
115
- Codemod frameworks are language-specific, so if you’re hopping between multiple languages—or trying to migrate a shared API—you have to learn different frameworks.
115
116
116
117
GritQL is our attempt to develop a powerful middle ground:
118
+
117
119
- Exploratory analysis is easy: just put a code snippet in backticks and use `$metavariables` for holes you want to represent.
118
120
- Incrementally add complexity by introducing side conditions with where clauses.
119
121
- Reuse named patterns to avoid rebuilding queries, and use shared patterns from our [standard library](https://github.com/getgrit/stdlib) for common tasks like ensuring modules are imported.
0 commit comments