-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/getgrit/gritql into main-wa…
…tchMode
- Loading branch information
Showing
16 changed files
with
634 additions
and
78 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
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
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
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
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,2 @@ | ||
.gritmodules* | ||
*.log |
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
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
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,11 @@ | ||
version: 0.0.1 | ||
patterns: | ||
- file: ../docs/guides/version_5_upgrade.md | ||
- file: ../docs/guides/something.md | ||
- name: remove_console_error | ||
level: error | ||
body: | | ||
engine marzano(0.1) | ||
language js | ||
`console.error($_)` => . |
82 changes: 82 additions & 0 deletions
82
crates/gritmodule/fixtures/pattern_files/docs/guides/something.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
--- | ||
title: Compare `null` using `===` or `!==` | ||
--- | ||
|
||
Comparing to `null` needs a type-checking operator (=== or !==), to avoid incorrect results when the value is `undefined`. | ||
|
||
tags: #good | ||
|
||
```grit | ||
engine marzano(0.1) | ||
language js | ||
// We use the syntax-tree node binary_expression to capture all expressions where $a and $b are operated on by "==" or "!=". | ||
// This code takes advantage of Grit's allowing us to nest rewrites inside match conditions and to match syntax-tree fields on patterns. | ||
binary_expression($operator, $left, $right) where { | ||
$operator <: or { "==" => `===` , "!=" => `!==` }, | ||
or { $left <: `null`, $right <: `null`} | ||
} | ||
``` | ||
|
||
``` | ||
``` | ||
|
||
## `$val == null` => `$val === null` | ||
|
||
```javascript | ||
if (val == null) { | ||
done(); | ||
} | ||
``` | ||
|
||
```typescript | ||
if (val === null) { | ||
done(); | ||
} | ||
``` | ||
|
||
## `$val != null` => `$val !== null` | ||
|
||
```javascript | ||
if (val != null) { | ||
done(); | ||
} | ||
``` | ||
|
||
```typescript | ||
if (val !== null) { | ||
done(); | ||
} | ||
``` | ||
|
||
## `$val != null` => `$val !== null` into `while` | ||
|
||
```javascript | ||
while (val != null) { | ||
did(); | ||
} | ||
``` | ||
|
||
```typescript | ||
while (val !== null) { | ||
did(); | ||
} | ||
``` | ||
|
||
## Do not change `$val === null` | ||
|
||
```javascript | ||
if (val === null) { | ||
done(); | ||
} | ||
``` | ||
|
||
## Do not change `$val !== null` | ||
|
||
``` | ||
while (val !== null) { | ||
doSomething(); | ||
} | ||
``` |
Oops, something went wrong.