From 65667c0dce2e394ecdd1d7fe364456bb1ecdfe7f Mon Sep 17 00:00:00 2001 From: Freddie Ridell Date: Wed, 18 Mar 2026 23:36:44 +0000 Subject: [PATCH] Add setup documentation and example config files --- bough.config.toml | 5 +++++ docs/bough.config.toml | 1 + docs/setup/index.md | 6 ++++++ docs/setup/init.md | 38 ++++++++++++++++++++++++++++++++++++++ docs/setup/javascript.md | 4 +++- docs/setup/typescript.md | 29 +++++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 bough.config.toml create mode 100644 docs/bough.config.toml create mode 100644 docs/setup/init.md create mode 100644 docs/setup/typescript.md diff --git a/bough.config.toml b/bough.config.toml new file mode 100644 index 00000000..a100d2eb --- /dev/null +++ b/bough.config.toml @@ -0,0 +1,5 @@ +base_root_dir = "." +include = ["**/*"] +exclude = ["target/**/*"] +test.cmd = "echo 'run test command'" +[lang.js] diff --git a/docs/bough.config.toml b/docs/bough.config.toml new file mode 100644 index 00000000..d989c59f --- /dev/null +++ b/docs/bough.config.toml @@ -0,0 +1 @@ +base_root_dir = "." diff --git a/docs/setup/index.md b/docs/setup/index.md index 39f0776d..8728630a 100644 --- a/docs/setup/index.md +++ b/docs/setup/index.md @@ -6,3 +6,9 @@ idx = 1 `bough` follows a principle of config over plugins. To get `bough` to mutate your files you have to tell it what language you're using and how to find your files using globs. We provide a menu of configs for languages `bough` supports. + +- [JavaScript] +- [TypeScript] + +[JavaScript]: /setup/javascript +[TypeScript]: /setup/typescript diff --git a/docs/setup/init.md b/docs/setup/init.md new file mode 100644 index 00000000..841c3233 --- /dev/null +++ b/docs/setup/init.md @@ -0,0 +1,38 @@ ++++ +title = "Initalizing Config" ++++ + +`bough` reads config formatted as `toml`, `yaml`, and `json`. We will use `toml` for the rest of this tutorial + +`bough` looks for config files in the current dir, and parent dirs, in the locations: + +- `bough.config.toml` +- `.bough.toml` +- `.config/bough.toml` + +run + +```bash +bough show config +``` + +in an uninitialized project to see the full ordered list of config search paths. + +## Minimal Config + +```toml +base_root_dir = "." +include = ["**/*"] +exclude = ["target/**/*"] +test.cmd = "echo 'run test command'" +[lang.js] +``` + +- `base_root_dir`: Your project root, probably where your `.git` directory is. **Resolved relative to the directory containing your config file!**. Bough requires this explicitly to avoid "magically" detecting your project root and getting it wrong. Example + - `/foo/bar/baz/bough.config.toml` + - contains `base_root_dir = "../qux"` + - resolves: `/foo/bar/quz` +- `include`: Multiple globs matching **ALL** files that are part of your mutation test. These will be coppied into each test workspace. You can check matched files by running `bough show files` +- `exclude`: Multiple globs matching **ALL** files that are **NOT** part of your mutation test. These will **NOT** be coppied into each test workspace. You can check matched files by running `bough show files` +- `test.cmd`: The test command to run +- `[lang.js]`: At least one config section to describe which mutations systems to use. This example is for JavaScript, but any supported language can be used. diff --git a/docs/setup/javascript.md b/docs/setup/javascript.md index 872dbafb..b142dd54 100644 --- a/docs/setup/javascript.md +++ b/docs/setup/javascript.md @@ -2,10 +2,12 @@ title = "Configuing for JavaScript" +++ +Include a `[lang.js]` section in your config with `include` and `exclude` globs. These control which files bough will attempt to mutate. + ```toml [lang.js] include = [ "src/**/*.js", "src/**/*.jsx", ] -exclude = [ "**/*.test.*" ] +exclude = [ "**/*.test.*", "**/*__mock__*/**", ] ``` ## Vitest diff --git a/docs/setup/typescript.md b/docs/setup/typescript.md new file mode 100644 index 00000000..de952b54 --- /dev/null +++ b/docs/setup/typescript.md @@ -0,0 +1,29 @@ ++++ +title = "Configuing for TypeScript" ++++ + +Include a `[lang.ts]` section in your config with `include` and `exclude` globs. These control which files bough will attempt to mutate. + +```toml +[lang.ts] +include = [ "src/**/*.ts", "src/**/*.tsx", ] +exclude = [ "**/*.test.*", "**/*__mock__*/**", ] +``` + +## Vitest + +[vitest] allows in-src tests, which we don't want to mutate. The following config snippet tells bough not to mutate any code inside a `if(import.meta.vitest){}` block + +```toml +[lang.ts.skip] +query = [ + """ +(if_statement + condition: (parenthesized_expression + (member_expression + object: (meta_property) + property: (property_identifier) @_prop)) + (#eq? @_prop "vitest")) @skip +""", +] +``` -- knotmirror 0.0.1