@matrixai/lint 0.2.11 → 0.4.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/AGENTS.md +23 -0
- package/README.md +151 -83
- package/dist/bin/lint.js +119 -136
- package/dist/bin/lint.js.map +1 -1
- package/dist/config.d.ts +15 -0
- package/dist/config.js +120 -0
- package/dist/config.js.map +1 -0
- package/dist/configs/{js.d.ts → eslint.d.ts} +412 -29
- package/dist/configs/{js.js → eslint.js} +5 -4
- package/dist/configs/eslint.js.map +1 -0
- package/dist/configs/{prettier.config.mjs → prettier.config.js} +1 -1
- package/dist/configs/prettier.config.js.map +1 -0
- package/dist/domains/engine.d.ts +72 -0
- package/dist/domains/engine.js +160 -0
- package/dist/domains/engine.js.map +1 -0
- package/dist/domains/eslint.d.ts +3 -0
- package/dist/domains/eslint.js +72 -0
- package/dist/domains/eslint.js.map +1 -0
- package/dist/domains/files.d.ts +4 -0
- package/dist/domains/files.js +95 -0
- package/dist/domains/files.js.map +1 -0
- package/dist/domains/index.d.ts +14 -0
- package/dist/domains/index.js +83 -0
- package/dist/domains/index.js.map +1 -0
- package/dist/domains/markdown.d.ts +5 -0
- package/dist/domains/markdown.js +103 -0
- package/dist/domains/markdown.js.map +1 -0
- package/dist/domains/shell.d.ts +5 -0
- package/dist/domains/shell.js +58 -0
- package/dist/domains/shell.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/tsbuildinfo +1 -0
- package/dist/types.d.ts +31 -8
- package/dist/utils.d.ts +13 -18
- package/dist/utils.js +207 -94
- package/dist/utils.js.map +1 -1
- package/package.json +25 -14
- package/dist/configs/js.js.map +0 -1
- package/dist/configs/prettier.config.mjs.map +0 -1
- package/flake.lock +0 -78
- package/jest.config.mjs +0 -84
- /package/dist/configs/{prettier.config.d.mts → prettier.config.d.ts} +0 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# AGENTS
|
|
2
|
+
- Read the repo profile selector at [`.matrixai/repo-profile.yml`](.matrixai/repo-profile.yml).
|
|
3
|
+
- Enforce the universal hotset [`.matrixai/matrixai-standards/standards/HOTSET.md`](.matrixai/matrixai-standards/standards/HOTSET.md).
|
|
4
|
+
- Enforce the profile doc under [`.matrixai/matrixai-standards/standards/profiles/`](.matrixai/matrixai-standards/standards/profiles) matching `profile:` in `.matrixai/repo-profile.yml` (e.g., `library-js`, `application-js`, `worker-js-cloudflare`, `docusaurus-js-cloudflare`).
|
|
5
|
+
- Profile index (for discovery): [`.matrixai/matrixai-standards/standards/profiles/README.md`](.matrixai/matrixai-standards/standards/profiles/README.md)
|
|
6
|
+
- Tooling contract reference: [`.matrixai/matrixai-standards/standards/coding/tooling/tooling-contract.md`](.matrixai/matrixai-standards/standards/coding/tooling/tooling-contract.md) (commands, artifacts, expectations per profile).
|
|
7
|
+
- Prefer ASCII punctuation/symbols when an equivalent exists (see [`.matrixai/matrixai-standards/standards/HOTSET.md`](.matrixai/matrixai-standards/standards/HOTSET.md) [MXS-GEN-006]).
|
|
8
|
+
- Ensure edits comply with [`.editorconfig`](.editorconfig) (LF line endings, 2-space indent, final newline, trim trailing whitespace).
|
|
9
|
+
- Line-reference policy (applies to all agent-generated repository content: Markdown, docs, templates, and code comments):
|
|
10
|
+
- Never emit `path:line` (e.g. `foo.ts:1`, `README.md:126`) into repository files.
|
|
11
|
+
- Do NOT put `:number` inside Markdown link destinations: `[x](path:123)` is banned.
|
|
12
|
+
- If a line reference is needed, use either:
|
|
13
|
+
- `[x](path#heading-anchor)` (if possible), or
|
|
14
|
+
- `[x](path) (line 123)` (preferred, portable), or
|
|
15
|
+
- `[x](path#L123)` only when explicitly targeting a renderer that supports `#L` anchors.
|
|
16
|
+
- If you would have emitted `:1`, drop it entirely: use `path` with no line info.
|
|
17
|
+
- Apply repo-local golden commands and overrides here (use `npm run lintfix` during active development; use `npm run lint` for non-mutating CI checks):
|
|
18
|
+
- build: npm run build
|
|
19
|
+
- test: npm test
|
|
20
|
+
- lintfix: npm run lintfix
|
|
21
|
+
- lint: npm run lint
|
|
22
|
+
- docs: npm run docs
|
|
23
|
+
- bench: (not defined in this repo)
|
package/README.md
CHANGED
|
@@ -21,11 +21,13 @@ npm install --save-dev @matrixai/lint
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
+
### CLI
|
|
25
|
+
|
|
24
26
|
```sh
|
|
25
27
|
matrixai-lint
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
With autofix:
|
|
29
31
|
|
|
30
32
|
```sh
|
|
31
33
|
matrixai-lint --fix
|
|
@@ -33,120 +35,186 @@ matrixai-lint --fix
|
|
|
33
35
|
|
|
34
36
|
### CLI Options
|
|
35
37
|
|
|
36
|
-
| Flag
|
|
37
|
-
|
|
|
38
|
-
| _(no flag)_
|
|
39
|
-
| `--fix`
|
|
40
|
-
| `--user-config`
|
|
41
|
-
| `--config <path>` | Explicitly use a custom ESLint config file |
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
| Flag | Description |
|
|
39
|
+
| ------------------------ | ---------------------------------------------------------------------------- |
|
|
40
|
+
| _(no flag)_ | Uses built-in Matrix AI ESLint config |
|
|
41
|
+
| `--fix` | Enables auto-fixing via ESLint and Prettier |
|
|
42
|
+
| `--user-config` | Uses detected `eslint.config.[js,mjs,cjs,ts]` from the project root if found |
|
|
43
|
+
| `--eslint-config <path>` | Explicitly use a custom ESLint config file |
|
|
44
|
+
| `--eslint <targets>` | ESLint targets (files, roots, or globs); implies ESLint domain selection |
|
|
45
|
+
| `--markdown <targets>` | Markdown targets (files, roots, or globs); implies markdown domain selection |
|
|
46
|
+
| `--shell <targets>` | Shell targets (files, roots, or globs); implies shell domain selection |
|
|
47
|
+
| `--domain <id...>` | Run only selected domains (`eslint`, `shell`, `markdown`) |
|
|
48
|
+
| `--skip-domain <id...>` | Skip selected domains (`eslint`, `shell`, `markdown`) |
|
|
49
|
+
| `--list-domains` | Print available domains and short descriptions, then exit 0 |
|
|
50
|
+
| `--explain` | Print per-domain decision details before execution |
|
|
51
|
+
| `-v, --verbose` | Increase log verbosity (repeat for more detail) |
|
|
52
|
+
|
|
53
|
+
Domain selection behavior:
|
|
54
|
+
|
|
55
|
+
- With no selectors and no domain-specific target flags, all built-in domains
|
|
56
|
+
run by default.
|
|
57
|
+
- Passing `--eslint` and/or `--shell` implies explicit domain selection from
|
|
58
|
+
those flags.
|
|
59
|
+
- `--eslint ...` runs ESLint only.
|
|
60
|
+
- `--shell ...` runs shell only.
|
|
61
|
+
- Passing both runs both.
|
|
62
|
+
- Passing `--markdown` implies markdown domain selection.
|
|
63
|
+
- `--markdown ...` runs markdown only.
|
|
64
|
+
- Combined with other target flags, only those targeted domains run.
|
|
65
|
+
- `shellcheck` is optional only for default auto-run shell execution.
|
|
66
|
+
- If shell is explicitly requested (`--shell ...` or `--domain shell`),
|
|
67
|
+
missing `shellcheck` is a failure.
|
|
68
|
+
- `--shell` accepts target paths and glob patterns.
|
|
69
|
+
- Directories are used as roots.
|
|
70
|
+
- File paths and glob patterns are reduced to search roots, then `*.sh` files
|
|
71
|
+
are discovered under those roots.
|
|
72
|
+
- `--markdown` accepts target paths and glob patterns.
|
|
73
|
+
- Directories are used as roots.
|
|
74
|
+
- File paths and glob patterns are reduced to search roots, then `*.md` /
|
|
75
|
+
`*.mdx` files are discovered under those roots.
|
|
76
|
+
|
|
77
|
+
#### Targeted workflows
|
|
78
|
+
|
|
79
|
+
- Only ESLint on a subset of files:
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
matrixai-lint --eslint "src/**/*.{ts,tsx}" --domain eslint
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
- Only shell scripts under specific roots:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
matrixai-lint --shell scripts packages/*/scripts
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- Markdown only:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
matrixai-lint --domain markdown
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
- Markdown only under selected roots:
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
matrixai-lint --markdown standards templates README.md
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- Mixed scoped run (ESLint + shell only):
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
matrixai-lint --eslint "src/**/*.{ts,tsx}" --shell scripts
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Examples
|
|
44
110
|
|
|
45
111
|
```sh
|
|
46
112
|
matrixai-lint --fix
|
|
47
113
|
matrixai-lint --user-config
|
|
48
|
-
matrixai-lint --config ./eslint.config.js --fix
|
|
114
|
+
matrixai-lint --eslint-config ./eslint.config.js --fix
|
|
115
|
+
matrixai-lint --eslint "src/**/*.{ts,tsx}" --shell scripts
|
|
116
|
+
matrixai-lint --markdown standards templates README.md
|
|
117
|
+
matrixai-lint --domain eslint markdown
|
|
118
|
+
matrixai-lint --skip-domain markdown
|
|
119
|
+
matrixai-lint --list-domains
|
|
120
|
+
matrixai-lint --explain --domain eslint
|
|
121
|
+
matrixai-lint -v -v --domain markdown
|
|
49
122
|
```
|
|
50
123
|
|
|
51
|
-
###
|
|
124
|
+
### ESLint config (ESM / NodeNext)
|
|
52
125
|
|
|
53
|
-
|
|
54
|
-
|
|
126
|
+
`matrixai-lint` ships an ESLint Flat Config array and types for TypeScript
|
|
127
|
+
projects configured as NodeNext.
|
|
55
128
|
|
|
56
|
-
|
|
129
|
+
#### Default import
|
|
57
130
|
|
|
58
|
-
|
|
59
|
-
|
|
131
|
+
```js
|
|
132
|
+
// eslint.config.js
|
|
133
|
+
import { config } from '@matrixai/lint';
|
|
60
134
|
|
|
61
|
-
|
|
135
|
+
export default config;
|
|
136
|
+
```
|
|
62
137
|
|
|
63
|
-
|
|
64
|
-
root, you can configure the linter using a `matrixai-lint-config.json` file at
|
|
65
|
-
the root:
|
|
138
|
+
#### Explicit subpath import
|
|
66
139
|
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"forceInclude": ["scripts", "src/overrides"]
|
|
71
|
-
}
|
|
72
|
-
```
|
|
140
|
+
```js
|
|
141
|
+
// eslint.config.js
|
|
142
|
+
import matrixai from '@matrixai/lint/configs/eslint.js';
|
|
73
143
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
| `tsconfigPaths` | `string[]` | One or more paths to `tsconfig.json` files |
|
|
77
|
-
| `forceInclude` | `string[]` | Paths to always include, even if excluded by tsconfig (must be included by at least one) |
|
|
144
|
+
export default matrixai;
|
|
145
|
+
```
|
|
78
146
|
|
|
79
|
-
|
|
80
|
-
> TypeScript will throw a parsing error.
|
|
147
|
+
### Lint configuration file
|
|
81
148
|
|
|
82
|
-
|
|
149
|
+
The linter is TypeScript-aware and requires a `tsconfig.json` to determine which
|
|
150
|
+
files to lint and how to parse them. By default it looks for `tsconfig.json` in
|
|
151
|
+
the project root and uses the `include`/`exclude` entries.
|
|
83
152
|
|
|
84
|
-
|
|
153
|
+
If your project uses more than one `tsconfig.json` or does not have one at the
|
|
154
|
+
root, configure the linter using a `matrixai-lint-config.json` file at the root.
|
|
85
155
|
|
|
86
|
-
|
|
156
|
+
This config uses a versioned schema and must explicitly declare `"version": 2`:
|
|
87
157
|
|
|
88
|
-
```
|
|
89
|
-
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"version": 2,
|
|
161
|
+
"root": ".",
|
|
162
|
+
"domains": {
|
|
163
|
+
"eslint": {
|
|
164
|
+
"tsconfigPaths": [
|
|
165
|
+
"./tsconfig.base.json",
|
|
166
|
+
"./packages/core/tsconfig.json"
|
|
167
|
+
],
|
|
168
|
+
"forceInclude": ["scripts", "src/overrides"]
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
90
172
|
```
|
|
91
173
|
|
|
92
|
-
|
|
174
|
+
| Field | Type | Description |
|
|
175
|
+
| ------------------------------ | ---------- | ----------------------------------------------------------------------------------------- |
|
|
176
|
+
| `version` | `2` | Required schema version marker |
|
|
177
|
+
| `root` | `string` | Optional lint root (defaults to `.`). `tsconfigPaths` are resolved relative to this root. |
|
|
178
|
+
| `domains.eslint.tsconfigPaths` | `string[]` | One or more paths to `tsconfig.json` files |
|
|
179
|
+
| `domains.eslint.forceInclude` | `string[]` | Paths to always include, even if excluded by tsconfig (must be included by at least one) |
|
|
93
180
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```
|
|
181
|
+
Note: If a path in `forceInclude` is not included in any of the `tsconfigPaths`,
|
|
182
|
+
TypeScript will throw a parsing error.
|
|
97
183
|
|
|
98
|
-
|
|
184
|
+
### Public API
|
|
99
185
|
|
|
100
|
-
|
|
186
|
+
Supported imports:
|
|
101
187
|
|
|
102
|
-
- `
|
|
103
|
-
|
|
104
|
-
-
|
|
105
|
-
|
|
188
|
+
- `@matrixai/lint`: named export `config`; types `MatrixAILintCfg`,
|
|
189
|
+
`RawMatrixCfg`, `CLIOptions`.
|
|
190
|
+
- `@matrixai/lint/configs/eslint.js`: default export of the ESLint Flat Config
|
|
191
|
+
array (same shape as `config`).
|
|
192
|
+
- `@matrixai/lint/configs/prettier.config.js`: reusable Prettier options object.
|
|
106
193
|
|
|
107
|
-
|
|
194
|
+
The exported `config` is intended as a composable base preset for downstream
|
|
195
|
+
`eslint.config.js` files, not as an internal-only implementation detail.
|
|
108
196
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
import matrixai from '@matrixai/lint/config';
|
|
112
|
-
|
|
113
|
-
export default [
|
|
114
|
-
...matrixai,
|
|
115
|
-
{
|
|
116
|
-
rules: {
|
|
117
|
-
'@typescript-eslint/no-explicit-any': 'error',
|
|
118
|
-
'no-console': 'off',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
];
|
|
122
|
-
```
|
|
197
|
+
Any package import path not listed above is internal and not a stable public
|
|
198
|
+
API.
|
|
123
199
|
|
|
124
|
-
##
|
|
200
|
+
## Contributing
|
|
125
201
|
|
|
126
|
-
|
|
202
|
+
Golden commands:
|
|
127
203
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
npm
|
|
131
|
-
|
|
132
|
-
npm run build
|
|
133
|
-
# run the repl (this allows you to import from ./src)
|
|
134
|
-
npm run tsx
|
|
135
|
-
# run the tests
|
|
136
|
-
npm run test
|
|
137
|
-
# lint the source code
|
|
138
|
-
npm run lint
|
|
139
|
-
# automatically fix the source
|
|
140
|
-
npm run lintfix
|
|
141
|
-
```
|
|
204
|
+
- `npm run build`
|
|
205
|
+
- `npm run lint`
|
|
206
|
+
- `npm run lintfix`
|
|
207
|
+
- `npm run docs`
|
|
142
208
|
|
|
143
|
-
|
|
209
|
+
Notes:
|
|
144
210
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
211
|
+
- `npm run lint` and `npm run lintfix` invoke `npm run prepare` first so the
|
|
212
|
+
compiled CLI in `dist/bin/lint.js` stays up to date while keeping TypeScript
|
|
213
|
+
incremental rebuilds fast.
|
|
214
|
+
|
|
215
|
+
For the authoritative contributor guidance see [AGENTS.md](AGENTS.md).
|
|
148
216
|
|
|
149
|
-
|
|
217
|
+
Docs: https://matrixai.github.io/js-lint/
|
|
150
218
|
|
|
151
219
|
### Publishing
|
|
152
220
|
|
package/dist/bin/lint.js
CHANGED
|
@@ -1,182 +1,165 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import os from 'node:os';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import process from 'node:process';
|
|
5
|
-
import childProcess from 'node:child_process';
|
|
6
4
|
import fs from 'node:fs';
|
|
7
|
-
import { createRequire } from 'node:module';
|
|
8
5
|
import url from 'node:url';
|
|
9
|
-
import { Command } from 'commander';
|
|
6
|
+
import { Command, Option } from 'commander';
|
|
7
|
+
import Logger, { StreamHandler } from '@matrixai/logger';
|
|
8
|
+
import { LINT_DOMAINS, resolveDomainSelection, createBuiltInDomainRegistry, listLintDomains, evaluateLintDomains, runLintDomainDecisions, } from '../domains/index.js';
|
|
10
9
|
import * as utils from '../utils.js';
|
|
11
|
-
const platform = os.platform();
|
|
12
10
|
const program = new Command();
|
|
13
|
-
const DEFAULT_SHELLCHECK_SEARCH_ROOTS = ['./src', './scripts', './tests'];
|
|
14
11
|
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
|
15
|
-
const builtinPrettierCfg = path.resolve(dirname, '../configs/prettier.config.
|
|
12
|
+
const builtinPrettierCfg = path.resolve(dirname, '../configs/prettier.config.js');
|
|
16
13
|
program
|
|
17
14
|
.name('matrixai-lint')
|
|
18
15
|
.description('Lint source files, scripts, and markdown with configured rules.')
|
|
16
|
+
.addOption(new Option('-v, --verbose', 'Increase log verbosity')
|
|
17
|
+
.argParser((_, previous = 0) => previous + 1)
|
|
18
|
+
.default(0))
|
|
19
19
|
.option('-f, --fix', 'Automatically fix problems')
|
|
20
|
+
.option('--list-domains', 'List available lint domains and exit')
|
|
21
|
+
.option('--explain', 'Print per-domain selection and execution decisions')
|
|
20
22
|
.option('--user-config', 'Use user-provided ESLint config instead of built-in one')
|
|
21
|
-
.option('--config <path>', 'Path to explicit ESLint config file')
|
|
22
|
-
.option('--eslint <
|
|
23
|
-
.option('--
|
|
24
|
-
.
|
|
25
|
-
|
|
23
|
+
.option('--eslint-config <path>', 'Path to explicit ESLint config file')
|
|
24
|
+
.option('--eslint <target...>', 'ESLint targets (files, roots, or globs)')
|
|
25
|
+
.option('--markdown <target...>', 'Markdown targets (files, roots, or globs)')
|
|
26
|
+
.option('--shell <target...>', 'Shell targets (files, roots, or globs) used to derive shellcheck search roots')
|
|
27
|
+
.addOption(new Option('--domain <id...>', `Run only selected domains (${LINT_DOMAINS.join(', ')})`).choices(LINT_DOMAINS))
|
|
28
|
+
.addOption(new Option('--skip-domain <id...>', `Skip selected domains (${LINT_DOMAINS.join(', ')})`).choices(LINT_DOMAINS));
|
|
29
|
+
function describeAvailability(decision) {
|
|
30
|
+
if (decision.detection == null) {
|
|
31
|
+
return 'not-evaluated';
|
|
32
|
+
}
|
|
33
|
+
const detection = decision.detection;
|
|
34
|
+
const status = detection.available ? 'available' : 'unavailable';
|
|
35
|
+
const reason = detection.unavailableReason;
|
|
36
|
+
return reason != null && reason.length > 0
|
|
37
|
+
? `${status} (${detection.availabilityKind}; ${reason})`
|
|
38
|
+
: `${status} (${detection.availabilityKind})`;
|
|
39
|
+
}
|
|
40
|
+
function describeRelevance(decision) {
|
|
41
|
+
if (decision.detection == null) {
|
|
42
|
+
return decision.plannedAction === 'skip-unselected'
|
|
43
|
+
? 'not-evaluated (domain not selected)'
|
|
44
|
+
: 'not-evaluated';
|
|
45
|
+
}
|
|
46
|
+
const detection = decision.detection;
|
|
47
|
+
const status = detection.relevant ? 'relevant' : 'not-relevant';
|
|
48
|
+
const reason = detection.relevanceReason;
|
|
49
|
+
return reason != null && reason.length > 0 ? `${status} (${reason})` : status;
|
|
50
|
+
}
|
|
51
|
+
function printDomainList(logger, domains) {
|
|
52
|
+
logger.info('Available lint domains:');
|
|
53
|
+
for (const domainInfo of domains) {
|
|
54
|
+
logger.info(`- ${domainInfo.domain}: ${domainInfo.description}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function printExplain(logger, decisions) {
|
|
58
|
+
logger.info('[matrixai-lint] Domain execution plan:');
|
|
59
|
+
for (const decision of decisions) {
|
|
60
|
+
logger.info(`[matrixai-lint] - domain: ${decision.domain}`);
|
|
61
|
+
logger.info(`[matrixai-lint] selection: ${decision.selectionSource}${decision.explicitlyRequested ? ' (explicit)' : ''}`);
|
|
62
|
+
logger.info(`[matrixai-lint] relevance: ${describeRelevance(decision)}`);
|
|
63
|
+
logger.info(`[matrixai-lint] availability: ${describeAvailability(decision)}`);
|
|
64
|
+
if (decision.detectionError != null) {
|
|
65
|
+
logger.error(`[matrixai-lint] detection-error: ${decision.detectionError}`);
|
|
66
|
+
}
|
|
67
|
+
logger.info(`[matrixai-lint] planned-action: ${decision.plannedAction}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
26
70
|
async function main(argv = process.argv) {
|
|
27
71
|
await program.parseAsync(argv);
|
|
28
72
|
const options = program.opts();
|
|
73
|
+
const logger = new Logger('matrixai-lint', undefined, [new StreamHandler()]);
|
|
74
|
+
logger.setLevel(utils.verboseToLogLevel(options.verbose));
|
|
29
75
|
const fix = Boolean(options.fix);
|
|
30
76
|
const useUserConfig = Boolean(options.userConfig);
|
|
31
|
-
const explicitConfigPath = options.
|
|
77
|
+
const explicitConfigPath = options.eslintConfig;
|
|
78
|
+
const listDomainsOnly = Boolean(options.listDomains);
|
|
79
|
+
const explain = Boolean(options.explain);
|
|
32
80
|
const eslintPatterns = options.eslint;
|
|
81
|
+
const markdownPatterns = options.markdown;
|
|
33
82
|
const shellPatterns = options.shell;
|
|
83
|
+
const { selectedDomains, explicitlyRequestedDomains, selectionSources } = resolveDomainSelection(options);
|
|
84
|
+
const domainRegistry = createBuiltInDomainRegistry({
|
|
85
|
+
prettierConfigPath: builtinPrettierCfg,
|
|
86
|
+
});
|
|
87
|
+
if (listDomainsOnly) {
|
|
88
|
+
printDomainList(logger, listLintDomains({
|
|
89
|
+
registry: domainRegistry,
|
|
90
|
+
executionOrder: LINT_DOMAINS,
|
|
91
|
+
}));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
34
94
|
let hadFailure = false;
|
|
35
95
|
// Resolve which config file to use
|
|
36
96
|
let chosenConfig;
|
|
97
|
+
let isConfigValid = true;
|
|
37
98
|
if (explicitConfigPath !== undefined) {
|
|
38
99
|
const absolutePath = path.resolve(explicitConfigPath);
|
|
39
100
|
if (!fs.existsSync(absolutePath)) {
|
|
40
|
-
|
|
41
|
-
|
|
101
|
+
logger.error(`--eslint-config points to "${explicitConfigPath}", but that file does not exist.`);
|
|
102
|
+
hadFailure = true;
|
|
103
|
+
isConfigValid = false;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
chosenConfig = absolutePath;
|
|
42
107
|
}
|
|
43
|
-
chosenConfig = absolutePath;
|
|
44
108
|
}
|
|
45
109
|
else if (useUserConfig) {
|
|
46
110
|
chosenConfig = utils.findUserESLintConfig();
|
|
47
111
|
if (chosenConfig === undefined) {
|
|
48
|
-
|
|
112
|
+
logger.warn('--user-config given but no local ESLint config was found. Falling back to built-in config.');
|
|
49
113
|
}
|
|
50
114
|
}
|
|
51
|
-
|
|
52
|
-
|
|
115
|
+
const decisions = await evaluateLintDomains({
|
|
116
|
+
registry: domainRegistry,
|
|
117
|
+
selectedDomains,
|
|
118
|
+
explicitlyRequestedDomains,
|
|
119
|
+
selectionSources,
|
|
120
|
+
executionOrder: LINT_DOMAINS,
|
|
121
|
+
context: {
|
|
53
122
|
fix,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
123
|
+
logger,
|
|
124
|
+
chosenConfig,
|
|
125
|
+
isConfigValid,
|
|
126
|
+
eslintPatterns,
|
|
127
|
+
markdownPatterns,
|
|
128
|
+
shellPatterns,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
if (explain) {
|
|
132
|
+
printExplain(logger, decisions);
|
|
60
133
|
}
|
|
61
|
-
|
|
62
|
-
|
|
134
|
+
const hadDomainFailure = await runLintDomainDecisions({
|
|
135
|
+
registry: domainRegistry,
|
|
136
|
+
decisions,
|
|
137
|
+
context: {
|
|
138
|
+
fix,
|
|
139
|
+
logger,
|
|
140
|
+
chosenConfig,
|
|
141
|
+
isConfigValid,
|
|
142
|
+
eslintPatterns,
|
|
143
|
+
markdownPatterns,
|
|
144
|
+
shellPatterns,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
if (hadDomainFailure) {
|
|
63
148
|
hadFailure = true;
|
|
64
149
|
}
|
|
65
|
-
const searchRoots = (shellPatterns?.length ? shellPatterns : DEFAULT_SHELLCHECK_SEARCH_ROOTS)
|
|
66
|
-
.map((p) => path.resolve(process.cwd(), p))
|
|
67
|
-
.filter((p) => fs.existsSync(p));
|
|
68
|
-
// Linting shell scripts (this does not have auto-fixing)
|
|
69
|
-
const shellCheckArgs = [
|
|
70
|
-
...searchRoots,
|
|
71
|
-
'-type',
|
|
72
|
-
'f',
|
|
73
|
-
'-regextype',
|
|
74
|
-
'posix-extended',
|
|
75
|
-
'-regex',
|
|
76
|
-
'.*\\.(sh)',
|
|
77
|
-
'-exec',
|
|
78
|
-
'shellcheck',
|
|
79
|
-
'{}',
|
|
80
|
-
'+',
|
|
81
|
-
];
|
|
82
|
-
if (utils.commandExists('find') && utils.commandExists('shellcheck')) {
|
|
83
|
-
console.error('Running shellcheck:');
|
|
84
|
-
if (searchRoots.length === 0) {
|
|
85
|
-
console.warn('No search roots found for shellcheck. Skipping shellcheck.');
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
console.error(' ' + ['find', ...shellCheckArgs].join(' '));
|
|
89
|
-
try {
|
|
90
|
-
childProcess.execFileSync('find', shellCheckArgs, {
|
|
91
|
-
stdio: ['inherit', 'inherit', 'inherit'],
|
|
92
|
-
windowsHide: true,
|
|
93
|
-
encoding: 'utf-8',
|
|
94
|
-
shell: platform === 'win32' ? true : false,
|
|
95
|
-
cwd: process.cwd(),
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
console.error('Shellcheck failed. ' + err);
|
|
100
|
-
hadFailure = true;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
console.warn('Skipping shellcheck: find or shellcheck not found in environment.');
|
|
106
|
-
}
|
|
107
|
-
// Linting markdown files
|
|
108
|
-
// Always include README if it exists
|
|
109
|
-
const markdownFiles = [];
|
|
110
|
-
if (fs.existsSync('README.md'))
|
|
111
|
-
markdownFiles.push('README.md');
|
|
112
|
-
for (const dir of ['pages', 'blog', 'docs']) {
|
|
113
|
-
if (fs.existsSync(dir))
|
|
114
|
-
markdownFiles.push(...utils.collectMarkdown(dir));
|
|
115
|
-
}
|
|
116
|
-
if (markdownFiles.length === 0) {
|
|
117
|
-
console.warn('Skipping Prettier: no Markdown/MDX files found.');
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const prettierArgs = [
|
|
121
|
-
'--config',
|
|
122
|
-
builtinPrettierCfg,
|
|
123
|
-
'--config-precedence',
|
|
124
|
-
'cli-override',
|
|
125
|
-
'--no-editorconfig',
|
|
126
|
-
fix ? '--write' : '--check',
|
|
127
|
-
...markdownFiles,
|
|
128
|
-
];
|
|
129
|
-
console.error('Running prettier:');
|
|
130
|
-
const require = createRequire(import.meta.url);
|
|
131
|
-
let prettierBin = null;
|
|
132
|
-
try {
|
|
133
|
-
// Resolves to @matrixai/lint/node_modules/prettier/bin/prettier.cjs
|
|
134
|
-
prettierBin = require.resolve('prettier/bin/prettier.cjs');
|
|
135
|
-
}
|
|
136
|
-
catch {
|
|
137
|
-
// Bundled copy not found
|
|
138
|
-
}
|
|
139
|
-
try {
|
|
140
|
-
if (prettierBin) {
|
|
141
|
-
console.error(` ${prettierBin} \n ${prettierArgs.join('\n' + ' ')}`);
|
|
142
|
-
childProcess.execFileSync(process.execPath, [prettierBin, ...prettierArgs], {
|
|
143
|
-
stdio: 'inherit',
|
|
144
|
-
windowsHide: true,
|
|
145
|
-
encoding: 'utf-8',
|
|
146
|
-
cwd: process.cwd(),
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
console.error('prettier' + prettierArgs.join('\n' + ' '));
|
|
151
|
-
childProcess.execFileSync('prettier', prettierArgs, {
|
|
152
|
-
stdio: 'inherit',
|
|
153
|
-
windowsHide: true,
|
|
154
|
-
encoding: 'utf-8',
|
|
155
|
-
shell: platform === 'win32',
|
|
156
|
-
cwd: process.cwd(),
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (err) {
|
|
161
|
-
if (!fix) {
|
|
162
|
-
console.error('Prettier check failed.');
|
|
163
|
-
hadFailure = true;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw err; // Should not happen when --write
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
150
|
if (hadFailure) {
|
|
170
|
-
|
|
151
|
+
logger.error('[matrixai-lint] ✖ Linting failed.');
|
|
171
152
|
process.exit(1);
|
|
172
153
|
}
|
|
173
154
|
else {
|
|
174
|
-
|
|
155
|
+
logger.info('[matrixai-lint] ✔ Linting passed.');
|
|
175
156
|
}
|
|
176
157
|
}
|
|
177
|
-
/* eslint-enable no-console */
|
|
178
|
-
export default main;
|
|
179
158
|
if (import.meta.url.startsWith('file:')) {
|
|
180
|
-
|
|
159
|
+
const modulePath = url.fileURLToPath(import.meta.url);
|
|
160
|
+
if (process.argv[1] === modulePath) {
|
|
161
|
+
void main();
|
|
162
|
+
}
|
|
181
163
|
}
|
|
164
|
+
export default main;
|
|
182
165
|
//# sourceMappingURL=lint.js.map
|
package/dist/bin/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/bin/lint.ts"],"names":[],"mappings":";AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"lint.js","sourceRoot":"","sources":["../../src/bin/lint.ts"],"names":[],"mappings":";AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,MAAM,EAAE,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GAEvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,KAAK,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