@codacy/analysis-runner 0.6.2 → 0.8.1

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 (3) hide show
  1. package/dist/index.d.ts +133 -7
  2. package/dist/index.js +1341 -48
  3. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OutputFormat, Logger, AnalysisResult, ToolAdapter, AdapterDescriptor, CodacyConfig, ConfigurationFileCheckResult, CodacyToolConfig, Language, LogLevel } from '@codacy/tooling';
1
+ import { OutputFormat, Logger, AnalysisResult, ToolAdapter, AdapterDescriptor, CodacyConfig, ConfigurationFileCheckResult, CodacyToolConfig, IssueSeverity, IssueCategory, Language, DiscoveryResult, Issue, PatternSummary, LogLevel } from '@codacy/tooling';
2
2
  export { AnalysisResult, OutputFormat } from '@codacy/tooling';
3
3
 
4
4
  /**
@@ -52,6 +52,8 @@ interface AnalyzeOptions {
52
52
  onToolStart?: (toolId: string, displayName: string) => void;
53
53
  /** Called when a tool finishes executing. */
54
54
  onToolComplete?: (toolId: string, displayName: string, issueCount: number, durationMs: number) => void;
55
+ /** Called when a tool reports mid-execution progress (e.g. "Linting 50/200 files"). */
56
+ onToolProgress?: (toolId: string, displayName: string, message: string) => void;
55
57
  }
56
58
  /**
57
59
  * Runs analysis on the given repository and returns the unified result.
@@ -179,26 +181,71 @@ declare function createCodacyConfig(params?: {
179
181
  repositoryId?: string | null;
180
182
  repositoryName?: string | null;
181
183
  includeFiles?: string[];
184
+ autoFilters?: string;
182
185
  }): CodacyConfig;
183
186
 
184
187
  /**
185
- * Init mode logic — builds a CodacyConfig from four distinct sources:
188
+ * auto-filters.ts — Parses and applies --auto filter syntax.
189
+ *
190
+ * Filter syntax: comma-separated list of severity and category names.
191
+ * - Severity names: Info/Minor, Warning/Medium, High, Error/Critical (both accepted)
192
+ * - Category names: Security, ErrorProne, CodeStyle, etc.
193
+ * - `All` prefix on any token removes the `enabled: true` filter for that value.
194
+ * e.g. `AllCritical` includes ALL Critical patterns, not just default ones.
195
+ *
196
+ * Dimensions are ANDed (severity AND category). Values within a dimension are ORed.
197
+ * Omitting a dimension means "no restriction" for that dimension.
198
+ */
199
+
200
+ /** A single severity filter with its All-prefix status. */
201
+ interface SeverityFilter {
202
+ level: IssueSeverity;
203
+ all: boolean;
204
+ }
205
+ /** A single category filter with its All-prefix status. */
206
+ interface CategoryFilter {
207
+ category: IssueCategory;
208
+ all: boolean;
209
+ }
210
+ /** Parsed result of the --auto filter string. */
211
+ interface AutoFilters {
212
+ severities: SeverityFilter[];
213
+ categories: CategoryFilter[];
214
+ }
215
+ /**
216
+ * Parses a comma-separated auto-filter string into structured filters.
217
+ *
218
+ * Each token is classified as a severity or category by name lookup.
219
+ * The `All` prefix (case-insensitive) on a token removes the `enabled: true`
220
+ * constraint for that specific severity or category.
221
+ *
222
+ * Unrecognized tokens are collected and returned in the `unknown` array.
223
+ */
224
+ declare function parseAutoFilters(raw: string): {
225
+ filters: AutoFilters;
226
+ unknown: string[];
227
+ };
228
+
229
+ /**
230
+ * Init mode logic — builds a CodacyConfig from five distinct sources:
186
231
  *
187
232
  * - `initLocalConfig` — detect languages + tools with a local config file
233
+ * - `initAutoConfig` — discover stack, then select tools/patterns by framework match
188
234
  * - `initDefaultConfig` — same as local, enriched with API-sourced pattern defaults
189
235
  * - `initRemoteConfig` — fetch the full tool/pattern config from a remote Codacy repository
190
236
  * - `initContainerConfig`— read .codacyrc file (container run input) and extract file list
191
237
  *
192
- * All four functions return a `CodacyConfig` ready to be written by `writeCodacyConfig`.
238
+ * All five functions return a `CodacyConfig` ready to be written by `writeCodacyConfig`.
193
239
  * None of them write to disk — that is the caller's responsibility.
194
240
  */
