loadwise 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 +88 -19
- package/agent/hooks/check-edited-file.mjs +146 -28
- package/dist/bin/github-action.js +3 -74
- package/dist/bin/loadwise.js +12 -12
- package/dist/lib/accessibility/aria-tables.js +10 -6
- package/dist/lib/accessibility/document-reference-rules.js +13 -3
- package/dist/lib/accessibility/jsx-elements.js +34 -16
- package/dist/lib/accessibility/native-interactive.js +51 -13
- package/dist/lib/accessibility/rules.js +4 -2
- package/dist/lib/accessibility/site-fixes/aria-typo.js +65 -0
- package/dist/lib/accessibility/site-fixes/html-language.js +45 -9
- package/dist/lib/accessibility/template-elements.js +5 -3
- package/dist/lib/editor/actions.js +15 -9
- package/dist/lib/editor/diagnostics.js +110 -107
- package/dist/lib/editor/finding-comparison.js +4 -25
- package/dist/lib/editor/hover-markdown.js +104 -0
- package/dist/lib/editor/inline-fix.js +50 -0
- package/dist/lib/editor/inline-recommendation.js +27 -0
- package/dist/lib/editor/language-server.js +94 -18
- package/dist/lib/editor/scan-session.js +2 -1
- package/dist/lib/editor/standalone-performance-examples.js +48 -0
- package/dist/lib/maintainability/analysis/analyze-source.js +2 -0
- package/dist/lib/maintainability/architecture/architecture.js +50 -2
- package/dist/lib/maintainability/cli/inputs.js +12 -5
- package/dist/lib/maintainability/cli/site-fix.js +3 -0
- package/dist/lib/maintainability/cli.js +6 -3
- package/dist/lib/maintainability/examples.js +48 -0
- package/dist/lib/maintainability/quality/modern-node-callbacks.js +188 -0
- package/dist/lib/maintainability/quality/modern-syntax.js +301 -0
- package/dist/lib/maintainability/quality/tsconfig-strict.js +307 -15
- package/dist/lib/maintainability/rule-ids.js +18 -0
- package/dist/lib/maintainability/scan-changed.js +33 -2
- package/dist/lib/maintainability/scan.js +10 -1
- package/dist/lib/maintainability/site-fixes/unused-bindings.js +15 -6
- package/dist/lib/maintainability/unused/module-usage-signatures.js +116 -0
- package/dist/lib/maintainability/unused/module-usage.js +67 -106
- package/dist/lib/maintainability/unused/unused-bindings.js +143 -8
- package/dist/lib/maintainability/unused/unused-dependencies.js +218 -0
- package/dist/lib/maintainability/unused/unused-modules.js +4 -0
- package/dist/lib/performance/analysis/missing-packages.js +3 -0
- package/dist/lib/performance/analysis/source-text.js +2 -2
- package/dist/lib/performance/analyze.js +4 -1
- package/dist/lib/performance/async/floating-promises.js +25 -4
- package/dist/lib/performance/cli/cli-output.js +9 -3
- package/dist/lib/performance/cli/cli-policy.js +25 -2
- package/dist/lib/performance/cli/cli-scan.js +25 -24
- package/dist/lib/performance/cli/scan-outcome.js +19 -1
- package/dist/lib/performance/cli/shared-security-inputs.js +27 -0
- package/dist/lib/performance/cli/watch.js +27 -8
- package/dist/lib/performance/collections/collection-lookups.js +27 -10
- package/dist/lib/performance/collections/collection-reduce.js +32 -2
- package/dist/lib/performance/collections/collections.js +28 -0
- package/dist/lib/performance/collections/repeated.js +25 -1
- package/dist/lib/performance/contracts/cli.js +22 -11
- package/dist/lib/performance/contracts/git-files.js +46 -1
- package/dist/lib/performance/datastores/pooling.js +1 -17
- package/dist/lib/performance/datastores/postgres.js +41 -33
- package/dist/lib/performance/engine/native.js +5 -1
- package/dist/lib/performance/frontend/angular-template-calls.js +187 -0
- package/dist/lib/performance/frontend/frontend-dom-perf.js +68 -8
- package/dist/lib/performance/frontend/frontend-perf.js +115 -171
- package/dist/lib/performance/frontend/frontend-render-perf.js +7 -3
- package/dist/lib/performance/frontend/jsx-element-perf.js +171 -0
- package/dist/lib/performance/frontend/next-fetch-waterfall.js +346 -29
- package/dist/lib/performance/frontend/rxjs-subscriptions.js +155 -0
- package/dist/lib/performance/frontend/seo/client-fetched-content.js +196 -0
- package/dist/lib/performance/frontend/seo/navigation-without-link.js +116 -0
- package/dist/lib/performance/frontend/seo/next-routes.js +114 -0
- package/dist/lib/performance/frontend/seo/route-metadata.js +158 -0
- package/dist/lib/performance/frontend/seo/seo-rules.js +9 -0
- package/dist/lib/performance/frontend/seo/sitewide-noindex.js +103 -0
- package/dist/lib/performance/frontend/template-tracking.js +86 -2
- package/dist/lib/performance/frontend/vue-options-hooks.js +108 -0
- package/dist/lib/performance/orm/prisma.js +1 -25
- package/dist/lib/performance/projects.js +3 -2
- package/dist/lib/performance/query-loops/service-loops.js +38 -8
- package/dist/lib/performance/request/json-stringify-output.js +82 -4
- package/dist/lib/performance/request/promise-schedulers.js +180 -0
- package/dist/lib/performance/request/request-handlers.js +43 -4
- package/dist/lib/performance/request/unbounded-promise-all.js +13 -52
- package/dist/lib/performance/rule-ids.js +26 -2
- package/dist/lib/performance/site-fix.js +1 -0
- package/dist/lib/reliability/react-bugs.js +9 -0
- package/dist/lib/reliability/react-state-aliases.js +94 -4
- package/dist/lib/reliability/react-state.js +24 -5
- package/dist/lib/security/auth-crypto/secrets.js +121 -16
- package/dist/lib/security/cli.js +1 -1
- package/dist/lib/security/credential-entropy.js +12 -0
- package/dist/lib/security/deps/lockfiles.js +3 -1
- package/dist/lib/security/examples/files.js +110 -0
- package/dist/lib/security/examples/request-forgery.js +1 -1
- package/dist/lib/security/exposure/frontend-security.js +11 -2
- package/dist/lib/security/exposure/prototype-pollution.js +73 -4
- package/dist/lib/security/files/azure-pipelines.js +69 -0
- package/dist/lib/security/files/bitbucket-pipelines.js +32 -0
- package/dist/lib/security/files/ci-platforms.js +16 -0
- package/dist/lib/security/files/ci-shared.js +260 -0
- package/dist/lib/security/files/circleci.js +81 -0
- package/dist/lib/security/files/dockerfile.js +188 -3
- package/dist/lib/security/files/github-actions.js +490 -0
- package/dist/lib/security/files/gitlab-ci.js +90 -0
- package/dist/lib/security/files/hcl.js +264 -0
- package/dist/lib/security/files/hosting-config.js +159 -0
- package/dist/lib/security/files/http-headers.js +65 -0
- package/dist/lib/security/files/index.js +62 -7
- package/dist/lib/security/files/jenkinsfile.js +482 -0
- package/dist/lib/security/files/json-nodes.js +67 -0
- package/dist/lib/security/files/nginx.js +501 -0
- package/dist/lib/security/files/package-scripts.js +175 -0
- package/dist/lib/security/files/rule-ids.js +29 -0
- package/dist/lib/security/files/secret-values.js +31 -5
- package/dist/lib/security/files/secrets.js +44 -13
- package/dist/lib/security/files/terraform.js +345 -0
- package/dist/lib/security/injection/nosql.js +2 -1
- package/dist/lib/security/injection/sql.js +2 -2
- package/dist/lib/security/lexical-declaration.js +28 -0
- package/dist/lib/security/pg-identifier-guards.js +90 -1
- package/dist/lib/security/request-forgery/member-chain.js +41 -0
- package/dist/lib/security/request-forgery/open-redirect.js +45 -8
- package/dist/lib/security/request-forgery/shared.js +18 -3
- package/dist/lib/security/rule-descriptions.js +29 -0
- package/dist/lib/security/rule-ids.js +29 -0
- package/dist/lib/security/taint/original-string-validation.js +229 -0
- package/dist/lib/security/taint/validators.js +1 -1
- package/dist/lib/shared/agent/review-delivery.js +3 -1
- package/dist/lib/shared/analysis/ast-semantics.js +17 -1
- package/dist/lib/shared/analysis/hot-path-graph.js +55 -19
- package/dist/lib/shared/analysis/next-env-config.js +232 -0
- package/dist/lib/shared/analysis/scan-cache-git.js +114 -0
- package/dist/lib/shared/analysis/scan-cache-loadwise-packages.js +54 -0
- package/dist/lib/shared/analysis/scan-cache-project-inputs.js +221 -0
- package/dist/lib/shared/analysis/scan-cache-sources.js +235 -0
- package/dist/lib/shared/analysis/scan-cache-storage.js +24 -0
- package/dist/lib/shared/analysis/scan-cache.js +158 -174
- package/dist/lib/shared/check-watch.js +3 -3
- package/dist/lib/shared/check.js +25 -4
- package/dist/lib/shared/config.js +1 -1
- package/dist/lib/shared/conventional-projects.js +40 -0
- package/dist/lib/shared/fix/fix-command.js +2 -0
- package/dist/lib/shared/fix/fix-usage.js +47 -0
- package/dist/lib/shared/fix/project-file-access.js +43 -20
- package/dist/lib/shared/fix.js +4 -35
- package/dist/lib/shared/formats/security-cwe.js +29 -0
- package/dist/lib/shared/project-root.js +1 -1
- package/dist/lib/shared/reporting/action-comparison.js +78 -0
- package/dist/lib/shared/reporting/automatic-fix-signal.js +7 -2
- package/dist/lib/shared/reporting/check-text.js +7 -5
- package/dist/lib/shared/reporting/pillars.js +28 -8
- package/dist/lib/shared/reporting/source-report.js +4 -4
- package/dist/lib/shared/system/git.js +31 -16
- package/dist/lib/shared/system/glob.js +146 -19
- package/dist/lib/shared/system/terminal-style.js +2 -2
- package/dist/lib/shared/workspaces.js +6 -1
- package/package.json +4 -1
- package/schema/loadwise.config.schema.json +86 -0
|
@@ -7,7 +7,8 @@ import { cliEntryPath, packageManifest } from '../shared/package-root.js';
|
|
|
7
7
|
import { CodeActionKind, CodeLensRefreshRequest, DidChangeConfigurationNotification, DidChangeWatchedFilesNotification, FileChangeType, RegistrationRequest, TextDocumentSyncKind, TextDocuments, UnregistrationRequest, createConnection, } from 'vscode-languageserver/node';
|
|
8
8
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
9
9
|
import { codeActions, codeLenses, commands, fixAllKind } from './actions.js';
|
|
10
|
-
import { buildDiagnostics, hoverFor } from './diagnostics.js';
|
|
10
|
+
import { buildDiagnostics, findingFixIsApplied, hoverFor, inlayHints } from './diagnostics.js';
|
|
11
|
+
import { inlineFix, suggestFix } from './inline-fix.js';
|
|
11
12
|
import { createDismissals } from './dismissals.js';
|
|
12
13
|
import { createEditorDocument, readDiskDocument } from './editor-document.js';
|
|
13
14
|
import { createScanSession, explicitProject } from './scan-session.js';
|
|
@@ -26,6 +27,7 @@ const defaultSettings = {
|
|
|
26
27
|
cli: '',
|
|
27
28
|
severity: 'default',
|
|
28
29
|
codeLens: true,
|
|
30
|
+
inlineRecommendations: true,
|
|
29
31
|
useProjectCheckers: false,
|
|
30
32
|
};
|
|
31
33
|
// Only these change what the checkers report; severity and code lenses only change how it is shown.
|
|
@@ -45,6 +47,10 @@ function settingsFrom(value) {
|
|
|
45
47
|
settings.severity = section.severity;
|
|
46
48
|
if (typeof section.codeLens === 'boolean')
|
|
47
49
|
settings.codeLens = section.codeLens;
|
|
50
|
+
if (typeof section.tabAutofix === 'boolean')
|
|
51
|
+
settings.tabAutofix = section.tabAutofix;
|
|
52
|
+
if (typeof section.inlineRecommendations === 'boolean')
|
|
53
|
+
settings.inlineRecommendations = section.inlineRecommendations;
|
|
48
54
|
if (typeof section.useProjectCheckers === 'boolean')
|
|
49
55
|
settings.useProjectCheckers = section.useProjectCheckers;
|
|
50
56
|
return settings;
|
|
@@ -54,8 +60,8 @@ function scanSettingsKey(settings) {
|
|
|
54
60
|
}
|
|
55
61
|
// A parent folder and a folder nested in it both report the nested files. One diagnostic is shown
|
|
56
62
|
// for each, taken from the deepest folder, whose settings and dismissals own the file.
|
|
57
|
-
function findingKey({ uri, diagnostic }) {
|
|
58
|
-
return JSON.stringify([uri, diagnostic.source, diagnostic.code, diagnostic.range,
|
|
63
|
+
function findingKey({ uri, diagnostic, anchor }) {
|
|
64
|
+
return JSON.stringify([uri, diagnostic.source, diagnostic.code, diagnostic.range, anchor.message]);
|
|
59
65
|
}
|
|
60
66
|
function uniqueFindings(entries) {
|
|
61
67
|
const unique = new Map();
|
|
@@ -72,12 +78,16 @@ function parseArguments(args) {
|
|
|
72
78
|
if (unknown.length)
|
|
73
79
|
throw new Error(usage);
|
|
74
80
|
}
|
|
75
|
-
function serverCapabilities() {
|
|
81
|
+
function serverCapabilities(clientCapabilities) {
|
|
76
82
|
return {
|
|
77
83
|
textDocumentSync: { openClose: true, change: TextDocumentSyncKind.Incremental, save: { includeText: false } },
|
|
78
84
|
hoverProvider: true,
|
|
79
85
|
codeActionProvider: { codeActionKinds: [CodeActionKind.QuickFix, fixAllKind] },
|
|
80
86
|
codeLensProvider: { resolveProvider: false },
|
|
87
|
+
inlayHintProvider: true,
|
|
88
|
+
...(clientCapabilities.textDocument?.inlineCompletion
|
|
89
|
+
? { inlineCompletionProvider: true }
|
|
90
|
+
: { completionProvider: {} }),
|
|
81
91
|
executeCommandProvider: { commands: Object.values(commands) },
|
|
82
92
|
workspace: { workspaceFolders: { supported: true, changeNotifications: true } },
|
|
83
93
|
};
|
|
@@ -152,11 +162,12 @@ function startServer(connection) {
|
|
|
152
162
|
function folderFor(filename) {
|
|
153
163
|
return foldersFor(filename)[0];
|
|
154
164
|
}
|
|
165
|
+
const appliedInBuffer = new WeakSet();
|
|
155
166
|
// A folder with loadwise.enabled off also hides what an enclosing folder reports for its files.
|
|
156
167
|
function visibleFindings(entries) {
|
|
157
168
|
return uniqueFindings(entries).filter((entry) => {
|
|
158
169
|
const owner = folderFor(entry.filename);
|
|
159
|
-
return !owner || settingsFor(owner).enabled;
|
|
170
|
+
return !appliedInBuffer.has(entry) && (!owner || settingsFor(owner).enabled);
|
|
160
171
|
});
|
|
161
172
|
}
|
|
162
173
|
function entriesFor(uri) {
|
|
@@ -186,21 +197,22 @@ function startServer(connection) {
|
|
|
186
197
|
}
|
|
187
198
|
// Folders finish their checkers at different times, so refreshes asked for while any folder is
|
|
188
199
|
// still scanning wait and go out once, after the last one finishes, for the final combined view.
|
|
189
|
-
let
|
|
200
|
+
let presentationRefreshPending = false;
|
|
190
201
|
function anyFolderScanning() {
|
|
191
202
|
return [...folders.values()].some((folder) => folder.session.isScanning());
|
|
192
203
|
}
|
|
193
|
-
function
|
|
194
|
-
if (!
|
|
204
|
+
function flushPresentationRefresh() {
|
|
205
|
+
if (!presentationRefreshPending || anyFolderScanning())
|
|
195
206
|
return;
|
|
196
|
-
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
207
|
+
presentationRefreshPending = false;
|
|
208
|
+
if (capabilities.workspace?.codeLens?.refreshSupport)
|
|
209
|
+
connection.sendRequest(CodeLensRefreshRequest.type).catch(() => { });
|
|
210
|
+
if (capabilities.workspace?.inlayHint?.refreshSupport)
|
|
211
|
+
connection.languages.inlayHint.refresh().catch(() => { });
|
|
200
212
|
}
|
|
201
|
-
function
|
|
202
|
-
|
|
203
|
-
|
|
213
|
+
function refreshEditorPresentation() {
|
|
214
|
+
presentationRefreshPending = true;
|
|
215
|
+
flushPresentationRefresh();
|
|
204
216
|
}
|
|
205
217
|
// Unchanged files are not resent, and files whose findings are gone get an empty list.
|
|
206
218
|
function sendDiagnostics() {
|
|
@@ -225,7 +237,7 @@ function startServer(connection) {
|
|
|
225
237
|
published.set(uri, text);
|
|
226
238
|
connection.sendDiagnostics({ uri, diagnostics }).catch(() => { });
|
|
227
239
|
}
|
|
228
|
-
|
|
240
|
+
refreshEditorPresentation();
|
|
229
241
|
}
|
|
230
242
|
const maxDirtySnapshotBytes = 4 * 1024 * 1024;
|
|
231
243
|
function rebuildEntries(folder, changedFile) {
|
|
@@ -277,6 +289,10 @@ function startServer(connection) {
|
|
|
277
289
|
savedDocumentFor,
|
|
278
290
|
uriFor,
|
|
279
291
|
}));
|
|
292
|
+
for (const entry of rebuilt) {
|
|
293
|
+
if (entry.anchor.fix && findingFixIsApplied(entry, cachedDocumentFor(entry.filename)))
|
|
294
|
+
appliedInBuffer.add(entry);
|
|
295
|
+
}
|
|
280
296
|
folder.entries = retained.concat(rebuilt);
|
|
281
297
|
return true;
|
|
282
298
|
}
|
|
@@ -299,7 +315,7 @@ function startServer(connection) {
|
|
|
299
315
|
sendDiagnostics();
|
|
300
316
|
}
|
|
301
317
|
function updateProgress() {
|
|
302
|
-
|
|
318
|
+
flushPresentationRefresh();
|
|
303
319
|
const scanning = anyFolderScanning();
|
|
304
320
|
if (!scanning && progress) {
|
|
305
321
|
progress.done();
|
|
@@ -584,10 +600,36 @@ function startServer(connection) {
|
|
|
584
600
|
}
|
|
585
601
|
await Promise.all(initialFolders.map(addFolder));
|
|
586
602
|
});
|
|
587
|
-
return {
|
|
603
|
+
return {
|
|
604
|
+
capabilities: serverCapabilities(capabilities),
|
|
605
|
+
serverInfo: { name: 'loadwise', version: packageManifest.version },
|
|
606
|
+
};
|
|
588
607
|
});
|
|
589
608
|
documents.onDidOpen(({ document }) => documentOpened(document));
|
|
590
609
|
documents.onDidClose(({ document }) => documentClosed(document.uri));
|
|
610
|
+
documents.onDidChangeContent(({ document }) => {
|
|
611
|
+
const filename = filenameOf(document.uri);
|
|
612
|
+
if (filename === undefined || openUris.get(fileKey(filename))?.at(-1) !== document.uri)
|
|
613
|
+
return;
|
|
614
|
+
const key = fileKey(filename);
|
|
615
|
+
const candidates = foldersFor(filename).flatMap((folder) => folder.entries.filter((entry) => entry.anchor.fix && fileKey(entry.filename) === key));
|
|
616
|
+
if (!candidates.length)
|
|
617
|
+
return;
|
|
618
|
+
const snapshot = documentFor(filename);
|
|
619
|
+
let changed = false;
|
|
620
|
+
for (const entry of candidates) {
|
|
621
|
+
const applied = findingFixIsApplied(entry, snapshot);
|
|
622
|
+
if (applied === appliedInBuffer.has(entry))
|
|
623
|
+
continue;
|
|
624
|
+
if (applied)
|
|
625
|
+
appliedInBuffer.add(entry);
|
|
626
|
+
else
|
|
627
|
+
appliedInBuffer.delete(entry);
|
|
628
|
+
changed = true;
|
|
629
|
+
}
|
|
630
|
+
if (changed)
|
|
631
|
+
sendDiagnostics();
|
|
632
|
+
});
|
|
591
633
|
documents.onDidSave(({ document }) => {
|
|
592
634
|
const filename = filenameOf(document.uri);
|
|
593
635
|
if (filename === undefined)
|
|
@@ -635,6 +677,40 @@ function startServer(connection) {
|
|
|
635
677
|
return hover ? { contents: { kind: 'markdown', value: hover.markdown }, range: hover.range } : null;
|
|
636
678
|
});
|
|
637
679
|
connection.onCodeAction((params) => codeActions(entriesFor(params.textDocument.uri), params, fixWorkspace()));
|
|
680
|
+
connection.languages.inlayHint.on(({ textDocument, range }) => {
|
|
681
|
+
const findings = entriesFor(textDocument.uri);
|
|
682
|
+
if (!findings.length)
|
|
683
|
+
return [];
|
|
684
|
+
const folder = folderFor(findings[0].filename);
|
|
685
|
+
if (!folder || settingsFor(folder).inlineRecommendations === false)
|
|
686
|
+
return [];
|
|
687
|
+
const document = documentFor(findings[0].filename);
|
|
688
|
+
if (!document)
|
|
689
|
+
return [];
|
|
690
|
+
const tabAutofix = !document.isDirty && settingsFor(folder).tabAutofix === true;
|
|
691
|
+
return inlayHints(document, findings, range, folder.root, tabAutofix);
|
|
692
|
+
});
|
|
693
|
+
function completionFix({ textDocument, position }) {
|
|
694
|
+
const open = documents.get(textDocument.uri);
|
|
695
|
+
if (!open || (savedVersions.get(open.uri) !== open.version && pendingDiskChecks.get(open.uri) !== open.version))
|
|
696
|
+
return;
|
|
697
|
+
const findings = entriesFor(textDocument.uri);
|
|
698
|
+
if (!findings.length)
|
|
699
|
+
return;
|
|
700
|
+
const folder = folderFor(findings[0].filename);
|
|
701
|
+
if (!folder || settingsFor(folder).inlineRecommendations === false)
|
|
702
|
+
return;
|
|
703
|
+
const document = documentFor(findings[0].filename);
|
|
704
|
+
return document && inlineFix(document, findings, position);
|
|
705
|
+
}
|
|
706
|
+
connection.languages.inlineCompletion.on((params) => {
|
|
707
|
+
const fix = params.context.selectedCompletionInfo ? undefined : completionFix(params);
|
|
708
|
+
return fix ? [fix] : [];
|
|
709
|
+
});
|
|
710
|
+
connection.onCompletion((params) => {
|
|
711
|
+
const fix = capabilities.textDocument?.inlineCompletion ? undefined : completionFix(params);
|
|
712
|
+
return fix ? [suggestFix(fix)] : [];
|
|
713
|
+
});
|
|
638
714
|
connection.onCodeLens(({ textDocument }) => {
|
|
639
715
|
const filename = filenameOf(textDocument.uri);
|
|
640
716
|
const folder = filename === undefined ? undefined : folderFor(filename);
|
|
@@ -16,6 +16,7 @@ import { hasInfrastructureFiles } from '../security/files/index.js';
|
|
|
16
16
|
import { createProjectCheckerReader } from './project-policy.js';
|
|
17
17
|
import { createPolyglotSelectionReader } from './polyglot-selection.js';
|
|
18
18
|
import { configlessSources, coveringConfig, hasWorkspaceSources } from '../shared/workspaces.js';
|
|
19
|
+
import { conventionalProjects } from '../shared/conventional-projects.js';
|
|
19
20
|
import { isRecord } from '../shared/system/is-record.js';
|
|
20
21
|
import { errorMessage } from '../shared/system/error-code.js';
|
|
21
22
|
import { editorScanVariable, editorWatchSecurityVariable } from '../shared/system/environment.js';
|
|
@@ -114,7 +115,7 @@ async function configTarget(root, setting) {
|
|
|
114
115
|
// These walk the tree synchronously, so they run only for a folder without a config, once per
|
|
115
116
|
// change of its files.
|
|
116
117
|
function probeConfiglessInputs(root) {
|
|
117
|
-
const hasSources = Boolean(hasWorkspaceSources(root) || configlessSources(root) || coveringConfig(root));
|
|
118
|
+
const hasSources = Boolean(hasWorkspaceSources(root) || conventionalProjects(root).length || configlessSources(root) || coveringConfig(root));
|
|
118
119
|
return { hasSources, hasInfrastructure: !hasSources && hasInfrastructureFiles(root) };
|
|
119
120
|
}
|
|
120
121
|
function accessibilityArgs(project, inputs) {
|
|
@@ -40,6 +40,12 @@ const standaloneExamples = {
|
|
|
40
40
|
code: 'interval(1000).pipe(takeUntilDestroyed()).subscribe(tick);',
|
|
41
41
|
note: 'End the subscription with the component.',
|
|
42
42
|
},
|
|
43
|
+
'angular-template-method-call': {
|
|
44
|
+
language: 'typescript',
|
|
45
|
+
before: "@Component({ template: '{{ total() }}' })\nclass Cart { total() { return this.lines.reduce((sum, line) => sum + line.price, 0); } }",
|
|
46
|
+
code: "@Component({ template: '{{ total() }}' })\nclass Cart { total = computed(() => this.lines().reduce((sum, line) => sum + line.price, 0)); }",
|
|
47
|
+
note: 'A computed signal recalculates only when the lines change.',
|
|
48
|
+
},
|
|
43
49
|
'api-enum-value-removed': contractExample('typescript', "type Status = 'open' | 'closed' | 'archived';", "type Status = 'open' | 'closed' | 'archived'; // keep accepting 'archived'", 'Keep accepting the old value (map it to the new one) until clients stop sending it.'),
|
|
44
50
|
'api-removed-field': contractExample('typescript', 'class UserDto {\n name: string;\n}', 'class UserDto {\n name: string;\n /** @deprecated read name */\n fullName?: string;\n}', 'Deprecate a response field first and remove it after clients stop reading it.'),
|
|
45
51
|
'api-removed-operation': contractExample('graphql', 'type Query {\n user(id: ID!): User\n}', 'type Query {\n user(id: ID!): User\n userV2(id: ID!): User\n}', 'Keep the old operation (or serve /v1 beside a new /v2) until no deployed client calls it.'),
|
|
@@ -152,6 +158,18 @@ const standaloneExamples = {
|
|
|
152
158
|
code: "import debounce from 'lodash/debounce';",
|
|
153
159
|
note: 'Import subpaths.',
|
|
154
160
|
},
|
|
161
|
+
'frontend-navigation-without-link': {
|
|
162
|
+
language: 'tsx',
|
|
163
|
+
before: "<div onClick={() => router.push('/pricing')}>Pricing</div>",
|
|
164
|
+
code: '<Link href="/pricing">Pricing</Link>',
|
|
165
|
+
note: 'Link from next/link (or react-router) renders an <a href> that crawlers follow and users can open in a new tab.',
|
|
166
|
+
},
|
|
167
|
+
'frontend-render-blocking-script': {
|
|
168
|
+
language: 'tsx',
|
|
169
|
+
before: '<head><script src="https://cdn.example.com/tag.js"></script></head>',
|
|
170
|
+
code: '<head><script defer src="https://cdn.example.com/tag.js"></script></head>',
|
|
171
|
+
note: 'defer keeps document order; async or next/script also stop the script blocking first paint.',
|
|
172
|
+
},
|
|
155
173
|
'guard-query-per-request': {
|
|
156
174
|
language: 'javascript',
|
|
157
175
|
before: 'async function canActivate(context) {\n const user = await this.users.findOne({ where: { id } });\n}',
|
|
@@ -249,6 +267,24 @@ const standaloneExamples = {
|
|
|
249
267
|
code: 'return await User.findById(id).lean();',
|
|
250
268
|
note: 'Using .lean() returns a plain JavaScript object directly without hydrating a Mongoose Document.',
|
|
251
269
|
},
|
|
270
|
+
'next-client-fetched-page-content': {
|
|
271
|
+
language: 'tsx',
|
|
272
|
+
before: "'use client';\nexport default function Page() {\n const [posts, setPosts] = useState([]);\n useEffect(() => { fetch('/api/posts').then((r) => r.json()).then(setPosts); }, []);\n return <PostList posts={posts} />;\n}",
|
|
273
|
+
code: 'export default async function Page() {\n const posts = await getPosts();\n return <PostList posts={posts} />;\n}',
|
|
274
|
+
note: 'Fetch on the server so the content is in the HTML; keep interactive parts in a client child component.',
|
|
275
|
+
},
|
|
276
|
+
'next-missing-route-metadata': {
|
|
277
|
+
language: 'tsx',
|
|
278
|
+
before: 'export default function Page() {\n return <Pricing />;\n}',
|
|
279
|
+
code: "export const metadata = { title: 'Pricing', description: 'Plans for teams of every size.' };\n\nexport default function Page() {\n return <Pricing />;\n}",
|
|
280
|
+
note: 'Or set title.template and a default description once in app/layout.tsx.',
|
|
281
|
+
},
|
|
282
|
+
'next-sitewide-noindex': {
|
|
283
|
+
language: 'tsx',
|
|
284
|
+
before: 'export const metadata = { robots: { index: false } };',
|
|
285
|
+
code: "export const metadata = {\n robots: process.env.VERCEL_ENV === 'production' ? undefined : { index: false },\n};",
|
|
286
|
+
note: 'Keep preview and staging deploys out of search without hiding production.',
|
|
287
|
+
},
|
|
252
288
|
'notification-send-in-loop': {
|
|
253
289
|
language: 'javascript',
|
|
254
290
|
before: 'for (const token of tokens) await messaging.send({ token, notification });',
|
|
@@ -342,6 +378,12 @@ const standaloneExamples = {
|
|
|
342
378
|
code: "useEffect(() => { window.addEventListener('resize', onResize); return () => window.removeEventListener('resize', onResize); }, []);",
|
|
343
379
|
note: 'Return a cleanup that removes what the effect added.',
|
|
344
380
|
},
|
|
381
|
+
'react-unthrottled-input-fetch': {
|
|
382
|
+
language: 'tsx',
|
|
383
|
+
before: '<input onChange={(event) => fetch(`/api/search?q=${event.target.value}`)} />',
|
|
384
|
+
code: "const search = useMemo(() => debounce((q: string) => fetch('/api/search?q=' + q), 300), []);\n<input onChange={(event) => search(event.target.value)} />",
|
|
385
|
+
note: 'Debounce the request, or fetch from an effect that aborts the previous one.',
|
|
386
|
+
},
|
|
345
387
|
'redis-command-in-loop': {
|
|
346
388
|
language: 'javascript',
|
|
347
389
|
before: "for (const id of ids) await redis.get('user:' + id);",
|
|
@@ -484,6 +526,12 @@ const standaloneExamples = {
|
|
|
484
526
|
code: "rows.map((r) => h('li', { key: r.id }, r.name))",
|
|
485
527
|
note: 'Give each item a stable key.',
|
|
486
528
|
},
|
|
529
|
+
'vue-v-if-with-v-for': {
|
|
530
|
+
language: 'typescript',
|
|
531
|
+
before: '// <li v-for="order in orders" v-if="order.paid" :key="order.id">',
|
|
532
|
+
code: 'const paidOrders = computed(() => orders.value.filter((order) => order.paid));\n// <li v-for="order in paidOrders" :key="order.id">',
|
|
533
|
+
note: 'Filter once in a computed list and loop over it.',
|
|
534
|
+
},
|
|
487
535
|
'vue-watch-missing-cleanup': {
|
|
488
536
|
language: 'typescript',
|
|
489
537
|
before: "onMounted(() => { window.addEventListener('resize', f); });",
|
|
@@ -13,6 +13,7 @@ import { checkUnusedBindings } from '../unused/unused-bindings.js';
|
|
|
13
13
|
import { checkStrayConsole } from '../quality/stray-console.js';
|
|
14
14
|
import { checkDeprecatedApis } from '../quality/deprecated-apis.js';
|
|
15
15
|
import { checkTypeSafetyHygiene } from '../quality/type-safety-hygiene.js';
|
|
16
|
+
import { checkModernSyntax } from '../quality/modern-syntax.js';
|
|
16
17
|
import { locateDiagnostic, remainingSyntaxFailures } from '../../shared/analysis/valid-javascript.js';
|
|
17
18
|
const READ_CONCURRENCY = 64;
|
|
18
19
|
// Synchronous opens are slow on Windows; overlapping them hides most of that latency.
|
|
@@ -85,6 +86,7 @@ function analyzeSource(root, file, text, resolve, options = {}) {
|
|
|
85
86
|
...checkStrayConsole(source, file, compilerOptions ?? {}, limits?.allowedConsoleMethods),
|
|
86
87
|
...checkDeprecatedApis(source, file),
|
|
87
88
|
...checkTypeSafetyHygiene(source, file),
|
|
89
|
+
...checkModernSyntax(source, file),
|
|
88
90
|
],
|
|
89
91
|
edges: collectEdges(source, file, resolve, compilerOptions),
|
|
90
92
|
constEnums: exportedConstEnums(source),
|
|
@@ -141,7 +141,54 @@ function metadataTypes(node) {
|
|
|
141
141
|
? [node.type, ...node.parameters.map((parameter) => parameter.type)]
|
|
142
142
|
: [node.type];
|
|
143
143
|
}
|
|
144
|
+
// `(() => { ... })()` and `(function () { ... })()` run their body while the enclosing code runs. An
|
|
145
|
+
// async or generator body may pause before reading anything, so only plain functions count.
|
|
146
|
+
function immediatelyInvoked(node) {
|
|
147
|
+
if (!ts.isArrowFunction(node) && !ts.isFunctionExpression(node))
|
|
148
|
+
return false;
|
|
149
|
+
if (node.asteriskToken || hasModifier(node, ts.SyntaxKind.AsyncKeyword))
|
|
150
|
+
return false;
|
|
151
|
+
let callee = node;
|
|
152
|
+
while (ts.isParenthesizedExpression(callee.parent))
|
|
153
|
+
callee = callee.parent;
|
|
154
|
+
return ts.isCallExpression(callee.parent) && callee.parent.expression === callee && !callee.parent.questionDotToken;
|
|
155
|
+
}
|
|
156
|
+
// Whether a statement may leave its block through `return`, `throw`, `break` or `continue`. Only
|
|
157
|
+
// statements can do that, so expressions, functions and classes are not searched. An unlabeled
|
|
158
|
+
// `break` inside a nested loop or switch, `continue` inside a nested loop, and a `throw` inside a
|
|
159
|
+
// nested `try` with a `catch` stay in the block.
|
|
160
|
+
function mayExitEarly(node, breakable = false, loop = false, caught = false) {
|
|
161
|
+
if (ts.isReturnStatement(node))
|
|
162
|
+
return true;
|
|
163
|
+
if (ts.isThrowStatement(node))
|
|
164
|
+
return !caught;
|
|
165
|
+
if (ts.isBreakStatement(node))
|
|
166
|
+
return !breakable || node.label !== undefined;
|
|
167
|
+
if (ts.isContinueStatement(node))
|
|
168
|
+
return !loop || node.label !== undefined;
|
|
169
|
+
if (ts.isExpression(node) || ts.isFunctionLike(node) || ts.isClassLike(node))
|
|
170
|
+
return false;
|
|
171
|
+
const nestedLoop = loop || ts.isIterationStatement(node, false);
|
|
172
|
+
const nestedBreakable = breakable || nestedLoop || ts.isSwitchStatement(node);
|
|
173
|
+
return (ts.forEachChild(node, (child) => {
|
|
174
|
+
const childCaught = caught || (ts.isTryStatement(node) && child === node.tryBlock && !!node.catchClause);
|
|
175
|
+
return mayExitEarly(child, nestedBreakable, nestedLoop, childCaught);
|
|
176
|
+
}) ?? false);
|
|
177
|
+
}
|
|
178
|
+
// Where the first statement of a block that may exit early ends. Statements after it may never run,
|
|
179
|
+
// as in `(() => { if (!enabled) return; require('./b'); })()`.
|
|
180
|
+
function earlyExitEnd(node) {
|
|
181
|
+
if (!ts.isBlock(node))
|
|
182
|
+
return Number.POSITIVE_INFINITY;
|
|
183
|
+
for (const statement of node.statements)
|
|
184
|
+
if (mayExitEarly(statement))
|
|
185
|
+
return statement.end;
|
|
186
|
+
return Number.POSITIVE_INFINITY;
|
|
187
|
+
}
|
|
144
188
|
function alwaysEvaluatedChild(node, child) {
|
|
189
|
+
// A try block and its finally block always start; only the catch clause is conditional.
|
|
190
|
+
if (ts.isTryStatement(node))
|
|
191
|
+
return child === node.tryBlock || child === node.finallyBlock;
|
|
145
192
|
if (ts.isIfStatement(node) ||
|
|
146
193
|
ts.isSwitchStatement(node) ||
|
|
147
194
|
ts.isWhileStatement(node) ||
|
|
@@ -153,7 +200,7 @@ function alwaysEvaluatedChild(node, child) {
|
|
|
153
200
|
if (ts.isPropertyDeclaration(node))
|
|
154
201
|
return child !== node.initializer || hasModifier(node, ts.SyntaxKind.StaticKeyword);
|
|
155
202
|
if (ts.isFunctionLike(node))
|
|
156
|
-
return ts.isDecorator(child);
|
|
203
|
+
return ts.isDecorator(child) || (immediatelyInvoked(node) && child === node.body);
|
|
157
204
|
if (ts.isForStatement(node))
|
|
158
205
|
return child === node.initializer || child === node.condition;
|
|
159
206
|
if (ts.isConditionalExpression(node))
|
|
@@ -339,9 +386,10 @@ function collectEdges(sourceFile, file, resolve, compilerOptions = {}) {
|
|
|
339
386
|
(ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node)))
|
|
340
387
|
used.add((compilerOptions.jsxFactory || 'React.createElement').split('.')[0]);
|
|
341
388
|
const conditional = !deferred && conditionallyExecuted(node);
|
|
389
|
+
const exitEnd = deferred ? Number.POSITIVE_INFINITY : earlyExitEnd(node);
|
|
342
390
|
for (let index = bufferChildren(node) - 1; index >= 0; index--) {
|
|
343
391
|
const child = childBuffer[index];
|
|
344
|
-
pushNode(child, deferred || (conditional && !alwaysEvaluatedChild(node, child)));
|
|
392
|
+
pushNode(child, deferred || child.pos >= exitEnd || (conditional && !alwaysEvaluatedChild(node, child)));
|
|
345
393
|
// Decorators run when the class is defined, even for members whose bodies run later.
|
|
346
394
|
if (conditional && ts.isParameter(child))
|
|
347
395
|
for (const decorator of ts.getDecorators(child) || [])
|
|
@@ -38,11 +38,15 @@ function noteMissingBase(diagnostic) {
|
|
|
38
38
|
}
|
|
39
39
|
console.error(`Note: ${location}${message} Checked with this config's own settings until it is installed.`);
|
|
40
40
|
}
|
|
41
|
-
function listFiles(root, exclude = [], isIgnored = () => false, gitEntries) {
|
|
41
|
+
function listFiles(root, exclude = [], isIgnored = () => false, gitEntries, coverage) {
|
|
42
42
|
const directory = path.resolve(root);
|
|
43
43
|
const exclusions = new Set(exclude.map((value) => path.posix.normalize(normalizeSlashes(value)).replace(/\/$/, '')));
|
|
44
44
|
const files = new Set();
|
|
45
45
|
const folders = new Map([['.', true]]);
|
|
46
|
+
function noteLink(entry) {
|
|
47
|
+
if (coverage && entry?.isSymbolicLink())
|
|
48
|
+
coverage.skippedLink = true;
|
|
49
|
+
}
|
|
46
50
|
function ignoredFolder(relative) {
|
|
47
51
|
const name = path.posix.basename(relative);
|
|
48
52
|
return (isIgnored(relative, true) ||
|
|
@@ -55,10 +59,10 @@ function listFiles(root, exclude = [], isIgnored = () => false, gitEntries) {
|
|
|
55
59
|
const known = folders.get(relative);
|
|
56
60
|
if (known !== undefined)
|
|
57
61
|
return known;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
const visible = !ignoredFolder(relative) && !exclusions.has(relative) && safeFolder(path.posix.dirname(relative));
|
|
63
|
+
const stat = visible ? fs.lstatSync(path.join(directory, relative), { throwIfNoEntry: false }) : undefined;
|
|
64
|
+
noteLink(stat);
|
|
65
|
+
const permitted = stat?.isDirectory() === true;
|
|
62
66
|
folders.set(relative, permitted);
|
|
63
67
|
return permitted;
|
|
64
68
|
}
|
|
@@ -75,6 +79,7 @@ function listFiles(root, exclude = [], isIgnored = () => false, gitEntries) {
|
|
|
75
79
|
continue;
|
|
76
80
|
const absolute = path.join(directory, file);
|
|
77
81
|
const stat = fs.lstatSync(absolute, { throwIfNoEntry: false });
|
|
82
|
+
noteLink(stat);
|
|
78
83
|
if (stat?.isFile() && !ignored)
|
|
79
84
|
files.add(file);
|
|
80
85
|
else if (stat?.isDirectory() && safeFolder(file) && fs.existsSync(path.join(absolute, '.git')))
|
|
@@ -99,6 +104,8 @@ function listFiles(root, exclude = [], isIgnored = () => false, gitEntries) {
|
|
|
99
104
|
const file = path.posix.join(relative, entry.name);
|
|
100
105
|
if (ignoredPath(file, entry.isDirectory()))
|
|
101
106
|
continue;
|
|
107
|
+
if (entry.isSymbolicLink() && !ignoredFolder(file))
|
|
108
|
+
noteLink(entry);
|
|
102
109
|
if (entry.isFile())
|
|
103
110
|
files.add(file);
|
|
104
111
|
else if (entry.isDirectory() && !ignoredFolder(file)) {
|
|
@@ -214,6 +214,9 @@ function relatedCount(finding) {
|
|
|
214
214
|
function attachSiteFixes(findings, root, options) {
|
|
215
215
|
const load = createFileCache(root);
|
|
216
216
|
load.identifierIndex = options?.identifierIndex;
|
|
217
|
+
load.reportedUnusedImports = new Set(findings
|
|
218
|
+
.filter((finding) => finding.ruleId === 'unused-import')
|
|
219
|
+
.map((finding) => `${finding.file}:${finding.line}:${finding.column}`));
|
|
217
220
|
// The largest duplicate groups claim new module names first; a smaller group with the same helper
|
|
218
221
|
// name gets a numbered one.
|
|
219
222
|
const ordered = findings.toSorted((left, right) => relatedCount(right) - relatedCount(left));
|
|
@@ -8,7 +8,7 @@ import { fixLines } from './cli/fix-text.js';
|
|
|
8
8
|
import { loadSettings } from '../shared/config.js';
|
|
9
9
|
import { parseMaintainabilityArguments } from './cli/scan-arguments.js';
|
|
10
10
|
import { resolveFormat, renderReports } from '../shared/formats/index.js';
|
|
11
|
-
import {
|
|
11
|
+
import { reportTextFindings } from '../shared/reporting/automatic-fix-signal.js';
|
|
12
12
|
import { reportRulePackFingerprint } from '../shared/reporting/rule-pack-fingerprint.js';
|
|
13
13
|
import { contractRules } from '../shared/formats/contract-rules.js';
|
|
14
14
|
import { quoteArgument } from '../shared/system/shell-argument.js';
|
|
@@ -171,7 +171,10 @@ async function scanProject(root, values, { changes, inScope }) {
|
|
|
171
171
|
if (isIgnored)
|
|
172
172
|
policy.isIgnored = (file, subtree) => isIgnored(root, file, subtree);
|
|
173
173
|
const scanResult = changes
|
|
174
|
-
? await (await import('./scan-changed.js')).scanChangedFiles(root, policy, [...changes.keys()], {
|
|
174
|
+
? await (await import('./scan-changed.js')).scanChangedFiles(root, policy, [...changes.keys()], {
|
|
175
|
+
inScope,
|
|
176
|
+
mayEnableRule: (ruleId) => settings.mayEnableRule(ruleId),
|
|
177
|
+
})
|
|
175
178
|
: values.graph !== undefined
|
|
176
179
|
? checkImportedGraph(values.graph, policy)
|
|
177
180
|
: await (await import('./scan.js')).scan(root, policy, {
|
|
@@ -339,7 +342,7 @@ async function printScanReport(report, options) {
|
|
|
339
342
|
else
|
|
340
343
|
await printTextReport(report, options);
|
|
341
344
|
if (format === 'text')
|
|
342
|
-
|
|
345
|
+
reportTextFindings(report.findings);
|
|
343
346
|
}
|
|
344
347
|
async function main(args) {
|
|
345
348
|
if (args[0] === 'agent')
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
|
|
2
2
|
const examples = {
|
|
3
|
+
'arguments-object': {
|
|
4
|
+
before: ['function sum() {', ' return Array.from(arguments).reduce((a, b) => a + b, 0);', '}'],
|
|
5
|
+
after: ['function sum(...values: number[]) {', ' return values.reduce((a, b) => a + b, 0);', '}'],
|
|
6
|
+
},
|
|
3
7
|
'data-access-boundary': {
|
|
4
8
|
before: ['// src/http/handler.ts', 'import { Pool } from "pg";', 'const rows = await new Pool().query(sql);'],
|
|
5
9
|
after: ['// src/http/handler.ts', 'import { loadUsers } from "../data/users";', 'const rows = await loadUsers();'],
|
|
@@ -95,10 +99,30 @@ const examples = {
|
|
|
95
99
|
'send({ to: a, from: b, subject: c, body: d });',
|
|
96
100
|
],
|
|
97
101
|
},
|
|
102
|
+
'node-callback-api': {
|
|
103
|
+
before: [
|
|
104
|
+
"import fs from 'node:fs';",
|
|
105
|
+
'fs.readFile(path, "utf8", (err, text) => {',
|
|
106
|
+
' if (err) return done(err);',
|
|
107
|
+
' done(null, text);',
|
|
108
|
+
'});',
|
|
109
|
+
],
|
|
110
|
+
after: ["import { readFile } from 'node:fs/promises';", 'const text = await readFile(path, "utf8");'],
|
|
111
|
+
},
|
|
98
112
|
'query-mutates-state': {
|
|
99
113
|
before: ['/** @maintainabilityQuery */', 'current() { this.count += 1; return this.count; }'],
|
|
100
114
|
after: ['/** @maintainabilityQuery */', 'current() { return this.count; }', 'increment() { this.count += 1; }'],
|
|
101
115
|
},
|
|
116
|
+
'redundant-promise-wrapper': {
|
|
117
|
+
before: [
|
|
118
|
+
'function load(id) {',
|
|
119
|
+
' return new Promise((resolve, reject) => {',
|
|
120
|
+
' fetchUser(id).then(resolve, reject);',
|
|
121
|
+
' });',
|
|
122
|
+
'}',
|
|
123
|
+
],
|
|
124
|
+
after: ['function load(id) {', ' return fetchUser(id);', '}'],
|
|
125
|
+
},
|
|
102
126
|
'stray-console': {
|
|
103
127
|
before: ['export function placeOrder(order: Order) {', " console.log('placing', order.id);", '}'],
|
|
104
128
|
after: [
|
|
@@ -107,6 +131,22 @@ const examples = {
|
|
|
107
131
|
'}',
|
|
108
132
|
],
|
|
109
133
|
},
|
|
134
|
+
'then-chain-in-async': {
|
|
135
|
+
before: [
|
|
136
|
+
'async function loadProfile(id) {',
|
|
137
|
+
' return fetch(`/users/${id}`)',
|
|
138
|
+
' .then((res) => res.json())',
|
|
139
|
+
' .then((user) => user.profile);',
|
|
140
|
+
'}',
|
|
141
|
+
],
|
|
142
|
+
after: [
|
|
143
|
+
'async function loadProfile(id) {',
|
|
144
|
+
' const res = await fetch(`/users/${id}`);',
|
|
145
|
+
' const user = await res.json();',
|
|
146
|
+
' return user.profile;',
|
|
147
|
+
'}',
|
|
148
|
+
],
|
|
149
|
+
},
|
|
110
150
|
'ts-suppression-without-reason': {
|
|
111
151
|
before: ['// @ts-ignore', 'legacyClient.connect(options);'],
|
|
112
152
|
after: ['// @ts-expect-error legacyClient types omit the options argument', 'legacyClient.connect(options);'],
|
|
@@ -127,6 +167,10 @@ const examples = {
|
|
|
127
167
|
'}',
|
|
128
168
|
],
|
|
129
169
|
},
|
|
170
|
+
'unused-dependency': {
|
|
171
|
+
before: ['// package.json declares "legacy-formatter"', '// No source or configuration references it.'],
|
|
172
|
+
after: ['// Verify deployment and plug-in usage.', '// If unused, remove it with your package manager.'],
|
|
173
|
+
},
|
|
130
174
|
'unused-export': {
|
|
131
175
|
before: ['// helpers.ts', 'export const used = () => 1;', 'export const neverImported = () => 2;'],
|
|
132
176
|
after: ['// helpers.ts', 'export const used = () => 1;', 'const neverImported = () => 2; // or delete it'],
|
|
@@ -148,6 +192,10 @@ const examples = {
|
|
|
148
192
|
],
|
|
149
193
|
after: ['function total(items) {', ' return items.reduce((sum, item) => sum + item, 0);', '}'],
|
|
150
194
|
},
|
|
195
|
+
'var-declaration': {
|
|
196
|
+
before: ['for (var i = 0; i < items.length; i++) {', ' var item = items[i];', '}'],
|
|
197
|
+
after: ['for (let i = 0; i < items.length; i++) {', ' const item = items[i];', '}'],
|
|
198
|
+
},
|
|
151
199
|
};
|
|
152
200
|
function exampleFor(ruleId) {
|
|
153
201
|
return examples[ruleId];
|