Skip to content

Commit a4619eb

Browse files
committed
Docs update
1 parent 154bf0d commit a4619eb

File tree

6 files changed

+68
-20
lines changed

6 files changed

+68
-20
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ tool and library for [xarray]() datasets.
1212
Its design is heavily inspired by [ESLint](https://eslint.org/).
1313

1414
**IMPORTANT NOTE**: This project just started and is under development,
15-
there is no stable release yet.
15+
there is no stable release yet. See
16+
[to-do list](docs/todo.md).
1617

1718
## Features
1819

@@ -31,7 +32,6 @@ The following rule plugins are currently built into the code base:
3132
[tiny data](https://tutorial.xarray.dev/intermediate/data_cleaning/05.1_intro.html)
3233
and the
3334
[CF-Conventions](https://cfconventions.org/cf-conventions/cf-conventions.html).
34-
3535
- `xcube`: Implementing the rules for
3636
[xcube datasets](https://xcube.readthedocs.io/en/latest/cubespec.html).
3737
Note this plugins will be moved into a separate GitHub repo later

docs/api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,19 @@ All described objects can be imported from the `xrlint.all` module.
1717
## Class `RuleConfig`
1818

1919
::: xrlint.rule.RuleConfig
20+
21+
## Class `Rule`
22+
23+
::: xrlint.rule.Rule
24+
25+
## Class `RuleMeta`
26+
27+
::: xrlint.rule.RuleMeta
28+
29+
## Class `RuleOp`
30+
31+
::: xrlint.rule.RuleOp
32+
33+
## Class `RuleContext`
34+
35+
::: xrlint.rule.RuleContext

docs/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tool and library for [xarray]() datasets.
66
Its design is heavily inspired by [ESLint](https://eslint.org/).
77

88
**IMPORTANT NOTE**: This project just started and is under development,
9-
there is no stable release yet.
9+
there is no stable release yet. See [to-do list](https://github.com/bcdev/xrlint/blob/main/docs/todo.md).
1010

1111
## Features
1212

@@ -25,7 +25,6 @@ The following rule plugins are currently built into the code base:
2525
[tiny data](https://tutorial.xarray.dev/intermediate/data_cleaning/05.1_intro.html)
2626
and the
2727
[CF-Conventions](https://cfconventions.org/cf-conventions/cf-conventions.html).
28-
2928
- `xcube`: Implementing the rules for
3029
[xcube datasets](https://xcube.readthedocs.io/en/latest/cubespec.html).
3130
Note this plugins will be moved into a separate GitHub repo later

xrlint/config.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Config(ToDictMixin):
5555
"""Configuration object.
5656
A configuration object contains all the information XRLint
5757
needs to execute on a set of dataset files.
58+
59+
You should not use the class constructor directly.
60+
Instead, use the `Config.from_value()` function.
5861
"""
5962

6063
name: str | None = None
@@ -79,33 +82,33 @@ class Config(ToDictMixin):
7982
"""
8083

8184
linter_options: dict[str, Any] | None = None
82-
"""An object containing options related to the linting process."""
85+
"""A dictionary containing options related to the linting process."""
8386

8487
opener_options: dict[str, Any] | None = None
85-
"""An object containing options that are passed to
88+
"""A dictionary containing options that are passed to
8689
the dataset opener.
8790
"""
8891

8992
processor: Union["ProcessorOp", str, None] = None
90-
"""processor - Either an object compatible with the `ProcessorOp`
93+
"""Either an object compatible with the `ProcessorOp`
9194
interface or a string indicating the name of a processor inside
9295
of a plugin (i.e., `"pluginName/processorName"`).
9396
"""
9497

9598
plugins: dict[str, "Plugin"] | None = None
96-
"""An object containing a name-value mapping of plugin names to
99+
"""A dictionary containing a name-value mapping of plugin names to
97100
plugin objects. When `files` is specified, these plugins are only
98101
available to the matching files.
99102
"""
100103

101104
rules: dict[str, "RuleConfig"] | None = None
102-
"""An object containing the configured rules.
105+
"""A dictionary containing the configured rules.
103106
When `files` or `ignores` are specified, these rule configurations
104107
are only available to the matching files.
105108
"""
106109

107110
settings: dict[str, Any] | None = None
108-
"""An object containing name-value pairs of information
111+
"""A dictionary containing name-value pairs of information
109112
that should be available to all rules.
110113
"""
111114

@@ -117,8 +120,8 @@ def from_value(cls, value: Any) -> "Config":
117120
118121
Args:
119122
value: A `Config` object, a `dict` containing the
120-
configuration properties, or `None` which
121-
converts into an empty configuration.
123+
configuration properties, or `None` which
124+
converts into an empty configuration.
122125
Returns:
123126
A `Config` object.
124127
"""
@@ -161,16 +164,27 @@ def global_ignores(self) -> list[str]:
161164
if self.ignores
162165
and not (
163166
self.files
164-
or self.rules
165-
or self.plugins
166-
or self.settings
167167
or self.linter_options
168168
or self.opener_options
169+
or self.plugins
170+
or self.rules
171+
or self.settings
169172
)
170173
else []
171174
)
172175

173176
def get_rule(self, rule_id: str) -> "Rule":
177+
"""Get the rule for the given rule identifier `rule_id`.
178+
179+
Args:
180+
rule_id: The rule identifier including plugin namespace, if any.
181+
Format `<rule-name>` (builtin rules) or `<plugin-name>/<rule-name>`.
182+
Returns:
183+
A `Rule` object.
184+
Raises:
185+
ValueError: If either the plugin is unknown in this configuration
186+
or the rule name is unknown.
187+
"""
174188
if "/" in rule_id:
175189
plugin_name, rule_name = rule_id.split("/", maxsplit=1)
176190
else:
@@ -333,7 +347,11 @@ def merge_configs(
333347

334348
@dataclass(frozen=True)
335349
class ConfigList:
336-
"""A holder for a list of `Config` objects."""
350+
"""A holder for a list of `Config` objects.
351+
352+
You should not use the class constructor directly.
353+
Instead, use the `ConfigList.from_value()` function.
354+
"""
337355

338356
configs: list[Config] = field(default_factory=list)
339357
"""The list of `Config` objects."""

xrlint/linter.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020

2121
def new_linter(
22-
recommended: bool = True, config: Config | dict | None = None, **config_kwargs
22+
recommended: bool = True,
23+
config: Config | dict | None = None,
24+
**config_kwargs: dict[str, Any],
2325
) -> "Linter":
2426
"""Create a new `Linter` with all built-in plugins configured.
2527
@@ -43,6 +45,9 @@ def new_linter(
4345
class Linter:
4446
"""The linter.
4547
48+
You should not use the constructor directly.
49+
Instead, use the `new_linter()` function.
50+
4651
Args:
4752
config: The linter's configuration.
4853
config_kwargs: Individual linter configuration options.
@@ -55,7 +60,7 @@ class Linter:
5560
def __init__(
5661
self,
5762
config: Config | dict[str, Any] | None = None,
58-
**config_kwargs,
63+
**config_kwargs: dict[str, Any],
5964
):
6065
self._config = merge_configs(config, config_kwargs)
6166

@@ -70,7 +75,7 @@ def verify_dataset(
7075
*,
7176
file_path: str | None = None,
7277
config: Config | dict[str, Any] | None = None,
73-
**config_kwargs,
78+
**config_kwargs: dict[str, Any],
7479
) -> Result:
7580
"""Verify a dataset.
7681

xrlint/rule.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212

1313

1414
class RuleContext(ABC):
15-
"""The context passed to the verifier of a rule."""
15+
"""The context passed to the verifier of a rule.
16+
17+
You should never create instances of this class yourself.
18+
Instances of this interface are passed to the `RuleOp`'s
19+
methods.
20+
"""
1621

1722
@property
1823
@abstractmethod
@@ -65,6 +70,8 @@ def attr(self, ctx: RuleContext, node: AttrNode):
6570

6671
@dataclass(frozen=True, kw_only=True)
6772
class RuleMeta(ToDictMixin):
73+
"""Rule metadata."""
74+
6875
name: str
6976
"""Rule name. Mandatory."""
7077

@@ -115,6 +122,9 @@ class Rule:
115122
class RuleConfig:
116123
"""A rule configuration.
117124
125+
You should not use the class constructor directly.
126+
Instead, use the `RuleConfig.from_value()` function.
127+
118128
Args:
119129
severity: rule severity, one of `2` (error), `1` (warn), or `0` (off)
120130
args: rule operation arguments.

0 commit comments

Comments
 (0)