Enable --strict checks for mypy

This commit is contained in:
Ajeet D'Souza 2021-10-28 12:23:14 +05:30
parent ed47c2b1ac
commit 279e393d5c
6 changed files with 44 additions and 30 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
contrib/completions/* linguist-generated=true
contrib/completions/README.md linguist-generated=false

View File

@ -3,23 +3,35 @@
"code_blocks": false,
"tables": false
},
"MD033": false
"MD033": false,
"MD041": false
} -->
<div align="center">
# zoxide
[![crates.io][crates.io-badge]][crates.io]
[![Downloads][downloads-badge]][releases]
[![Built with Nix][builtwithnix-badge]][builtwithnix]
zoxide is a smarter cd command, inspired by z and autojump. It keeps track of
the directories you use most frequently, and uses a ranking algorithm to
navigate to the best match.
zoxide is a **smarter cd command**, inspired by z and autojump.
It remembers which directories you use most frequently, so you can "jump" to
them in just a few keystrokes.<br />
zoxide works on all major shells.
[Getting started](#getting-started) •
[Installation](#installation) •
[Configuration](#configuration) •
[Integrations](#third-party-integrations)
</div>
## Getting started
![Tutorial][tutorial]
## Examples
```sh
z foo # cd into highest ranked directory matching foo
z foo bar # cd into highest ranked directory matching foo and bar
@ -34,7 +46,7 @@ zi foo # cd with interactive selection (using fzf)
Read more about the matching algorithm [here][algorithm-matching].
## Getting started
## Installation
### *Step 1: Install zoxide*
@ -137,7 +149,7 @@ To install zoxide, use a package manager:
To start using zoxide, add it to your shell.
<details>
<summary>bash</summary>
<summary>Bash</summary>
Add this to your configuration (usually `~/.bashrc`):
@ -148,7 +160,7 @@ eval "$(zoxide init bash)"
</details>
<details>
<summary>elvish</summary>
<summary>Elvish</summary>
Add this to your configuration (usually `~/.elvish/rc.elv`):
@ -161,7 +173,7 @@ Note: zoxide only supports elvish v0.16.0 and above.
</details>
<details>
<summary>fish</summary>
<summary>Fish</summary>
Add this to your configuration (usually `~/.config/fish/config.fish`):
@ -172,7 +184,7 @@ zoxide init fish | source
</details>
<details>
<summary>nushell</summary>
<summary>Nushell</summary>
Add this to your configuration (find it by running `config path` in Nushell):
@ -185,7 +197,7 @@ Note: zoxide only supports Nushell v0.37.0 and above.
</details>
<details>
<summary>powershell</summary>
<summary>PowerShell</summary>
Add this to your configuration (find it by running `echo $profile` in
PowerShell):
@ -200,7 +212,7 @@ Invoke-Expression (& {
</details>
<details>
<summary>xonsh</summary>
<summary>Xonsh</summary>
Add this to your configuration (usually `~/.xonshrc`):
@ -211,7 +223,7 @@ execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
</details>
<details>
<summary>zsh</summary>
<summary>Zsh</summary>
Add this to your configuration (usually `~/.zshrc`):
@ -222,7 +234,7 @@ eval "$(zoxide init zsh)"
</details>
<details>
<summary>any POSIX shell</summary>
<summary>Any POSIX shell</summary>
Add this to your configuration:

View File

@ -1,8 +1,6 @@
# completions
Shell completions for zoxide, auto-generated by [`clap`][clap].
Since `clap` itself is in beta at the moment, these completions should not be
treated as stable either.
Shell completions for zoxide, generated by [clap]. Since clap is in beta, these
completions should not be treated as stable.
[clap]: https://github.com/clap-rs/clap

View File

@ -4,7 +4,7 @@ use clap::{AppSettings, ArgEnum, Parser, ValueHint};
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
_ZO_DATA_DIR Path for zoxide data files
_ZO_ECHO Prints the matched directory before navigating to it when set to 1
_ZO_ECHO Print the matched directory before navigating to it when set to 1
_ZO_EXCLUDE_DIRS List of directory globs to be excluded
_ZO_FZF_OPTS Custom flags to pass to fzf
_ZO_MAXAGE Maximum total age after which entries start getting deleted

View File

@ -286,7 +286,7 @@ mod tests {
let opts = Opts { cmd, hook, echo, resolve_symlinks };
let source = Xonsh(&opts).render().unwrap();
Command::new("mypy").args(&["--command", &source]).assert().success().stderr("");
Command::new("mypy").args(&["--command", &source, "--strict"]).assert().success().stderr("");
}
#[rstest]

View File

@ -8,7 +8,7 @@ import os
import os.path
import subprocess
import sys
from typing import AnyStr, Dict, List, Optional
import typing
import xonsh.dirstack # type: ignore # pylint: disable=import-error
import xonsh.environ # type: ignore # pylint: disable=import-error
@ -20,13 +20,13 @@ import xonsh.environ # type: ignore # pylint: disable=import-error
def __zoxide_bin() -> str:
"""Finds and returns the location of the zoxide binary."""
zoxide = xonsh.environ.locate_binary("zoxide")
zoxide = typing.cast(str, xonsh.environ.locate_binary("zoxide"))
if zoxide is None:
zoxide = "zoxide"
return zoxide
def __zoxide_env() -> Dict[str, str]:
def __zoxide_env() -> typing.Dict[str, str]:
"""Returns the current environment."""
return builtins.__xonsh__.env.detype() # type: ignore # pylint:disable=no-member
@ -43,7 +43,7 @@ def __zoxide_pwd() -> str:
return pwd
def __zoxide_cd(path: Optional[AnyStr] = None):
def __zoxide_cd(path: typing.Optional[typing.AnyStr] = None) -> None:
"""cd + custom logic based on the value of _ZO_ECHO."""
if path is None:
args = []
@ -63,10 +63,12 @@ class ZoxideSilentException(Exception):
"""Exit without complaining."""
def __zoxide_errhandler(func):
def __zoxide_errhandler(
func: typing.Callable[[typing.List[str]], None]
) -> typing.Callable[[typing.List[str]], int]:
"""Print exception and exit with error code 1."""
def wrapper(args: List[str]):
def wrapper(args: typing.List[str]) -> int:
try:
func(args)
return 0
@ -94,7 +96,7 @@ if "__zoxide_hook" not in globals():
{%- else if hook == InitHook::Pwd %}
@builtins.events.on_chdir # type: ignore # pylint:disable=no-member
{%- endif %}
def __zoxide_hook(**_kwargs):
def __zoxide_hook(**_kwargs: typing.Any) -> None:
"""Hook to add new entries to the database."""
pwd = __zoxide_pwd()
zoxide = __zoxide_bin()
@ -114,7 +116,7 @@ if "__zoxide_hook" not in globals():
@__zoxide_errhandler
def __zoxide_z(args: List[str]):
def __zoxide_z(args: typing.List[str]) -> None:
"""Jump to a directory using only keywords."""
if args == []:
__zoxide_cd()
@ -139,7 +141,7 @@ def __zoxide_z(args: List[str]):
@__zoxide_errhandler
def __zoxide_zi(args: List[str]):
def __zoxide_zi(args: typing.List[str]) -> None:
"""Jump to a directory using interactive search."""
try:
zoxide = __zoxide_bin()