Skip to content

Commit

Permalink
doc: improve language argument
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Dec 7, 2023
1 parent 26582d7 commit 4b091fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions website/guide/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Using ast-grep can be as simple as running a single command in your terminal:
sg --pattern 'var code = $PAT' --rewrite 'let code = $PAT' --lang js
```

The command above will replace `var` statement with `let` for all JavaScript files.
The command above will replace `var` statement with `let` for all <abbr title="ast-grep will also infer the language if you omit --lang">JavaScript</abbr> files.

---

Expand Down Expand Up @@ -94,4 +94,4 @@ It is written in Rust, a native language and utilize multiple cores. (It can eve
You can start from creating a one-liner to rewrite code at command line with minimal investment. Later if you see some code smell recurrently appear in your projects, you can write a linting rule in YAML with a few patterns combined. Finally if you are a library author or framework designer, ast-grep provide programmatic interface to rewrite or transpile code efficiently.

### Pragmatism
ast-grep comes with batteries included. Interactive code modification is available. Linter and language server work out of box when you install the command line tool. ast-grep is also shipped with test à for rule authors.
ast-grep comes with batteries included. Interactive code modification is available. Linter and language server work out of box when you install the command line tool. ast-grep is also shipped with test à for rule authors.
19 changes: 14 additions & 5 deletions website/guide/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,21 @@ We can write this pattern to find all property checking code.
$PROP && $PROP()
```

It is a valid `ast-grep` pattern! We can use it in command line! Use `pattern` argument to specify our target
and also `lang` is needed to tell ast-grep our target code language.
It is a valid `ast-grep` pattern! We can use it in command line! Use `pattern` argument to specify our target.
Optionally, we can use `lang` to tell ast-grep our target code language.

```shell
sg --pattern '$PROP && $PROP()' --lang ts TypeScript/src # path to TS source
:::code-group
```shell [Full Command]
sg --pattern '$PROP && $PROP()' --lang ts TypeScript/src
```
```shell [Short Form]
sg -p '$PROP && $PROP()' -l ts TypeScript/src
```
```shell [Without Lang]
# ast-grep will infer languages based on file extensions
sg -p '$PROP && $PROP()' TypeScript/src
```
:::

## Rewrite

Expand Down Expand Up @@ -127,4 +136,4 @@ Hope you enjoy the power of AST editing in plain programming language pattern. O
Links to catalog pages...
-->
-->

0 comments on commit 4b091fc

Please sign in to comment.