195
241
 
196
242
  /**
197
- * Detects programming languages present in the repository by listing git-tracked
198
- * files and matching their extensions/filenames against LANGUAGE_CONFIG.
243
+ * Detects programming languages present in the repository by matching file
244
+ * extensions/filenames against LANGUAGE_CONFIG. When `precomputedFiles` is
245
+ * provided, uses that list directly instead of running `git ls-files`.
199
246
  * Returns languages sorted alphabetically for deterministic output.
200
247
  */
201
- declare function detectLanguages(repositoryRoot: string): Promise<Language[]>;
248
+ declare function detectLanguages(repositoryRoot: string, precomputedFiles?: string[]): Promise<Language[]>;
202
249
  /** Stats returned alongside the config from `initLocalConfig`. */
203
250
  interface InitLocalStats {
204
251
  /** Whether a .codacy.yaml file was found and its exclude paths were applied. */
@@ -280,6 +327,41 @@ declare function initRemoteConfig(repositoryRoot: string, provider: string, orga
280
327
  * ```
281
328
  */
282
329
  declare function initContainerConfig(repositoryRoot: string, adapters: Readonly<ToolAdapter>[]): Promise<CodacyConfig>;
330
+ /** Stats returned alongside the config from `initAutoConfig`. */
331
+ interface InitAutoStats {
332
+ /** Number of languages detected by discover. */
333
+ detectedLanguages: number;
334
+ /** Number of frameworks detected by discover. */
335
+ detectedFrameworks: number;
336
+ /** Number of libraries detected by discover. */
337
+ detectedLibraries: number;
338
+ /** Number of tool entries added to the config. */
339
+ selectedTools: number;
340
+ /** Whether a .codacy.yaml file was found and its exclude paths were applied. */
341
+ codacyYamlApplied: boolean;
342
+ }
343
+ /**
344
+ * `--auto [filters]` mode.
345
+ *
346
+ * Runs `discover()` to detect the repository's tech stack, then selects tools
347
+ * by language overlap and filters patterns using per-tool framework mappings.
348
+ *
349
+ * Framework-specific patterns (those matching a mapping entry) are included only
350
+ * if the corresponding dependency was detected — and they bypass the `enabled`
351
+ * filter. Universal patterns (not in any mapping) are included only if
352
+ * `enabled: true`, unless an `All`-prefixed filter widens the gate.
353
+ *
354
+ * Severity and category filters are ANDed across dimensions, ORed within.
355
+ *
356
+ * **Known limitation (v1):** When both TypeScript and JavaScript are detected,
357
+ * ESLint core rules and their `@typescript-eslint` equivalents may both be
358
+ * enabled, potentially causing duplicate findings. This will be addressed in v2
359
+ * via conflict-resolution metadata in the mapping files.
360
+ */
361
+ declare function initAutoConfig(repositoryRoot: string, adapters: Readonly<ToolAdapter>[], descriptors: AdapterDescriptor[], filters?: AutoFilters, onDiscoveryComplete?: (result: DiscoveryResult) => void, rawFilterString?: string): Promise<{
362
+ config: CodacyConfig;
363
+ stats: InitAutoStats;
364
+ }>;
283
365
 
284
366
  /**
285
367
  * .codacy.yaml ingestion — reads the standard Codacy configuration file from
@@ -339,6 +421,28 @@ declare function resolveEngineToAdapter(engineName: string, adapters: Readonly<T
339
421
  */
340
422
  declare function applyCodacyYamlExcludes(config: CodacyConfig, yamlConfig: CodacyYamlConfig, adapters: Readonly<ToolAdapter>[], logger?: Logger): CodacyConfig;
341
423
 
424
+ /**
425
+ * Computes pattern-level summary statistics for analysis results.
426
+ *
427
+ * Groups issues by Severity → Category → Pattern, producing a PatternSummary
428
+ * that formatters can render. Called inside analyze() where adapter metadata
429
+ * (pattern titles, tool display names) is available.
430
+ */
431
+
432
+ /** Resolved metadata for a pattern, built from adapter.patternsMetadata. */
433
+ interface PatternMetadataLookup {
434
+ title: string;
435
+ toolDisplayName: string;
436
+ }
437
+ /**
438
+ * Computes a PatternSummary from issues and a pattern metadata lookup.
439
+ *
440
+ * The lookup maps patternId → { title, toolDisplayName } and should be built
441
+ * from adapter.patternsMetadata before calling this function. Patterns not
442
+ * in the lookup fall back to patternId as the title and toolId as display name.
443
+ */
444
+ declare function computePatternSummary(issues: readonly Issue[], lookup: ReadonlyMap<string, PatternMetadataLookup>): PatternSummary;
445
+
342
446
  /**
343
447
  * File discovery and routing — finds files in a repository, applies exclusion
344
448
  * layers (.gitignore, global exclude, per-tool exclude), and routes files to
@@ -464,4 +568,26 @@ declare function rotateLogFiles(logsDir: string, maxFiles: number): void;
464
568
  */
465
569
  declare function createLogger(options?: LoggerOptions): Logger;
466
570
 
467
- export { type AdapterFactory, type AnalyzeOptions, type CodacyYamlConfig, type CodacyYamlEngineConfig, type ExecutionMode, type IgnoredFilesResult, type InitDefaultStats, type InitLocalStats, type InitRemoteStats, type LoggerOptions, analyze, applyCodacyYamlExcludes, buildToolConfig, clearAdapters, configureApiToken, createCodacyConfig, createLogger, detectLanguages, formatOutput, formatTextSummary, getAdapter, getRegisteredAdapters, getRegisteredDescriptors, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, listDiffFiles, listIgnoredFiles, listPrFiles, listStagedFiles, readCodacyConfig, readCodacyYaml, registerAdapter, registerLazyAdapter, resolveEngineToAdapter, rotateLogFiles, validateApiToken, writeCodacyConfig };
571
+ /**
572
+ * Repository discovery — scans a codebase and identifies languages, file patterns,
573
+ * notable files, frameworks, and libraries.
574
+ *
575
+ * The discover() function is the main entry point. It runs a 4-phase pipeline:
576
+ * 1. File discovery (extensions, notable files)
577
+ * 2. Language detection (reuses detectLanguages)
578
+ * 3. Manifest parsing (dependency extraction)
579
+ * 4. Dependency classification (framework / library / platform / tool)
580
+ */
581
+
582
+ /** Options for the discover function. */
583
+ interface DiscoverOptions {
584
+ /** Skip dependency extraction from manifests (only detect files and languages). */
585
+ skipDependencies?: boolean;
586
+ }
587
+ /**
588
+ * Scans a repository and returns a structured report of languages, file patterns,
589
+ * notable files, frameworks, and libraries.
590
+ */
591
+ declare function discover(repositoryRoot: string, options?: DiscoverOptions): Promise<DiscoveryResult>;
592
+
593
+ export { type AdapterFactory, type AnalyzeOptions, type AutoFilters, type CategoryFilter, type CodacyYamlConfig, type CodacyYamlEngineConfig, type DiscoverOptions, type ExecutionMode, type IgnoredFilesResult, type InitAutoStats, type InitDefaultStats, type InitLocalStats, type InitRemoteStats, type LoggerOptions, type PatternMetadataLookup, type SeverityFilter, analyze, applyCodacyYamlExcludes, buildToolConfig, clearAdapters, computePatternSummary, configureApiToken, createCodacyConfig, createLogger, detectLanguages, discover, formatOutput, formatTextSummary, getAdapter, getRegisteredAdapters, getRegisteredDescriptors, initAutoConfig, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, listDiffFiles, listIgnoredFiles, listPrFiles, listStagedFiles, parseAutoFilters, readCodacyConfig, readCodacyYaml, registerAdapter, registerLazyAdapter, resolveEngineToAdapter, rotateLogFiles, validateApiToken, writeCodacyConfig };