Skip to content
Open
11 changes: 10 additions & 1 deletion app/utils/package-content-hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const POSSIBLY_UNNECESSARY_FILES: ReadonlySet<string> = new Set([
'.editorconfig',
'.prettierignore',
'.eslintignore',
'.jshintignore',
'.gitignore',
'.gitattributes',
'.travis.yml',
'tsconfig.json',
'.node-version',
'.nvmrc',
Expand All @@ -27,6 +29,10 @@ const POSSIBLY_UNNECESSARY_FILES: ReadonlySet<string> = new Set([
'.env.production.local',
'.nycrc',
'nyc.json',
'CHANGELOG.md',
'changelog.md',
'CHANGELOG.markdown',
'changelog.markdown',
])

const POSSIBLY_UNNECESSARY_DIRECTORIES: ReadonlySet<string> = new Set([
Expand All @@ -37,9 +43,10 @@ const POSSIBLY_UNNECESSARY_DIRECTORIES: ReadonlySet<string> = new Set([
'.zed',
'test',
'tests',
'__tests__',
'spec',
'specs',
'example',
'examples',
])

const POSSIBLY_UNNECESSARY_DIRECTORY_PATTERNS: readonly RegExp[] = [/^__.+__$/]
Expand All @@ -58,6 +65,8 @@ const POSSIBLY_UNNECESSARY_PATTERNS: readonly RegExp[] = [
/^\.(?!npmrc$)[a-z][a-z0-9_-]*rc$/,
/^\.(?!npmrc\.)[a-z][a-z0-9_-]*rc\.(?:json|js|cjs|mjs|yml|yaml|toml)$/,
/^\.[a-z][a-z0-9_-]*\.config\.(?:js|cjs|mjs|ts|mts|cts)$/,
// Match files ending in .test.js, .test.ts, .spec.js, .spec.ts, etc.
/(?:test|spec)\.(?:j|t)s$/,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
]

export function isPossiblyUnnecessaryContent(name: string, type: 'file' | 'directory'): boolean {
Expand Down
25 changes: 25 additions & 0 deletions test/unit/app/utils/package-content-hints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('isPossiblyUnnecessaryContent', () => {
expect(isPossiblyUnnecessaryContent('.gitattributes', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('.prettierignore', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('.eslintignore', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('.jshintignore', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('tsconfig.json', 'file')).toBe(true)
})

Expand All @@ -30,6 +31,25 @@ describe('isPossiblyUnnecessaryContent', () => {
expect(isPossiblyUnnecessaryContent('nyc.json', 'file')).toBe(true)
})

it('flags editor and CI files', () => {
expect(isPossiblyUnnecessaryContent('.travis.yml', 'file')).toBe(true)
})

it('flags test files', () => {
expect(isPossiblyUnnecessaryContent('test.js', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('index.test.js', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('index.spec.js', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('index.test.ts', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('index.spec.ts', 'file')).toBe(true)
})

it('flags changelog files', () => {
expect(isPossiblyUnnecessaryContent('CHANGELOG.md', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('changelog.md', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('CHANGELOG.markdown', 'file')).toBe(true)
expect(isPossiblyUnnecessaryContent('changelog.markdown', 'file')).toBe(true)
})

it('matches ESLint configuration patterns', () => {
for (const extension of ['js', 'cjs', 'mjs', 'ts', 'mts', 'cts']) {
expect(isPossiblyUnnecessaryContent(`eslint.config.${extension}`, 'file')).toBe(true)
Expand Down Expand Up @@ -105,6 +125,11 @@ describe('isPossiblyUnnecessaryContent', () => {
expect(isPossiblyUnnecessaryContent('specs', 'directory')).toBe(true)
})

it('flags example directories', () => {
expect(isPossiblyUnnecessaryContent('example', 'directory')).toBe(true)
expect(isPossiblyUnnecessaryContent('examples', 'directory')).toBe(true)
})

it('does not flag ordinary source files or directories', () => {
expect(isPossiblyUnnecessaryContent('index.js', 'file')).toBe(false)
expect(isPossiblyUnnecessaryContent('package.json', 'file')).toBe(false)
Expand Down
Loading