|
| 1 | +# Configure XRLint |
| 2 | + |
| 3 | +_**Note**: this chapter's material is based on the documentation of how to [configure ESLint](https://eslint.org/docs/latest/use/configure/). |
| 4 | +Many parts have been copied and adjusted as it applies in many similar ways to XRLint._ |
| 5 | + |
| 6 | +## Configuration File |
| 7 | + |
| 8 | +The XRLint configuration file may be named any of the following: |
| 9 | + |
| 10 | +* `xrlint_config.yaml` |
| 11 | +* `xrlint_config.json` |
| 12 | +* `xrlint_config.py` |
| 13 | + |
| 14 | +It should be placed in the root directory of your project and export |
| 15 | +an array of [configuration objects](#configuration-objects) or |
| 16 | +references to [predefined configuration objects](#predefined-configuration-objects). |
| 17 | + |
| 18 | +Here’s a YAML example: |
| 19 | + |
| 20 | +```yaml |
| 21 | +- files: ["**/*.zarr", "**/*.nc"] |
| 22 | +- plugins: |
| 23 | + xcube: xrlint.plugins.xcube |
| 24 | +- recommended |
| 25 | +- xcube/recommended |
| 26 | +``` |
| 27 | +
|
| 28 | +Same using JSON: |
| 29 | +
|
| 30 | +```json |
| 31 | +[ |
| 32 | + {"files": ["**/*.zarr", "**/*.nc"]}, |
| 33 | + { |
| 34 | + "plugins": { |
| 35 | + "xcube": "xrlint.plugins.xcube" |
| 36 | + } |
| 37 | + }, |
| 38 | + "recommended", |
| 39 | + "xcube/recommended" |
| 40 | +] |
| 41 | +``` |
| 42 | + |
| 43 | +And as Python script: |
| 44 | + |
| 45 | +```python |
| 46 | +def export_configs(): |
| 47 | + return [ |
| 48 | + {"files": ["**/*.zarr", "**/*.nc"]}, |
| 49 | + { |
| 50 | + "plugins": { |
| 51 | + "xcube": "xrlint.plugins.xcube" |
| 52 | + } |
| 53 | + }, |
| 54 | + "recommended", |
| 55 | + "xcube/recommended" |
| 56 | + ] |
| 57 | +``` |
| 58 | + |
| 59 | + |
| 60 | +## Configuration Objects |
| 61 | + |
| 62 | +Each configuration object contains all of the information XRLint needs |
| 63 | +to execute on a set of files. Each configuration object is made up of |
| 64 | +these properties: |
| 65 | + |
| 66 | +* `name` - A name for the configuration object. |
| 67 | + This is used in error messages and config inspector to help identify which |
| 68 | + configuration object is being used. |
| 69 | +* `files` - A list of glob patterns indicating the files that the |
| 70 | + configuration object should apply to. If not specified, the configuration |
| 71 | + object applies to all files matched by any other configuration object. |
| 72 | +* `ignores` - A list of glob patterns indicating the files that the |
| 73 | + configuration object should not apply to. If not specified, the configuration |
| 74 | + object applies to all files matched by files. If ignores is used without any |
| 75 | + other keys in the configuration object, then the patterns act as _global ignores_. |
| 76 | +* `opener_options` - A dictionary specifying keyword-arguments that are passed |
| 77 | + directly to the `xarray.open_dataset()` function. The available options are |
| 78 | + dependent on the xarray backend selected by the `engine` option. |
| 79 | +* `linter_options` - A dictionary containing settings related to |
| 80 | + the linting process. (Currently not used.) |
| 81 | +* `processor` - A string indicating the name of a processor inside of a plugin, |
| 82 | + i.e., `"<plugin-name>/<processor-name>"`. In Python configurations |
| 83 | + it can also be an object of type `ProcessorOp` containing |
| 84 | + `preprocess()` and `postprocess()` methods. |
| 85 | +* `plugins` - A dictionary containing a name-value mapping of plugin names |
| 86 | + to either plugin module names or `Plugin` objects. When `files` is specified, |
| 87 | + these plugins are only available to the matching files. |
| 88 | +* `rules` - An object containing the configured rules. |
| 89 | + When `files` or `ignores` are specified, these rule configurations are only |
| 90 | + available to the matching files. |
| 91 | +* `settings` - An object containing name-value pairs of information that should |
| 92 | + be available to all rules. |
0 commit comments