spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / classify / is-generated-file / is-generated-file.ts
29 lines · 1.1 KBRaw
1import { baseNameOf } from '../base-name-of'
2import { rootedPathOf } from '../rooted-path-of'
3import { GENERATED_DIRECTORIES } from './generated-directories'
4import { GENERATED_FILENAME_PATTERNS } from './generated-filename-patterns'
5import { GENERATED_FILENAMES } from './generated-filenames'
6import { GENERATED_SUFFIXES } from './generated-suffixes'
7
8/**
9 * Whether a repository-relative path names generated or vendored content,
10 * by the Linguist-style rules the engine's own diff panel applies.
11 *
12 * @param path the file's path from the repository root, `/`-separated
13 * @returns whether the diff pane counts it among the tests and generated files
14 */
15export function isGeneratedFile(path: string) {
16 const name = baseNameOf(path).toLowerCase()
17 const rooted = rootedPathOf(path)
18
19 const hasGeneratedSuffix = GENERATED_SUFFIXES.some(suffix =>
20 name.endsWith(suffix),
21 )
22
23 return (
24 GENERATED_FILENAMES.has(name) ||
25 hasGeneratedSuffix ||
26 GENERATED_DIRECTORIES.some(directory => rooted.includes(directory)) ||
27 GENERATED_FILENAME_PATTERNS.some(pattern => pattern.test(name))
28 )
29}