loadwise 0.5.0 → 0.6.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.
Files changed (132) hide show
  1. package/README.md +543 -628
  2. package/bin/loadwise.js +5 -1
  3. package/lib/accessibility/frontend-detect.js +2 -1
  4. package/lib/accessibility/rule-ids.js +12 -9
  5. package/lib/accessibility/template-attributes.js +4 -2
  6. package/{editor/accessibility-examples.cjs → lib/editor/accessibility-examples.js} +20 -21
  7. package/lib/editor/actions.js +117 -0
  8. package/{editor/apply-fix.cjs → lib/editor/apply-fix.js} +1 -6
  9. package/{editor/control-flow-comparison.cjs → lib/editor/control-flow-comparison.js} +1 -3
  10. package/lib/editor/diagnostics.js +365 -0
  11. package/lib/editor/dismissals.js +111 -0
  12. package/lib/editor/editor-document.js +99 -0
  13. package/{editor/finding-comparison.cjs → lib/editor/finding-comparison.js} +4 -7
  14. package/lib/editor/fix-edits.js +200 -0
  15. package/lib/editor/language-server.js +437 -0
  16. package/{editor/maintainability-examples.cjs → lib/editor/maintainability-examples.js} +1 -3
  17. package/{editor/perf-site-comparison.cjs → lib/editor/perf-site-comparison.js} +1 -3
  18. package/lib/editor/perf-watch.js +78 -0
  19. package/{editor/performance-examples.cjs → lib/editor/performance-examples.js} +129 -128
  20. package/{editor/reliability-examples.cjs → lib/editor/reliability-examples.js} +100 -41
  21. package/lib/editor/scan-session.js +334 -0
  22. package/{editor/security-examples.cjs → lib/editor/security-examples.js} +28 -32
  23. package/lib/editor/server-commands.js +232 -0
  24. package/{editor/source-example.cjs → lib/editor/source-example.js} +3 -5
  25. package/{editor/standalone-performance-examples.cjs → lib/editor/standalone-performance-examples.js} +349 -333
  26. package/lib/editor/types/dismissal.js +1 -0
  27. package/lib/editor/types/fix-example.js +1 -0
  28. package/lib/editor/types/source-document.js +1 -0
  29. package/lib/editor/workspace-files.js +78 -0
  30. package/lib/editor/workspace-paths.js +22 -0
  31. package/lib/maintainability/analyze-source.js +2 -0
  32. package/lib/maintainability/apply-fix.js +1 -1
  33. package/lib/maintainability/cli.js +1 -1
  34. package/lib/maintainability/examples.js +58 -41
  35. package/lib/maintainability/rule-ids.js +29 -14
  36. package/lib/maintainability/scan-changed.js +3 -0
  37. package/lib/maintainability/scan.js +13 -9
  38. package/lib/maintainability/tsconfig-strict.js +69 -0
  39. package/lib/maintainability/type-safety-hygiene.js +204 -0
  40. package/lib/performance/analyze.js +2 -0
  41. package/lib/performance/cli-arguments.js +0 -2
  42. package/lib/performance/cli-policy.js +17 -9
  43. package/lib/performance/cli-scan.js +10 -8
  44. package/lib/performance/cli.js +4 -23
  45. package/lib/performance/editor-signal.js +1 -1
  46. package/lib/performance/finding-text.js +3 -3
  47. package/lib/performance/fix-cli.js +1 -1
  48. package/lib/performance/frontend-perf.js +7 -0
  49. package/lib/performance/frontend-render-perf.js +200 -0
  50. package/lib/performance/llm-max-tokens.js +56 -0
  51. package/lib/performance/native.js +46 -26
  52. package/lib/performance/polyglot.js +22 -1
  53. package/lib/performance/pooling.js +38 -23
  54. package/lib/performance/projects.js +42 -21
  55. package/lib/performance/rule-ids.js +236 -222
  56. package/lib/performance/site-fixes/database.js +3 -1
  57. package/lib/performance/site-fixes/integrity.js +15 -1
  58. package/lib/performance/source-inputs.js +18 -6
  59. package/lib/performance/unscanned-javascript.js +66 -19
  60. package/lib/reliability/analyze.js +12 -0
  61. package/lib/reliability/child-process.js +106 -0
  62. package/lib/reliability/error-values.js +177 -0
  63. package/lib/reliability/pool-timeout.js +79 -0
  64. package/lib/reliability/react-bugs.js +602 -0
  65. package/lib/reliability/resource-leaks.js +3 -6
  66. package/lib/reliability/rule-ids.js +169 -127
  67. package/lib/reliability/switch-exhaustive.js +284 -0
  68. package/lib/reliability/uncaught-exception.js +223 -0
  69. package/lib/security/auth-crypto/rule-ids.js +3 -2
  70. package/lib/security/cli.js +6 -5
  71. package/lib/security/deps/rule-ids.js +1 -0
  72. package/lib/security/examples/auth-crypto.cjs +5 -4
  73. package/lib/security/examples/deps.cjs +1 -0
  74. package/lib/security/examples/exposure.cjs +55 -42
  75. package/lib/security/examples/files.cjs +1 -0
  76. package/lib/security/examples/injection.cjs +1 -0
  77. package/lib/security/examples/moved.cjs +5 -4
  78. package/lib/security/examples/request-forgery.cjs +1 -0
  79. package/lib/security/exposure/client-env.js +113 -0
  80. package/lib/security/exposure/frontend-security.js +12 -10
  81. package/lib/security/exposure/index.js +14 -3
  82. package/lib/security/exposure/jsx-url.js +267 -0
  83. package/lib/security/exposure/next-image-config.js +34 -0
  84. package/lib/security/exposure/package-manifest.js +45 -0
  85. package/lib/security/exposure/react-version.js +45 -0
  86. package/lib/security/exposure/rule-ids.js +16 -12
  87. package/lib/security/files/index.js +1 -1
  88. package/lib/security/files/rule-ids.js +1 -0
  89. package/lib/security/injection/code.js +24 -10
  90. package/lib/security/injection/command.js +81 -28
  91. package/lib/security/injection/nosql.js +109 -22
  92. package/lib/security/injection/redos.js +152 -308
  93. package/lib/security/injection/regex-pattern.js +290 -0
  94. package/lib/security/injection/regex.js +30 -11
  95. package/lib/security/injection/rule-ids.js +2 -1
  96. package/lib/security/injection/shared.js +19 -1
  97. package/lib/security/injection/sql.js +83 -2
  98. package/lib/security/request-forgery/rule-ids.js +1 -0
  99. package/lib/security/rule-descriptions.js +36 -32
  100. package/lib/security/rule-ids.js +74 -67
  101. package/lib/security/taint/filename-guard.js +3 -1
  102. package/lib/security/taint/guards.js +84 -10
  103. package/lib/security/taint/index.js +124 -13
  104. package/lib/security/taint/propagate.js +10 -7
  105. package/lib/security/taint/sanitizers.js +7 -3
  106. package/lib/security/taint/sources.js +6 -3
  107. package/lib/security/taint/summaries.js +13 -1
  108. package/lib/security/taint/url-parts.js +14 -5
  109. package/lib/shared/agent-session.js +2 -2
  110. package/lib/shared/check.js +16 -6
  111. package/lib/shared/explain.js +5 -5
  112. package/lib/shared/fix-convergence.js +1 -1
  113. package/lib/shared/formats/finding-location.js +6 -2
  114. package/lib/shared/formats/sarif.js +3 -3
  115. package/lib/shared/heap-limit.js +20 -3
  116. package/lib/shared/pillars.js +7 -7
  117. package/lib/shared/rule-docs.js +12 -0
  118. package/lib/shared/scan-cache.js +0 -1
  119. package/lib/shared/workspaces.js +31 -9
  120. package/package.json +12 -19
  121. package/plugin/.claude-plugin/plugin.json +1 -1
  122. package/schema/loadwise.config.schema.json +44 -0
  123. package/editor/README.md +0 -47
  124. package/examples/redis-keys.otlp.json +0 -22
  125. package/lib/maintainability/notify-editor.js +0 -1
  126. package/lib/performance/editor-report.js +0 -191
  127. package/lib/performance/editor-setup.js +0 -189
  128. package/lib/performance/editor-watch-supervisor.js +0 -104
  129. package/lib/performance/editor-watch.js +0 -193
  130. package/lib/performance/notify-editor.js +0 -1
  131. package/lib/performance/recursive-watch.js +0 -181
  132. /package/lib/{performance/types/editor-report.js → editor/types/comparison.js} +0 -0
