@rslint/core 0.5.2 → 0.5.4-canary.1781059600
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/bin/rslint.cjs +21 -4
- package/dist/0~engine.js +406 -0
- package/dist/34.js +33 -0
- package/dist/browser.d.ts +52 -39
- package/dist/browser.js +42 -74
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +1051 -93
- package/dist/config-loader.d.ts +45 -14
- package/dist/config-loader.js +95 -59
- package/dist/eslint-plugin/612.js +43 -0
- package/dist/eslint-plugin/index.d.ts +892 -0
- package/dist/eslint-plugin/index.js +26692 -0
- package/dist/eslint-plugin/lint-worker.js +26225 -0
- package/dist/eslint-plugin/types.d.ts +23 -0
- package/dist/eslint-plugin/types.js +1 -0
- package/dist/index.d.ts +626 -19
- package/dist/index.js +598 -15
- package/dist/service.d.ts +360 -30
- package/dist/service.js +19 -34
- package/package.json +27 -11
- package/dist/browser.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/config-loader.d.ts.map +0 -1
- package/dist/configs/import.d.ts +0 -6
- package/dist/configs/import.d.ts.map +0 -1
- package/dist/configs/import.js +0 -7
- package/dist/configs/index.d.ts +0 -16
- package/dist/configs/index.d.ts.map +0 -1
- package/dist/configs/index.js +0 -32
- package/dist/configs/javascript.d.ts +0 -6
- package/dist/configs/javascript.d.ts.map +0 -1
- package/dist/configs/javascript.js +0 -72
- package/dist/configs/jest.d.ts +0 -7
- package/dist/configs/jest.d.ts.map +0 -1
- package/dist/configs/jest.js +0 -35
- package/dist/configs/promise.d.ts +0 -6
- package/dist/configs/promise.d.ts.map +0 -1
- package/dist/configs/promise.js +0 -20
- package/dist/configs/react-hooks.d.ts +0 -6
- package/dist/configs/react-hooks.d.ts.map +0 -1
- package/dist/configs/react-hooks.js +0 -24
- package/dist/configs/react.d.ts +0 -6
- package/dist/configs/react.d.ts.map +0 -1
- package/dist/configs/react.js +0 -31
- package/dist/configs/typescript.d.ts +0 -8
- package/dist/configs/typescript.d.ts.map +0 -1
- package/dist/configs/typescript.js +0 -119
- package/dist/configs/unicorn.d.ts +0 -8
- package/dist/configs/unicorn.d.ts.map +0 -1
- package/dist/configs/unicorn.js +0 -161
- package/dist/define-config.d.ts +0 -109
- package/dist/define-config.d.ts.map +0 -1
- package/dist/define-config.js +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/node.d.ts +0 -31
- package/dist/node.d.ts.map +0 -1
- package/dist/node.js +0 -116
- package/dist/service.d.ts.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -342
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
- package/dist/utils/args.d.ts +0 -19
- package/dist/utils/args.d.ts.map +0 -1
- package/dist/utils/args.js +0 -101
- package/dist/utils/config-discovery.d.ts +0 -47
- package/dist/utils/config-discovery.d.ts.map +0 -1
- package/dist/utils/config-discovery.js +0 -238
- package/dist/worker.d.ts +0 -2
- package/dist/worker.d.ts.map +0 -1
- package/dist/worker.js +0 -114
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import picomatch from 'picomatch';
|
|
4
|
-
import { globSync as tinyglobbySync } from 'tinyglobby';
|
|
5
|
-
export const JS_CONFIG_FILES = [
|
|
6
|
-
'rslint.config.js',
|
|
7
|
-
'rslint.config.mjs',
|
|
8
|
-
'rslint.config.ts',
|
|
9
|
-
'rslint.config.mts',
|
|
10
|
-
];
|
|
11
|
-
export function findJSConfig(cwd) {
|
|
12
|
-
for (const name of JS_CONFIG_FILES) {
|
|
13
|
-
const p = path.join(cwd, name);
|
|
14
|
-
if (fs.existsSync(p))
|
|
15
|
-
return p;
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Walk upward from startDir to the filesystem root, returning the first
|
|
21
|
-
* rslint JS/TS config file found. Returns null if none is found.
|
|
22
|
-
*/
|
|
23
|
-
export function findJSConfigUp(startDir) {
|
|
24
|
-
let dir = path.resolve(startDir);
|
|
25
|
-
while (true) {
|
|
26
|
-
const found = findJSConfig(dir);
|
|
27
|
-
if (found)
|
|
28
|
-
return found;
|
|
29
|
-
const parent = path.dirname(dir);
|
|
30
|
-
if (parent === dir)
|
|
31
|
-
return null;
|
|
32
|
-
dir = parent;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Recursively scan a directory for all rslint JS/TS config files.
|
|
37
|
-
* Skips node_modules and .git directories (aligned with ESLint defaults).
|
|
38
|
-
* Uses tinyglobby (fdir-backed) for fast directory traversal.
|
|
39
|
-
*
|
|
40
|
-
* tinyglobby returns POSIX-style paths even on Windows, so the result is
|
|
41
|
-
* normalized through path.normalize to match the native separator that
|
|
42
|
-
* findJSConfigUp / path.join produce. Without this, Map<configPath, ...>
|
|
43
|
-
* dedupe against findJSConfigUp results fails on Windows.
|
|
44
|
-
*/
|
|
45
|
-
export function findJSConfigsInDir(startDir) {
|
|
46
|
-
const resolved = path.resolve(startDir);
|
|
47
|
-
return tinyglobbySync(['**/rslint.config.{js,mjs,ts,mts}'], {
|
|
48
|
-
cwd: resolved,
|
|
49
|
-
absolute: true,
|
|
50
|
-
dot: true,
|
|
51
|
-
ignore: ['**/node_modules/**', '**/.git/**'],
|
|
52
|
-
}).map((p) => path.normalize(p));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Discover JS/TS config files for the given targets.
|
|
56
|
-
*
|
|
57
|
-
* For file arguments, config is searched upward from each file's directory,
|
|
58
|
-
* so different files can find different configs (monorepo multi-config).
|
|
59
|
-
*
|
|
60
|
-
* For no-args and directory arguments, config is searched upward from the
|
|
61
|
-
* starting point AND nested configs within the scope are scanned. This
|
|
62
|
-
* ensures sub-package configs in a monorepo are discovered when linting
|
|
63
|
-
* from the root.
|
|
64
|
-
*/
|
|
65
|
-
export function discoverConfigs(files, dirs, cwd, explicitConfig) {
|
|
66
|
-
// Map: configPath -> configDirectory
|
|
67
|
-
const configs = new Map();
|
|
68
|
-
const addConfig = (configPath) => {
|
|
69
|
-
if (!configs.has(configPath)) {
|
|
70
|
-
configs.set(configPath, path.dirname(configPath));
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
if (explicitConfig) {
|
|
74
|
-
const resolved = path.resolve(cwd, explicitConfig);
|
|
75
|
-
addConfig(resolved);
|
|
76
|
-
return configs;
|
|
77
|
-
}
|
|
78
|
-
// Collect unique start directories for upward config search
|
|
79
|
-
const startDirs = new Set();
|
|
80
|
-
// Collect directories to scan for nested configs
|
|
81
|
-
const scanDirs = [];
|
|
82
|
-
if (files.length === 0 && dirs.length === 0) {
|
|
83
|
-
startDirs.add(cwd);
|
|
84
|
-
scanDirs.push(cwd);
|
|
85
|
-
}
|
|
86
|
-
// Deduplicate file directories before searching
|
|
87
|
-
for (const file of files) {
|
|
88
|
-
startDirs.add(path.dirname(file));
|
|
89
|
-
}
|
|
90
|
-
for (const dir of dirs) {
|
|
91
|
-
startDirs.add(dir);
|
|
92
|
-
scanDirs.push(dir);
|
|
93
|
-
}
|
|
94
|
-
// Upward traversal: find nearest config for each start directory
|
|
95
|
-
for (const startDir of startDirs) {
|
|
96
|
-
const configPath = findJSConfigUp(startDir);
|
|
97
|
-
if (configPath) {
|
|
98
|
-
addConfig(configPath);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// Scan for nested configs within the target scope (no-args and dir-args).
|
|
102
|
-
// Broken configs are tolerated by runWithJSConfigs (skipped with warning).
|
|
103
|
-
for (const dir of scanDirs) {
|
|
104
|
-
for (const configPath of findJSConfigsInDir(dir)) {
|
|
105
|
-
addConfig(configPath);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return configs;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Check if a config entry is a "global ignore" entry — an entry with only
|
|
112
|
-
* `ignores` and no other meaningful fields. Aligns with ESLint flat config
|
|
113
|
-
* semantics where such entries prevent directory traversal.
|
|
114
|
-
*/
|
|
115
|
-
function isGlobalIgnoreEntry(entry) {
|
|
116
|
-
const ignores = entry.ignores;
|
|
117
|
-
if (!Array.isArray(ignores) || ignores.length === 0)
|
|
118
|
-
return false;
|
|
119
|
-
return (entry.files == null &&
|
|
120
|
-
entry.rules == null &&
|
|
121
|
-
entry.plugins == null &&
|
|
122
|
-
entry.languageOptions == null &&
|
|
123
|
-
entry.settings == null);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Extract global ignore patterns from a config's entries.
|
|
127
|
-
*/
|
|
128
|
-
function getGlobalIgnores(entries) {
|
|
129
|
-
const patterns = [];
|
|
130
|
-
for (const entry of entries) {
|
|
131
|
-
if (isGlobalIgnoreEntry(entry)) {
|
|
132
|
-
for (const pattern of entry.ignores) {
|
|
133
|
-
patterns.push(pattern);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return patterns;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Check if a directory path is matched by any of the given ignore patterns.
|
|
141
|
-
* Patterns are resolved relative to the parent config's directory.
|
|
142
|
-
* Uses picomatch for full glob support (**, *, {}, etc.).
|
|
143
|
-
*
|
|
144
|
-
* A directory is considered ignored if the pattern matches the directory
|
|
145
|
-
* itself or any of its ancestor paths. For example, pattern `__tests__/**`
|
|
146
|
-
* matches both `__tests__/` and `__tests__/fixtures/`.
|
|
147
|
-
*/
|
|
148
|
-
function isDirIgnoredByPatterns(dirPath, patterns, parentConfigDir) {
|
|
149
|
-
const relDir = path.relative(parentConfigDir, dirPath);
|
|
150
|
-
if (!relDir || relDir.startsWith('..'))
|
|
151
|
-
return false;
|
|
152
|
-
const normalizedRelDir = relDir.split(path.sep).join('/');
|
|
153
|
-
for (const pattern of patterns) {
|
|
154
|
-
// Skip empty or negation patterns.
|
|
155
|
-
if (!pattern || pattern.startsWith('!'))
|
|
156
|
-
continue;
|
|
157
|
-
// Skip file-level patterns (ending with /**/* or /*). These only ignore
|
|
158
|
-
// files inside a directory, NOT the directory itself. ESLint v10's
|
|
159
|
-
// isDirectoryIgnored does not block traversal for file-level patterns,
|
|
160
|
-
// allowing `!` re-include to work for files inside.
|
|
161
|
-
// Only directory-level patterns (ending with /** or /) block traversal.
|
|
162
|
-
if (pattern.endsWith('/**/*') ||
|
|
163
|
-
(pattern.endsWith('/*') && !pattern.endsWith('/**')))
|
|
164
|
-
continue;
|
|
165
|
-
const isMatch = picomatch(pattern, { dot: true });
|
|
166
|
-
// Check if the pattern matches the directory itself or a file inside it.
|
|
167
|
-
// We test: the dir path, dir path + trailing slash, and a synthetic
|
|
168
|
-
// child path to handle patterns like `dir/**`.
|
|
169
|
-
if (isMatch(normalizedRelDir) ||
|
|
170
|
-
isMatch(normalizedRelDir + '/') ||
|
|
171
|
-
isMatch(normalizedRelDir + '/x')) {
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
// For nested dirs, also check if any parent segment matches.
|
|
175
|
-
// e.g., pattern `__tests__/**` should match `__tests__/fixtures/deep`.
|
|
176
|
-
const segments = normalizedRelDir.split('/');
|
|
177
|
-
for (let i = 1; i < segments.length; i++) {
|
|
178
|
-
const partial = segments.slice(0, i).join('/');
|
|
179
|
-
if (isMatch(partial) ||
|
|
180
|
-
isMatch(partial + '/') ||
|
|
181
|
-
isMatch(partial + '/x')) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Filter out nested configs whose directory is covered by an ancestor config's
|
|
190
|
-
* global ignores. Aligns with ESLint v10 behavior: when traversing directories,
|
|
191
|
-
* global ignores in a parent config prevent entering ignored directories, so
|
|
192
|
-
* nested configs in those directories are never discovered.
|
|
193
|
-
*
|
|
194
|
-
* Example: root config has `{ ignores: ['__tests__/**'] }`.
|
|
195
|
-
* A nested config at `__tests__/fixtures/rslint.config.js` is filtered out
|
|
196
|
-
* because `__tests__/fixtures/` is within the root config's global ignores.
|
|
197
|
-
*/
|
|
198
|
-
export function filterConfigsByParentIgnores(configEntries) {
|
|
199
|
-
if (configEntries.length <= 1)
|
|
200
|
-
return configEntries;
|
|
201
|
-
// Resolve symlinks and normalize trailing slashes for reliable ancestor checks.
|
|
202
|
-
const resolvedDirs = new Map();
|
|
203
|
-
for (const entry of configEntries) {
|
|
204
|
-
let dir = entry.configDirectory.replace(/[/\\]+$/, '');
|
|
205
|
-
try {
|
|
206
|
-
dir = fs.realpathSync(dir);
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
// Keep the original (stripped) path if realpath fails
|
|
210
|
-
}
|
|
211
|
-
resolvedDirs.set(entry, dir);
|
|
212
|
-
}
|
|
213
|
-
// Sort by directory depth (shallowest first) so parents are processed first
|
|
214
|
-
const sorted = [...configEntries].sort((a, b) => (resolvedDirs.get(a)?.length ?? 0) - (resolvedDirs.get(b)?.length ?? 0));
|
|
215
|
-
const result = [];
|
|
216
|
-
for (const config of sorted) {
|
|
217
|
-
let ignored = false;
|
|
218
|
-
const configDir = resolvedDirs.get(config);
|
|
219
|
-
for (const parent of result) {
|
|
220
|
-
const parentDir = resolvedDirs.get(parent);
|
|
221
|
-
if (!configDir.startsWith(parentDir + path.sep) &&
|
|
222
|
-
configDir !== parentDir) {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
const globalIgnores = getGlobalIgnores(parent.entries);
|
|
226
|
-
if (globalIgnores.length === 0)
|
|
227
|
-
continue;
|
|
228
|
-
if (isDirIgnoredByPatterns(configDir, globalIgnores, parentDir)) {
|
|
229
|
-
ignored = true;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (!ignored) {
|
|
234
|
-
result.push(config);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return result;
|
|
238
|
-
}
|
package/dist/worker.d.ts
DELETED
package/dist/worker.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":""}
|
package/dist/worker.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/// <reference lib="webworker" />
|
|
2
|
-
// Global state for the worker
|
|
3
|
-
let rslintProcess = null;
|
|
4
|
-
// const nextMessageId = 1;
|
|
5
|
-
const pendingMessages = new Map();
|
|
6
|
-
/**
|
|
7
|
-
* Initialize the rslint process (could be WASM or other browser-compatible implementation)
|
|
8
|
-
*/
|
|
9
|
-
async function initializeRslint() {
|
|
10
|
-
try {
|
|
11
|
-
// In a real implementation, this would load the rslint WASM module
|
|
12
|
-
// or initialize a browser-compatible version of rslint
|
|
13
|
-
// For now, we'll simulate the initialization
|
|
14
|
-
// Example: Load WASM module
|
|
15
|
-
// const rslintWasm = await import('./rslint.wasm');
|
|
16
|
-
// rslintProcess = await rslintWasm.default();
|
|
17
|
-
// rslint-disable-next-line no-console
|
|
18
|
-
console.log('Rslint worker initialized');
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
console.error('Failed to initialize rslint:', error);
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Send a message to the rslint process
|
|
27
|
-
*/
|
|
28
|
-
async function sendToRslint(kind, data) {
|
|
29
|
-
if (!rslintProcess) {
|
|
30
|
-
throw new Error('Rslint process not initialized');
|
|
31
|
-
}
|
|
32
|
-
// In a real implementation, this would call the appropriate method on the rslint process
|
|
33
|
-
// For now, we'll simulate the response
|
|
34
|
-
switch (kind) {
|
|
35
|
-
case 'handshake':
|
|
36
|
-
return { version: '1.0.0', status: 'ok' };
|
|
37
|
-
case 'lint':
|
|
38
|
-
// Simulate linting response
|
|
39
|
-
return {
|
|
40
|
-
diagnostics: [],
|
|
41
|
-
errorCount: 0,
|
|
42
|
-
fileCount: data.files?.length || 0,
|
|
43
|
-
ruleCount: 0,
|
|
44
|
-
duration: '0ms',
|
|
45
|
-
};
|
|
46
|
-
case 'applyFixes':
|
|
47
|
-
// Simulate apply fixes response
|
|
48
|
-
return {
|
|
49
|
-
fixedContent: [data.fileContent],
|
|
50
|
-
wasFixed: false,
|
|
51
|
-
appliedCount: 0,
|
|
52
|
-
unappliedCount: data.diagnostics?.length || 0,
|
|
53
|
-
};
|
|
54
|
-
case 'exit':
|
|
55
|
-
rslintProcess = null;
|
|
56
|
-
return { status: 'ok' };
|
|
57
|
-
default:
|
|
58
|
-
throw new Error(`Unknown message kind: ${kind}`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Handle messages from the main thread
|
|
63
|
-
*/
|
|
64
|
-
async function handleMessage(event) {
|
|
65
|
-
const { id, kind, data } = event.data;
|
|
66
|
-
try {
|
|
67
|
-
// Ensure rslint is initialized
|
|
68
|
-
if (!rslintProcess && kind !== 'exit') {
|
|
69
|
-
await initializeRslint();
|
|
70
|
-
}
|
|
71
|
-
// Send message to rslint and get response
|
|
72
|
-
const response = await sendToRslint(kind, data);
|
|
73
|
-
// Send response back to main thread
|
|
74
|
-
self.postMessage({
|
|
75
|
-
id,
|
|
76
|
-
kind: 'response',
|
|
77
|
-
data: response,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
// Send error back to main thread
|
|
82
|
-
self.postMessage({
|
|
83
|
-
id,
|
|
84
|
-
kind: 'error',
|
|
85
|
-
data: {
|
|
86
|
-
message: error instanceof Error ? error.message : String(error),
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Handle worker errors
|
|
93
|
-
*/
|
|
94
|
-
function handleError(error) {
|
|
95
|
-
console.error('Worker error:', error);
|
|
96
|
-
// Send error to main thread for all pending messages
|
|
97
|
-
for (const [id] of pendingMessages) {
|
|
98
|
-
self.postMessage({
|
|
99
|
-
id,
|
|
100
|
-
kind: 'error',
|
|
101
|
-
data: {
|
|
102
|
-
message: `Worker error: ${error.message}`,
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
pendingMessages.clear();
|
|
107
|
-
}
|
|
108
|
-
// Set up event listeners
|
|
109
|
-
self.addEventListener('message', handleMessage);
|
|
110
|
-
self.addEventListener('error', handleError);
|
|
111
|
-
// Initialize the worker
|
|
112
|
-
// rslint-disable-next-line no-console
|
|
113
|
-
console.log('Rslint worker started');
|
|
114
|
-
export {};
|