From 4b091fc5d6cb69dcf87161c92045c2f90d68e2d0 Mon Sep 17 00:00:00 2001 From: HerrintonDarkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:45:29 -0800 Subject: [PATCH] doc: improve language argument --- website/guide/introduction.md | 4 ++-- website/guide/quick-start.md | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/website/guide/introduction.md b/website/guide/introduction.md index 8dbac514..17dfe556 100644 --- a/website/guide/introduction.md +++ b/website/guide/introduction.md @@ -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 JavaScript files. --- @@ -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. \ No newline at end of file diff --git a/website/guide/quick-start.md b/website/guide/quick-start.md index 40cc5a3d..959ad65e 100644 --- a/website/guide/quick-start.md +++ b/website/guide/quick-start.md @@ -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 @@ -127,4 +136,4 @@ Hope you enjoy the power of AST editing in plain programming language pattern. O Links to catalog pages... ---> +--> \ No newline at end of file