package/bin/loadwise.js CHANGED
@@ -13,6 +13,7 @@ const usage = `Usage:
13
13
  loadwise fix --all [performance] [reliability] [maintainability] [security] [accessibility] [--json]
14
14
  loadwise fix --handoff [performance] [reliability] [maintainability] [security] [accessibility]
15
15
  loadwise explain <rule-id>
16
+ loadwise lsp [--stdio]
16
17
  loadwise --version
17
18
  loadwise agent init [--mode ask|auto] [--hook [block|warn|off]]
18
19
  loadwise agent instructions
@@ -35,6 +36,7 @@ fix --yes applies automatic edits. fix --all also applies edits marked for revie
35
36
  fix --json with --yes or --all records the applied hunks and outstanding findings in its output for review.
36
37
  perf, rel, maint, sec and a11y run one checker with its full command set; \`loadwise perf --help\`, \`loadwise rel --help\`, \`loadwise maint --help\` \`loadwise sec --help\` and \`loadwise a11y --help\` list their commands and flags.
37
38
  explain prints the rule's default impact, description and an illustrative change when available.
39
+ lsp runs the language server on stdin and stdout for any editor with a Language Server Protocol client: findings from every checker as diagnostics, with hovers, fixes, dismissals and code lenses.
38
40
  Recognized coding-agent sessions receive review instructions automatically. agent instructions prints the review workflow. Optional agent init writes it into AGENTS.md and imports it from CLAUDE.md.
39
41
  An active agent can run check --json directly or use the loadwise_check MCP tool for a fresh offline report.
40
42
  Add --review to a combined check or bulk fix to keep its original report and print the same handoff for any coding agent. agent pending lists saved handoffs for this project.
@@ -58,6 +60,8 @@ async function main(args) {
58
60
  return (await import('../lib/shared/fix.js')).runFix(rest);
59
61
  if (command === 'explain')
60
62
  return (await import('../lib/shared/explain.js')).runExplain(rest);
63
+ if (command === 'lsp')
64
+ return (await import('../lib/editor/language-server.js')).runLanguageServer(rest);
61
65
  if (command === '--version' || command === '-v') {
62
66
  if (rest.length)
63
67
  throw new Error('Usage: loadwise --version');
@@ -79,7 +83,7 @@ const inProcessCheckers = new Set(['perf', 'rel', 'maint', 'sec', 'a11y']);
79
83
  function respawnIfHeapTooSmall(commandArgs) {
80
84
  if (!inProcessCheckers.has(commandArgs[0]) || !shouldRespawnWithLargerHeap())
81
85
  return false;
82
- process.exitCode = respawnWithLargerHeap(import.meta.filename, commandArgs);
86
+ respawnWithLargerHeap(import.meta.filename, commandArgs);
83
87
  return true;
84
88
  }
85
89
  function runMain(commandArgs) {
@@ -87,7 +87,8 @@ function hasFrontendSourcesInWorkspaces(directory, selectors) {
87
87
  if (!selectors.length)
88
88
  return hasFrontendSources(directory);
89
89
  try {
90
- const chosen = selectWorkspaces(discoverWorkspaces(directory).packages, path.resolve(directory), selectors);
90
+ const { packages, withoutConfig } = discoverWorkspaces(directory);
91
+ const chosen = selectWorkspaces([...packages, ...withoutConfig], path.resolve(directory), selectors);
91
92
  return chosen.some((workspace) => hasFrontendSources(workspace.directory));
92
93
  }
93
94
  catch {
@@ -1,35 +1,38 @@
1
1
  // Rules about markup that people using screen readers, keyboards or zoom cannot use. JSX is read from the shared
2
2
  // TypeScript pass; HTML files and Vue, Svelte and Angular templates are read as markup files beside it.
3
+ // Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
3
4
  const knownRules = new Set([
4
- 'a11y-img-missing-alt',
5
5
  'a11y-button-missing-type',
6
6
  'a11y-clickable-non-interactive',
7
- 'a11y-invalid-aria',
8
- 'a11y-missing-form-label',
9
7
  'a11y-html-missing-lang',
10
8
  'a11y-iframe-missing-title',
9
+ 'a11y-img-missing-alt',
10
+ 'a11y-invalid-aria',
11
+ 'a11y-missing-form-label',
11
12
  'a11y-positive-tabindex',
12
13
  'a11y-viewport-zoom-disabled',
13
14
  ]);
15
+ // Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
14
16
  const impactByRule = {
15
- 'a11y-img-missing-alt': 'high',
16
17
  'a11y-button-missing-type': 'medium',
17
18
  'a11y-clickable-non-interactive': 'high',
18
- 'a11y-invalid-aria': 'high',
19
- 'a11y-missing-form-label': 'high',
20
19
  'a11y-html-missing-lang': 'medium',
21
20
  'a11y-iframe-missing-title': 'medium',
21
+ 'a11y-img-missing-alt': 'high',
22
+ 'a11y-invalid-aria': 'high',
23
+ 'a11y-missing-form-label': 'high',
22
24
  'a11y-positive-tabindex': 'medium',
23
25
  'a11y-viewport-zoom-disabled': 'high',
24
26
  };
27
+ // Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
25
28
  const descriptionByRule = {
26
- 'a11y-img-missing-alt': 'An image has no alt text, so screen readers announce its file name or nothing.',
27
29
  'a11y-button-missing-type': 'A button inside a form has no type, so it submits the form even when it only meant to run a handler.',
28
30
  'a11y-clickable-non-interactive': 'A click handler sits on a non-interactive element without a role and keyboard support, so keyboard users cannot activate it.',
29
- 'a11y-invalid-aria': 'An ARIA attribute or role is misspelled or invalid, so assistive technology ignores it.',
30
- 'a11y-missing-form-label': 'A form control has no label, so screen readers announce it without its purpose.',
31
31
  'a11y-html-missing-lang': 'The html element has no lang attribute, so screen readers guess the pronunciation.',
32
32
  'a11y-iframe-missing-title': 'An iframe has no title, so screen readers cannot say what it contains.',
33
+ 'a11y-img-missing-alt': 'An image has no alt text, so screen readers announce its file name or nothing.',
34
+ 'a11y-invalid-aria': 'An ARIA attribute or role is misspelled or invalid, so assistive technology ignores it.',
35
+ 'a11y-missing-form-label': 'A form control has no label, so screen readers announce it without its purpose.',
33
36
  'a11y-positive-tabindex': 'A positive tabindex reorders keyboard focus away from the visual order.',
34
37
  'a11y-viewport-zoom-disabled': 'The viewport meta tag disables zoom, so people with low vision cannot enlarge the page.',
35
38
  };
@@ -16,10 +16,12 @@ function hasInterpolation(dialect, value) {
16
16
  }
17
17
  // `@click.stop`, `(click)="$event.stopPropagation()"` or `on:click={(e) => e.stopPropagation()}` keeps a click inside
18
18
  // a panel from reaching a backdrop; it is not a way to activate the element, so it is left out like a missing handler.
19
- const propagationOnlyHandler = /^\s*(?:\(?[\w$]*\)?\s*=>\s*)?\{?\s*(?:[\w$]+\.(?:stopPropagation|preventDefault)\(\)\s*;?\s*)+\}?\s*$/;
19
+ // Each whitespace run has one place to match, so a long run of spaces cannot make the test backtrack. The arrow
20
+ // parameter starts with a name or a parenthesis, never a space, for the same reason.
21
+ const propagationOnlyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?(?:\{\s*)?(?:[\w$]+\.(?:stopPropagation|preventDefault)\(\)\s*(?:;\s*)?)+(?:\}\s*)?$/;
20
22
  // `@click="() => {}"` does nothing, so it is no more a way to activate the element than a propagation-only handler. A
21
23
  // Svelte `on:click={…}` value keeps its closing brace, hence the optional second one.
22
- const emptyHandler = /^\s*(?:\(?[\w$]*\)?\s*=>\s*)?\{\s*\}\}?\s*$/;
24
+ const emptyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?\{\s*\}\}?\s*$/;
23
25
  function eventAttribute(event, rawValue, isBareAllowed) {
24
26
  const isBare = rawValue === undefined || rawValue.trim() === '';
25
27
  if (isBare && isBareAllowed)
@@ -1,12 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exampleFor = exampleFor;
1
+ // Keep sorted by rule id; test/shared/registry-order.test.ts checks it.
4
2
  const examples = {
5
- 'a11y-img-missing-alt': {
6
- jsx: { before: '<img src={logo} />', code: '<img src={logo} alt="Company logo" />' },
7
- html: { before: '<img src="logo.png">', code: '<img src="logo.png" alt="Company logo">' },
8
- note: 'Describe the image, or use alt="" if it is decorative.',
9
- },
10
3
  'a11y-button-missing-type': {
11
4
  jsx: {
12
5
  before: '<button onClick={save}>Save</button>',
@@ -29,6 +22,24 @@ const examples = {
29
22
  },
30
23
  note: 'A button works with the keyboard and screen readers without extra attributes.',
31
24
  },
25
+ 'a11y-html-missing-lang': {
26
+ jsx: { before: '<html>', code: '<html lang="en">' },
27
+ html: { before: '<html>', code: '<html lang="en">' },
28
+ note: 'Set the language of the page content.',
29
+ },
30
+ 'a11y-iframe-missing-title': {
31
+ jsx: { before: '<iframe src={mapUrl} />', code: '<iframe src={mapUrl} title="Store location map" />' },
32
+ html: {
33
+ before: '<iframe src="/map"></iframe>',
34
+ code: '<iframe src="/map" title="Store location map"></iframe>',
35
+ },
36
+ note: 'The title is what screen readers announce for the frame.',
37
+ },
38
+ 'a11y-img-missing-alt': {
39
+ jsx: { before: '<img src={logo} />', code: '<img src={logo} alt="Company logo" />' },
40
+ html: { before: '<img src="logo.png">', code: '<img src="logo.png" alt="Company logo">' },
41
+ note: 'Describe the image, or use alt="" if it is decorative.',
42
+ },
32
43
  'a11y-invalid-aria': {
33
44
  jsx: { before: '<div aria-lable="Close" />', code: '<div aria-label="Close" />' },
34
45
  html: { before: '<div aria-lable="Close"></div>', code: '<div aria-label="Close"></div>' },
@@ -45,19 +56,6 @@ const examples = {
45
56
  },
46
57
  note: 'A placeholder is not a label; wrap the input, or use label for, or aria-label.',
47
58
  },
48
- 'a11y-html-missing-lang': {
49
- jsx: { before: '<html>', code: '<html lang="en">' },
50
- html: { before: '<html>', code: '<html lang="en">' },
51
- note: 'Set the language of the page content.',
52
- },
53
- 'a11y-iframe-missing-title': {
54
- jsx: { before: '<iframe src={mapUrl} />', code: '<iframe src={mapUrl} title="Store location map" />' },
55
- html: {
56
- before: '<iframe src="/map"></iframe>',
57
- code: '<iframe src="/map" title="Store location map"></iframe>',
58
- },
59
- note: 'The title is what screen readers announce for the frame.',
60
- },
61
59
  'a11y-positive-tabindex': {
62
60
  jsx: { before: '<div tabIndex={2} />', code: '<div tabIndex={0} />' },
63
61
  html: { before: '<div tabindex="2"></div>', code: '<div tabindex="0"></div>' },
@@ -88,3 +86,4 @@ function exampleFor(ruleId, languageId) {
88
86
  return;
89
87
  return { language: 'html', ...html, note };
90
88
  }
89
+ export { exampleFor };
@@ -0,0 +1,117 @@
1
+ // Code actions and code lenses for the published findings of one file.
2
+ import { CodeActionKind } from 'vscode-languageserver';
3
+ import { bulkFixesFor, fixAllEdit, fixEdit, missingFolders } from './fix-edits.js';
4
+ const commands = {
5
+ scan: 'loadwise.scan',
6
+ applyFix: 'loadwise.applyFix',
7
+ applyAllFixes: 'loadwise.applyAllFixes',
8
+ dismiss: 'loadwise.dismiss',
9
+ showDismissed: 'loadwise.showDismissed',
10
+ restoreDismissed: 'loadwise.restoreDismissed',
11
+ };
12
+ const fixAllKind = CodeActionKind.SourceFixAll + '.loadwise';
13
+ const applyAllTitle = 'Apply all Loadwise fixes in this file';
14
+ // `only` asks for a kind and everything below it: source.fixAll covers source.fixAll.loadwise.
15
+ function kindRequested(only, kind) {
16
+ if (!only)
17
+ return kind !== fixAllKind;
18
+ return only.some((requested) => kind === requested || kind.startsWith(requested + '.'));
19
+ }
20
+ // The lightbulb appears with the cursor anywhere on a flagged line, not only on the reported token.
21
+ function onLines(entry, range) {
22
+ const flagged = entry.diagnostic.range;
23
+ return flagged.start.line <= range.end.line && flagged.end.line >= range.start.line;
24
+ }
25
+ function command(title, name, argument) {
26
+ return { title, command: name, arguments: [argument] };
27
+ }
28
+ function applyFixAction(entry, fix, workspace) {
29
+ const title = 'Apply fix: ' + entry.anchor.ruleId;
30
+ const action = {
31
+ title,
32
+ kind: CodeActionKind.QuickFix,
33
+ diagnostics: [entry.diagnostic],
34
+ isPreferred: !fix.requiresReview,
35
+ };
36
+ const result = fixEdit(fix, workspace);
37
+ if (result.edit === undefined)
38
+ action.disabled = { reason: result.error };
39
+ // A new file in a missing folder goes through the command, which makes the folder first.
40
+ else if (missingFolders(result.createdFiles).length)
41
+ action.command = command(title, commands.applyFix, fix);
42
+ else
43
+ action.edit = result.edit;
44
+ return action;
45
+ }
46
+ function dismissAction(entry, title, dismissal) {
47
+ return {
48
+ title,
49
+ kind: CodeActionKind.QuickFix,
50
+ diagnostics: [entry.diagnostic],
51
+ command: command(title, commands.dismiss, dismissal),
52
+ };
53
+ }
54
+ function quickFixes(entries, range, uri, workspace) {
55
+ const actions = [];
56
+ const fileWide = new Set();
57
+ for (const entry of entries.filter((candidate) => onLines(candidate, range))) {
58
+ const { fix, dismissal, ruleId } = entry.anchor;
59
+ if (fix)
60
+ actions.push(applyFixAction(entry, fix, workspace));
61
+ actions.push(dismissAction(entry, 'Dismiss this finding (' + ruleId + ')', dismissal));
62
+ if (fileWide.has(ruleId))
63
+ continue;
64
+ fileWide.add(ruleId);
65
+ actions.push(dismissAction(entry, 'Dismiss ' + ruleId + ' in this file', { file: dismissal.file, ruleId: dismissal.ruleId }));
66
+ }
67
+ if (actions.length && bulkFixesFor(entries).eligible.length > 1) {
68
+ actions.push({
69
+ title: applyAllTitle,
70
+ kind: CodeActionKind.QuickFix,
71
+ command: command(applyAllTitle, commands.applyAllFixes, uri),
72
+ });
73
+ }
74
+ return actions;
75
+ }
76
+ // Runs for "Fix All" and code actions on save, so it carries the edit itself instead of a command.
77
+ function fixAllActions(entries, uri, workspace) {
78
+ const { eligible } = bulkFixesFor(entries);
79
+ if (!eligible.length)
80
+ return [];
81
+ const { edit, applied, createdFiles } = fixAllEdit(eligible, workspace);
82
+ if (!applied)
83
+ return [];
84
+ if (missingFolders(createdFiles).length) {
85
+ return [{ title: applyAllTitle, kind: fixAllKind, command: command(applyAllTitle, commands.applyAllFixes, uri) }];
86
+ }
87
+ return [{ title: applyAllTitle, kind: fixAllKind, edit }];
88
+ }
89
+ function codeActions(entries, range, only, uri, workspace) {
90
+ const actions = [];
91
+ if (kindRequested(only, CodeActionKind.QuickFix))
92
+ actions.push(...quickFixes(entries, range, uri, workspace));
93
+ // Building the fix-all edit reads files, so it runs only when the editor asks for that kind.
94
+ if (only && kindRequested(only, fixAllKind))
95
+ actions.push(...fixAllActions(entries, uri, workspace));
96
+ return actions;
97
+ }
98
+ // One-click buttons above each fixable line, so applying a fix does not need the code action menu.
99
+ function codeLenses(entries, uri) {
100
+ const fixable = entries.filter((entry) => entry.anchor.fix);
101
+ const lenses = [];
102
+ const bulkCount = bulkFixesFor(fixable).eligible.length;
103
+ const top = { start: { line: 0, character: 0 }, end: { line: 0, character: 0 } };
104
+ if (bulkCount > 1) {
105
+ const title = 'Apply all ' + bulkCount + ' Loadwise fixes in this file';
106
+ lenses.push({ range: top, command: command(title, commands.applyAllFixes, uri) });
107
+ }
108
+ for (const { anchor, diagnostic } of fixable) {
109
+ if (!anchor.fix)
110
+ continue;
111
+ const line = diagnostic.range.start.line;
112
+ const range = { start: { line, character: 0 }, end: { line, character: 0 } };
113
+ lenses.push({ range, command: command('Apply fix: ' + anchor.ruleId, commands.applyFix, anchor.fix) }, { range, command: command('Dismiss', commands.dismiss, anchor.dismissal) });
114
+ }
115
+ return lenses;
116
+ }
117
+ export { codeActions, codeLenses, commands, fixAllKind };
@@ -1,9 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyChangesToText = applyChangesToText;
4
- exports.applyFix = applyFix;
5
- exports.isChangeApplied = isChangeApplied;
6
- exports.locateChange = locateChange;
7
1
  // Applies a site fix to file text. A fix stores the exact original lines, so it is applied only
8
2
  // where those lines still exist; an edit made since the scan moves or removes them and the fix then
9
3
  // refuses instead of guessing.
@@ -185,3 +179,4 @@ function applyFix(fix, { readFile, writeFile }, options) {
185
179
  writeFile(file, text);
186
180
  return { files: updates.map(([file]) => file) };
187
181
  }
182
+ export { applyChangesToText, applyFix, isChangeApplied, locateChange };
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.controlFlowComparison = controlFlowComparison;
4
1
  const scriptLanguages = new Set(['javascript', 'javascriptreact', 'typescript', 'typescriptreact']);
5
2
  const maximumSnippetLength = 200;
6
3
  const maximumBindingDistance = 12;
@@ -131,3 +128,4 @@ function matchesSavedExcerpt(document, row, comparison) {
131
128
  return actual === indent + line || (!line && !actual);
132
129
  });
133
130
  }
131
+ export { controlFlowComparison };