bash-explainer 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -14
- package/THIRD_PARTY_NOTICES.md +6 -6
- package/dist/cli.js +233 -201
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,13 +44,14 @@ bash-explainer --check install.sh # constructs its shell (#!/bin/sh: dash…
|
|
|
44
44
|
| --- | --- |
|
|
45
45
|
| `-e`, `--command <text>` | explain this command line |
|
|
46
46
|
| `-l`, `--line <n>[-<m>]` | only these lines |
|
|
47
|
-
| `--check` | report constructs the script's shell lacks, other risks (script injection in GitHub Actions, Docker `RUN` pipes without `pipefail`…) and the pitfalls of a script (`
|
|
48
|
-
| `--strict` | with `--check`, also exit 1 if there is a warning
|
|
47
|
+
| `--check` | report errors (lines that fail every time, such as `[` without `]`, `x = 1`, `echo $((09))`, `#!/usr/bin/env bash -e`, a syntax error in a plain script, and constructs the script's shell lacks; nothing is reported after a command that surely stops the script, such as `exit 0` or `exec` with a command. What says the shell reads the text wrongly (`x = 1`, a syntax error) is a warning, which only `--strict` fails on, after a command that only may stop it (`source`, `trap`, an `exit` in a function), and in a file only its name says is a script, or standard input with no first line; no syntax error is reported in a host file or in a file not surely a script), other risks (script injection in GitHub Actions, Docker `RUN` pipes without `pipefail`…) and the pitfalls of a script (`rm -rf $DIR/*`, `curl … | sh`…); exit 1 if there is an error |
|
|
48
|
+
| `--strict` | with `--check`, also exit 1 if there is a warning |
|
|
49
|
+
| `--counts <file>` | with `--check`, also append the numbers of problems to the file as `name=value` lines (`errors`, `warnings`, `infos`, `pitfalls`, and `failing`: those that make the exit status 1), as `$GITHUB_OUTPUT` reads them. A symbolic link at the last part of the path is refused. Here `warnings` counts the problems at warning level; the GitHub Action's `warnings` output keeps its old meaning, the problems that fail the step, which is `failing` here |
|
|
49
50
|
| `--shell <name>` | the script's shell: `bash`, `sh`, `dash`, `ash`, `yash`, `ksh`, `mksh`, `zsh` (default: from the shebang or the file name) |
|
|
50
51
|
| `--bash-version <v>` | the bash release to explain for: `5.2` (default) or `5.3`; constructs of a later release are explained as it runs them, and `--check` warns about them |
|
|
51
52
|
| `--kind <kind>` | what the file is: `shell`, `dockerfile`, `makefile`, `yaml`, `npm`, `markdown`, `python`, `jenkinsfile` (default: from the file name) |
|
|
52
53
|
| `--lang <en\|ja>` | language (default: from `LANG`) |
|
|
53
|
-
| `--sarif <file>` | with `--check`, also write the problems to this file as SARIF, whatever `--format` prints (so one run gives annotations and a SARIF file) |
|
|
54
|
+
| `--sarif <file>` | with `--check`, also write the problems to this file as SARIF, whatever `--format` prints (so one run gives annotations and a SARIF file). A symbolic link at the last part of the path is refused |
|
|
54
55
|
| `--format <format>` | `text`, `markdown` or `json`; with `--check`, also `github` (annotations in GitHub Actions) or `sarif` (for code scanning) |
|
|
55
56
|
| `--no-examples` | leave out worked examples |
|
|
56
57
|
| `--config <file>` | read the settings from this file (see [Settings](#settings)) |
|
|
@@ -60,25 +61,30 @@ bash-explainer --check install.sh # constructs its shell (#!/bin/sh: dash…
|
|
|
60
61
|
| `--lsp` | run as a Language Server on standard input and output (see [In your editor](#in-your-editor-language-server)) |
|
|
61
62
|
| `--color`, `--no-color` | colour the text output (default: when writing to a terminal; `NO_COLOR` turns it off) |
|
|
62
63
|
|
|
64
|
+
The exit status is 0; with `--check`, 1 if a problem fails the check; and 2 if the tool could not run (a usage error, a file it cannot read). It is also 2 after a bug of the tool on a line, and for a file nested too deep to read: the output still has what it could say, the other files too, and standard error tells which.
|
|
65
|
+
|
|
63
66
|
In the text output, a construct is labelled with its keywords and a placeholder for what is left out (`while` *condition* `do` *commands* `done`): the placeholder is in italics and dim with colour, and shown as `‹condition›` without. With `--format json`, `label` is that text and `labelParts` lists the parts (`{ "text": "while" }`, `{ "text": "condition", "placeholder": true }`…).
|
|
64
67
|
|
|
65
68
|
A row or a note about a part of bash ends with the sections of the GNU Bash Reference Manual it is about: `(Bash manual 3.7.2)` in the text output, links to the sections on gnu.org with `--format markdown`. The numbers are those of the bash 5.2 manual. With `--format json`, a token has them in `refs` (`["3.7.2"]`), and `facts` lists the notes that come from the message catalog, with their `id`, `kind` (`note` or `pitfall`), `text` and `refs`.
|
|
66
69
|
|
|
67
|
-
`--check` prints problems as compilers do (`file:line:column: warning: … [code]`), so editors and CI can pick them up. With `--format github` they become GitHub Actions annotations, shown on the pull request's diff; with `--format sarif`, a SARIF file for code scanning (
|
|
70
|
+
`--check` prints problems as compilers do (`file:line:column: warning: … [code]`), so editors and CI can pick them up. With `--format github` they become GitHub Actions annotations, shown on the pull request's diff; with `--format sarif`, a SARIF file for code scanning (an error is an `error` result, a warning a `warning`, information a `note`).
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
Problems have three levels: an error (red) for a line that fails every time as written, a warning (yellow) for damage that cannot be undone under some values, and information (blue) for what goes wrong only with some values or on some systems. `--check` fails on every error, on a warning only with `--strict`, and never on information. The pitfalls of a shell script are problems too, with their own codes; turn them off with `--set diagnostics.pitfalls=false` (the errors stay). The severity names the level, so a problem's text has no "Error:" of its own; a pitfall keeps its word ("Pitfall:", "Caveat:").
|
|
70
73
|
|
|
71
74
|
```text
|
|
72
75
|
$ bash-explainer --check deploy.sh
|
|
73
|
-
deploy.sh:
|
|
74
|
-
deploy.sh:4:1: warning: Pitfall: x =… runs a command named x; it is not an assignment. Write x
|
|
76
|
+
deploy.sh:3:1: error: [ has no ] as its last argument, so it fails when it runs, without evaluating the condition ([: missing ']', status 2). This is not a syntax error but an error of the command [ at run time [bracket-missing-close]
|
|
77
|
+
deploy.sh:4:1: warning: Pitfall: x =… runs a command named x; it is not an assignment. Write x=1 with no spaces around = [assignment-with-spaces]
|
|
78
|
+
deploy.sh:5:1: info: Caveat: without -r, backslashes in the input are taken as escapes and lost. Usually write read -r [read-without-r]
|
|
75
79
|
$ echo $?
|
|
76
|
-
|
|
80
|
+
1
|
|
77
81
|
```
|
|
78
82
|
|
|
83
|
+
In the explanation, a note starts with the mark and the word of its level, in its colour: `ⓧ Error:` in red, `⚠ Pitfall:` in yellow, `ⓘ Caveat:` in blue, and a plain fact's `ℹ`, dim. Errors come first.
|
|
84
|
+
|
|
79
85
|
## Settings
|
|
80
86
|
|
|
81
|
-
The tool takes the settings of the VS Code extension that have a meaning in a terminal: `language`, `notes.idioms`, `notes.pitfalls`, `notes.basis`, `shell`, `bashVersion`, `yq.flavor`, `diagnostics.ignore`, `diagnostics.embedded`, `diagnostics.pitfalls`, `examples.enabled`, `examples.disabled` and `customCommands` (see [Settings](https://github.com/sf624/bash-explainer/blob/v0.
|
|
87
|
+
The tool takes the settings of the VS Code extension that have a meaning in a terminal: `language`, `notes.idioms`, `notes.pitfalls`, `notes.basis`, `shell`, `bashVersion`, `yq.flavor`, `diagnostics.ignore`, `diagnostics.embedded`, `diagnostics.pitfalls`, `examples.enabled`, `examples.disabled` and `customCommands` (see [Settings](https://github.com/sf624/bash-explainer/blob/v0.10.0/README.md#settings) for what each one does). They come from a JSON file with the keys of VS Code's `settings.json`, with or without `bashExplainer.`; comments and trailing commas are allowed, and nested objects too (`{ "notes": { "idioms": false } }`):
|
|
82
88
|
|
|
83
89
|
```jsonc
|
|
84
90
|
{
|
|
@@ -123,7 +129,7 @@ With `language` set to `auto` (the default), the language follows `LC_ALL`, `LC_
|
|
|
123
129
|
|
|
124
130
|
## In CI (GitHub Actions)
|
|
125
131
|
|
|
126
|
-
The repository is also a GitHub Action, which
|
|
132
|
+
The repository is also a GitHub Action, which installs this tool at its own version in a directory of its own, outside the checked-out repository, and runs it there on your files. The registry is the one your workflow or machine configures (`setup-node`'s `registry-url`, `npm_config_registry`, your user's npm settings); npm settings kept in the repository do not apply to it:
|
|
127
133
|
|
|
128
134
|
```yaml
|
|
129
135
|
- uses: actions/checkout@v5
|
|
@@ -134,9 +140,9 @@ The repository is also a GitHub Action, which runs this tool at its own version:
|
|
|
134
140
|
|
|
135
141
|
`@v0` follows the latest 0.x release. To stay on one version, use its tag (`@v0.2.0`); to be sure the code cannot change, its commit SHA (`@<sha> # v0.2.0`), which Dependabot can keep up to date.
|
|
136
142
|
|
|
137
|
-

|
|
138
144
|
|
|
139
|
-
|
|
145
|
+
Problems appear on the pull request's diff. Errors fail the step (`fail-on-warning: 'false'` keeps it green, errors too); warnings fail it only with `strict: 'true'`. So by default a construct the script's shell lacks fails the step only where it surely fails: what the shell refuses while it reads the file (`a=(1)`, `<<<`, also in a function never called), and a command it surely gets to. In a function, in a branch, or after a command that may stop the script (`. ./lib`, an `exit` in a function), it may never run, so it is a warning: `strict: 'true'` is what catches a bashism there. The inputs: `files` (bash globs; default `**/*.sh`; a file whose real path is outside the workspace is skipped with a notice), `shell` (default: from each script), `bash-version` (`5.2` or `5.3`, the bash release that bash scripts are checked for; default `5.2`, where `${ cmd; }` is an error), `fail-on-warning`, `strict` (also fail on a warning; default `'false'`), `sarif` (also write a SARIF file, for `github/codeql-action/upload-sarif`; a path in the workspace or the runner's temp directory must stay there when its symbolic links are followed) and `package` (another npm package spec to run; a relative path is relative to the workspace; install scripts do not run, except that npm prepares a package from git). The outputs: `errors`, the number of errors; `warnings`, the number of problems that fail the step (the errors, and with `strict` the warnings); and `pitfalls`, the number of pitfalls (warnings and notices; an error is none). The counts come from the tool's `--counts`; with an older tool, `errors` is 0. The annotations of pitfalls are titled `Bash Explainer (pitfall): <code>`, and those that fail the step come first, since GitHub shows only the first annotations of a step. `strict` needs a tool with `--strict`, and `bash-version` one with `--bash-version`: with a `package` pin to an older one, the step fails and says so. In other CI systems, run `npx bash-explainer --check <files>` and use the exit status.
|
|
140
146
|
|
|
141
147
|
## In your editor (Language Server)
|
|
142
148
|
|
|
@@ -179,8 +185,8 @@ Settings: the keys of the VS Code extension's settings that have a meaning here,
|
|
|
179
185
|
|
|
180
186
|
## Privacy
|
|
181
187
|
|
|
182
|
-
Everything runs in the Node.js process: the tool contains no code that opens a network connection or starts a process, which a test checks on every change. See [Privacy](https://github.com/sf624/bash-explainer/blob/v0.
|
|
188
|
+
Everything runs in the Node.js process: the tool contains no code that opens a network connection or starts a process, which a test checks on every change. See [Privacy](https://github.com/sf624/bash-explainer/blob/v0.10.0/README.md#privacy).
|
|
183
189
|
|
|
184
190
|
## License
|
|
185
191
|
|
|
186
|
-
[MIT](https://github.com/sf624/bash-explainer/blob/v0.
|
|
192
|
+
[MIT](https://github.com/sf624/bash-explainer/blob/v0.10.0/LICENSE). Third-party components: [THIRD_PARTY_NOTICES.md](https://github.com/sf624/bash-explainer/blob/v0.10.0/THIRD_PARTY_NOTICES.md).
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -8,7 +8,7 @@ Bash Explainer includes the following third-party software and artwork (CC-BY-4.
|
|
|
8
8
|
|
|
9
9
|
| Component | Version | License | Included as |
|
|
10
10
|
| --- | --- | --- | --- |
|
|
11
|
-
| [unbash](https://github.com/webpro-nl/unbash) | 6.0.
|
|
11
|
+
| [unbash](https://github.com/webpro-nl/unbash) | 6.0.3 | ISC | bundled into `dist/extension.js`; bundled into `dist/web/extension.js` |
|
|
12
12
|
| [@vscode/codicons](https://github.com/microsoft/vscode-codicons) | 0.0.46-24 | CC-BY-4.0 | icons copied into `media/icons.js` |
|
|
13
13
|
| [microsoft/vscode](https://github.com/microsoft/vscode) | 1.143.1 | MIT | the token colours of the default colour themes copied into `src/ui/vscodeThemes.json`, bundled into `dist/extension.js` and `dist/web/extension.js` |
|
|
14
14
|
|
|
@@ -16,14 +16,14 @@ Bash Explainer includes the following third-party software and artwork (CC-BY-4.
|
|
|
16
16
|
|
|
17
17
|
| Component | Version | License | Included as |
|
|
18
18
|
| --- | --- | --- | --- |
|
|
19
|
-
| [unbash](https://github.com/webpro-nl/unbash) | 6.0.
|
|
19
|
+
| [unbash](https://github.com/webpro-nl/unbash) | 6.0.3 | ISC | bundled into `app.js` |
|
|
20
20
|
| [@codemirror/commands](https://code.haverbeke.berlin/codemirror/commands) | 6.11.1 | MIT | bundled into `app.js` |
|
|
21
21
|
| [@codemirror/language](https://code.haverbeke.berlin/codemirror/language) | 6.13.1 | MIT | bundled into `app.js` |
|
|
22
22
|
| [@codemirror/legacy-modes](https://code.haverbeke.berlin/codemirror/legacy-modes) | 6.5.5 | MIT | bundled into `app.js` |
|
|
23
23
|
| [@codemirror/lint](https://code.haverbeke.berlin/codemirror/lint) | 6.9.7 | MIT | bundled into `app.js` |
|
|
24
24
|
| [@codemirror/state](https://code.haverbeke.berlin/codemirror/state) | 6.7.6 | MIT | bundled into `app.js` |
|
|
25
25
|
| [@codemirror/streamparser](https://code.haverbeke.berlin/codemirror/streamparser) | 6.0.0 | MIT | bundled into `app.js` |
|
|
26
|
-
| [@codemirror/view](https://code.haverbeke.berlin/codemirror/view) | 6.43.
|
|
26
|
+
| [@codemirror/view](https://code.haverbeke.berlin/codemirror/view) | 6.43.15 | MIT | bundled into `app.js` |
|
|
27
27
|
| [@lezer/common](https://code.haverbeke.berlin/lezer/common) | 1.5.3 | MIT | bundled into `app.js` |
|
|
28
28
|
| [@lezer/highlight](https://code.haverbeke.berlin/lezer/highlight) | 1.2.5 | MIT | bundled into `app.js` |
|
|
29
29
|
| [@marijn/find-cluster-break](https://code.haverbeke.berlin/marijn/find-cluster-break) | 1.0.4 | MIT | bundled into `app.js` |
|
|
@@ -36,7 +36,7 @@ Bash Explainer includes the following third-party software and artwork (CC-BY-4.
|
|
|
36
36
|
|
|
37
37
|
| Component | Version | License | Included as |
|
|
38
38
|
| --- | --- | --- | --- |
|
|
39
|
-
| [unbash](https://github.com/webpro-nl/unbash) | 6.0.
|
|
39
|
+
| [unbash](https://github.com/webpro-nl/unbash) | 6.0.3 | ISC | bundled into `dist/cli.js` |
|
|
40
40
|
|
|
41
41
|
## License texts
|
|
42
42
|
|
|
@@ -147,8 +147,8 @@ Copyright (c) Microsoft Corporation. https://github.com/microsoft/vscode-codicon
|
|
|
147
147
|
The icons are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0):
|
|
148
148
|
https://creativecommons.org/licenses/by/4.0/legalcode
|
|
149
149
|
|
|
150
|
-
Bash Explainer copies
|
|
151
|
-
chevron-down, list-tree, comment-discussion, warning, info) from src/icons/*.svg of @vscode/codicons
|
|
150
|
+
Bash Explainer copies twelve of the icons (collapse-all, expand-all, copy, book, arrow-left, gear,
|
|
151
|
+
chevron-down, list-tree, comment-discussion, error, warning, info) from src/icons/*.svg of @vscode/codicons
|
|
152
152
|
0.0.46-24, unmodified, as SVG path data drawn in the theme's colours, in the header of the extension's
|
|
153
153
|
panel, in the top bar and the hover cards of the web page and beside the notes of an explanation.
|
|
154
154
|
The licensor offers the icons as-is and makes no representations or warranties of any kind concerning
|