Skip to content

Commit 1f06dd0

Browse files
committed
refactor: do not use Symbol in configuration mapping
1 parent 641d1c2 commit 1f06dd0

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

lib/groupFilesByConfig.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ export const groupFilesByConfig = async ({ configs, files, singleConfigMode }) =
1111
const filesByConfig = {}
1212

1313
/** Configs are sorted deepest first by `searchConfigs` */
14-
for (const filepath of Reflect.ownKeys(configs)) {
15-
const config = configs[filepath]
16-
14+
for (const [filepath, config] of Object.entries(configs)) {
1715
/** When passed an explicit config object via the Node.js API‚ or an explicit path, skip logic */
1816
if (singleConfigMode) {
1917
filesByConfig[filepath] = { config, files }

lib/runAll.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
restoreUnstagedChangesSkipped,
3737
} from './state.js'
3838
import { GitRepoError, GetStagedFilesError, GitError, ConfigNotFoundError } from './symbols.js'
39-
import { ConfigObjectSymbol, searchConfigs } from './searchConfigs.js'
39+
import { searchConfigs } from './searchConfigs.js'
4040

4141
const debugLog = debug('lint-staged:runAll')
4242

@@ -125,7 +125,7 @@ export const runAll = async (
125125
}
126126

127127
const foundConfigs = await searchConfigs({ configObject, configPath, cwd, gitDir }, logger)
128-
const numberOfConfigs = Reflect.ownKeys(foundConfigs).length
128+
const numberOfConfigs = Object.keys(foundConfigs).length
129129

130130
// Throw if no configurations were found
131131
if (numberOfConfigs === 0) {
@@ -157,13 +157,8 @@ export const runAll = async (
157157
// Set of all staged files that matched a task glob. Values in a set are unique.
158158
const matchedFiles = new Set()
159159

160-
for (const configPath of Reflect.ownKeys(filesByConfig)) {
161-
const { config, files } = filesByConfig[configPath]
162-
163-
const configName =
164-
configPath === ConfigObjectSymbol
165-
? 'Config object'
166-
: normalize(path.relative(cwd, configPath))
160+
for (const [configPath, { config, files }] of Object.entries(filesByConfig)) {
161+
const configName = configPath ? normalize(path.relative(cwd, configPath)) : 'Config object'
167162

168163
const stagedFileChunks = chunkFiles({ baseDir: gitDir, files, maxArgLength, relative })
169164

lib/searchConfigs.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ const sortDeepestParth = (a, b) => (numberOfLevels(a) > numberOfLevels(b) ? -1 :
2323

2424
const isInsideDirectory = (dir) => (file) => file.startsWith(normalize(dir))
2525

26-
export const ConfigObjectSymbol = Symbol()
27-
2826
/**
2927
* Search all config files from the git repository, preferring those inside `cwd`.
3028
*
@@ -46,7 +44,7 @@ export const searchConfigs = async (
4644
if (configObject) {
4745
debugLog('Using single direct configuration object...')
4846

49-
return { [ConfigObjectSymbol]: validateConfig(configObject, 'config object', logger) }
47+
return { '': validateConfig(configObject, 'config object', logger) }
5048
}
5149

5250
// Use only explicit config path instead of discovering multiple

test/searchConfigs.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import normalize from 'normalize-path'
44

55
import { execGit } from '../lib/execGit.js'
66
import { loadConfig } from '../lib/loadConfig.js'
7-
import { ConfigObjectSymbol, searchConfigs } from '../lib/searchConfigs.js'
7+
import { searchConfigs } from '../lib/searchConfigs.js'
88

99
jest.mock('../lib/resolveConfig', () => ({
1010
/** Unfortunately necessary due to non-ESM tests. */
@@ -47,7 +47,7 @@ describe('searchConfigs', () => {
4747

4848
it('should return config for valid config object', async () => {
4949
await expect(searchConfigs({ configObject: { '*.js': 'eslint' } })).resolves.toEqual({
50-
[ConfigObjectSymbol]: { '*.js': 'eslint' },
50+
'': { '*.js': 'eslint' },
5151
})
5252
})
5353

0 commit comments

Comments
 (0)