@eslint/shell 0.0.0-stage → 0.1.2
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/LICENSE +201 -0
- package/README.md +167 -2
- package/dist/index.d.ts +79 -0
- package/dist/index.js +74 -0
- package/dist/languages/shell-language.d.ts +36 -0
- package/dist/languages/shell-language.js +72 -0
- package/dist/languages/shell-source-code.d.ts +55 -0
- package/dist/languages/shell-source-code.js +184 -0
- package/dist/parser/parse.d.ts +32 -0
- package/dist/parser/parse.js +758 -0
- package/dist/rules/no-backticks.d.ts +8 -0
- package/dist/rules/no-backticks.js +46 -0
- package/dist/rules/no-expansions-in-single-quotes.d.ts +8 -0
- package/dist/rules/no-expansions-in-single-quotes.js +42 -0
- package/dist/rules/no-ls-iteration.d.ts +8 -0
- package/dist/rules/no-ls-iteration.js +42 -0
- package/dist/rules/no-unquoted-expansions.d.ts +9 -0
- package/dist/rules/no-unquoted-expansions.js +91 -0
- package/dist/rules/no-unused-vars.d.ts +11 -0
- package/dist/rules/no-unused-vars.js +382 -0
- package/dist/rules/no-useless-cat.d.ts +8 -0
- package/dist/rules/no-useless-cat.js +76 -0
- package/dist/rules/no-useless-echo.d.ts +8 -0
- package/dist/rules/no-useless-echo.js +42 -0
- package/dist/rules/no-variables-in-printf-format.d.ts +8 -0
- package/dist/rules/no-variables-in-printf-format.js +60 -0
- package/dist/rules/require-cd-guard.d.ts +8 -0
- package/dist/rules/require-cd-guard.js +74 -0
- package/dist/rules/require-read-r.d.ts +8 -0
- package/dist/rules/require-read-r.js +83 -0
- package/dist/rules/utils.d.ts +35 -0
- package/dist/rules/utils.js +100 -0
- package/dist/types.d.ts +343 -0
- package/dist/types.js +7 -0
- package/dist/visitor-keys.d.ts +5 -0
- package/dist/visitor-keys.js +59 -0
- package/package.json +75 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ESLint Shell Language Plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A shell language plugin for [ESLint](https://eslint.org), providing:
|
|
4
|
+
|
|
5
|
+
- an ESLint-style **parser** for shell scripts (wrapping
|
|
6
|
+
[mvdan-sh](https://www.npmjs.com/package/mvdan-sh), the parser behind
|
|
7
|
+
`shfmt`) that produces an ESTree-style syntax tree,
|
|
8
|
+
- an ESLint **language** implementation so rules can traverse that tree,
|
|
9
|
+
- **rules** inspired by [ShellCheck](https://www.shellcheck.net) checks, and
|
|
10
|
+
- a **recommended configuration**.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install --save-dev eslint @eslint/shell
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Node.js `^20.19.0 || ^22.13.0 || >=24`. Tested with ESLint v10.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Add the plugin to your `eslint.config.js`:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { defineConfig } from "eslint/config";
|
|
26
|
+
import shell from "@eslint/shell";
|
|
27
|
+
|
|
28
|
+
export default defineConfig([
|
|
29
|
+
{
|
|
30
|
+
// use the recommended rules for *.sh and *.bash files
|
|
31
|
+
files: ["**/*.sh", "**/*.bash"],
|
|
32
|
+
plugins: { shell },
|
|
33
|
+
extends: ["shell/recommended"],
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or configure it manually:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { defineConfig } from "eslint/config";
|
|
42
|
+
import shell from "@eslint/shell";
|
|
43
|
+
|
|
44
|
+
export default defineConfig([
|
|
45
|
+
{
|
|
46
|
+
files: ["**/*.sh"],
|
|
47
|
+
plugins: { shell },
|
|
48
|
+
language: "shell/bash",
|
|
49
|
+
rules: {
|
|
50
|
+
"shell/no-backticks": "error",
|
|
51
|
+
"shell/no-unquoted-expansions": "error",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Languages
|
|
58
|
+
|
|
59
|
+
The plugin provides one language per shell dialect:
|
|
60
|
+
|
|
61
|
+
| Language | Description |
|
|
62
|
+
| ------------- | ------------------------------------- |
|
|
63
|
+
| `shell/bash` | Bash. Used by the recommended config. |
|
|
64
|
+
| `shell/posix` | POSIX `sh`, without Bash extensions. |
|
|
65
|
+
| `shell/mksh` | MirBSD Korn shell. |
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { defineConfig } from "eslint/config";
|
|
69
|
+
import shell from "@eslint/shell";
|
|
70
|
+
|
|
71
|
+
export default defineConfig([
|
|
72
|
+
{
|
|
73
|
+
files: ["**/*.sh"],
|
|
74
|
+
plugins: { shell },
|
|
75
|
+
extends: ["shell/recommended"],
|
|
76
|
+
language: "shell/posix",
|
|
77
|
+
},
|
|
78
|
+
]);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Rules
|
|
82
|
+
|
|
83
|
+
Each rule mirrors a well-known ShellCheck check.
|
|
84
|
+
|
|
85
|
+
| Rule | ShellCheck | Description | Fixable | Recommended |
|
|
86
|
+
| ---------------------------------------------------------------------------------- | ---------- | ------------------------------------------------------- | ------- | ----------- |
|
|
87
|
+
| [`no-backticks`](./docs/rules/no-backticks.md) | SC2006 | Use `$(...)` instead of legacy backticks | ✅ | error |
|
|
88
|
+
| [`no-expansions-in-single-quotes`](./docs/rules/no-expansions-in-single-quotes.md) | SC2016 | Expressions don't expand in single quotes | | warn |
|
|
89
|
+
| [`no-ls-iteration`](./docs/rules/no-ls-iteration.md) | SC2045 | Don't iterate over `ls` output; use globs | | error |
|
|
90
|
+
| [`no-unquoted-expansions`](./docs/rules/no-unquoted-expansions.md) | SC2086/46 | Quote expansions subject to word splitting and globbing | ✅ | error |
|
|
91
|
+
| [`no-unused-vars`](./docs/rules/no-unused-vars.md) | SC2034 | Disallow variables that are assigned but never used | | error |
|
|
92
|
+
| [`no-useless-cat`](./docs/rules/no-useless-cat.md) | SC2002 | Don't pipe from a single-file `cat` | | error |
|
|
93
|
+
| [`no-useless-echo`](./docs/rules/no-useless-echo.md) | SC2116 | Disallow `$(echo ...)` | | error |
|
|
94
|
+
| [`no-variables-in-printf-format`](./docs/rules/no-variables-in-printf-format.md) | SC2059 | Don't put variables in the `printf` format string | | error |
|
|
95
|
+
| [`require-cd-guard`](./docs/rules/require-cd-guard.md) | SC2164 | Handle `cd` failure with `\|\| exit` (has suggestions) | | error |
|
|
96
|
+
| [`require-read-r`](./docs/rules/require-read-r.md) | SC2162 | Use `read -r` so backslashes aren't mangled | ✅ | error |
|
|
97
|
+
|
|
98
|
+
### Rule options
|
|
99
|
+
|
|
100
|
+
`shell/no-unused-vars` accepts an object option:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
"shell/no-unused-vars": ["error", { allowed: ["MY_GLOBAL"] }]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Configuration comments
|
|
107
|
+
|
|
108
|
+
Standard ESLint configuration comments work inside shell scripts:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# eslint-disable-next-line shell/no-backticks
|
|
112
|
+
echo `pwd`
|
|
113
|
+
|
|
114
|
+
echo `pwd` # eslint-disable-line shell/no-backticks -- legacy
|
|
115
|
+
|
|
116
|
+
# eslint shell/no-useless-echo: "warn"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Syntax tree
|
|
120
|
+
|
|
121
|
+
The tree format is documented in [docs/syntax-tree.md](docs/syntax-tree.md).
|
|
122
|
+
Nodes carry `start`/`end` character offsets instead of `range`/`loc`
|
|
123
|
+
properties; use `sourceCode.getRange(node)` and `sourceCode.getLoc(node)`.
|
|
124
|
+
|
|
125
|
+
The parser is also exported directly:
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
import { parseShell } from "@eslint/shell";
|
|
129
|
+
|
|
130
|
+
const { ast, comments } = parseShell('echo "hello"\n');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm install
|
|
137
|
+
npm test # unit + integration tests (Vitest)
|
|
138
|
+
npm run lint # ESLint on the plugin's own sources
|
|
139
|
+
npm run fmt # Prettier
|
|
140
|
+
npm run build # compile TypeScript to dist/
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Pre-commit hooks (via [yorkie](https://www.npmjs.com/package/yorkie) and
|
|
144
|
+
lint-staged) run Prettier and ESLint on staged files. Releases are managed
|
|
145
|
+
with [release-please](https://github.com/googleapis/release-please) through
|
|
146
|
+
GitHub Actions.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
Apache-2.0
|
|
151
|
+
|
|
152
|
+
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
|
|
153
|
+
<!--sponsorsstart-->
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## Sponsors
|
|
157
|
+
|
|
158
|
+
The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
|
|
159
|
+
to get your logo on our READMEs and [website](https://eslint.org/sponsors).
|
|
160
|
+
|
|
161
|
+
<h3>Gold Sponsors</h3>
|
|
162
|
+
<p><a href="#"><img src="https://images.opencollective.com/vite-ecosystem-fund/logo.png" alt="Vite Ecosystem Fund" height="96"></a> <a href="https://forceindexer.com"><img src="https://images.opencollective.com/forceindexer/588566e/logo.png" alt="ForceIndexer" height="96"></a> <a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a> <a href="https://www.coderabbit.ai/?utm_source=cr_org&utm_medium=github"><img src="https://avatars.githubusercontent.com/u/132028505" alt="CodeRabbit" height="96"></a> <a href="https://automattic.com"><img src="https://avatars.githubusercontent.com/u/887802" alt="Automattic" height="96"></a></p><h3>Silver Sponsors</h3>
|
|
163
|
+
<p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/d472863/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/2d6c3b6/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
|
|
164
|
+
<p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://opensource.sap.com"><img src="https://avatars.githubusercontent.com/u/2531208" alt="SAP" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://citadel-ai.com"><img src="https://avatars.githubusercontent.com/u/75781367" alt="Citadel AI" height="32"></a> <a href="https://www.testmuai.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="TestMu AI Open Source Office (Formerly LambdaTest)" height="32"></a></p>
|
|
165
|
+
<h3>Technology Sponsors</h3>
|
|
166
|
+
Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
|
|
167
|
+
<p><a href="https://netlify.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/netlify-icon.svg" alt="Netlify" height="32"></a> <a href="https://algolia.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/algolia-icon.svg" alt="Algolia" height="32"></a> <a href="https://1password.com"><img src="https://raw.githubusercontent.com/eslint/eslint.org/main/src/assets/images/techsponsors/1password-icon.svg" alt="1Password" height="32"></a></p>
|
|
168
|
+
<!--sponsorsend-->
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The @eslint/shell plugin: a shell language definition for
|
|
3
|
+
* ESLint, ShellCheck-inspired rules, and a recommended configuration.
|
|
4
|
+
* @author Claude Opus 5.5
|
|
5
|
+
*/
|
|
6
|
+
import { ShellLanguage } from "./languages/shell-language.js";
|
|
7
|
+
declare const plugin: {
|
|
8
|
+
meta: {
|
|
9
|
+
name: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
version: string;
|
|
12
|
+
};
|
|
13
|
+
languages: {
|
|
14
|
+
bash: ShellLanguage;
|
|
15
|
+
posix: ShellLanguage;
|
|
16
|
+
mksh: ShellLanguage;
|
|
17
|
+
};
|
|
18
|
+
rules: {
|
|
19
|
+
"no-backticks": import("./types.js").ShellRuleDefinition<{
|
|
20
|
+
MessageIds: "useDollarParen";
|
|
21
|
+
}>;
|
|
22
|
+
"no-expansions-in-single-quotes": import("./types.js").ShellRuleDefinition<{
|
|
23
|
+
MessageIds: "expansionInSingleQuotes";
|
|
24
|
+
}>;
|
|
25
|
+
"no-ls-iteration": import("./types.js").ShellRuleDefinition<{
|
|
26
|
+
MessageIds: "lsIteration";
|
|
27
|
+
}>;
|
|
28
|
+
"no-unquoted-expansions": import("./types.js").ShellRuleDefinition<{
|
|
29
|
+
MessageIds: "unquotedParameterExpansion" | "unquotedCommandSubstitution";
|
|
30
|
+
}>;
|
|
31
|
+
"no-unused-vars": import("./types.js").ShellRuleDefinition<{
|
|
32
|
+
MessageIds: "unusedVariable";
|
|
33
|
+
RuleOptions: [{
|
|
34
|
+
allowed?: string[];
|
|
35
|
+
}?];
|
|
36
|
+
}>;
|
|
37
|
+
"no-useless-cat": import("./types.js").ShellRuleDefinition<{
|
|
38
|
+
MessageIds: "uselessCat";
|
|
39
|
+
}>;
|
|
40
|
+
"no-useless-echo": import("./types.js").ShellRuleDefinition<{
|
|
41
|
+
MessageIds: "uselessEcho";
|
|
42
|
+
}>;
|
|
43
|
+
"no-variables-in-printf-format": import("./types.js").ShellRuleDefinition<{
|
|
44
|
+
MessageIds: "variableInFormat";
|
|
45
|
+
}>;
|
|
46
|
+
"require-cd-guard": import("./types.js").ShellRuleDefinition<{
|
|
47
|
+
MessageIds: "uncheckedCd" | "addGuard";
|
|
48
|
+
}>;
|
|
49
|
+
"require-read-r": import("./types.js").ShellRuleDefinition<{
|
|
50
|
+
MessageIds: "missingR";
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
configs: {
|
|
54
|
+
recommended: {
|
|
55
|
+
name: string;
|
|
56
|
+
files: string[];
|
|
57
|
+
language: string;
|
|
58
|
+
plugins: {};
|
|
59
|
+
rules: {
|
|
60
|
+
"shell/no-backticks": string;
|
|
61
|
+
"shell/no-expansions-in-single-quotes": string;
|
|
62
|
+
"shell/no-ls-iteration": string;
|
|
63
|
+
"shell/no-unquoted-expansions": string;
|
|
64
|
+
"shell/no-unused-vars": string;
|
|
65
|
+
"shell/no-useless-cat": string;
|
|
66
|
+
"shell/no-useless-echo": string;
|
|
67
|
+
"shell/no-variables-in-printf-format": string;
|
|
68
|
+
"shell/require-cd-guard": string;
|
|
69
|
+
"shell/require-read-r": string;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export default plugin;
|
|
75
|
+
export { ShellLanguage } from "./languages/shell-language.js";
|
|
76
|
+
export { ShellSourceCode } from "./languages/shell-source-code.js";
|
|
77
|
+
export { parseShell, ShellSyntaxError } from "./parser/parse.js";
|
|
78
|
+
export { visitorKeys } from "./visitor-keys.js";
|
|
79
|
+
export type * from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The @eslint/shell plugin: a shell language definition for
|
|
3
|
+
* ESLint, ShellCheck-inspired rules, and a recommended configuration.
|
|
4
|
+
* @author Claude Opus 5.5
|
|
5
|
+
*/
|
|
6
|
+
//------------------------------------------------------------------------------
|
|
7
|
+
// Plugin
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
import { ShellLanguage } from "./languages/shell-language.js";
|
|
10
|
+
import noBackticks from "./rules/no-backticks.js";
|
|
11
|
+
import noExpansionsInSingleQuotes from "./rules/no-expansions-in-single-quotes.js";
|
|
12
|
+
import noLsIteration from "./rules/no-ls-iteration.js";
|
|
13
|
+
import noUnquotedExpansions from "./rules/no-unquoted-expansions.js";
|
|
14
|
+
import noUnusedVars from "./rules/no-unused-vars.js";
|
|
15
|
+
import noUselessCat from "./rules/no-useless-cat.js";
|
|
16
|
+
import noUselessEcho from "./rules/no-useless-echo.js";
|
|
17
|
+
import noVariablesInPrintfFormat from "./rules/no-variables-in-printf-format.js";
|
|
18
|
+
import requireCdGuard from "./rules/require-cd-guard.js";
|
|
19
|
+
import requireReadR from "./rules/require-read-r.js";
|
|
20
|
+
const rules = {
|
|
21
|
+
"no-backticks": noBackticks,
|
|
22
|
+
"no-expansions-in-single-quotes": noExpansionsInSingleQuotes,
|
|
23
|
+
"no-ls-iteration": noLsIteration,
|
|
24
|
+
"no-unquoted-expansions": noUnquotedExpansions,
|
|
25
|
+
"no-unused-vars": noUnusedVars,
|
|
26
|
+
"no-useless-cat": noUselessCat,
|
|
27
|
+
"no-useless-echo": noUselessEcho,
|
|
28
|
+
"no-variables-in-printf-format": noVariablesInPrintfFormat,
|
|
29
|
+
"require-cd-guard": requireCdGuard,
|
|
30
|
+
"require-read-r": requireReadR,
|
|
31
|
+
};
|
|
32
|
+
const plugin = {
|
|
33
|
+
meta: {
|
|
34
|
+
name: "@eslint/shell",
|
|
35
|
+
namespace: "shell",
|
|
36
|
+
version: "0.1.2", // x-release-please-version
|
|
37
|
+
},
|
|
38
|
+
languages: {
|
|
39
|
+
bash: new ShellLanguage({ mode: "bash" }),
|
|
40
|
+
posix: new ShellLanguage({ mode: "posix" }),
|
|
41
|
+
mksh: new ShellLanguage({ mode: "mksh" }),
|
|
42
|
+
},
|
|
43
|
+
rules,
|
|
44
|
+
configs: {
|
|
45
|
+
recommended: {
|
|
46
|
+
name: "shell/recommended",
|
|
47
|
+
files: ["**/*.sh", "**/*.bash"],
|
|
48
|
+
language: "shell/bash",
|
|
49
|
+
plugins: {},
|
|
50
|
+
rules: {
|
|
51
|
+
"shell/no-backticks": "error",
|
|
52
|
+
"shell/no-expansions-in-single-quotes": "warn",
|
|
53
|
+
"shell/no-ls-iteration": "error",
|
|
54
|
+
"shell/no-unquoted-expansions": "error",
|
|
55
|
+
"shell/no-unused-vars": "error",
|
|
56
|
+
"shell/no-useless-cat": "error",
|
|
57
|
+
"shell/no-useless-echo": "error",
|
|
58
|
+
"shell/no-variables-in-printf-format": "error",
|
|
59
|
+
"shell/require-cd-guard": "error",
|
|
60
|
+
"shell/require-read-r": "error",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
//------------------------------------------------------------------------------
|
|
66
|
+
// Exports
|
|
67
|
+
//------------------------------------------------------------------------------
|
|
68
|
+
// The recommended config must reference the plugin itself.
|
|
69
|
+
Object.assign(plugin.configs.recommended.plugins, { shell: plugin });
|
|
70
|
+
export default plugin;
|
|
71
|
+
export { ShellLanguage } from "./languages/shell-language.js";
|
|
72
|
+
export { ShellSourceCode } from "./languages/shell-source-code.js";
|
|
73
|
+
export { parseShell, ShellSyntaxError } from "./parser/parse.js";
|
|
74
|
+
export { visitorKeys } from "./visitor-keys.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The ShellLanguage class, the ESLint Language implementation
|
|
3
|
+
* for shell scripts.
|
|
4
|
+
*/
|
|
5
|
+
import type { File, Language, OkParseResult, ParseResult } from "@eslint/core";
|
|
6
|
+
import { ShellSourceCode } from "./shell-source-code.js";
|
|
7
|
+
import type { ShellLanguageOptions, ShellNode, ShellVariant, CommentNode, ProgramNode } from "../types.js";
|
|
8
|
+
export interface ShellLanguageConstructorOptions {
|
|
9
|
+
/** The shell dialect to parse. Defaults to `"bash"`. */
|
|
10
|
+
mode?: ShellVariant;
|
|
11
|
+
}
|
|
12
|
+
export type ShellOkParseResult = OkParseResult<ProgramNode> & {
|
|
13
|
+
comments: CommentNode[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* ESLint Language implementation for shell scripts. Each instance parses
|
|
17
|
+
* one shell dialect, chosen by the `mode` constructor option.
|
|
18
|
+
*/
|
|
19
|
+
export declare class ShellLanguage implements Language<{
|
|
20
|
+
LangOptions: ShellLanguageOptions;
|
|
21
|
+
Code: ShellSourceCode;
|
|
22
|
+
RootNode: ProgramNode;
|
|
23
|
+
Node: ShellNode;
|
|
24
|
+
}> {
|
|
25
|
+
#private;
|
|
26
|
+
fileType: "text";
|
|
27
|
+
lineStart: 1;
|
|
28
|
+
columnStart: 1;
|
|
29
|
+
nodeTypeKey: string;
|
|
30
|
+
visitorKeys: Record<string, string[]>;
|
|
31
|
+
defaultLanguageOptions: ShellLanguageOptions;
|
|
32
|
+
constructor({ mode }?: ShellLanguageConstructorOptions);
|
|
33
|
+
validateLanguageOptions(): void;
|
|
34
|
+
parse(file: File): ParseResult<ProgramNode>;
|
|
35
|
+
createSourceCode(file: File, parseResult: ShellOkParseResult): ShellSourceCode;
|
|
36
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The ShellLanguage class, the ESLint Language implementation
|
|
3
|
+
* for shell scripts.
|
|
4
|
+
*/
|
|
5
|
+
import { ShellSyntaxError, parseShell } from "../parser/parse.js";
|
|
6
|
+
import { ShellSourceCode } from "./shell-source-code.js";
|
|
7
|
+
import { visitorKeys } from "../visitor-keys.js";
|
|
8
|
+
const SHELL_MODES = new Set(["bash", "posix", "mksh"]);
|
|
9
|
+
/**
|
|
10
|
+
* ESLint Language implementation for shell scripts. Each instance parses
|
|
11
|
+
* one shell dialect, chosen by the `mode` constructor option.
|
|
12
|
+
*/
|
|
13
|
+
export class ShellLanguage {
|
|
14
|
+
fileType = "text";
|
|
15
|
+
lineStart = 1;
|
|
16
|
+
columnStart = 1;
|
|
17
|
+
nodeTypeKey = "type";
|
|
18
|
+
visitorKeys = visitorKeys;
|
|
19
|
+
defaultLanguageOptions = {};
|
|
20
|
+
#mode;
|
|
21
|
+
constructor({ mode = "bash" } = {}) {
|
|
22
|
+
if (!SHELL_MODES.has(mode)) {
|
|
23
|
+
throw new TypeError(`Invalid shell mode "${String(mode)}". Expected "bash", "posix", or "mksh".`);
|
|
24
|
+
}
|
|
25
|
+
this.#mode = mode;
|
|
26
|
+
}
|
|
27
|
+
validateLanguageOptions() {
|
|
28
|
+
// There are no language options to validate.
|
|
29
|
+
}
|
|
30
|
+
parse(file) {
|
|
31
|
+
const text = file.body;
|
|
32
|
+
try {
|
|
33
|
+
const { ast, comments } = parseShell(text, {
|
|
34
|
+
variant: this.#mode,
|
|
35
|
+
path: file.path,
|
|
36
|
+
});
|
|
37
|
+
return { ok: true, ast, comments };
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error instanceof ShellSyntaxError) {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
errors: [
|
|
44
|
+
{
|
|
45
|
+
message: error.message,
|
|
46
|
+
line: error.line,
|
|
47
|
+
column: error.column,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
errors: [
|
|
55
|
+
{
|
|
56
|
+
message: error instanceof Error
|
|
57
|
+
? error.message
|
|
58
|
+
: String(error),
|
|
59
|
+
line: 1,
|
|
60
|
+
column: 1,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
createSourceCode(file, parseResult) {
|
|
67
|
+
return new ShellSourceCode({
|
|
68
|
+
text: file.body,
|
|
69
|
+
ast: parseResult.ast,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|