Skip to content

Commit 6456a7d

Browse files
committed
refactor: parse context only
1 parent 183e2b4 commit 6456a7d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/rules/no-extraneous-dependencies.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,23 @@ function reportIfMissing(
328328
})
329329
}
330330

331-
function testConfig(config: string[] | boolean | undefined, filename: string, context: RuleContext) {
331+
function testConfig(
332+
config: string[] | boolean | undefined,
333+
context: RuleContext,
334+
) {
332335
// Simplest configuration first, either a boolean or nothing.
333336
if (typeof config === 'boolean' || config === undefined) {
334337
return config
335338
}
339+
const filename = context.physicalFilename
336340
// Array of globs.
337341
return config.some(
338342
c =>
339343
minimatch(filename, c) ||
340-
minimatch(filename, path.join(context.cwd, c), { windowsPathsNoEscape: true }),
344+
minimatch(filename, path.resolve(context.cwd, c), {
345+
windowsPathsNoEscape: true,
346+
}) ||
347+
minimatch(filename, path.resolve(c), { windowsPathsNoEscape: true }),
341348
)
342349
}
343350

@@ -398,18 +405,15 @@ export default createRule<[Options?], MessageId>({
398405
create(context) {
399406
const options = context.options[0] || {}
400407

401-
const filename = context.physicalFilename
402-
403408
const deps =
404409
getDependencies(context, options.packageDir) || extractDepFields({})
405410

406411
const depsOptions = {
407-
allowDevDeps: testConfig(options.devDependencies, filename, context) !== false,
408-
allowOptDeps:
409-
testConfig(options.optionalDependencies, filename, context) !== false,
410-
allowPeerDeps: testConfig(options.peerDependencies, filename, context) !== false,
412+
allowDevDeps: testConfig(options.devDependencies, context) !== false,
413+
allowOptDeps: testConfig(options.optionalDependencies, context) !== false,
414+
allowPeerDeps: testConfig(options.peerDependencies, context) !== false,
411415
allowBundledDeps:
412-
testConfig(options.bundledDependencies, filename, context) !== false,
416+
testConfig(options.bundledDependencies, context) !== false,
413417
verifyInternalDeps: !!options.includeInternal,
414418
verifyTypeImports: !!options.includeTypes,
415419
}

0 commit comments

Comments
 (0)